From 48c83245c9746390692bea18d1d5f901d8a4484f Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 1 Apr 2024 17:00:05 -0700 Subject: [PATCH] Start making use of partial item --- .../entity/CompressionChamberBlockEntity.java | 4 +- .../entity/ItemScrubberBlockEntity.java | 4 +- .../entity/MagicalScrubberBlockEntity.java | 13 +++++-- .../blocks/entity/UncrafterBlockEntity.java | 4 +- .../zontreck/otemod/items/PartialItem.java | 37 ++++++++++++++++++- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/zontreck/otemod/blocks/entity/CompressionChamberBlockEntity.java b/src/main/java/dev/zontreck/otemod/blocks/entity/CompressionChamberBlockEntity.java index e8f2c73..049f03f 100644 --- a/src/main/java/dev/zontreck/otemod/blocks/entity/CompressionChamberBlockEntity.java +++ b/src/main/java/dev/zontreck/otemod/blocks/entity/CompressionChamberBlockEntity.java @@ -45,7 +45,6 @@ public class CompressionChamberBlockEntity extends BlockEntity implements MenuPr super(ModEntities.COMPRESSION_CHAMBER.get(), pPos, pBlockState); outputSlot = new OutputItemStackHandler(outputItems); - inputSlot = new InputItemStackHandler(itemsHandler); data = new ContainerData() { @Override @@ -91,7 +90,6 @@ public class CompressionChamberBlockEntity extends BlockEntity implements MenuPr } }; private ItemStackHandler outputSlot; - private ItemStackHandler inputSlot; private final OTEEnergy ENERGY_STORAGE = new OTEEnergy(ENERGY_REQUIREMENT*3, ENERGY_REQUIREMENT*512) { @@ -149,7 +147,7 @@ public class CompressionChamberBlockEntity extends BlockEntity implements MenuPr public void onLoad() { super.onLoad(); - lazyItemHandler = LazyOptional.of(()->inputSlot); + lazyItemHandler = LazyOptional.of(()->itemsHandler); lazyOutputItems = LazyOptional.of(()->outputSlot); lazyEnergyHandler = LazyOptional.of(()->ENERGY_STORAGE); } diff --git a/src/main/java/dev/zontreck/otemod/blocks/entity/ItemScrubberBlockEntity.java b/src/main/java/dev/zontreck/otemod/blocks/entity/ItemScrubberBlockEntity.java index 0600198..53f00c3 100644 --- a/src/main/java/dev/zontreck/otemod/blocks/entity/ItemScrubberBlockEntity.java +++ b/src/main/java/dev/zontreck/otemod/blocks/entity/ItemScrubberBlockEntity.java @@ -59,7 +59,6 @@ public class ItemScrubberBlockEntity extends BlockEntity implements MenuProvider } }; private ItemStackHandler outputSlot; - private ItemStackHandler inputSlot; private final OTEEnergy ENERGY_STORAGE = new OTEEnergy(ENERGY_REQ*3, ENERGY_REQ+512) { @@ -81,7 +80,6 @@ public class ItemScrubberBlockEntity extends BlockEntity implements MenuProvider public ItemScrubberBlockEntity(BlockPos pos, BlockState state) { super(ModEntities.ITEM_SCRUBBER.get(), pos, state); outputSlot = new OutputItemStackHandler(outputItems); - inputSlot = new InputItemStackHandler(itemsHandler); this.data = new ContainerData() { @@ -152,7 +150,7 @@ public class ItemScrubberBlockEntity extends BlockEntity implements MenuProvider public void onLoad() { super.onLoad(); - lazyItemHandler = LazyOptional.of(()->inputSlot); + lazyItemHandler = LazyOptional.of(()->itemsHandler); lazyOutputItems = LazyOptional.of(()->outputSlot); lazyEnergyHandler = LazyOptional.of(()->ENERGY_STORAGE); } diff --git a/src/main/java/dev/zontreck/otemod/blocks/entity/MagicalScrubberBlockEntity.java b/src/main/java/dev/zontreck/otemod/blocks/entity/MagicalScrubberBlockEntity.java index e9d5edc..8d16da7 100644 --- a/src/main/java/dev/zontreck/otemod/blocks/entity/MagicalScrubberBlockEntity.java +++ b/src/main/java/dev/zontreck/otemod/blocks/entity/MagicalScrubberBlockEntity.java @@ -6,6 +6,8 @@ import dev.zontreck.libzontreck.util.ItemUtils; import dev.zontreck.otemod.implementation.energy.IThresholdsEnergy; import dev.zontreck.otemod.implementation.energy.OTEEnergy; import dev.zontreck.otemod.implementation.scrubber.MagicalScrubberMenu; +import dev.zontreck.otemod.items.ModItems; +import dev.zontreck.otemod.items.PartialItem; import dev.zontreck.otemod.networking.ModMessages; import dev.zontreck.otemod.networking.packets.EnergySyncS2CPacket; import net.minecraft.core.BlockPos; @@ -64,7 +66,6 @@ public class MagicalScrubberBlockEntity extends BlockEntity implements MenuProvi } }; private ItemStackHandler outputSlot; - private ItemStackHandler inputSlot; private final OTEEnergy ENERGY_STORAGE = new OTEEnergy(ENERGY_REQ*3, ENERGY_REQ+512) { @@ -85,7 +86,6 @@ public class MagicalScrubberBlockEntity extends BlockEntity implements MenuProvi public MagicalScrubberBlockEntity(BlockPos pos, BlockState state) { super(ModEntities.MAGICAL_SCRUBBER.get(), pos, state); outputSlot = new OutputItemStackHandler(outputItems); - inputSlot = new InputItemStackHandler(itemsHandler); this.data = new ContainerData() { @@ -156,7 +156,7 @@ public class MagicalScrubberBlockEntity extends BlockEntity implements MenuProvi public void onLoad() { super.onLoad(); - lazyItemHandler = LazyOptional.of(()->inputSlot); + lazyItemHandler = LazyOptional.of(()->itemsHandler); lazyOutputItems = LazyOptional.of(()->outputSlot); lazyEnergyHandler = LazyOptional.of(()->ENERGY_STORAGE); } @@ -256,6 +256,13 @@ public class MagicalScrubberBlockEntity extends BlockEntity implements MenuProvi //Map enchants = main.getAllEnchantments(); Map enchantments = ItemUtils.getEnchantments(main.copy()); + if(!main.is(ModItems.PARTIAL_ITEM.get())) + { + entity.itemsHandler.setStackInSlot(0, PartialItem.makePartialItem(main, true, false)); + entity.resetProgress(); + return; + } + if(enchantments.size()>0) { Iterator> iEntries = enchantments.entrySet().iterator(); diff --git a/src/main/java/dev/zontreck/otemod/blocks/entity/UncrafterBlockEntity.java b/src/main/java/dev/zontreck/otemod/blocks/entity/UncrafterBlockEntity.java index 544dd50..16bbfac 100644 --- a/src/main/java/dev/zontreck/otemod/blocks/entity/UncrafterBlockEntity.java +++ b/src/main/java/dev/zontreck/otemod/blocks/entity/UncrafterBlockEntity.java @@ -58,7 +58,6 @@ public class UncrafterBlockEntity extends BlockEntity implements MenuProvider, I } }; private ItemStackHandler outputSlot; - private ItemStackHandler inputSlot; private final OTEEnergy ENERGY_STORAGE = new OTEEnergy(ENERGY_REQ*3, ENERGY_REQ+512) { @@ -79,7 +78,6 @@ public class UncrafterBlockEntity extends BlockEntity implements MenuProvider, I public UncrafterBlockEntity(BlockPos pos, BlockState state) { super(ModEntities.UNCRAFTER.get(), pos, state); outputSlot = new OutputItemStackHandler(outputItems); - inputSlot = new InputItemStackHandler(itemsHandler); this.data = new ContainerData() { @@ -150,7 +148,7 @@ public class UncrafterBlockEntity extends BlockEntity implements MenuProvider, I public void onLoad() { super.onLoad(); - lazyItemHandler = LazyOptional.of(()->inputSlot); + lazyItemHandler = LazyOptional.of(()->itemsHandler); lazyOutputItems = LazyOptional.of(()->outputSlot); lazyEnergyHandler = LazyOptional.of(()->ENERGY_STORAGE); } diff --git a/src/main/java/dev/zontreck/otemod/items/PartialItem.java b/src/main/java/dev/zontreck/otemod/items/PartialItem.java index c0d519d..66bd5f8 100644 --- a/src/main/java/dev/zontreck/otemod/items/PartialItem.java +++ b/src/main/java/dev/zontreck/otemod/items/PartialItem.java @@ -9,18 +9,35 @@ import net.minecraft.server.commands.GiveCommand; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Map; public class PartialItem extends Item { private static final String TAG_UNCRAFT_REMAIN = "remaining"; private static final String TAG_UNCRAFT_LIST = "Items"; + @Override + public boolean isEnchantable(ItemStack p_41456_) { + return true; + } + + @Override + public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { + return false; + } + + @Override + public boolean isBookEnchantable(ItemStack stack, ItemStack book) { + return false; + } public PartialItem() { super (new Properties().fireResistant()); @@ -36,8 +53,12 @@ public class PartialItem extends Item { tooltip.add(ChatHelpers.macro("!Dark_Red!Number of uncraft steps remaining: [0]", "!Yellow!" + stack.getTag().getInt(TAG_UNCRAFT_REMAIN))); } + if(stack.getTag().contains(ItemStack.TAG_ENCH)) + { + tooltip.add(ChatHelpers.macro("!Dark_Red!Number of Enchantments remaining: [0]", "!Yellow!" + stack.getTag().getList(ItemStack.TAG_ENCH, Tag.TAG_COMPOUND).size())); + } } else { - tooltip.add(ChatHelpers.macro("!Dark_Red!This partial item appears to be invalid, and contains no item fragments.")); + tooltip.add(ChatHelpers.macro("!Dark_Red!This partial item appears to be invalid, and contains no fragments.")); } } @@ -67,4 +88,18 @@ public class PartialItem extends Item { return ForgeRegistries.ITEMS.getValue(new ResourceLocation(item)); } + + public static ItemStack makePartialItem(ItemStack original, boolean enchantMode, boolean uncraftMode) + { + if(enchantMode) + { + ItemStack partial = new ItemStack(ModItems.PARTIAL_ITEM.get(), 1); + CompoundTag tag = new CompoundTag(); + tag.put(ItemStack.TAG_ENCH, original.getTag().get(ItemStack.TAG_ENCH)); + + partial.setTag(tag); + + return partial; + } else return original; + } }