Start making use of partial item
This commit is contained in:
parent
afb21dd2c8
commit
48c83245c9
5 changed files with 49 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<Enchantment, Integer> enchants = main.getAllEnchantments();
|
||||
Map<Enchantment, Integer> 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<Map.Entry<Enchantment,Integer>> iEntries = enchantments.entrySet().iterator();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue