diff --git a/src/main/java/ru/betterend/blocks/basis/BlockPedestal.java b/src/main/java/ru/betterend/blocks/basis/BlockPedestal.java index 6267bbe5..e492ff65 100644 --- a/src/main/java/ru/betterend/blocks/basis/BlockPedestal.java +++ b/src/main/java/ru/betterend/blocks/basis/BlockPedestal.java @@ -106,14 +106,12 @@ public class BlockPedestal extends BlockBaseNotFull implements BlockEntityProvid if (pedestal.isEmpty()) { ItemStack itemStack = player.getStackInHand(hand); if (itemStack.isEmpty()) return ActionResult.CONSUME; - world.setBlockState(pos, state.with(HAS_ITEM, true)); - pedestal.setStack(0, itemStack.split(1)); + pedestal.setStack(world, state, itemStack.split(1)); return ActionResult.SUCCESS; } else { ItemStack itemStack = pedestal.getStack(0); if (player.giveItemStack(itemStack)) { - world.setBlockState(pos, state.with(HAS_ITEM, false)); - pedestal.removeStack(0); + pedestal.removeStack(world, state); return ActionResult.SUCCESS; } return ActionResult.FAIL; diff --git a/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java b/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java index 0c42dc75..cbd95f79 100644 --- a/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java @@ -41,18 +41,19 @@ public class InfusionPedestalEntity extends PedestalBlockEntity { @Override public void fromTag(BlockState state, CompoundTag tag) { + super.fromTag(state, tag); if (tag.contains("ritual")) { this.linkedRitual = new InfusionRitual(world, pos); this.linkedRitual.fromTag(tag.getCompound("ritual")); } - super.fromTag(state, tag); } @Override public CompoundTag toTag(CompoundTag tag) { + super.toTag(tag); if (hasRitual()) { tag.put("ritual", linkedRitual.toTag(new CompoundTag())); } - return super.toTag(tag); + return tag; } } diff --git a/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java b/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java index 423f29c6..1e483554 100644 --- a/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java @@ -8,6 +8,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; import net.minecraft.util.Tickable; +import net.minecraft.world.World; +import ru.betterend.blocks.basis.BlockPedestal; import ru.betterend.registry.EndBlockEntities; public class PedestalBlockEntity extends BlockEntity implements Inventory, Tickable { @@ -57,11 +59,21 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka public ItemStack removeStack(int slot) { return this.activeItem = ItemStack.EMPTY; } + + public void removeStack(World world, BlockState state) { + world.setBlockState(pos, state.with(BlockPedestal.HAS_ITEM, false)); + this.removeStack(0); + } @Override public void setStack(int slot, ItemStack stack) { this.activeItem = stack; } + + public void setStack(World world, BlockState state, ItemStack stack) { + world.setBlockState(pos, state.with(BlockPedestal.HAS_ITEM, true)); + this.setStack(0, stack); + } @Override public boolean canPlayerUse(PlayerEntity player) { @@ -89,8 +101,9 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka @Override public CompoundTag toTag(CompoundTag tag) { + super.toTag(tag); tag.put("active_item", activeItem.toTag(new CompoundTag())); - return super.toTag(tag); + return tag; } @Override diff --git a/src/main/java/ru/betterend/interfaces/CompoundSerializer.java b/src/main/java/ru/betterend/interfaces/CompoundSerializer.java index 8fd82c18..d0b6cc0e 100644 --- a/src/main/java/ru/betterend/interfaces/CompoundSerializer.java +++ b/src/main/java/ru/betterend/interfaces/CompoundSerializer.java @@ -3,6 +3,6 @@ package ru.betterend.interfaces; import net.minecraft.nbt.CompoundTag; public interface CompoundSerializer { - public abstract CompoundTag toTag(CompoundTag tag); - public abstract T fromTag(CompoundTag tag); + public abstract CompoundTag beToTag(CompoundTag tag); + public abstract T beFromTag(CompoundTag tag); } diff --git a/src/main/java/ru/betterend/mixin/common/IngredientMixin.java b/src/main/java/ru/betterend/mixin/common/IngredientMixin.java index 5144e268..c146ec0a 100644 --- a/src/main/java/ru/betterend/mixin/common/IngredientMixin.java +++ b/src/main/java/ru/betterend/mixin/common/IngredientMixin.java @@ -21,7 +21,7 @@ public abstract class IngredientMixin implements CompoundSerializer protected abstract void cacheMatchingStacks(); @Override - public CompoundTag toTag(CompoundTag tag) { + public CompoundTag beToTag(CompoundTag tag) { this.cacheMatchingStacks(); int i = 0; tag.putInt("length", matchingStacks.length); @@ -34,7 +34,7 @@ public abstract class IngredientMixin implements CompoundSerializer } @Override - public Ingredient fromTag(CompoundTag tag) { + public Ingredient beFromTag(CompoundTag tag) { int length = tag.getInt("length"); ItemStack[] stacks = new ItemStack[length]; for (int i = 0; i < length; i++) { diff --git a/src/main/java/ru/betterend/recipe/InfusionRecipes.java b/src/main/java/ru/betterend/recipe/InfusionRecipes.java index 328dd7b5..a386e654 100644 --- a/src/main/java/ru/betterend/recipe/InfusionRecipes.java +++ b/src/main/java/ru/betterend/recipe/InfusionRecipes.java @@ -1,5 +1,6 @@ package ru.betterend.recipe; +import net.minecraft.item.Items; import ru.betterend.recipe.builders.InfusionRecipe; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; @@ -14,5 +15,18 @@ public class InfusionRecipes { .addCatalyst(4, EndItems.CRYSTAL_SHARDS) .addCatalyst(6, EndItems.CRYSTAL_SHARDS) .build(); + + InfusionRecipe.Builder.create("eternal_crystal") + .setInput(EndItems.CRYSTAL_SHARDS) + .setOutput(EndItems.ETERNAL_CRYSTAL) + .addCatalyst(0, Items.END_CRYSTAL) + .addCatalyst(2, Items.END_CRYSTAL) + .addCatalyst(4, Items.END_CRYSTAL) + .addCatalyst(6, Items.END_CRYSTAL) + .addCatalyst(1, EndItems.ENDER_DUST) + .addCatalyst(3, EndItems.ENDER_DUST) + .addCatalyst(5, EndItems.ENDER_DUST) + .addCatalyst(7, EndItems.ENDER_DUST) + .build(); } } diff --git a/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java b/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java index 0bccf0eb..ba15384b 100644 --- a/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java @@ -217,29 +217,28 @@ public class InfusionRecipe implements Recipe { public InfusionRecipe fromTag(CompoundTag tag) { Identifier id = new Identifier(tag.getString("id")); InfusionRecipe recipe = new InfusionRecipe(id); - CompoundSerializer inputSerializer = this.toSerializer(recipe.input); - recipe.input = inputSerializer.fromTag(tag.getCompound("input")); + CompoundSerializer ingredientSerializer = this.toSerializer(Ingredient.EMPTY); + recipe.input = ingredientSerializer.beFromTag(tag.getCompound("input")); recipe.output = ItemStack.fromTag(tag.getCompound("output")); recipe.time = tag.getInt("time"); CompoundTag catalysts = tag.getCompound("catalysts"); for(int i = 0; i < recipe.catalysts.length; i++) { String key = Integer.toString(i); - CompoundSerializer cataSerializer = this.toSerializer(recipe.catalysts[i]); - recipe.catalysts[i] = cataSerializer.fromTag(catalysts.getCompound(key)); + recipe.catalysts[i] = ingredientSerializer.beFromTag(catalysts.getCompound(key)); } return recipe; } public CompoundTag toTag(InfusionRecipe recipe, CompoundTag tag) { CompoundSerializer inputSerializer = this.toSerializer(recipe.input); - tag.put("input", inputSerializer.toTag(new CompoundTag())); + tag.put("input", inputSerializer.beToTag(new CompoundTag())); tag.put("output", recipe.output.toTag(new CompoundTag())); tag.putInt("time", recipe.time); CompoundTag catalysts = new CompoundTag(); for(int i = 0; i < recipe.catalysts.length; i++) { String key = Integer.toString(i); CompoundSerializer cataSerializer = this.toSerializer(recipe.catalysts[i]); - catalysts.put(key, cataSerializer.toTag(new CompoundTag())); + catalysts.put(key, cataSerializer.beToTag(new CompoundTag())); } tag.put("catalysts", catalysts); return tag; diff --git a/src/main/java/ru/betterend/rituals/InfusionRitual.java b/src/main/java/ru/betterend/rituals/InfusionRitual.java index 6a1eb157..9c229275 100644 --- a/src/main/java/ru/betterend/rituals/InfusionRitual.java +++ b/src/main/java/ru/betterend/rituals/InfusionRitual.java @@ -2,6 +2,7 @@ package ru.betterend.rituals; import java.awt.Point; +import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventory; @@ -60,6 +61,7 @@ public class InfusionRitual implements Inventory { this.activeRecipe = this.world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null); if (activeRecipe != null) { this.time = this.activeRecipe.getInfusionTime(); + this.progress = 0; return true; } return false; @@ -69,9 +71,11 @@ public class InfusionRitual implements Inventory { if (!isValid() || !hasRecipe()) return; this.progress++; if (progress == time) { - this.input.setStack(0, activeRecipe.craft(this)); + BlockState inputState = world.getBlockState(input.getPos()); + this.input.removeStack(world, inputState); + this.input.setStack(world, inputState, activeRecipe.craft(this)); for (PedestalBlockEntity catalyst : catalysts) { - catalyst.clear(); + catalyst.removeStack(world, world.getBlockState(catalyst.getPos())); } this.activeRecipe = null; this.progress = 0;