Skip to content

Commit

Permalink
major bugfixes
Browse files Browse the repository at this point in the history
- Fixed porting issues from new features in the 1.7 branch.
- Fixed a couple crashes.
- Hearth Furnace GUI opens.
- Fixed player collisions with blocks.
- Fixed trains and stock not moving.

Shout out to my manager, "S" for the inspiration to keep a fire lit.
  • Loading branch information
EternalBlueFlame committed Sep 12, 2023
1 parent 20241b4 commit 9d1ca7b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 58 deletions.
9 changes: 6 additions & 3 deletions src/main/java/ebf/tim/blocks/BlockDynamic.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import depreciated.minecraft.util.IIcon;
import ebf.tim.TrainsInMotion;
import ebf.tim.utility.CommonUtil;
import ebf.tim.utility.DebugUtil;
import ebf.tim.utility.TransportSlotManager;
import fexcraft.tmt.slim.ModelBase;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -114,13 +115,15 @@ public TileEntity createNewTileEntity(World world, int meta) {

//@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
return new AxisAlignedBB((double)x + hitboxShape()[0], (double)y + hitboxShape()[1], (double)z + hitboxShape()[2],
(double)x + hitboxShape()[3], (double)y + hitboxShape()[4], (double)z + hitboxShape()[5]);
return new AxisAlignedBB((double)hitboxShape()[0], (double)hitboxShape()[1], (double)hitboxShape()[2],
(double)hitboxShape()[3], (double)hitboxShape()[4], (double)hitboxShape()[5]).offset(x,y,z);
}
@Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState) {
//this.setBlockBoundsBasedOnState(world, x, y, z);
collidingBoxes.add(this.getCollisionBoundingBoxFromPool(world, pos.getX(),pos.getY(),pos.getZ()));
if (entityBox.intersects(this.getCollisionBoundingBoxFromPool(world, pos.getX(), pos.getY(), pos.getZ()))) {
collidingBoxes.add(this.getCollisionBoundingBoxFromPool(world, pos.getX(), pos.getY(), pos.getZ()));
}
}
@Override
public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/ebf/tim/entities/EntitySeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public void writeSpawnData(ByteBuf buffer) {
}

