mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-02-24 15:00:48 +00:00
more train coupling stuff
This commit is contained in:
parent
85ce4008a1
commit
e120654403
@ -1,5 +1,6 @@
|
|||||||
package com.hbm.entity.train;
|
package com.hbm.entity.train;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.hbm.blocks.rail.IRailNTM;
|
import com.hbm.blocks.rail.IRailNTM;
|
||||||
@ -93,6 +94,7 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
if(neighbor.getCoupledTo(closestNeighborCoupling) != null) continue;
|
if(neighbor.getCoupledTo(closestNeighborCoupling) != null) continue;
|
||||||
this.couple(closestOwnCoupling, neighbor);
|
this.couple(closestOwnCoupling, neighbor);
|
||||||
neighbor.couple(closestNeighborCoupling, this);
|
neighbor.couple(closestNeighborCoupling, this);
|
||||||
|
player.swingItem();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,10 +284,14 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
public abstract TrackGauge getGauge();
|
public abstract TrackGauge getGauge();
|
||||||
/** Returns the length between the core and one of the bogies */
|
/** Returns the length between the core and one of the bogies */
|
||||||
public abstract double getLengthSpan();
|
public abstract double getLengthSpan();
|
||||||
/* Returns a collision box, usually smaller than the entity's AABB for rendering, which is used for colliding trains */
|
/** Returns a collision box, usually smaller than the entity's AABB for rendering, which is used for colliding trains */
|
||||||
public AxisAlignedBB getCollisionBox() {
|
public AxisAlignedBB getCollisionBox() {
|
||||||
return this.boundingBox;
|
return this.boundingBox;
|
||||||
}
|
}
|
||||||
|
/** Returns a collision box used for block collisions when derailed */
|
||||||
|
@Override public AxisAlignedBB getBoundingBox() {
|
||||||
|
return this.boundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the "true" position of the train, i.e. the block it wants to snap to */
|
/** Returns the "true" position of the train, i.e. the block it wants to snap to */
|
||||||
public BlockPos getCurentAnchorPos() {
|
public BlockPos getCurentAnchorPos() {
|
||||||
@ -417,6 +423,8 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
|
|
||||||
if(dist <= 0) return null;
|
if(dist <= 0) return null;
|
||||||
|
|
||||||
|
if(coupling == TrainCoupling.BACK) dist *= -1;
|
||||||
|
|
||||||
Vec3 rot = Vec3.createVectorHelper(0, 0, dist);
|
Vec3 rot = Vec3.createVectorHelper(0, 0, dist);
|
||||||
rot.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180D));
|
rot.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180D));
|
||||||
rot.xCoord += this.renderX;
|
rot.xCoord += this.renderX;
|
||||||
@ -433,4 +441,11 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
if(coupling == TrainCoupling.FRONT) this.coupledFront = to;
|
if(coupling == TrainCoupling.FRONT) this.coupledFront = to;
|
||||||
if(coupling == TrainCoupling.BACK) this.coupledBack = to;
|
if(coupling == TrainCoupling.BACK) this.coupledBack = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LogicalTrainUnit {
|
||||||
|
|
||||||
|
List<EntityRailCarBase> trains = new ArrayList();
|
||||||
|
|
||||||
|
//TBI
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,7 +129,7 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
|||||||
if(nearestSeat == -1) {
|
if(nearestSeat == -1) {
|
||||||
player.mountEntity(this);
|
player.mountEntity(this);
|
||||||
} else {
|
} else {
|
||||||
SeatDummyEntity dummySeat = new SeatDummyEntity(worldObj, this);
|
SeatDummyEntity dummySeat = new SeatDummyEntity(worldObj, this, nearestSeat);
|
||||||
Vec3 passengerSeat = this.getPassengerSeats()[nearestSeat];
|
Vec3 passengerSeat = this.getPassengerSeats()[nearestSeat];
|
||||||
passengerSeat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
passengerSeat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||||
double x = renderX + passengerSeat.xCoord;
|
double x = renderX + passengerSeat.xCoord;
|
||||||
@ -194,16 +194,17 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
|||||||
private double trainX;
|
private double trainX;
|
||||||
private double trainY;
|
private double trainY;
|
||||||
private double trainZ;
|
private double trainZ;
|
||||||
public EntityRailCarBase train;
|
public EntityRailCarRidable train;
|
||||||
|
|
||||||
public SeatDummyEntity(World world) { super(world); this.setSize(0.5F, 0.1F);}
|
public SeatDummyEntity(World world) { super(world); this.setSize(0.5F, 0.1F);}
|
||||||
public SeatDummyEntity(World world, EntityRailCarBase train) {
|
public SeatDummyEntity(World world, EntityRailCarRidable train, int index) {
|
||||||
this(world);
|
this(world);
|
||||||
this.train = train;
|
this.train = train;
|
||||||
if(train != null) this.dataWatcher.updateObject(3, train.getEntityId());
|
if(train != null) this.dataWatcher.updateObject(3, train.getEntityId());
|
||||||
|
this.dataWatcher.updateObject(4, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void entityInit() { this.dataWatcher.addObject(3, new Integer(0)); }
|
@Override protected void entityInit() { this.dataWatcher.addObject(3, new Integer(0)); this.dataWatcher.addObject(4, new Integer(0)); }
|
||||||
@Override protected void writeEntityToNBT(NBTTagCompound nbt) { }
|
@Override protected void writeEntityToNBT(NBTTagCompound nbt) { }
|
||||||
@Override public boolean writeToNBTOptional(NBTTagCompound nbt) { return false; }
|
@Override public boolean writeToNBTOptional(NBTTagCompound nbt) { return false; }
|
||||||
@Override public void readEntityFromNBT(NBTTagCompound nbt) { this.setDead(); }
|
@Override public void readEntityFromNBT(NBTTagCompound nbt) { this.setDead(); }
|
||||||
@ -238,7 +239,30 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
|||||||
@Override
|
@Override
|
||||||
public void updateRiderPosition() {
|
public void updateRiderPosition() {
|
||||||
if(this.riddenByEntity != null) {
|
if(this.riddenByEntity != null) {
|
||||||
this.riddenByEntity.setPosition(this.posX, this.posY + 1, this.posZ);
|
|
||||||
|
if(train == null) {
|
||||||
|
int eid = this.dataWatcher.getWatchableObjectInt(3);
|
||||||
|
Entity entity = worldObj.getEntityByID(eid);
|
||||||
|
if(entity instanceof EntityRailCarRidable) {
|
||||||
|
train = (EntityRailCarRidable) entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//fallback for when train is null
|
||||||
|
if(train == null) {
|
||||||
|
this.riddenByEntity.setPosition(posX, posY + 1, posZ);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//doing it like this instead of with the position directly removes any discrepancies caused by entity tick order
|
||||||
|
//mmhmhmhm silky smooth
|
||||||
|
int index = this.dataWatcher.getWatchableObjectInt(4);
|
||||||
|
Vec3 rot = this.train.getPassengerSeats()[index];
|
||||||
|
rot.rotateAroundY((float) (-train.rotationYaw * Math.PI / 180));
|
||||||
|
double x = train.renderX + rot.xCoord;
|
||||||
|
double y = train.renderY + rot.yCoord;
|
||||||
|
double z = train.renderZ + rot.zCoord;
|
||||||
|
this.riddenByEntity.setPosition(x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,11 +51,12 @@ public class TrainCargoTram extends EntityRailCarElectric implements IGUIProvide
|
|||||||
|
|
||||||
@Override public TrackGauge getGauge() { return TrackGauge.STANDARD; }
|
@Override public TrackGauge getGauge() { return TrackGauge.STANDARD; }
|
||||||
@Override public double getLengthSpan() { return 1.5; }
|
@Override public double getLengthSpan() { return 1.5; }
|
||||||
@Override public Vec3 getRiderSeatPosition() { return Vec3.createVectorHelper(0.375, 2.25, 0.5); }
|
@Override public Vec3 getRiderSeatPosition() { return Vec3.createVectorHelper(0.375, 2.375, 0.5); }
|
||||||
@Override public boolean shouldRiderSit() { return false; }
|
@Override public boolean shouldRiderSit() { return false; }
|
||||||
@Override public int getSizeInventory() { return 29; }
|
@Override public int getSizeInventory() { return 29; }
|
||||||
@Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.getEntityName() : "container.trainTram"; }
|
@Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.getEntityName() : "container.trainTram"; }
|
||||||
@Override public AxisAlignedBB getCollisionBox() { return AxisAlignedBB.getBoundingBox(renderX, renderY, renderZ, renderX, renderY + 1, renderZ).expand(4, 0, 4); }
|
@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 int getMaxPower() { return this.getPowerConsumption() * 100; }
|
@Override public int getMaxPower() { return this.getPowerConsumption() * 100; }
|
||||||
@Override public int getPowerConsumption() { return 10; }
|
@Override public int getPowerConsumption() { return 10; }
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.hbm.entity.train;
|
|||||||
|
|
||||||
import com.hbm.blocks.rail.IRailNTM.TrackGauge;
|
import com.hbm.blocks.rail.IRailNTM.TrackGauge;
|
||||||
|
|
||||||
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.util.DamageSource;
|
||||||
import net.minecraft.util.Vec3;
|
import net.minecraft.util.Vec3;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@ -28,6 +29,8 @@ public class TrainCargoTramTrailer extends EntityRailCarCargo {
|
|||||||
@Override public double getLengthSpan() { return 1.5; }
|
@Override public double getLengthSpan() { return 1.5; }
|
||||||
@Override public int getSizeInventory() { return 29; }
|
@Override public int getSizeInventory() { return 29; }
|
||||||
@Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.getEntityName() : "container.trainTramTrailer"; }
|
@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
|
@Override
|
||||||
public double getCurrentSpeed() {
|
public double getCurrentSpeed() {
|
||||||
|
|||||||
@ -8,12 +8,14 @@ import com.hbm.entity.train.TrainCargoTram;
|
|||||||
import com.hbm.entity.train.TrainCargoTramTrailer;
|
import com.hbm.entity.train.TrainCargoTramTrailer;
|
||||||
import com.hbm.items.ItemEnumMulti;
|
import com.hbm.items.ItemEnumMulti;
|
||||||
import com.hbm.util.EnumUtil;
|
import com.hbm.util.EnumUtil;
|
||||||
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ItemTrain extends ItemEnumMulti {
|
public class ItemTrain extends ItemEnumMulti {
|
||||||
@ -74,7 +76,13 @@ public class ItemTrain extends ItemEnumMulti {
|
|||||||
if(train != null && train.getGauge() == ((IRailNTM) b).getGauge(world, x, y, z)) {
|
if(train != null && train.getGauge() == ((IRailNTM) b).getGauge(world, x, y, z)) {
|
||||||
if(!world.isRemote) {
|
if(!world.isRemote) {
|
||||||
train.setPosition(x + fx, y + fy, z + fz);
|
train.setPosition(x + fx, y + fy, z + fz);
|
||||||
|
BlockPos anchor = train.getCurentAnchorPos();
|
||||||
train.rotationYaw = entity.rotationYaw;
|
train.rotationYaw = entity.rotationYaw;
|
||||||
|
Vec3 corePos = train.getRelPosAlongRail(anchor, 0);
|
||||||
|
train.setPosition(corePos.xCoord, corePos.yCoord, corePos.zCoord);
|
||||||
|
Vec3 frontPos = train.getRelPosAlongRail(anchor, train.getLengthSpan());
|
||||||
|
Vec3 backPos = train.getRelPosAlongRail(anchor, -train.getLengthSpan());
|
||||||
|
train.rotationYaw = train.generateYaw(frontPos, backPos);
|
||||||
world.spawnEntityInWorld(train);
|
world.spawnEntityInWorld(train);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user