diff --git a/src/main/java/gregtech/api/block/machines/MachineItemBlock.java b/src/main/java/gregtech/api/block/machines/MachineItemBlock.java index 4d97969ae99..42febdc36b5 100644 --- a/src/main/java/gregtech/api/block/machines/MachineItemBlock.java +++ b/src/main/java/gregtech/api/block/machines/MachineItemBlock.java @@ -18,6 +18,7 @@ import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -184,4 +185,10 @@ public CreativeTabs[] getCreativeTabs() { tabs[tabs.length - 1] = getCreativeTab(); return tabs; } + + @Override + public int getItemStackLimit(@Nonnull ItemStack stack) { + MetaTileEntity metaTileEntity = GTUtility.getMetaTileEntity(stack); + return metaTileEntity != null ? metaTileEntity.getItemStackLimit(stack) : super.getItemStackLimit(stack); + } } diff --git a/src/main/java/gregtech/api/capability/GregtechDataCodes.java b/src/main/java/gregtech/api/capability/GregtechDataCodes.java index e7e5fee86df..049167fbab9 100644 --- a/src/main/java/gregtech/api/capability/GregtechDataCodes.java +++ b/src/main/java/gregtech/api/capability/GregtechDataCodes.java @@ -142,6 +142,12 @@ public class GregtechDataCodes { // From MetaTileEntityHolder public static final String CUSTOM_NAME = "CustomName"; + // From MetaTileEntity + public static final String TAG_KEY_PAINTING_COLOR = "PaintingColor"; + public static final String TAG_KEY_FRAGILE = "Fragile"; + public static final String TAG_KEY_MUFFLED = "Muffled"; + + // MTE Trait Names public static final String ABSTRACT_WORKABLE_TRAIT = "RecipeMapWorkable"; diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index bea29eb6dc8..440b3bda6d4 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -91,9 +91,6 @@ public abstract class MetaTileEntity implements ICoverable, IVoidable { public static final IndexedCuboid6 FULL_CUBE_COLLISION = new IndexedCuboid6(null, Cuboid6.full); - public static final String TAG_KEY_PAINTING_COLOR = "PaintingColor"; - public static final String TAG_KEY_FRAGILE = "Fragile"; - public static final String TAG_KEY_MUFFLED = "Muffled"; public final ResourceLocation metaTileEntityId; IGregTechTileEntity holder; @@ -1265,6 +1262,10 @@ public static void clearInventory(NonNullList itemBuffer, IItemHandle } } + public int getItemStackLimit(ItemStack stack) { + return 64; + } + /** * Called whenever a MetaTileEntity is placed in world by {@link Block#onBlockPlacedBy} *

diff --git a/src/main/java/gregtech/client/renderer/texture/Textures.java b/src/main/java/gregtech/client/renderer/texture/Textures.java index 9ccde053099..d618a886208 100644 --- a/src/main/java/gregtech/client/renderer/texture/Textures.java +++ b/src/main/java/gregtech/client/renderer/texture/Textures.java @@ -286,6 +286,8 @@ public class Textures { public static final SimpleOverlayRenderer HPCA_ADVANCED_DAMAGED_ACTIVE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/damaged_advanced_active"); public static final SimpleOverlayRenderer HPCA_EMPTY_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/empty"); public static final SimpleOverlayRenderer HPCA_HEAT_SINK_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/heat_sink"); + public static final SimpleOverlayRenderer TAPED_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_ducttape"); + public static final SimpleOverlayRenderer COVER_INTERFACE_FLUID = new SimpleOverlayRenderer("cover/cover_interface_fluid"); public static final SimpleOverlayRenderer COVER_INTERFACE_FLUID_GLASS = new SimpleOverlayRenderer("cover/cover_interface_fluid_glass"); diff --git a/src/main/java/gregtech/common/items/MetaItem1.java b/src/main/java/gregtech/common/items/MetaItem1.java index 0389ca1c517..36ac90989d1 100644 --- a/src/main/java/gregtech/common/items/MetaItem1.java +++ b/src/main/java/gregtech/common/items/MetaItem1.java @@ -715,6 +715,7 @@ public void registerSubItems() { DUCT_TAPE = addItem(502, "duct_tape"); WIRELESS = addItem(503, "wireless"); CAMERA = addItem(504, "camera"); + BASIC_TAPE = addItem(505, "basic_tape"); // Circuit Components: ID 516-565 VACUUM_TUBE = addItem(516, "circuit.vacuum_tube").setUnificationData(OrePrefix.circuit, Tier.ULV); diff --git a/src/main/java/gregtech/common/items/MetaItems.java b/src/main/java/gregtech/common/items/MetaItems.java index 8d48b8130b7..00e1545998f 100644 --- a/src/main/java/gregtech/common/items/MetaItems.java +++ b/src/main/java/gregtech/common/items/MetaItems.java @@ -113,6 +113,7 @@ private MetaItems() { public static MetaItem.MetaValueItem CARBON_MESH; public static MetaItem.MetaValueItem CARBON_FIBER_PLATE; public static MetaItem.MetaValueItem DUCT_TAPE; + public static MetaItem.MetaValueItem BASIC_TAPE; public static MetaItem.MetaValueItem NEUTRON_REFLECTOR; diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCrate.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCrate.java index 448341d98ed..0364afa6107 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCrate.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCrate.java @@ -1,6 +1,7 @@ package gregtech.common.metatileentities.storage; import codechicken.lib.colour.ColourRGBA; +import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; @@ -14,11 +15,15 @@ import gregtech.api.unification.material.Material; import gregtech.api.util.GTUtility; import gregtech.client.renderer.texture.Textures; +import gregtech.common.items.MetaItems; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; @@ -30,11 +35,16 @@ import javax.annotation.Nullable; import java.util.List; +import static gregtech.api.capability.GregtechDataCodes.IS_TAPED; +import static gregtech.api.capability.GregtechDataCodes.TAG_KEY_PAINTING_COLOR; + public class MetaTileEntityCrate extends MetaTileEntity { private final Material material; private final int inventorySize; - private ItemStackHandler inventory; + protected ItemStackHandler inventory; + private boolean isTaped; + private final String TAPED_NBT = "Taped"; public MetaTileEntityCrate(ResourceLocation metaTileEntityId, Material material, int inventorySize) { super(metaTileEntityId); @@ -72,7 +82,9 @@ protected void initializeInventory() { @Override public void clearMachineInventory(NonNullList itemBuffer) { - clearInventory(itemBuffer, inventory); + if(!isTaped) { + clearInventory(itemBuffer, inventory); + } } @Override @@ -97,6 +109,16 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, int baseColor = ColourRGBA.multiply(GTUtility.convertRGBtoOpaqueRGBA_CL(material.getMaterialRGB()), GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering())); Textures.METAL_CRATE.render(renderState, translation, baseColor, pipeline); } + boolean taped = isTaped; + if (renderContextStack != null && renderContextStack.getTagCompound() != null) { + NBTTagCompound tag = renderContextStack.getTagCompound(); + if (tag.hasKey(TAPED_NBT) && tag.getBoolean(TAPED_NBT)) { + taped = true; + } + } + if (taped) { + Textures.TAPED_OVERLAY.render(renderState, translation, pipeline); + } } @Override @@ -115,10 +137,39 @@ protected ModularUI createUI(EntityPlayer entityPlayer) { return builder.build(getHolder(), entityPlayer); } + @Override + public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) { + ItemStack stack = playerIn.getHeldItem(hand); + if(playerIn.isSneaking() && !isTaped) { + if (stack.isItemEqual(MetaItems.DUCT_TAPE.getStackForm()) || stack.isItemEqual(MetaItems.BASIC_TAPE.getStackForm())) { + if (!playerIn.isCreative()) { + stack.shrink(1); + } + isTaped = true; + if (!getWorld().isRemote) { + writeCustomData(IS_TAPED, buf -> buf.writeBoolean(isTaped)); + markDirty(); + } + return true; + } + } + return super.onRightClick(playerIn, hand, facing, hitResult); + } + + @Override + public int getItemStackLimit(ItemStack stack) { + NBTTagCompound tag = stack.getTagCompound(); + if (tag != null && tag.getBoolean(TAPED_NBT)) { + return 1; + } + return super.getItemStackLimit(stack); + } + @Override public NBTTagCompound writeToNBT(NBTTagCompound data) { super.writeToNBT(data); data.setTag("Inventory", inventory.serializeNBT()); + data.setBoolean(TAPED_NBT, isTaped); return data; } @@ -126,6 +177,52 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) { public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); this.inventory.deserializeNBT(data.getCompoundTag("Inventory")); + if(data.hasKey(TAPED_NBT)) { + this.isTaped = data.getBoolean(TAPED_NBT); + } + } + + @Override + public void initFromItemStackData(NBTTagCompound data) { + super.initFromItemStackData(data); + if (data.hasKey(TAG_KEY_PAINTING_COLOR)) { + this.setPaintingColor(data.getInteger(TAG_KEY_PAINTING_COLOR)); + } + this.isTaped = data.getBoolean(TAPED_NBT); + if(isTaped) { + this.inventory.deserializeNBT(data.getCompoundTag("Inventory")); + } + + data.removeTag(TAPED_NBT); + data.removeTag(TAG_KEY_PAINTING_COLOR); + + this.isTaped = false; + } + + @Override + public void writeItemStackData(NBTTagCompound data) { + super.writeItemStackData(data); + + // Account for painting color when breaking the crate + if (this.isPainted()) { + data.setInteger(TAG_KEY_PAINTING_COLOR, this.getPaintingColor()); + } + // Don't write tape NBT if not taped, to stack with ones from JEI + if(isTaped) { + data.setBoolean(TAPED_NBT, isTaped); + data.setTag("Inventory", inventory.serializeNBT()); + } + } + + @Override + public void receiveCustomData(int dataId, PacketBuffer buf) { + super.receiveCustomData(dataId, buf); + + if(dataId == IS_TAPED) { + this.isTaped = buf.readBoolean(); + scheduleRenderUpdate(); + markDirty(); + } } @Override @@ -136,6 +233,7 @@ protected boolean shouldSerializeInventories() { @Override public void addInformation(ItemStack stack, @Nullable World player, List tooltip, boolean advanced) { tooltip.add(I18n.format("gregtech.universal.tooltip.item_storage_capacity", inventorySize)); + tooltip.add(I18n.format("gregtech.crate.tooltip.taped_movement")); } @Override diff --git a/src/main/java/gregtech/loaders/recipe/MachineRecipeLoader.java b/src/main/java/gregtech/loaders/recipe/MachineRecipeLoader.java index 3f4473b4ec3..51382767fa0 100644 --- a/src/main/java/gregtech/loaders/recipe/MachineRecipeLoader.java +++ b/src/main/java/gregtech/loaders/recipe/MachineRecipeLoader.java @@ -14,6 +14,7 @@ import gregtech.api.unification.material.properties.PropertyKey; import gregtech.api.unification.ore.OrePrefix; import gregtech.api.unification.stack.MaterialStack; +import gregtech.api.unification.stack.UnificationEntry; import gregtech.common.ConfigHolder; import gregtech.common.blocks.*; import gregtech.common.blocks.BlockMachineCasing.MachineCasingType; @@ -679,6 +680,9 @@ private static void registerAssemblerRecipes() { ASSEMBLER_RECIPES.recipeBuilder().EUt(VA[LV]).input(foil, Polycaprolactam, 2).input(CARBON_MESH).fluidInputs(Polyethylene.getFluid(144)).output(DUCT_TAPE, 4).duration(100).buildAndRegister(); ASSEMBLER_RECIPES.recipeBuilder().EUt(VA[LV]).input(foil, Polybenzimidazole).input(CARBON_MESH).fluidInputs(Polyethylene.getFluid(72)).output(DUCT_TAPE, 8).duration(100).buildAndRegister(); + ModHandler.addShapedRecipe("basic_tape", BASIC_TAPE.getStackForm(), " P ", "PSP", " P ", 'P', new UnificationEntry(plate, Paper), 'S', STICKY_RESIN.getStackForm()); + ASSEMBLER_RECIPES.recipeBuilder().EUt(VA[ULV]).input(plate, Paper, 2).input(STICKY_RESIN).output(BASIC_TAPE, 2).duration(100).buildAndRegister(); + ASSEMBLER_RECIPES.recipeBuilder() .input(plateDouble, Steel, 2) .input(ring, Bronze, 2) diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 06a612e0757..7a81e8c4d7b 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -796,6 +796,8 @@ metaitem.neutron_reflector.name=Iridium Neutron Reflector metaitem.neutron_reflector.tooltip=Indestructible metaitem.duct_tape.name=BrainTech Aerospace Advanced Reinforced Duct Tape FAL-84 metaitem.duct_tape.tooltip=If you can't fix it with this, use more of it! +metaitem.basic_tape.name=Tape +metaitem.basic_tape.tooltip=Not strong enough for mechanical issues metaitem.component.grinder.diamond.name=Diamond Grinding Head metaitem.component.grinder.tungsten.name=Tungsten Grinding Head @@ -2648,6 +2650,7 @@ gregtech.machine.crate.aluminium.name=Aluminium Crate gregtech.machine.crate.stainless_steel.name=Stainless Steel Crate gregtech.machine.crate.titanium.name=Titanium Crate gregtech.machine.crate.tungstensteel.name=Tungstensteel Crate +gregtech.crate.tooltip.taped_movement=Can be Taped to keep inventory contents when broken # Safe gregtech.machine.locked_safe.name=Locked Safe diff --git a/src/main/resources/assets/gregtech/models/item/metaitems/basic_tape.json b/src/main/resources/assets/gregtech/models/item/metaitems/basic_tape.json new file mode 100644 index 00000000000..e4c791adb3d --- /dev/null +++ b/src/main/resources/assets/gregtech/models/item/metaitems/basic_tape.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "gregtech:items/metaitems/basic_tape" + } +} diff --git a/src/main/resources/assets/gregtech/textures/items/metaitems/basic_tape.png b/src/main/resources/assets/gregtech/textures/items/metaitems/basic_tape.png new file mode 100644 index 00000000000..5017923b38c Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/items/metaitems/basic_tape.png differ