Skip to content

Commit

Permalink
Allow Taping crates to keep inventory (#1310)
Browse files Browse the repository at this point in the history
Co-authored-by: serenibyss <10861407+serenibyss@users.noreply.github.com>
  • Loading branch information
ALongStringOfNumbers and serenibyss authored Nov 15, 2023
1 parent 2e247cd commit 463b3c1
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/main/java/gregtech/api/capability/GregtechDataCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1265,6 +1262,10 @@ public static void clearInventory(NonNullList<ItemStack> itemBuffer, IItemHandle
}
}

public int getItemStackLimit(ItemStack stack) {
return 64;
}

/**
* Called whenever a MetaTileEntity is placed in world by {@link Block#onBlockPlacedBy}
* <p>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/client/renderer/texture/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/common/items/MetaItem1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/common/items/MetaItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -72,7 +82,9 @@ protected void initializeInventory() {

@Override
public void clearMachineInventory(NonNullList<ItemStack> itemBuffer) {
clearInventory(itemBuffer, inventory);
if(!isTaped) {
clearInventory(itemBuffer, inventory);
}
}

@Override
Expand All @@ -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
Expand All @@ -115,17 +137,92 @@ 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;
}

@Override
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
Expand All @@ -136,6 +233,7 @@ protected boolean shouldSerializeInventories() {
@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
tooltip.add(I18n.format("gregtech.universal.tooltip.item_storage_capacity", inventorySize));
tooltip.add(I18n.format("gregtech.crate.tooltip.taped_movement"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "gregtech:items/metaitems/basic_tape"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 463b3c1

Please sign in to comment.