@Override
public void updateRiderPosition() {
if (this.getPassenger() != null) {
this.getPassenger().setPosition(this.posX, this.posY+(getWorld().isRemote?(this.getPassenger()==Minecraft.getMinecraft().thePlayer?0.4:-1.3):-1.5), this.posZ);
public void updatePassenger(Entity passenger) {
if (this.isPassenger(passenger)) {
passenger.setPosition(this.posX, this.posY+(getWorld().isRemote?(passenger==Minecraft.getMinecraft().player?0.4:-1.3):-1.5), this.posZ);
}
}

Expand All @@ -158,6 +158,10 @@ public void addPassenger(Entity passenger) {
super.addPassenger(passenger);
}

@Override
public void removePassenger(Entity passenger) {
super.removePassenger(passenger);
}

public boolean isControlSeat(){return controller;}
public boolean isLocoControlSeat(){return controller && locomotive;}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/ebf/tim/entities/GenericRailTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,18 +412,18 @@ public AxisAlignedBB getCollisionBox(Entity collidedWith){
public boolean canBeCollidedWith() {return true;}
/**client only positioning of the transport, this should help to smooth the movement*/
@SideOnly(Side.CLIENT)
public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double p_70056_5_, float p_70056_7_, float p_70056_8_, int p_70056_9_) {
public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport){
if (backBogie !=null && frontBogie != null){

setRotation(CommonUtil.atan2degreesf(
backBogie.posZ - frontBogie.posZ,
backBogie.posX - frontBogie.posX),
CommonUtil.calculatePitch(backBogie.posY, frontBogie.posY,Math.abs(rotationPoints()[0]) + Math.abs(rotationPoints()[1])));

transportX=p_70056_1_;
transportY=p_70056_3_;
transportZ=p_70056_5_;
tickOffset = p_70056_9_+2;
transportX=x;
transportY=y;
transportZ=z;
tickOffset = posRotationIncrements+2;

//handle bogie rotations
if(renderData!=null && renderData.bogies!=null){
Expand All @@ -446,7 +446,7 @@ public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double
}
}
}else {
this.setPosition(p_70056_1_, p_70056_3_, p_70056_5_);
this.setPosition(x, y, z);
}
}

Expand Down Expand Up @@ -1171,6 +1171,10 @@ public void onUpdate() {
prevPosX = posX;
prevPosZ = posZ;
if(tickOffset >0) {

cachedVectors[1] = new Vec3f(-rotationPoints()[0], 0, 0).rotatePoint(0, rotationYaw, 0)
.addVector(backBogie.posX,backBogie.posY,backBogie.posZ);
setPosition(cachedVectors[1].xCoord, cachedVectors[1].yCoord,cachedVectors[1].zCoord);
setPosition(
this.posX + (this.transportX - this.posX) / (double) this.tickOffset,
this.posY + (this.transportY - this.posY) / (double) this.tickOffset,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ebf/tim/gui/GUIPaintBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void onClick() {

@Override
public FontRenderer getFont() {
return fontRendererObj;
return fontRenderer;
}
}
);
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/ebf/tim/gui/GUISeatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public void drawScreen(int parWidth, int parHeight, float p_73863_3_) {
this.drawDefaultBackground();
super.drawScreen(parWidth, parHeight, p_73863_3_);
locations = new ArrayList<>();
guiLeft=new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaledWidth();
guiTop=new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaledHeight();
guiLeft=new ScaledResolution(Minecraft.getMinecraft()).getScaledWidth();
guiTop=new ScaledResolution(Minecraft.getMinecraft()).getScaledHeight();

if (entity.getRiderOffsets().length==0 || entity.getRiderOffsets() == null){
return;
}
for(EntitySeat seat : entity.seats) {
if (seat.getPassenger() != null) {
if (seat.getPassenger() == Minecraft.getMinecraft().thePlayer) {
if (seat.getPassenger() == Minecraft.getMinecraft().player) {
currentSeat = seat;
}
filledSeatIDs.add(seat.getEntityId());
Expand Down Expand Up @@ -93,24 +93,24 @@ public void defineButtons(){
column++;
activeRow=0;
}
int width = fontRendererObj.getStringWidth("Empty Seat") + 6;
int width = fontRenderer.getStringWidth("Empty Seat") + 6;
if (entity.seats.get(i).getPassenger() instanceof EntityPlayer) {

if (fontRendererObj.getStringWidth(entity.seats.get(i).getPassenger().getCommandSenderName()) > width) {
width = fontRendererObj.getStringWidth(entity.seats.get(i).getPassenger().getCommandSenderName()) + 7;
if (fontRenderer.getStringWidth(entity.seats.get(i).getPassenger().getName()) > width) {
width = fontRenderer.getStringWidth(entity.seats.get(i).getPassenger().getName()) + 7;
if(width%2 !=0)
width++;
}
buttonList.add(
new GUIButton(percentLeft(50)-60-(totalColumns/2)+(column*120)-(width/2), percentTop(25)+(28*activeRow+1)-11, width,20,entity.seats.get(i).getPassenger().getCommandSenderName()) {
new GUIButton(percentLeft(50)-60-(totalColumns/2)+(column*120)-(width/2), percentTop(25)+(28*activeRow+1)-11, width,20,entity.seats.get(i).getPassenger().getName()) {
@Override
public String getHoverText() {
return "Seat is currently occupied";
}
@Override
public void onClick() {}
@Override
public FontRenderer getFont(){return fontRendererObj;}
public FontRenderer getFont(){return fontRenderer;}
}
);
} else { //TODO: add an else if for things that aren't players. this becomes important for stuff like stock cars or putting villagers in player seats
Expand All @@ -126,15 +126,15 @@ public void onClick() {

}
@Override
public FontRenderer getFont(){return fontRendererObj;}
public FontRenderer getFont(){return fontRenderer;}
}
);
}
locations.add(new Vector2f(percentLeft(50)-88-(totalColumns/2)+(column*120)-(width/2),percentTop(25)+(28*activeRow+1)-13));
activeRow++;
}
buttonList.add(
new GUIButton( percentLeft(50)-((fontRendererObj.getStringWidth("Close")+7)/2), percentTop(75)-10, fontRendererObj.getStringWidth("Close")+7,20,"Close") {
new GUIButton( percentLeft(50)-((fontRenderer.getStringWidth("Close")+7)/2), percentTop(75)-10, fontRenderer.getStringWidth("Close")+7,20,"Close") {
@Override
public String getHoverText() {
return "Close Inventory";
Expand All @@ -144,7 +144,7 @@ public void onClick() {
mc.displayGuiScreen(null);
}
@Override
public FontRenderer getFont(){return fontRendererObj;}
public FontRenderer getFont(){return fontRenderer;}
}
);
break;
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/ebf/tim/gui/GUITransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void onClick() {
@Override
public FontRenderer getFont(){return fontRenderer;}
});
if (transport.getRiderOffsets().length > 0 || transport.getRiderOffsets() != null) {
if (transport.getRiderOffsets() != null && transport.getRiderOffsets().length > 0) {
this.buttons.add(new GUIButton((int)guiLeft+166,(int)guiTop+166, 18,18) {
@Override
public String getHoverText() {
Expand All @@ -287,7 +287,7 @@ public void onClick() {
}

@Override
public FontRenderer getFont(){return fontRendererObj;}
public FontRenderer getFont(){return fontRenderer;}
});
}
//train specific
Expand Down Expand Up @@ -433,11 +433,11 @@ private void renderPassengerInventory(Minecraft mc){
if (i/(rows+1) >=5*(rows+1)){
rows++;
}
if (i==0 && transport.riddenByEntity instanceof AbstractClientPlayer){
mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.riddenByEntity).getLocationSkin());
if (i==0 && transport.getPassengers().get(0) instanceof AbstractClientPlayer){
mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.getPassengers().get(0)).getLocationSkin());
ClientUtil.drawTexturedRect(guiLeft + 108 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 23, 23, 36, 56);
} else if (i>0 && transport.seats.get(i-1).riddenByEntity instanceof AbstractClientPlayer){
mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.seats.get(i-1).riddenByEntity).getLocationSkin());
} else if (i>0 && transport.seats.get(i-1).getPassengers().get(0) instanceof AbstractClientPlayer){
mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.seats.get(i-1).getPassengers().get(0)).getLocationSkin());
ClientUtil.drawTexturedRect(guiLeft + 108 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 23, 23, 36, 56);
}
}
Expand Down Expand Up @@ -507,7 +507,9 @@ private void renderTankerInventory(Minecraft mc, int mouseX, int mouseY){
Tessellator.bindTexture(URIRegistry.GUI_PREFIX.getResource("gui.png"));
ClientUtil.drawTexturedRect(186, 40 + (-20 * i), 16, 0, 90, 18, 16, 16);

if (transport.getTankInfo()[i] != null && transport.getTankInfo()[i].fluid.amount > 0) {
if (transport.getTankInfo()[i] != null && transport.getTankInfo()[i].fluid != null &&
transport.getTankInfo()[i].fluid.getFluid() != null &&
transport.getTankInfo()[i].fluid.getFluid().getBlock() !=null&& transport.getTankInfo()[i].fluid.amount > 0) {
liquid = transport.getTankInfo()[i].fluid.amount;
if (liquid != 0) {
liquid /= transport.getTankInfo()[i].capacity;
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/ebf/tim/networking/PacketSeatUpdate.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package ebf.tim.networking;

import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import ebf.tim.TrainsInMotion;
import ebf.tim.entities.EntitySeat;
import ebf.tim.entities.GenericRailTransport;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

/**
* <h1>Seat Packet</h1>
* bi-directional packet for managing seat changes while in a piece of stock.
Expand Down Expand Up @@ -52,18 +53,18 @@ public static class Handler implements IMessageHandler<PacketSeatUpdate,IMessage
EntitySeat oldSeat;
EntitySeat newSeat;
if (ctx.side == Side.SERVER) {
rollingStockEntity = (GenericRailTransport) ctx.getServerHandler().playerEntity.worldObj.getEntityByID(message.rollingStockId);
playerEntity = ctx.getServerHandler().playerEntity.worldObj.getEntityByID(message.playerId);
rollingStockEntity = (GenericRailTransport) ctx.getServerHandler().player.world.getEntityByID(message.rollingStockId);
playerEntity = ctx.getServerHandler().player.world.getEntityByID(message.playerId);

} else {
rollingStockEntity = (GenericRailTransport) Minecraft.getMinecraft().theWorld.getEntityByID(message.rollingStockId);
playerEntity = Minecraft.getMinecraft().theWorld.getEntityByID(message.playerId);
rollingStockEntity = (GenericRailTransport) Minecraft.getMinecraft().world.getEntityByID(message.rollingStockId);
playerEntity = Minecraft.getMinecraft().world.getEntityByID(message.playerId);
}
oldSeat = rollingStockEntity.seats.get(message.oldSeatIndex);
newSeat = rollingStockEntity.seats.get(message.newSeatIndex);
newSeat.addPassenger(playerEntity);
oldSeat.removePassenger(playerEntity);
playerEntity.mountEntity(newSeat);
//playerEntity.getPassengers(newSeat);
if (ctx.side == Side.SERVER) {
TrainsInMotion.updateChannel.sendToAllAround(new PacketSeatUpdate(message.rollingStockId,message.playerId,message.oldSeatIndex,message.newSeatIndex),
new NetworkRegistry.TargetPoint(playerEntity.dimension,rollingStockEntity.posX,rollingStockEntity.posY,rollingStockEntity.posZ,256D));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ebf/tim/utility/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ebf.tim.registry.TiMFluids;
import ebf.tim.registry.TiMItems;
import ebf.tim.registry.TiMOres;
import fexcraft.fcl.common.Static;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
Expand Down
36 changes: 19 additions & 17 deletions src/main/java/train/blocks/hearth/ContainerOpenHearthFurnace.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package train.blocks.hearth;

import ebf.tim.blocks.TileEntityStorage;
import ebf.tim.utility.DebugUtil;
import ebf.tim.utility.TransportSlotManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ContainerOpenHearthFurnace extends TransportSlotManager {

private TileEntityOpenHearthFurnace furnace;
private int cookTime;
private int burnTime;
private int itemBurnTime;


public ContainerOpenHearthFurnace(InventoryPlayer inventoryplayer, TileEntityOpenHearthFurnace tileentityFurnace) {
public ContainerOpenHearthFurnace(InventoryPlayer inventoryplayer, TileEntityStorage tileentityFurnace) {
super(inventoryplayer,tileentityFurnace);
furnace=tileentityFurnace;
}

@Override
Expand Down Expand Up @@ -47,36 +48,37 @@ public void addListener(IContainerListener listener) {//1.12 variant
public void detectAndSendChanges() {
super.detectAndSendChanges();

TileEntityOpenHearthFurnace furnace = (TileEntityOpenHearthFurnace)hostInventory;
for (IContainerListener icontainerlistener : this.listeners) {
if (this.cookTime != this.furnace.getField(2)) {
icontainerlistener.sendWindowProperty(this, 2, this.furnace.getField(2));
if (this.cookTime != furnace.furnaceCookTime) {
icontainerlistener.sendWindowProperty(this, 2, furnace.furnaceCookTime);
}

if (this.burnTime != this.furnace.getField(0)) {
icontainerlistener.sendWindowProperty(this, 0, this.furnace.getField(0));
if (this.burnTime != furnace.furnaceBurnTime) {
icontainerlistener.sendWindowProperty(this, 0, furnace.furnaceBurnTime);
}

if (this.itemBurnTime != this.furnace.getField(1)) {
icontainerlistener.sendWindowProperty(this, 1, this.furnace.getField(1));
if (this.itemBurnTime != furnace.currentItemBurnTime) {
icontainerlistener.sendWindowProperty(this, 1, furnace.currentItemBurnTime);
}
}

this.cookTime = this.furnace.getField(2);
this.burnTime = this.furnace.getField(0);
this.itemBurnTime = this.furnace.getField(1);
this.cookTime = furnace.furnaceCookTime;
this.burnTime = furnace.furnaceBurnTime;
this.itemBurnTime = furnace.currentItemBurnTime;
}

@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int i, int j) {
if (i == 0) {
furnace.furnaceCookTime = j;
((TileEntityOpenHearthFurnace)hostInventory).furnaceCookTime = j;
}
if (i == 1) {
furnace.furnaceBurnTime = j;
else if (i == 1) {
((TileEntityOpenHearthFurnace)hostInventory).furnaceBurnTime = j;
}
if (i == 2) {
furnace.currentItemBurnTime = j;
else if (i == 2) {
((TileEntityOpenHearthFurnace)hostInventory).currentItemBurnTime = j;
}
}
}

0 comments on commit 9d1ca7b

Please sign in to comment.