From ccce86a41c716c3d549325abc52e81e5188b1a08 Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 31 May 2023 15:18:16 +0200 Subject: [PATCH] usable tram trailer --- changelog | 2 +- .../entity/train/TrainCargoTramTrailer.java | 141 +++++++++++++++++- .../hbm/inventory/FluidContainerRegistry.java | 1 + .../gui/vehicles/gui_cargo_tram_trailer.png | Bin 0 -> 1382 bytes 4 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/assets/hbm/textures/gui/vehicles/gui_cargo_tram_trailer.png diff --git a/changelog b/changelog index 9e3e29f28..68bff38a5 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,6 @@ ## Added * Laminate glass - * A new variant of refinroced glass with higher blast resistance + * A new variant of reinforced glass with higher blast resistance ## Changed * Updated russian localization diff --git a/src/main/java/com/hbm/entity/train/TrainCargoTramTrailer.java b/src/main/java/com/hbm/entity/train/TrainCargoTramTrailer.java index e077a14da..05d465476 100644 --- a/src/main/java/com/hbm/entity/train/TrainCargoTramTrailer.java +++ b/src/main/java/com/hbm/entity/train/TrainCargoTramTrailer.java @@ -1,13 +1,31 @@ package com.hbm.entity.train; -import com.hbm.blocks.rail.IRailNTM.TrackGauge; +import org.lwjgl.opengl.GL11; +import com.hbm.blocks.rail.IRailNTM.TrackGauge; +import com.hbm.inventory.gui.GuiInfoContainer; +import com.hbm.lib.RefStrings; +import com.hbm.main.MainRegistry; +import com.hbm.tileentity.IGUIProvider; + +import cpw.mods.fml.common.network.internal.FMLNetworkHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.Vec3; import net.minecraft.world.World; -public class TrainCargoTramTrailer extends EntityRailCarCargo { +public class TrainCargoTramTrailer extends EntityRailCarCargo implements IGUIProvider { /* * @@ -28,15 +46,11 @@ public class TrainCargoTramTrailer extends EntityRailCarCargo { @Override public double getMaxRailSpeed() { return 1; } @Override public TrackGauge getGauge() { return TrackGauge.STANDARD; } @Override public double getLengthSpan() { return 1.5; } - @Override public int getSizeInventory() { return 29; } + @Override public int getSizeInventory() { return 45; } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.getEntityName() : "container.trainTramTrailer"; } @Override public AxisAlignedBB getCollisionBox() { return AxisAlignedBB.getBoundingBox(renderX, renderY, renderZ, renderX, renderY + 1, renderZ).expand(4, 0, 4); } @Override public double getCouplingDist(TrainCoupling coupling) { return coupling != null ? 2.75 : 0; } - - @Override - public double getCurrentSpeed() { - return 0; //we'll figure out how linked carts work later on - i hope - } + @Override public double getCurrentSpeed() { return 0; } @Override public DummyConfig[] getDummies() { @@ -55,4 +69,115 @@ public class TrainCargoTramTrailer extends EntityRailCarCargo { return true; } + + @Override + public boolean interactFirst(EntityPlayer player) { + if(super.interactFirst(player)) return false; + + if(!this.worldObj.isRemote) { + FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, worldObj, this.getEntityId(), 0, 0); + } + + return true; + } + + @Override + public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { + return new ContainerTrainCargoTramTrailer(player.inventory, this); + } + + @Override + @SideOnly(Side.CLIENT) + public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { + return new GUITrainCargoTramTrailer(player.inventory, this); + } + + /* + * ##### ##### # # ##### ##### ### # # ##### #### + * # # # ## # # # # # ## # # # # + * # # # # # # # ##### # # # # ### #### + * # # # # ## # # # # # ## # # # + * ##### ##### # # # # # ### # # ##### # # + */ + public static class ContainerTrainCargoTramTrailer extends Container { + private TrainCargoTramTrailer train; + public ContainerTrainCargoTramTrailer(InventoryPlayer invPlayer, TrainCargoTramTrailer train) { + this.train = train; + for(int i = 0; i < 5; i++) { + for(int j = 0; j < 9; j++) { + this.addSlotToContainer(new Slot(train, i * 7 + j, 8 + j * 18, 18 + i * 18)); + } + } + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 9; j++) { + this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 140 + i * 18)); + } + } + for(int i = 0; i < 9; i++) { + this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 198)); + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { + ItemStack stackCopy = null; + Slot slot = (Slot) this.inventorySlots.get(slotIndex); + if(slot != null && slot.getHasStack()) { + ItemStack stack = slot.getStack(); + stackCopy = stack.copy(); + if(slotIndex < train.getSizeInventory()) { + if(!this.mergeItemStack(stack, train.getSizeInventory(), this.inventorySlots.size(), true)) { + return null; + } + } else + if(!this.mergeItemStack(stack, 0, 45, false)) { + return null; + } + if(stack.stackSize == 0) { + slot.putStack((ItemStack) null); + } else { + slot.onSlotChanged(); + } + } + return stackCopy; + } + + @Override + public boolean canInteractWith(EntityPlayer player) { + return train.isUseableByPlayer(player); + } + } + + /* + * ##### # # ### + * # # # # + * # ## # # # + * # # # # # + * ##### ##### ### + */ + @SideOnly(Side.CLIENT) + public static class GUITrainCargoTramTrailer extends GuiInfoContainer { + private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/vehicles/gui_cargo_tram_trailer.png"); + private TrainCargoTramTrailer train; + public GUITrainCargoTramTrailer(InventoryPlayer invPlayer, TrainCargoTramTrailer train) { + super(new ContainerTrainCargoTramTrailer(invPlayer, train)); + this.train = train; + this.xSize = 176; + this.ySize = 222; + } + + @Override + protected void drawGuiContainerForegroundLayer(int i, int j) { + String name = this.train.hasCustomInventoryName() ? this.train.getInventoryName() : I18n.format(this.train.getInventoryName()); + this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 0xffffff); + this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float intero, int x, int y) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(texture); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + } + } } diff --git a/src/main/java/com/hbm/inventory/FluidContainerRegistry.java b/src/main/java/com/hbm/inventory/FluidContainerRegistry.java index aacd3c2f2..4ad6a1b50 100644 --- a/src/main/java/com/hbm/inventory/FluidContainerRegistry.java +++ b/src/main/java/com/hbm/inventory/FluidContainerRegistry.java @@ -22,6 +22,7 @@ public class FluidContainerRegistry { public static void register() { FluidContainerRegistry.registerContainer(new FluidContainer(new ItemStack(Items.water_bucket), new ItemStack(Items.bucket), Fluids.WATER, 1000)); + FluidContainerRegistry.registerContainer(new FluidContainer(new ItemStack(Items.potionitem), new ItemStack(Items.glass_bottle), Fluids.WATER, 250)); FluidContainerRegistry.registerContainer(new FluidContainer(new ItemStack(Items.lava_bucket), new ItemStack(Items.bucket), Fluids.LAVA, 1000)); FluidContainerRegistry.registerContainer(new FluidContainer(new ItemStack(ModItems.bucket_mud), new ItemStack(Items.bucket), Fluids.WATZ, 1000)); FluidContainerRegistry.registerContainer(new FluidContainer(new ItemStack(ModItems.bucket_schrabidic_acid), new ItemStack(Items.bucket), Fluids.SCHRABIDIC, 1000)); diff --git a/src/main/resources/assets/hbm/textures/gui/vehicles/gui_cargo_tram_trailer.png b/src/main/resources/assets/hbm/textures/gui/vehicles/gui_cargo_tram_trailer.png new file mode 100644 index 0000000000000000000000000000000000000000..5e7ed276200f0d92e544acb4593b6c7f1a9ee672 GIT binary patch literal 1382 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%N?Bp530R%N1DIE+9tg@ai zjv*Cu-rhCLyIm%6>|uXf`<(^OZp$6l2UNe9wzIjY^$lAI|J%JyCSSNBmuR#2@}_uf zS54Dr4nb6F* zLGZ*Jv1f1cS%exs-rz{_`&^vEGOI5gtMk#Vg8OST(2!@(Z*Z8%N;jU#tn2G_xV#ZA zbRIJta2f=ZNK>9*dG`E9!3--irkR)j$VfLXONI;0V?+&5d@vQmD$`?v< zSd5ncv@~P#Jq{PLVMdA>0tSKNve)66iT!c61utcI7`AvY9D59l7{62RKFu$D^KSmH zv$MJN_0*3VH#~f|uj22gM^7*EvCKPk(!TGn_y+q^fd?*I{sg6U5O}xa`|JjHYpx2Z z{VXPv>hE)3_yGi6y?h|0Fzz>2NR)02lQH5-HYz)*RMD4KbT{-`f65cpXK>^#igaDNQv(A&plzQ zr&>O33WgPb$U|R($W6XPiwloqwLaUby(oLSJAati2z8^>9D?c3Ap~f;oQM z|Mp5XcslvWLt65NBnqS?0Z%25B}sELBuV%@f8eH&F|pU-aUnM>|62bLxDb|595rL} ze$g2pZ*b)RbA`>Ed418i@->za0hRL5fb$Fm@!yt3~ANLLUry37l&iMmLEO^KRF8>&{U#1>)SsVKoq|DRR&t;uc GLK6U;S>omZ literal 0 HcmV?d00001