Skip to content

Commit

Permalink
Add the wandbook!
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaTheMartian committed Jun 12, 2024
1 parent 0a40d22 commit a601c01
Show file tree
Hide file tree
Showing 27 changed files with 850 additions and 130 deletions.
3 changes: 3 additions & 0 deletions src/generated/resources/assets/arcane/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"item.arcane.large_auraglass_bottle": "Large Auraglass Bottle",
"item.arcane.larimar_core": "Larimar Focus",
"item.arcane.medium_auraglass_bottle": "Medium Auraglass Bottle",
"item.arcane.mystical_wandbook": "Mystical Wandbook",
"item.arcane.polished_idocrase": "Polished Idocrase",
"item.arcane.polished_larimar": "Polished Larimar",
"item.arcane.purified_raw_copper": "Purified Raw Copper",
Expand Down Expand Up @@ -138,6 +139,7 @@
"item.arcane.wand_oak": "Oak Wand",
"item.arcane.wand_spruce": "Spruce Wand",
"item.arcane.wand_warped": "Warped Wand",
"item.arcane.wandbook": "Wandbook",
"itemGroup.arcane.arcane_spells_tab": "Arcane (Spells)",
"itemGroup.arcane.arcane_tab": "Arcane",
"key.arcane.open_enderpack": "Open Enderpack",
Expand Down Expand Up @@ -169,6 +171,7 @@
"messages.arcane.pedestal_set_spell": "Spell set!",
"messages.arcane.push_rate": "Push Rate: ",
"messages.arcane.selected": "Selected block",
"messages.arcane.selection": "Selection: ",
"messages.arcane.set_mode_to": "Set mode to ",
"messages.arcane.spell": "Spell: ",
"messages.arcane.spell_min_level": "Required Wand Level: ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"item": "minecraft:glass_bottle"
},
{
"item": "minecraft:bone_meal"
"item": "arcane:auraglass_dust"
},
{
"item": "arcane:auraglass_dust"
"item": "minecraft:bone_meal"
}
],
"result": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"category": "misc",
"ingredients": [
{
"item": "arcane:polished_idocrase"
"tag": "c:obsidians"
},
{
"tag": "c:obsidians"
},
{
"tag": "c:obsidians"
"item": "arcane:polished_idocrase"
}
],
"result": {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/martian/arcane/ArcaneMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import martian.arcane.api.ArcaneRegistry;
import martian.arcane.client.ArcaneClient;
import martian.arcane.common.networking.c2s.C2SOpenEnderpackPayload;
import martian.arcane.common.networking.c2s.C2SSetSelectionComponent;
import martian.arcane.common.networking.s2c.S2CSyncAuraAttachment;
import martian.arcane.common.registry.*;
import martian.arcane.datagen.ArcaneDatagen;
Expand Down Expand Up @@ -58,7 +59,8 @@ public ArcaneMod(IEventBus modBus) {
modBus.addListener(RegisterPayloadHandlersEvent.class, event -> {
final PayloadRegistrar registrar = event.registrar("1");
registrar.playToServer(C2SOpenEnderpackPayload.TYPE, C2SOpenEnderpackPayload.CODEC, C2SOpenEnderpackPayload::handler);
registrar.playBidirectional(S2CSyncAuraAttachment.TYPE, S2CSyncAuraAttachment.CODEC, S2CSyncAuraAttachment::handler);
registrar.playToServer(C2SSetSelectionComponent.TYPE, C2SSetSelectionComponent.CODEC, C2SSetSelectionComponent::handler);
registrar.playToClient(S2CSyncAuraAttachment.TYPE, S2CSyncAuraAttachment.CODEC, S2CSyncAuraAttachment::handler);
});

modBus.addListener(ArcaneRegistries::registerRegisters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import org.jetbrains.annotations.NotNull;

public class AbstractAuraBlockEntityWithSingleItem extends AbstractAuraBlockEntity implements ISingleItemContainer {
public class AbstractAuraBlockEntityWithSingleItem extends AbstractAuraBlockEntity implements Container, IItemHandlerModifiable {
protected ItemStack stack = ItemStack.EMPTY;
public boolean hasSignal = false;

Expand All @@ -28,9 +30,21 @@ public ItemStack getItem() {

public void setItem(ItemStack stack) {
this.stack = stack;
setChanged();
BlockHelpers.sync(this);
}

// Container implementation
@Override
public int getContainerSize() {
return 1;
}

@Override
public int getMaxStackSize() {
return 1;
}

@Override
public boolean isEmpty() {
return stack.isEmpty();
Expand All @@ -39,32 +53,34 @@ public boolean isEmpty() {
@Override
@NotNull
@Deprecated
public ItemStack getItem(int slot) {
public ItemStack getItem(int ignoredSlot) {
return stack;
}

@Override
@NotNull
@Deprecated
public ItemStack removeItem(int slot, int amount) {
ItemStack stack = getItem().copy().split(amount);
getItem().shrink(amount);
public ItemStack removeItem(int ignoredSlot, int amount) {
ItemStack s = stack.copy().split(amount);
stack.shrink(amount);
setChanged();
BlockHelpers.sync(this);
return stack;
return s;
}

@Override
@NotNull
public ItemStack removeItemNoUpdate(int slot) {
ItemStack old = getItem(slot);
this.stack = ItemStack.EMPTY;
public ItemStack removeItemNoUpdate(int ignoredSlot) {
ItemStack old = stack.copy();
setItem(ItemStack.EMPTY);
return old;
}

@Override
@Deprecated
public void setItem(int slot, @NotNull ItemStack stack) {
public void setItem(int ignoredSlot, @NotNull ItemStack stack) {
this.stack = stack;
setChanged();
BlockHelpers.sync(this);
}

Expand All @@ -78,6 +94,12 @@ public void clearContent() {
setItem(ItemStack.EMPTY);
}

@Override
public boolean canPlaceItem(int ignoredSlot, ItemStack stack) {
return getItem().getCount() == 0 && stack.getCount() <= 1;
}

// Serialization
@Override
public void saveAdditional(@NotNull CompoundTag nbt, HolderLookup.@NotNull Provider provider) {
NBTHelpers.putItemStack(provider, nbt, NBTHelpers.KEY_STACK, stack);
Expand Down Expand Up @@ -109,4 +131,53 @@ public Packet<ClientGamePacketListener> getUpdatePacket() {
hasSignal = nbt.getBoolean(NBTHelpers.KEY_HAS_SIGNAL);
return ClientboundBlockEntityDataPacket.create(this);
}

// IItemHandlerModifiable
@Override
public void setStackInSlot(int i, ItemStack arg) {
setItem(arg);
}

@Override
public int getSlots() {
return 1;
}

@Override
public ItemStack getStackInSlot(int i) {
return getItem();
}

@Override
public ItemStack insertItem(int i, ItemStack arg, boolean simulate) {
if (!getItem().isEmpty())
return stack;

if (stack.getCount() > 1) {
if (!simulate)
setItem(stack.copyWithCount(1));
return stack.copyWithCount(stack.getCount() - 1);
}

return ItemStack.EMPTY;
}

@Override
public ItemStack extractItem(int i, int amount, boolean simulate) {
if (simulate) {
return stack.copy().split(amount);
} else {
return removeItem(i, amount);
}
}

@Override
public int getSlotLimit(int i) {
return 1;
}

@Override
public boolean isItemValid(int i, ItemStack arg) {
return true;
}
}
Loading

0 comments on commit a601c01

Please sign in to comment.