From 073ea6b498c5994dd601ab8a917d0677b2d59afa Mon Sep 17 00:00:00 2001 From: broscolotos Date: Sat, 3 Aug 2024 13:32:09 -0500 Subject: [PATCH] Slopes and SeatGUI progress - SeatGUI is mostly working; some odd things do happen when you use it when not in the control seat. - renamed some stuff in the main TC track movement method to make it a bit easier for new people to jump in and know what's happening. - reworked the slope acceleration to actually do something; two different "modes", one for consists with a locomotive and one for free-rolling rollingstock. --- src/main/java/ebf/tim/gui/GUIButton.java | 1 - src/main/java/ebf/tim/gui/GUISeatManager.java | 25 +- .../java/train/client/core/ClientProxy.java | 9 +- .../core/handlers/CustomRenderHandler.java | 2 + src/main/java/train/client/gui/GuiForney.java | 37 ++ .../java/train/client/gui/GuiFreight.java | 37 ++ src/main/java/train/client/gui/GuiLoco2.java | 34 ++ src/main/java/train/client/gui/GuiTender.java | 27 ++ .../blocks/ModelLeftParallelCurveTCTrack.java | 5 + src/main/java/train/common/Traincraft.java | 4 + .../java/train/common/api/EntityBogie.java | 22 ++ .../train/common/api/EntityRollingStock.java | 319 +++++++++--------- .../java/train/common/api/Locomotive.java | 14 +- .../java/train/common/core/CommonProxy.java | 8 + .../java/train/common/library/GuiIDs.java | 1 + 15 files changed, 384 insertions(+), 161 deletions(-) diff --git a/src/main/java/ebf/tim/gui/GUIButton.java b/src/main/java/ebf/tim/gui/GUIButton.java index f5c37ac73..9f52e535b 100644 --- a/src/main/java/ebf/tim/gui/GUIButton.java +++ b/src/main/java/ebf/tim/gui/GUIButton.java @@ -72,7 +72,6 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY){ /** draws the button*/ public void drawButton(int mouseX, int mouseY) { GL11.glPushMatrix(); - RenderHelper.enableStandardItemLighting(); TextureManager.bindTexture(buttonTextures); if(getColor()!=null){ GL11.glColor4f(getColor()[0]*0.00392156862f, getColor()[1]*0.00392156862f, getColor()[2]*0.00392156862f, 1.0F); diff --git a/src/main/java/ebf/tim/gui/GUISeatManager.java b/src/main/java/ebf/tim/gui/GUISeatManager.java index 4d761e9d7..8f3d82643 100644 --- a/src/main/java/ebf/tim/gui/GUISeatManager.java +++ b/src/main/java/ebf/tim/gui/GUISeatManager.java @@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.player.EntityPlayer; @@ -39,10 +40,13 @@ public class GUISeatManager extends GuiScreen { public GUISeatManager(EntityRollingStock transport) { entity=transport; } + public GUISeatManager(EntityPlayer player, EntityRollingStock transport) { + entity=transport; + } @Override public void initGui() { - if(entity !=null && entity.getRiderOffsets().length > 0) { + if (entity != null && entity.getRiderOffsets().length > 0) { } } @@ -65,7 +69,7 @@ public void drawScreen(int parWidth, int parHeight, float p_73863_3_) { } for(EntitySeat seat : entity.seats) { if (seat.getPassenger() != null) { - if (seat.getPassenger() == Minecraft.getMinecraft().thePlayer) { + if (seat.getPassenger() instanceof EntityPlayer && ((EntityPlayer)seat.getPassenger()).getDisplayName() == mc.thePlayer.getDisplayName()) { currentSeat = seat; } filledSeatIDs.add(seat.getEntityId()); @@ -77,6 +81,11 @@ public void drawScreen(int parWidth, int parHeight, float p_73863_3_) { switch(guiScreen) { case 0:{defineButtons();guiSeatManager();break;} } + for(Object guiButton: buttonList) { + if (guiButton instanceof GUIButton) { + ((GUIButton)guiButton).drawText(parWidth-(int)guiLeft,parHeight-(int)guiTop); + } + } } @Override public boolean doesGuiPauseGame() {return false;} @@ -134,8 +143,6 @@ public void onClick() { if (lastClickTick+5 < entity.ticksExisted) { Traincraft.updateChannel.sendToServer(new PacketSeatUpdate(entity.getEntityId(),currentSeat.getPassenger().getEntityId(),entity.seats.indexOf(currentSeat),buttonList.indexOf(this),entity.dimension)); lastClickTick = entity.ticksExisted; - } else { - System.out.println("Too fast"); } } @Override @@ -165,7 +172,12 @@ public void onClick() { } } - + @Override + protected void actionPerformed(GuiButton guibutton) { + if (guibutton instanceof GUIButton) { + ((GUIButton) guibutton).onClick(); + } + } public void guiSeatManager(){ @@ -180,6 +192,9 @@ public void guiSeatManager(){ if (seat.getPassenger() instanceof AbstractClientPlayer) { mc.getTextureManager().bindTexture(((AbstractClientPlayer) seat.getPassenger()).getLocationSkin()); ClientUtil.drawTexturedRect(locations.get(entity.seats.indexOf(seat)).x, locations.get(entity.seats.indexOf(seat)).y, 32, 64, 24, 24, 32, 64); + } else if (seat.getPassenger() instanceof EntityPlayer) { + mc.getTextureManager().bindTexture(Minecraft.getMinecraft().thePlayer.getLocationSkin()); + ClientUtil.drawTexturedRect(locations.get(entity.seats.indexOf(seat)).x, locations.get(entity.seats.indexOf(seat)).y, 32, 64, 24, 24, 32, 64); } } GL11.glPopMatrix(); diff --git a/src/main/java/train/client/core/ClientProxy.java b/src/main/java/train/client/core/ClientProxy.java index b7517520d..b586b8e6f 100644 --- a/src/main/java/train/client/core/ClientProxy.java +++ b/src/main/java/train/client/core/ClientProxy.java @@ -8,6 +8,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.VillagerRegistry; import ebf.tim.entities.EntitySeat; +import ebf.tim.gui.GUISeatManager; import javazoom.jl.decoder.JavaLayerUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundCategory; @@ -382,7 +383,8 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int return entity1 != null ? new GuiFixedOverlay(player, (EntityRollingStock) entity1) : null; case (GuiIDs.DYNAMIC_OVERLAY): return entity1 != null ? new GuiDynamicOverlay(player, (EntityRollingStock) entity1) : null; - + case (GuiIDs.SEAT_GUI): + return entity1 != null ? new GUISeatManager(player, (EntityRollingStock) entity1) : null; default: return null; } @@ -466,4 +468,9 @@ public void registerKeyBindingHandler() { public void setHook() { JavaLayerUtils.setHook(new JLayerHook(Minecraft.getMinecraft())); } + + @Override + public void seatGUI(EntityPlayer player, EntityRollingStock transport) { + Minecraft.getMinecraft().displayGuiScreen(new GUISeatManager(transport)); + } } \ No newline at end of file diff --git a/src/main/java/train/client/core/handlers/CustomRenderHandler.java b/src/main/java/train/client/core/handlers/CustomRenderHandler.java index 673a70434..023e22950 100644 --- a/src/main/java/train/client/core/handlers/CustomRenderHandler.java +++ b/src/main/java/train/client/core/handlers/CustomRenderHandler.java @@ -249,6 +249,8 @@ else if (item.getTrackType() == EnumTracks.VERY_LONG_STRAIGHT || item.getTrackTy turnSize = "medium"; } else if (item.getTrackType() == EnumTracks.LARGE_PARALLEL_CURVE || item.getTrackType() == EnumTracks.EMBEDDED_LARGE_PARALLEL_CURVE) { turnSize = "large"; + } else if (item.getTrackType() == EnumTracks.S_CURVE_20x2) { + turnSize = "20x2"; } if (item.getTrackOrientation(facing, MathHelper.wrapAngleTo180_float(player.rotationYaw)).equals("left")) { diff --git a/src/main/java/train/client/gui/GuiForney.java b/src/main/java/train/client/gui/GuiForney.java index ff45e7f7e..e5265f3f9 100644 --- a/src/main/java/train/client/gui/GuiForney.java +++ b/src/main/java/train/client/gui/GuiForney.java @@ -1,5 +1,7 @@ package train.client.gui; +import ebf.tim.gui.GUIButton; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.Entity; @@ -30,10 +32,13 @@ public class GuiForney extends GuiContainer { private int buttonPosX = 0; private int buttonPosY = 0; + private InventoryPlayer player; + private GUIButton buttonSeatManager; public GuiForney(InventoryPlayer inventoryplayer, Entity entityminecart) { super(new InventoryForney(inventoryplayer, (Locomotive) entityminecart)); loco = (Locomotive) entityminecart; + player = inventoryplayer; } @Override @@ -81,6 +86,36 @@ public void initGui() { } else { this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 130, buttonPosY - 10, 43, 10, "Locked")); } + if (loco.seats.size() > 1) { + this.buttonList.add(this.buttonSeatManager = new GUIButton(buttonPosX + 124,buttonPosY - 20, 51,10, "Seats") { + @Override + public String getHoverText() { + return "gui.seats"; + } + + @Override + public int[] getColor(){ + return null; + } + + @Override + public void onClick() { + Traincraft.proxy.seatGUI(player.player,loco); + } + + @Override + public FontRenderer getFont(){return fontRendererObj;} + }); + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float par3) { + for(Object guiButton: buttonList) { + if (guiButton instanceof GUIButton) { + ((GUIButton)guiButton).drawText(mouseX-(int)guiLeft,mouseY-(int)guiTop); + } + } } @Override @@ -119,6 +154,8 @@ protected void actionPerformed(GuiButton guibutton) { } else if (loco.riddenByEntity != null && loco.riddenByEntity instanceof EntityPlayer) { ((EntityPlayer) loco.riddenByEntity).addChatMessage(new ChatComponentText("You are not the owner")); } + } else if (guibutton instanceof GUIButton) { + ((GUIButton)guibutton).onClick(); } } diff --git a/src/main/java/train/client/gui/GuiFreight.java b/src/main/java/train/client/gui/GuiFreight.java index 72283086b..84df2b669 100644 --- a/src/main/java/train/client/gui/GuiFreight.java +++ b/src/main/java/train/client/gui/GuiFreight.java @@ -1,5 +1,7 @@ package train.client.gui; +import ebf.tim.gui.GUIButton; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.Entity; @@ -26,6 +28,7 @@ public class GuiFreight extends GuiContainer { private float yaw; private float roll; private boolean rollDown; + private GUIButton buttonSeatManager; private GuiButton buttonLock; public GuiFreight(EntityPlayer player, InventoryPlayer inventoryplayer, Entity entityminecart) { @@ -54,6 +57,27 @@ public void initGui() { } else { this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 130, buttonPosY - 10, 43, 10, "Locked")); } + if (freight.seats.size() > 1) { + this.buttonList.add(this.buttonSeatManager = new GUIButton(buttonPosX + 124,buttonPosY - 20, 51,10, "Seats") { + @Override + public String getHoverText() { + return "gui.seats"; + } + + @Override + public int[] getColor(){ + return null; + } + + @Override + public void onClick() { + Traincraft.proxy.seatGUI(player,freight); + } + + @Override + public FontRenderer getFont(){return fontRendererObj;} + }); + } } @Override @@ -91,6 +115,8 @@ protected void actionPerformed(GuiButton guibutton) { } else if (player != null) { player.addChatMessage(new ChatComponentText("You are not the owner")); } + } else if (guibutton instanceof GUIButton) { + ((GUIButton)guibutton).onClick(); } } @@ -130,6 +156,17 @@ public boolean intersectsWith(int mouseX, int mouseY) { return (mouseX >= j + 124 && mouseX <= j + 174 && mouseY >= k - 10 && mouseY <= k); } + + + @Override + public void drawScreen(int mouseX, int mouseY, float par3) { + for(Object guiButton: buttonList) { + if (guiButton instanceof GUIButton) { + ((GUIButton)guiButton).drawText(mouseX-(int)guiLeft,mouseY-(int)guiTop); + } + } + super.drawScreen(mouseX,mouseY,par3); + } @Override protected void drawGuiContainerForegroundLayer(int i, int j) { GL11.glDisable(GL11.GL_LIGHTING); diff --git a/src/main/java/train/client/gui/GuiLoco2.java b/src/main/java/train/client/gui/GuiLoco2.java index 162fa3ecb..2e2dd357e 100644 --- a/src/main/java/train/client/gui/GuiLoco2.java +++ b/src/main/java/train/client/gui/GuiLoco2.java @@ -1,5 +1,7 @@ package train.client.gui; +import ebf.tim.gui.GUIButton; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.Entity; @@ -30,10 +32,14 @@ public class GuiLoco2 extends GuiContainer { private int buttonPosX = 0; private int buttonPosY = 0; + private InventoryPlayer player; + private GUIButton buttonSeatManager; + public GuiLoco2(InventoryPlayer inventoryplayer, Entity entityminecart) { super(new InventoryLoco(inventoryplayer, (Locomotive) entityminecart)); loco = (Locomotive) entityminecart; + player = inventoryplayer; } @Override @@ -89,6 +95,27 @@ public void initGui() { this.buttonList.add(this.buttonLock = new GuiButton(4, buttonPosX + 108, buttonPosY - 22, 67, 12, "Start Engine")); } } + if (loco.seats.size() > 1) { + this.buttonList.add(this.buttonSeatManager = new GUIButton(buttonPosX + 108, buttonPosY - 20, 67,10, "Seats") { + @Override + public String getHoverText() { + return "gui.seats"; + } + + @Override + public int[] getColor(){ + return null; + } + + @Override + public void onClick() { + Traincraft.proxy.seatGUI(player.player,loco); + } + + @Override + public FontRenderer getFont(){return fontRendererObj;} + }); + } } @Override @@ -150,6 +177,8 @@ protected void actionPerformed(GuiButton guibutton) { loco.isLocoTurnedOn = true; guibutton.displayString = "Stop Engine"; } + } else if (guibutton instanceof GUIButton) { + ((GUIButton)guibutton).onClick(); } } @@ -234,6 +263,11 @@ public void drawScreen(int mouseX, int mouseY, float par3) { } } } + for(Object guiButton: buttonList) { + if (guiButton instanceof GUIButton) { + ((GUIButton)guiButton).drawText(mouseX-(int)guiLeft,mouseY-(int)guiTop); + } + } } @Override diff --git a/src/main/java/train/client/gui/GuiTender.java b/src/main/java/train/client/gui/GuiTender.java index a941484fc..34e899edd 100644 --- a/src/main/java/train/client/gui/GuiTender.java +++ b/src/main/java/train/client/gui/GuiTender.java @@ -1,5 +1,7 @@ package train.client.gui; +import ebf.tim.gui.GUIButton; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.Entity; @@ -25,6 +27,8 @@ public class GuiTender extends GuiContainer { private final EntityPlayer player; private GuiButton buttonLock; + private GUIButton buttonSeatManager; + public GuiTender(EntityPlayer player, InventoryPlayer inventoryplayer, Entity entityminecart) { super(new InventoryTender(inventoryplayer, (Tender) entityminecart)); @@ -45,6 +49,27 @@ public void initGui() { } else { this.buttonList.add(this.buttonLock = new GuiButton(3, var1 + 130, var2 - 10, 43, 10, "Locked")); } + if (tender.seats.size() > 1) { + this.buttonList.add(this.buttonSeatManager = new GUIButton((int)guiLeft+166,(int)guiTop+166, 18,18) { + @Override + public String getHoverText() { + return "gui.seats"; + } + + @Override + public int[] getColor(){ + return null; + } + + @Override + public void onClick() { + Traincraft.proxy.seatGUI(player,tender); + } + + @Override + public FontRenderer getFont(){return fontRendererObj;} + }); + } } @Override @@ -85,6 +110,8 @@ protected void actionPerformed(GuiButton guibutton) { } else if (player != null) { player.addChatMessage(new ChatComponentText("You are not the owner")); } + } else if (guibutton instanceof GUIButton) { + ((GUIButton)guibutton).onClick(); } } diff --git a/src/main/java/train/client/render/models/blocks/ModelLeftParallelCurveTCTrack.java b/src/main/java/train/client/render/models/blocks/ModelLeftParallelCurveTCTrack.java index 57d285791..4673c864f 100644 --- a/src/main/java/train/client/render/models/blocks/ModelLeftParallelCurveTCTrack.java +++ b/src/main/java/train/client/render/models/blocks/ModelLeftParallelCurveTCTrack.java @@ -16,17 +16,21 @@ public class ModelLeftParallelCurveTCTrack extends ModelBase { private IModelCustom modelSmallLeftParallelCurve; private IModelCustom modelMediumLeftParallelCurve; private IModelCustom modelLargeLeftParallelCurve; + private IModelCustom model20x2SCurveLeft; public ModelLeftParallelCurveTCTrack() { modelSmallLeftParallelCurve = AdvancedModelLoader.loadModel(new ResourceLocation(Info.modelPrefix + "track_curve_parallel_s_left.obj")); modelMediumLeftParallelCurve = AdvancedModelLoader.loadModel(new ResourceLocation(Info.modelPrefix + "track_curve_parallel_m_left.obj")); modelLargeLeftParallelCurve = AdvancedModelLoader.loadModel(new ResourceLocation(Info.modelPrefix + "track_curve_parallel_l_left.obj")); + model20x2SCurveLeft = AdvancedModelLoader.loadModel(new ResourceLocation(Info.modelPrefix + "20x2_s_curve_left.obj")); } public void renderSmall() {modelSmallLeftParallelCurve.renderAll();} public void renderMedium() {modelMediumLeftParallelCurve.renderAll();} public void renderLarge() {modelLargeLeftParallelCurve.renderAll();} + public void render20x2() {model20x2SCurveLeft.renderAll();} + public void render(String type, String variant, TileTCRail tcRail, double x, double y, double z) { int facing = tcRail.getWorldObj().getBlockMetadata(tcRail.xCoord, tcRail.yCoord, tcRail.zCoord); render( type, variant, facing, x, y, z, 1, 1, 1, 1 ); @@ -76,6 +80,7 @@ public void render(String type,String variant,int facing, double x, double y, do if(type.equals("small"))this.renderSmall(); if(type.equals("medium"))this.renderMedium(); if(type.equals("large"))this.renderLarge(); + if(type.equals("20x2"))this.render20x2(); GL11.glPopMatrix(); } diff --git a/src/main/java/train/common/Traincraft.java b/src/main/java/train/common/Traincraft.java index bff375868..d4af6f076 100644 --- a/src/main/java/train/common/Traincraft.java +++ b/src/main/java/train/common/Traincraft.java @@ -14,7 +14,9 @@ import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.VillagerRegistry; +import cpw.mods.fml.relauncher.Side; import ebf.tim.entities.EntitySeat; +import ebf.tim.networking.PacketSeatUpdate; import ebf.tim.utility.DebugUtil; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemArmor.ArmorMaterial; @@ -207,6 +209,8 @@ public void init(FMLInitializationEvent event) { VillagerRegistry.instance().registerVillageCreationHandler(villageHandler); proxy.registerVillagerSkin(ConfigHandler.TRAINCRAFT_VILLAGER_ID, "station_chief.png"); VillagerRegistry.instance().registerVillageTradeHandler(ConfigHandler.TRAINCRAFT_VILLAGER_ID, villageHandler); + Traincraft.updateChannel.registerMessage(PacketSeatUpdate.Handler.class, PacketSeatUpdate.class, 8, Side.CLIENT); + Traincraft.updateChannel.registerMessage(PacketSeatUpdate.Handler.class, PacketSeatUpdate.class, 9, Side.SERVER); proxy.registerBookHandler(); diff --git a/src/main/java/train/common/api/EntityBogie.java b/src/main/java/train/common/api/EntityBogie.java index 7f2fe928c..78d68477f 100644 --- a/src/main/java/train/common/api/EntityBogie.java +++ b/src/main/java/train/common/api/EntityBogie.java @@ -863,6 +863,17 @@ private void moveOnTCSlope(int j, double cx, double cz, double slopeAngle, doubl double norm = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); double newPosY = Math.abs(j + (Math.tan(slopeAngle * Math.abs(cz - this.posZ))) + this.yOffset + 0.3); + if (this.isDerail) { + for (int i = -2; i< 3;i++) { + if (worldObj.getBlock((int) Math.round(cx), (int) Math.round(newPosY) + i, (int) Math.round(this.posZ)) instanceof BlockTCRail || + worldObj.getBlock((int) Math.round(cx), (int) Math.round(newPosY) + i, (int) Math.round(this.posZ)) instanceof BlockTCRailGag) { + if (Math.round(this.entityMainTrain.posY) == Math.round(this.posY)) { + newPosY += i + 1; + break; + } + } + } + } this.setPosition(cx + 0.5D, newPosY, this.posZ); this.boundingBox.offset(0, 0 , Math.copySign(norm, this.motionZ)); @@ -880,6 +891,17 @@ private void moveOnTCSlope(int j, double cx, double cz, double slopeAngle, doubl double norm = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); double newPosY = (j + (Math.tan(slopeAngle * Math.abs(cx - this.posX))) + this.yOffset + 0.3); + if (this.isDerail) { + for (int i = -2; i< 3;i++) { + if (worldObj.getBlock((int) Math.round(this.posX), (int) Math.round(newPosY) + i, (int) Math.round(cz)) instanceof BlockTCRail || + worldObj.getBlock((int) Math.round(this.posX), (int) Math.round(newPosY) + i, (int) Math.round(cz)) instanceof BlockTCRailGag) { + if (Math.round(this.entityMainTrain.posY) == Math.round(this.posY)) { + newPosY += i + 1; + break; + } + } + } + } this.setPosition(this.posX, newPosY, cz + 0.5D); this.boundingBox.offset(Math.copySign(norm, this.motionX), 0 ,0); diff --git a/src/main/java/train/common/api/EntityRollingStock.java b/src/main/java/train/common/api/EntityRollingStock.java index e0d43599d..d6320d705 100644 --- a/src/main/java/train/common/api/EntityRollingStock.java +++ b/src/main/java/train/common/api/EntityRollingStock.java @@ -41,7 +41,6 @@ import net.minecraftforge.event.entity.minecart.MinecartCollisionEvent; import net.minecraftforge.event.entity.minecart.MinecartInteractEvent; import net.minecraftforge.event.entity.minecart.MinecartUpdateEvent; -import org.lwjgl.input.Keyboard; import train.client.core.handlers.SoundUpdaterRollingStock; import train.common.Traincraft; import train.common.adminbook.ServerLogger; @@ -49,7 +48,6 @@ import train.common.blocks.BlockTCRailGag; import train.common.core.HandleOverheating; import train.common.core.handlers.*; -import train.common.core.network.PacketKeyPress; import train.common.core.network.PacketRollingStockRotation; import train.common.core.util.DepreciatedUtil; import train.common.core.util.TraincraftUtil; @@ -516,7 +514,7 @@ public float getPlayerScale() { /** * gets packet from server and distribute for GUI handles motion * - * @param i + * @param */ public boolean isLockedAndNotOwner() { if (this.getTrainLockedFromPacket()) { @@ -539,13 +537,14 @@ public void keyHandlerFromPacket(int i) { if (i == 7) { if (this instanceof AbstractWorkCart) { ((EntityPlayer) this.seats.get(0).getPassenger()).openGui(Traincraft.instance, GuiIDs.CRAFTING_CART, worldObj, (int) this.posX, (int) this.posY, (int) this.posZ); + } else if (this.seats.size() > 1 && this.getInventoryRows() == 0 && riddenByEntity != null && riddenByEntity instanceof EntityPlayer) { + ((EntityPlayer) riddenByEntity).openGui(Traincraft.instance, GuiIDs.SEAT_GUI, worldObj, (int) this.posX, (int) this.posY, (int) this.posZ); } } if (i == 9) { if (this instanceof AbstractWorkCart) { ((EntityPlayer) this.seats.get(0).getPassenger()).openGui(Traincraft.instance, GuiIDs.FURNACE_CART, worldObj, (int) this.posX, (int) this.posY, (int) this.posZ); } - } @@ -828,9 +827,9 @@ public void onUpdate() { prevPosY = posY; prevPosZ = posZ; - int i = MathHelper.floor_double(posX); - int j = MathHelper.floor_double(posY); - int k = MathHelper.floor_double(posZ); + int floor_posX = MathHelper.floor_double(posX); + int floor_posY = MathHelper.floor_double(posY); + int floor_posZ = MathHelper.floor_double(posZ); if (needsBogieUpdate) { if (bogieLoco != null) { @@ -853,15 +852,15 @@ public void onUpdate() { bogieLoco.updateDistance(); } - if (worldObj.isAirBlock(i, j, k)) { - j--; - } else if (isRailBlockAt(worldObj, i, j + 1, k) || worldObj.getBlock(i, j + 1, k) == BlockIDs.tcRail.block || worldObj.getBlock(i, j + 1, k) == BlockIDs.tcRailGag.block) { - j++; + if (worldObj.isAirBlock(floor_posX, floor_posY, floor_posZ)) { + floor_posY--; + } else if (isRailBlockAt(worldObj, floor_posX, floor_posY + 1, floor_posZ) || worldObj.getBlock(floor_posX, floor_posY + 1, floor_posZ) == BlockIDs.tcRail.block || worldObj.getBlock(floor_posX, floor_posY + 1, floor_posZ) == BlockIDs.tcRailGag.block) { + floor_posY++; } - l = worldObj.getBlock(i, j, k); + l = worldObj.getBlock(floor_posX, floor_posY, floor_posZ); - updateOnTrack(i, j, k, l); + updateOnTrack(floor_posX, floor_posY, floor_posZ, l); updateTicks++; @@ -969,7 +968,7 @@ public void onUpdate() { linkhandler.handleStake(this, boundingBox); collisionhandler.handleCollisions(this, boundingBox); this.func_145775_I(); - MinecraftForge.EVENT_BUS.post(new MinecartUpdateEvent(this, i, j, k)); + MinecraftForge.EVENT_BUS.post(new MinecartUpdateEvent(this, floor_posX, floor_posY, floor_posZ)); //setBoundingBoxSmall(posX, posY, posZ, 0.98F, 0.7F); numLaps++; if ((this instanceof Locomotive) && (this.Link1 == 0) && (this.Link2 == 0) && numLaps > 700) { @@ -1009,50 +1008,50 @@ public void onUpdate() { boolean flag, flag1; - private void updateOnTrack(int i, int j, int k, Block l) { - if (canUseRail() && BlockRailBase.func_150051_a(l)) { + private void updateOnTrack(int floor_posX, int floor_posY, int floor_posZ, Block block) { //vanilla rails + if (canUseRail() && BlockRailBase.func_150051_a(block)) { Vec3 vec3d = TraincraftUtil.func_514_g(posX, posY, posZ); - int i1 = ((BlockRailBase) l).getBasicRailMetadata(worldObj, this, i, j, k); - meta = i1; - posY = j; + int blockMeta = ((BlockRailBase) block).getBasicRailMetadata(worldObj, this, floor_posX, floor_posY, floor_posZ); + meta = blockMeta; + posY = floor_posY; flag = false; - flag1 = l == Blocks.golden_rail; - if (l == Blocks.golden_rail) { - flag = worldObj.getBlockMetadata(i, j, k) > 2; - if (i1 == 8) { - i1 = 0; - } else if (i1 == 9) { - i1 = 1; + flag1 = block == Blocks.golden_rail; + if (flag1) { + flag = worldObj.getBlockMetadata(floor_posX, floor_posY, floor_posZ) > 2; + if (blockMeta == 8) { + blockMeta = 0; + } else if (blockMeta == 9) { + blockMeta = 1; } } - if (l == Blocks.detector_rail) { - worldObj.setBlockMetadataWithNotify(i, j, k, meta | 8, 3); - worldObj.notifyBlocksOfNeighborChange(i, j, k, l); - worldObj.notifyBlocksOfNeighborChange(i, j - 1, k, l); - worldObj.markBlockRangeForRenderUpdate(i, j, k, i, j, k); - worldObj.scheduleBlockUpdate(i, j, k, l, l.tickRate(worldObj)); + if (block == Blocks.detector_rail) { + worldObj.setBlockMetadataWithNotify(floor_posX, floor_posY, floor_posZ, meta | 8, 3); + worldObj.notifyBlocksOfNeighborChange(floor_posX, floor_posY, floor_posZ, block); + worldObj.notifyBlocksOfNeighborChange(floor_posX, floor_posY - 1, floor_posZ, block); + worldObj.markBlockRangeForRenderUpdate(floor_posX, floor_posY, floor_posZ, floor_posX, floor_posY, floor_posZ); + worldObj.scheduleBlockUpdate(floor_posX, floor_posY, floor_posZ, block, block.tickRate(worldObj)); } - if (i1 >= 2 && i1 <= 5) { - posY = (j + 1); + if (blockMeta >= 2 && blockMeta <= 5) { + posY = (floor_posY + 1); } - adjustSlopeVelocities(i1); + adjustSlopeVelocities(blockMeta); - int ai[][] = matrix[i1]; - double d9 = ai[1][0] - ai[0][0]; - double d10 = ai[1][2] - ai[0][2]; - double d11 = Math.sqrt(d9 * d9 + d10 * d10); + int[][] metaMatrix = matrix[blockMeta]; + double d9 = metaMatrix[1][0] - metaMatrix[0][0]; + double d10 = metaMatrix[1][2] - metaMatrix[0][2]; + double d11 = Math.sqrt(d9 * d9 + d10 * d10); //something normalized if (motionX * d9 + motionZ * d10 < 0.0D) { d9 = -d9; d10 = -d10; } - double d13 = Math.sqrt(motionX * motionX + motionZ * motionZ); - motionX = (d13 * d9) / d11; - motionZ = (d13 * d10) / d11; + double motionNormalized = Math.sqrt(motionX * motionX + motionZ * motionZ); + motionX = (motionNormalized * d9) / d11; + motionZ = (motionNormalized * d10) / d11; if (flag1 && !flag && shouldDoRailFunctions()) { if (Math.sqrt(motionX * motionX + motionZ * motionZ) < 0.029999999999999999D) { motionX = 0.0D; @@ -1064,19 +1063,19 @@ private void updateOnTrack(int i, int j, int k, Block l) { motionZ *= 0.5D; } } - double d17 = 0.0D; - double d18 = i + 0.5D + ai[0][0] * 0.5D; - double d19 = k + 0.5D + ai[0][2] * 0.5D; - double d20 = i + 0.5D + ai[1][0] * 0.5D; - double d21 = k + 0.5D + ai[1][2] * 0.5D; + double d17; + double d18 = floor_posX + 0.5D + metaMatrix[0][0] * 0.5D; + double d19 = floor_posZ + 0.5D + metaMatrix[0][2] * 0.5D; + double d20 = floor_posX + 0.5D + metaMatrix[1][0] * 0.5D; + double d21 = floor_posZ + 0.5D + metaMatrix[1][2] * 0.5D; d9 = d20 - d18; d10 = d21 - d19; if (d9 == 0.0D) { - posX = i + 0.5D; - d17 = posZ - k; + posX = floor_posX + 0.5D; + d17 = posZ - floor_posZ; } else if (d10 == 0.0D) { - posZ = k + 0.5D; - d17 = posX - i; + posZ = floor_posZ + 0.5D; + d17 = posX - floor_posX; } else { double d22 = posX - d18; double d24 = posZ - d19; @@ -1092,7 +1091,7 @@ private void updateOnTrack(int i, int j, int k, Block l) { /** * Handles derail */ - if ((this instanceof Locomotive || this instanceof ISecondBogie) && d13 > derailSpeed && i1 >= 6) { + if ((this instanceof Locomotive || this instanceof ISecondBogie) && motionNormalized > derailSpeed && blockMeta >= 6) { if (d9 > 0 && d10 < 0) { d10 = 0; d9 += 2; @@ -1119,14 +1118,14 @@ private void updateOnTrack(int i, int j, int k, Block l) { posZ = d19 + d10 * d17; setPosition(posX, posY + yOffset + 0.35, posZ); - moveMinecartOnRail(i, j, k, 0.0D); + moveMinecartOnRail(floor_posX, floor_posY, floor_posZ, 0.0D); - if (ai[0][1] != 0 && MathHelper.floor_double(posX) - i == ai[0][0] && - MathHelper.floor_double(posZ) - k == ai[0][2]) { - setPosition(posX, posY + ai[0][1], posZ); - } else if (ai[1][1] != 0 && MathHelper.floor_double(posX) - i == ai[1][0] && - MathHelper.floor_double(posZ) - k == ai[1][2]) { - setPosition(posX, posY + ai[1][1], posZ); + if (metaMatrix[0][1] != 0 && MathHelper.floor_double(posX) - floor_posX == metaMatrix[0][0] && + MathHelper.floor_double(posZ) - floor_posZ == metaMatrix[0][2]) { + setPosition(posX, posY + metaMatrix[0][1], posZ); + } else if (metaMatrix[1][1] != 0 && MathHelper.floor_double(posX) - floor_posX == metaMatrix[1][0] && + MathHelper.floor_double(posZ) - floor_posZ == metaMatrix[1][2]) { + setPosition(posX, posY + metaMatrix[1][1], posZ); } applyDragAndPushForces(); @@ -1140,16 +1139,16 @@ private void updateOnTrack(int i, int j, int k, Block l) { motionZ = (motionZ / d14) * (d14 + d28); } setPosition(posX, posY + yOffset - 0.8d, posZ); - int k1 = MathHelper.floor_double(posX); - int l1 = MathHelper.floor_double(posZ); - if (k1 != i || l1 != k) { + int entity_floor_posX = MathHelper.floor_double(posX); + int entity_floor_posZ = MathHelper.floor_double(posZ); + if (entity_floor_posX != floor_posX || entity_floor_posZ != floor_posZ) { double d15 = Math.sqrt(motionX * motionX + motionZ * motionZ); - motionX = d15 * (k1 - i); - motionZ = d15 * (l1 - k); + motionX = d15 * (entity_floor_posX - floor_posX); + motionZ = d15 * (entity_floor_posZ - floor_posZ); } if (shouldDoRailFunctions()) { - ((BlockRailBase) l).onMinecartPass(worldObj, this, i, j, k); + ((BlockRailBase) block).onMinecartPass(worldObj, this, floor_posX, floor_posY, floor_posZ); } if (flag && shouldDoRailFunctions()) { @@ -1157,28 +1156,28 @@ private void updateOnTrack(int i, int j, int k, Block l) { if (d31 > 0.01D) { motionX += (motionX / d31) * 0.059999999999999998D; motionZ += (motionZ / d31) * 0.059999999999999998D; - } else if (i1 == 1) { - if (worldObj.isBlockNormalCubeDefault(i - 1, j, k, false)) { + } else if (blockMeta == 1) { + if (worldObj.isBlockNormalCubeDefault(floor_posX - 1, floor_posY, floor_posZ, false)) { motionX = 0.02D; - } else if (worldObj.isBlockNormalCubeDefault(i + 1, j, k, false)) { + } else if (worldObj.isBlockNormalCubeDefault(floor_posX + 1, floor_posY, floor_posZ, false)) { motionX = -0.02D; } - } else if (i1 == 0) { - if (worldObj.isBlockNormalCubeDefault(i, j, k - 1, false)) { + } else if (blockMeta == 0) { + if (worldObj.isBlockNormalCubeDefault(floor_posX, floor_posY, floor_posZ - 1, false)) { motionZ = 0.02D; - } else if (worldObj.isBlockNormalCubeDefault(i, j, k + 1, false)) { + } else if (worldObj.isBlockNormalCubeDefault(floor_posX, floor_posY, floor_posZ + 1, false)) { motionZ = -0.02D; } } } - } else if (l == BlockIDs.tcRail.block) { + } else if (block == BlockIDs.tcRail.block) { limitSpeedOnTCRail(); //if(worldObj.getTileEntity(i,j,k)==null || !(worldObj.getTileEntity(i,j,k) instanceof TileTCRail))return; - TileTCRail tile = (TileTCRail) worldObj.getTileEntity(i, j, k); + TileTCRail tile = (TileTCRail) worldObj.getTileEntity(floor_posX, floor_posY, floor_posZ); int meta = tile.getBlockMetadata(); if (TCRailTypes.isStraightTrack(tile) || (TCRailTypes.isSwitchTrack(tile) && !tile.getSwitchState())) { - moveOnTCStraight(i, j, k, tile.xCoord, tile.zCoord, meta); + moveOnTCStraight(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.zCoord, meta); } else if (TCRailTypes.isTurnTrack(tile) || (TCRailTypes.isSwitchTrack(tile) && tile.getSwitchState())) { if (bogieLoco != null) { if (!bogieLoco.isOnRail()) { @@ -1187,57 +1186,57 @@ private void updateOnTrack(int i, int j, int k, Block l) { } if (derailSpeed == 0) { this.unLink(); - moveOnTCStraight(i, j, k, tile.xCoord, tile.zCoord, meta); + moveOnTCStraight(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.zCoord, meta); } else { - if (shouldIgnoreSwitch(tile, i, j, k, meta)) { + if (shouldIgnoreSwitch(tile, floor_posX, floor_posY, floor_posZ, meta)) { - moveOnTCStraight(i, j, k, tile.xCoord, tile.zCoord, meta); + moveOnTCStraight(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.zCoord, meta); } else { if (TCRailTypes.isTurnTrack(tile) || (TCRailTypes.isSwitchTrack(tile) && tile.getSwitchState())) - moveOnTC90TurnRail(i, j, k, tile.r, tile.cx, tile.cz); + moveOnTC90TurnRail(floor_posX, floor_posY, floor_posZ, tile.r, tile.cx, tile.cz); } // shouldIgnoreSwitch(tile, i, j, k, meta); // if (ItemTCRail.isTCTurnTrack(tile)) moveOnTC90TurnRail(i, j, k, r, cx, cy, // cz, tile.getType(), meta); } } else if (TCRailTypes.isSlopeTrack(tile)) { - moveOnTCSlope(j, tile.xCoord, tile.zCoord, tile.slopeAngle, tile.slopeHeight, meta); + moveOnTCSlope(floor_posY, tile.xCoord, tile.zCoord, tile.slopeAngle, tile.slopeHeight, meta); } else if (TCRailTypes.isCrossingTrack(tile)) { - moveOnTCTwoWaysCrossing(i, j, k, tile.xCoord, tile.yCoord, tile.zCoord, meta); + moveOnTCTwoWaysCrossing(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.yCoord, tile.zCoord, meta); } else if (TCRailTypes.isDiagonalCrossingTrack(tile)) { - moveOnTCDiamondCrossing(i, j, k, tile.xCoord, tile.yCoord, tile.zCoord, meta); + moveOnTCDiamondCrossing(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.yCoord, tile.zCoord, meta); } else if (TCRailTypes.isDiagonalTrack(tile)) { - moveOnTCDiagonal(i, j, k, tile.xCoord, tile.zCoord, tile.getBlockMetadata(), tile.getRailLength()); + moveOnTCDiagonal(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.zCoord, tile.getBlockMetadata(), tile.getRailLength()); } else if (TCRailTypes.isCurvedSlopeTrack(tile)) { - moveOnTCCurvedSlope(i, j, k, tile.r, tile.cx, tile.cz, tile.xCoord, tile.zCoord, meta, 1, tile.slopeAngle); + moveOnTCCurvedSlope(floor_posX, floor_posY, floor_posZ, tile.r, tile.cx, tile.cz, tile.xCoord, tile.zCoord, meta, 1, tile.slopeAngle); } - } else if (l == BlockIDs.tcRailGag.block) { + } else if (block == BlockIDs.tcRailGag.block) { limitSpeedOnTCRail(); - TileTCRailGag tileGag = (TileTCRailGag) worldObj.getTileEntity(i, j, k); + TileTCRailGag tileGag = (TileTCRailGag) worldObj.getTileEntity(floor_posX, floor_posY, floor_posZ); if (worldObj.getTileEntity(tileGag.originX, tileGag.originY, tileGag.originZ) instanceof TileTCRail) { TileTCRail tile = (TileTCRail) worldObj.getTileEntity(tileGag.originX, tileGag.originY, tileGag.originZ); if (TCRailTypes.isTurnTrack(tile)) { - moveOnTC90TurnRail(i, j, k, tile.r, tile.cx, tile.cz); + moveOnTC90TurnRail(floor_posX, floor_posY, floor_posZ, tile.r, tile.cx, tile.cz); } if (TCRailTypes.isStraightTrack(tile)) { - moveOnTCStraight(i, j, k, tile.xCoord, tile.zCoord, tile.getBlockMetadata()); + moveOnTCStraight(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.zCoord, tile.getBlockMetadata()); } if (TCRailTypes.isSlopeTrack(tile)) { - moveOnTCSlope(j, tile.xCoord, tile.zCoord, tile.slopeAngle, tile.slopeHeight, tile.getBlockMetadata()); + moveOnTCSlope(floor_posY, tile.xCoord, tile.zCoord, tile.slopeAngle, tile.slopeHeight, tile.getBlockMetadata()); } if (TCRailTypes.isDiagonalTrack(tile)) { - moveOnTCDiagonal(i, j, k, tile.xCoord, tile.zCoord, tile.getBlockMetadata(), tile.getRailLength()); + moveOnTCDiagonal(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.zCoord, tile.getBlockMetadata(), tile.getRailLength()); } else if (TCRailTypes.isDiagonalCrossingTrack(tile)) { - moveOnTCDiamondCrossing(i, j, k, tile.xCoord, tile.yCoord, tile.zCoord, meta); + moveOnTCDiamondCrossing(floor_posX, floor_posY, floor_posZ, tile.xCoord, tile.yCoord, tile.zCoord, meta); } if (TCRailTypes.isCurvedSlopeTrack(tile)) { - moveOnTCCurvedSlope(i, j, k, tile.r, tile.cx, tile.cz, tile.xCoord, tile.zCoord, tile.getBlockMetadata(), 1, tile.slopeAngle); + moveOnTCCurvedSlope(floor_posX, floor_posY, floor_posZ, tile.r, tile.cx, tile.cz, tile.xCoord, tile.zCoord, tile.getBlockMetadata(), 1, tile.slopeAngle); } } } else { - //moveMinecartOffRail(i,j,k); + moveMinecartOffRail(floor_posX,floor_posY,floor_posZ); super.onUpdate(); } @@ -1442,74 +1441,92 @@ private void moveOnTCStraight(int i, int j, int k, double cx, double cz, int met } } - private void moveOnTCSlope(int j, double cx, double cz, double slopeAngle, double slopeHeight, int meta) { - //posY = j + 2.5; - if (meta == 2 || meta == 0) { - - if (meta == 2) { - cz += 1; + private int numCarsOnSlope() { + int count = 0; + for(EntityRollingStock entity: train.getTrains()) { + int floorX = (int) Math.floor(entity.posX); + int floorY = (int) Math.floor(entity.posY); + int floorZ = (int) Math.floor(entity.posZ); + Block block = worldObj.getBlock(floorX, floorY, floorZ); + TileTCRail tile = null; + if (block instanceof BlockAir) { + floorY--; + block = worldObj.getBlock(floorX, floorY, floorZ); } - - double norm = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); - this.setPosition(cx + 0.5D, Math.abs(j + (Math.tan(slopeAngle * Math.abs(cz - this.posZ))) + this.yOffset + 0.3), this.posZ); - this.boundingBox.offset(0, 0, Math.copySign(norm, this.motionZ)); - this.posX = (this.boundingBox.minX + this.boundingBox.maxX) / 2.0D; - this.posY = this.boundingBox.minY + (double) this.yOffset - (double) this.ySize; - this.posZ = (this.boundingBox.minZ + this.boundingBox.maxZ) / 2.0D; - - if (!(this instanceof Locomotive) && !(this instanceof EntityTracksBuilder)) { - if ((this.posY - this.prevPosY) < 0) { - norm *= 1.02; - } else if ((this.posY - this.prevPosY) > 0) { - norm *= 0.98; - } - if (norm < 0.01) { - - if ((motionZ) < 0 && meta == 2) { - norm += 0.0001; - motionZ = Math.copySign(motionZ, 1); - } - if ((motionZ) > 0 && meta == 0) { - norm += 0.0001; - motionZ = Math.copySign(motionZ, -1); - } + if (block instanceof BlockTCRail) { + tile = (TileTCRail) worldObj.getTileEntity(floorX, floorY, floorZ); + } else if (block instanceof BlockTCRailGag) { + TileTCRailGag tileGag = (TileTCRailGag) worldObj.getTileEntity(floorX, floorY, floorZ); + if (worldObj.getTileEntity(tileGag.originX, tileGag.originY, tileGag.originZ) instanceof TileTCRail) { + tile = (TileTCRail) worldObj.getTileEntity(tileGag.originX, tileGag.originY, tileGag.originZ); } } - - this.motionX = 0.0D; - this.motionY = 0.0D; - this.motionZ = Math.copySign(norm, this.motionZ); - } else if (meta == 1 || meta == 3) { - if (meta == 1) { - cx += 1; + if (tile != null && tile.slopeAngle != 0) { + count++; } + } + return count; + } - double norm = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); - this.setPosition(this.posX, (j + (Math.tan(slopeAngle * Math.abs(cx - this.posX))) + this.yOffset + 0.3), cz + 0.5D); - this.boundingBox.offset(Math.copySign(norm, this.motionX), 0, 0); - this.posX = (this.boundingBox.minX + this.boundingBox.maxX) / 2.0D; - this.posY = this.boundingBox.minY + (double) this.yOffset - (double) this.ySize; - this.posZ = (this.boundingBox.minZ + this.boundingBox.maxZ) / 2.0D; + private int numCarsTotal() { + return train.getTrains().size(); + } - if (!(this instanceof Locomotive) && !(this instanceof EntityTracksBuilder)) { - if ((this.posY - this.prevPosY) < 0) { - norm *= 1.02; - } else if ((this.posY - this.prevPosY) > 0) { - norm *= 0.98; - } - if (norm < 0.01) { + private boolean hasLocomotive() { + return (train.getTrainPower() != 0); + } - if ((motionX) < 0 && meta == 1) { - norm += 0.0001; - motionX = Math.copySign(motionX, 1); - } - if ((motionX) > 0 && meta == 3) { - norm += 0.0001; - motionX = Math.copySign(motionX, -1); + private void moveOnTCSlope(int posY, double posX, double posZ, double slopeAngle, double slopeHeight, int meta) { + //posY = j + 2.5; + + if (meta == 2) { + posZ ++; + } + if (meta == 1) { + posX ++; + } + double normalizedSpeed = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); + + if (meta == 2 || meta == 0) { + this.setPosition(posX + 0.5D, Math.abs(posY + (Math.tan(slopeAngle * Math.abs(posZ - this.posZ))) + this.yOffset + 0.3), this.posZ); + this.boundingBox.offset(0, 0, Math.copySign(normalizedSpeed, this.motionZ)); + } + else if (meta == 1 || meta == 3) { + this.setPosition(this.posX, (posY + (Math.tan(slopeAngle * Math.abs(posX - this.posX))) + this.yOffset + 0.3), posZ + 0.5D); + this.boundingBox.offset(Math.copySign(normalizedSpeed, this.motionX), 0, 0); + } else { + return; + } + this.posX = (this.boundingBox.minX + this.boundingBox.maxX) / 2.0D; + this.posY = this.boundingBox.minY + (double) this.yOffset - (double) this.ySize; + this.posZ = (this.boundingBox.minZ + this.boundingBox.maxZ) / 2.0D; + if (this instanceof Locomotive && !((Locomotive) this).canBePulled) { //make this speedup only happen twice a second + if (this.ticksExisted % 10 == 0) { + int carsPulled = numCarsTotal(); + carsPulled--; //locomotive counting as two entities? + int carsOnSlope = numCarsOnSlope(); + if ((this.posY - this.prevPosY < 0)) { + normalizedSpeed *= (((double) carsOnSlope / carsPulled) * (slopeAngle)) + getDragAir(); + } else if ((this.posY - this.prevPosY) > 0.013) {//0.013 to account for the jank that happens when over slopes back to back. + normalizedSpeed *= 1 - (((double) carsOnSlope / carsPulled) * slopeAngle); + if (normalizedSpeed - 0.001 <= 0) { + normalizedSpeed = -0.001; } } } - this.motionX = Math.copySign(norm, this.motionX); + } else if (!hasLocomotive()) { //traincars. is a bit jumpy but doesn't seem to derail + if ((this.posY - this.prevPosY) < 0) { + normalizedSpeed *= 1 + (slopeAngle * 2); + } else if ((this.posY - this.prevPosY) > 0.013) { + normalizedSpeed *= (0.98 - (slopeAngle)); + } + } + if (meta == 2 || meta == 0) { + this.motionX = 0.0D; + this.motionY = 0.0D; + this.motionZ = Math.copySign(normalizedSpeed, this.motionZ); + } else { + this.motionX = Math.copySign(normalizedSpeed, this.motionX); this.motionY = 0.0D; this.motionZ = 0.0D; } @@ -2260,7 +2277,7 @@ protected void applyDragAndPushForces() { */ @Override public double getDragAir() { - return 0.98D; + return 0.9998D; } @Override diff --git a/src/main/java/train/common/api/Locomotive.java b/src/main/java/train/common/api/Locomotive.java index 817962022..6b2c64ca5 100644 --- a/src/main/java/train/common/api/Locomotive.java +++ b/src/main/java/train/common/api/Locomotive.java @@ -9,6 +9,7 @@ import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import ebf.tim.entities.EntitySeat; import io.netty.buffer.ByteBuf; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; @@ -58,7 +59,6 @@ public abstract class Locomotive extends EntityRollingStock implements IInventor private boolean backwardPressed = false; public boolean brakePressed = false; - public int speedLimit = 0; public String trainLevel = "1"; public int mtcStatus = 0; @@ -477,8 +477,16 @@ public void keyHandlerFromPacket(int i) { } if (i == 7) { - if (seats.size() != 0) - ((EntityPlayer) seats.get(0).getPassenger()).openGui(Traincraft.instance, GuiIDs.LOCO, worldObj, (int) this.posX, (int) this.posY, (int) this.posZ); + if (seats != null && seats.size() != 0) { + for(EntitySeat seat: seats) { + if(seat.isControlSeat() && seat.getPassenger() != null && playerEntity == seat.getPassenger()) { + ((EntityPlayer) seat.getPassenger()).openGui(Traincraft.instance, GuiIDs.LOCO, worldObj, (int) this.posX, (int) this.posY, (int) this.posZ); + break; + } else if (seat.getPassenger() != null && seat.getPassenger() instanceof EntityPlayer) { + Traincraft.proxy.seatGUI((EntityPlayer) seat.getPassenger(),this); + } + } + } } if (i == 12) { diff --git a/src/main/java/train/common/core/CommonProxy.java b/src/main/java/train/common/core/CommonProxy.java index 96329a1de..28840dfc5 100644 --- a/src/main/java/train/common/core/CommonProxy.java +++ b/src/main/java/train/common/core/CommonProxy.java @@ -6,6 +6,7 @@ import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.registry.GameRegistry; import ebf.tim.entities.EntitySeat; +import ebf.tim.gui.GUISeatManager; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.Entity; @@ -211,6 +212,10 @@ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int return entity1 instanceof EntityTracksBuilder ? new InventoryBuilder(player.inventory, (EntityTracksBuilder) entity1) : null; case (GuiIDs.LIQUID): return entity1 instanceof LiquidTank ? new InventoryLiquid(player.inventory, (LiquidTank) entity1) : null; + case (GuiIDs.SEAT_GUI): + if (entity instanceof EntityRollingStock) { + return riddenByEntity != null ? new GUISeatManager(player, (EntityRollingStock)entity) : null; //#!#doesn't work for whatever reason + } /*case (GuiIDs.FORTY_FOOT_CONTAINER): return new ContainerStorage((TileFortyFootContainer)te, player);*/ @@ -291,6 +296,9 @@ public void setHook() { } + public void seatGUI(EntityPlayer player, EntityRollingStock transport) { } + + public Object getTESR(){return null;} public Object getEntityRender(){return null;} public Object getNullRender(){return null;} diff --git a/src/main/java/train/common/library/GuiIDs.java b/src/main/java/train/common/library/GuiIDs.java index 64168d150..7099dea0e 100644 --- a/src/main/java/train/common/library/GuiIDs.java +++ b/src/main/java/train/common/library/GuiIDs.java @@ -28,4 +28,5 @@ public class GuiIDs { public static final int PAINTBRUSH = 106; public static final int FIXED_OVERLAY = 107; public static final int DYNAMIC_OVERLAY = 108; + public static final int SEAT_GUI = 109; } \ No newline at end of file