mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
some more train stuff
This commit is contained in:
parent
ccce86a41c
commit
36d4a4c4e0
@ -5,15 +5,13 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.hbm.blocks.ILookOverlay;
|
||||
import com.hbm.blocks.rail.IRailNTM;
|
||||
import com.hbm.blocks.rail.IRailNTM.RailContext;
|
||||
import com.hbm.blocks.rail.IRailNTM.TrackGauge;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.packet.AuxParticlePacketNT;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
@ -25,8 +23,9 @@ import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
|
||||
public abstract class EntityRailCarBase extends Entity {
|
||||
public abstract class EntityRailCarBase extends Entity implements ILookOverlay {
|
||||
|
||||
public LogicalTrainUnit ltu;
|
||||
public boolean isOnRail = true;
|
||||
@ -100,15 +99,16 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
if(neighbor.getCoupledTo(closestNeighborCoupling) != null) continue;
|
||||
this.couple(closestOwnCoupling, neighbor);
|
||||
neighbor.couple(closestNeighborCoupling, this);
|
||||
if(this.ltu != null) this.ltu.dissolve();
|
||||
if(neighbor.ltu != null) neighbor.ltu.dissolve();
|
||||
if(this.ltu != null) this.ltu.dissolveTrain();
|
||||
if(neighbor.ltu != null) neighbor.ltu.dissolveTrain();
|
||||
player.swingItem();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.ltu != null) {
|
||||
//DEBUG
|
||||
/*if(this.ltu != null) {
|
||||
|
||||
String id = Integer.toHexString(ltu.hashCode());
|
||||
|
||||
@ -121,7 +121,7 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
data.setString("text", id);
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, train.posX, train.posY + 1, train.posZ), new TargetPoint(this.dimension, train.posX, train.posY + 1, train.posZ, 50));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -169,15 +169,15 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
|
||||
if(this.coupledFront != null && this.coupledFront.isDead) {
|
||||
this.coupledFront = null;
|
||||
if(this.ltu != null) this.ltu.dissolve();
|
||||
if(this.ltu != null) this.ltu.dissolveTrain();
|
||||
}
|
||||
if(this.coupledBack != null && this.coupledBack.isDead) {
|
||||
this.coupledBack = null;
|
||||
if(this.ltu != null) this.ltu.dissolve();
|
||||
if(this.ltu != null) this.ltu.dissolveTrain();
|
||||
}
|
||||
|
||||
if(this.ltu == null && (this.coupledFront == null || this.coupledBack == null)) {
|
||||
LogicalTrainUnit.generate(this);
|
||||
LogicalTrainUnit.generateTrain(this);
|
||||
}
|
||||
|
||||
DummyConfig[] definitions = this.getDummies();
|
||||
@ -293,10 +293,10 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
}
|
||||
|
||||
/* Move carts together with links */
|
||||
for(LogicalTrainUnit ltu : ltus) ltu.combineLinks();
|
||||
for(LogicalTrainUnit ltu : ltus) ltu.combineWagons();
|
||||
|
||||
/* Move carts with unified speed */
|
||||
for(LogicalTrainUnit ltu : ltus) ltu.moveLinks();
|
||||
for(LogicalTrainUnit ltu : ltus) ltu.moveTrain();
|
||||
}
|
||||
|
||||
/** Returns the amount of blocks that the train should move per tick */
|
||||
@ -473,7 +473,7 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
protected EntityRailCarBase trains[];
|
||||
|
||||
/** Assumes that the train is an endpoint, i.e. that only one coupling is in use */
|
||||
public static LogicalTrainUnit generate(EntityRailCarBase train) {
|
||||
public static LogicalTrainUnit generateTrain(EntityRailCarBase train) {
|
||||
List<EntityRailCarBase> links = new ArrayList();
|
||||
Set<EntityRailCarBase> brake = new HashSet();
|
||||
links.add(train);
|
||||
@ -512,13 +512,15 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
return ltu;
|
||||
}
|
||||
|
||||
public void dissolve() {
|
||||
/** Removes the LTU from all wagons */
|
||||
public void dissolveTrain() {
|
||||
for(EntityRailCarBase train : trains) {
|
||||
train.ltu = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void combineLinks() {
|
||||
/** Find the center fo the train, then moves all wagons towards that center until the coupling points roughly touch */
|
||||
public void combineWagons() {
|
||||
|
||||
if(trains.length <= 1) return;
|
||||
|
||||
@ -529,19 +531,20 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
|
||||
for(int i = centerIndex - 1; i >= 0; i--) {
|
||||
EntityRailCarBase next = trains[i];
|
||||
moveTo(prev, next);
|
||||
moveWagonTo(prev, next);
|
||||
prev = next;
|
||||
}
|
||||
|
||||
prev = center;
|
||||
for(int i = centerIndex + 1; i < trains.length; i++) {
|
||||
EntityRailCarBase next = trains[i];
|
||||
moveTo(prev, next);
|
||||
moveWagonTo(prev, next);
|
||||
prev = next;
|
||||
}
|
||||
}
|
||||
|
||||
public static void moveTo(EntityRailCarBase prev, EntityRailCarBase next) {
|
||||
/** Moves one wagon to ne next until the coupling points roughly touch */
|
||||
public static void moveWagonTo(EntityRailCarBase prev, EntityRailCarBase next) {
|
||||
TrainCoupling prevCouple = prev.getCouplingFrom(next);
|
||||
TrainCoupling nextCouple = next.getCouplingFrom(prev);
|
||||
Vec3 prevLoc = prev.getCouplingPos(prevCouple);
|
||||
@ -556,7 +559,8 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
next.setPosition(newPos.xCoord, newPos.yCoord, newPos.zCoord);
|
||||
}
|
||||
|
||||
public void moveLinks() {
|
||||
/** Generates the speed of the train, then moves the rain along the rail */
|
||||
public void moveTrain() {
|
||||
|
||||
EntityRailCarBase prev = trains[0];
|
||||
TrainCoupling dir = prev.getCouplingFrom(null);
|
||||
@ -576,6 +580,12 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
totalSpeed = maxSpeed * Math.signum(totalSpeed);
|
||||
}
|
||||
|
||||
this.moveTrainBy(totalSpeed);
|
||||
}
|
||||
|
||||
/** Moves the entire train along the rail by a certain speed */
|
||||
public void moveTrainBy(double totalSpeed) {
|
||||
|
||||
for(EntityRailCarBase train : this.trains) {
|
||||
|
||||
BlockPos anchor = train.getCurentAnchorPos();
|
||||
@ -583,7 +593,7 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
|
||||
if(corePos == null) {
|
||||
train.derail();
|
||||
this.dissolve();
|
||||
this.dissolveTrain();
|
||||
return;
|
||||
} else {
|
||||
train.setPosition(corePos.xCoord, corePos.yCoord, corePos.zCoord);
|
||||
@ -593,7 +603,7 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
|
||||
if(frontPos == null || backPos == null) {
|
||||
train.derail();
|
||||
this.dissolve();
|
||||
this.dissolveTrain();
|
||||
return;
|
||||
} else {
|
||||
train.renderX = (frontPos.xCoord + backPos.xCoord) / 2D;
|
||||
@ -608,4 +618,14 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void printHook(RenderGameOverlayEvent.Pre event, World world, int x, int y, int z) {
|
||||
/*List<String> text = new ArrayList();
|
||||
text.add("LTU: " + this.ltu);
|
||||
text.add("Front: " + this.coupledFront);
|
||||
text.add("Back: " + this.coupledBack);
|
||||
ILookOverlay.printGeneric(event, this.toString(), 0xffff00, 0x404000, text);*/ //none of this shit is going to work anyway
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
package com.hbm.entity.train;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ILookOverlay;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.util.BobMathUtil;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@ -10,6 +15,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
|
||||
public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
|
||||
@ -80,8 +86,30 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
if(super.interactFirst(player)) return true;
|
||||
if(worldObj.isRemote) return true;
|
||||
|
||||
int nearestSeat = this.getNearestSeat(player);
|
||||
|
||||
if(nearestSeat == -1) {
|
||||
player.mountEntity(this);
|
||||
} else if(nearestSeat >= 0) {
|
||||
SeatDummyEntity dummySeat = new SeatDummyEntity(worldObj, this, nearestSeat);
|
||||
Vec3 passengerSeat = this.getPassengerSeats()[nearestSeat];
|
||||
passengerSeat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||
double x = renderX + passengerSeat.xCoord;
|
||||
double y = renderY + passengerSeat.yCoord;
|
||||
double z = renderZ + passengerSeat.zCoord;
|
||||
dummySeat.setPosition(x, y - 1, z);
|
||||
passengerSeats[nearestSeat] = dummySeat;
|
||||
worldObj.spawnEntityInWorld(dummySeat);
|
||||
player.mountEntity(dummySeat);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getNearestSeat(EntityPlayer player) {
|
||||
|
||||
double nearestDist = Double.POSITIVE_INFINITY;
|
||||
int nearestSeat = -1;
|
||||
int nearestSeat = -2;
|
||||
|
||||
Vec3[] seats = getPassengerSeats();
|
||||
for(int i = 0; i < seats.length; i++) {
|
||||
@ -124,24 +152,9 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
}
|
||||
}
|
||||
|
||||
if(nearestDist > 180) return true;
|
||||
if(nearestDist > 180) return -2;
|
||||
|
||||
if(nearestSeat == -1) {
|
||||
player.mountEntity(this);
|
||||
} else {
|
||||
SeatDummyEntity dummySeat = new SeatDummyEntity(worldObj, this, nearestSeat);
|
||||
Vec3 passengerSeat = this.getPassengerSeats()[nearestSeat];
|
||||
passengerSeat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||
double x = renderX + passengerSeat.xCoord;
|
||||
double y = renderY + passengerSeat.yCoord;
|
||||
double z = renderZ + passengerSeat.zCoord;
|
||||
dummySeat.setPosition(x, y - 1, z);
|
||||
passengerSeats[nearestSeat] = dummySeat;
|
||||
worldObj.spawnEntityInWorld(dummySeat);
|
||||
player.mountEntity(dummySeat);
|
||||
}
|
||||
|
||||
return true;
|
||||
return nearestSeat;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -266,4 +279,15 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void printHook(RenderGameOverlayEvent.Pre event, World world, int x, int y, int z) {
|
||||
List<String> text = new ArrayList();
|
||||
/*text.add("LTU: " + this.ltu);
|
||||
text.add("Front: " + this.coupledFront);
|
||||
text.add("Back: " + this.coupledBack);*/
|
||||
text.add("Nearest seat: " + this.getNearestSeat(MainRegistry.proxy.me()));
|
||||
ILookOverlay.printGeneric(event, this.toString(), 0xffff00, 0x404000, text);
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,6 +104,7 @@ import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Slot;
|
||||
@ -171,13 +172,22 @@ public class ModEventHandlerClient {
|
||||
World world = mc.theWorld;
|
||||
MovingObjectPosition mop = mc.objectMouseOver;
|
||||
|
||||
if(mop != null && mop.typeOfHit == mop.typeOfHit.BLOCK ) {
|
||||
if(mop != null) {
|
||||
|
||||
if(player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ILookOverlay) {
|
||||
((ILookOverlay) player.getHeldItem().getItem()).printHook(event, world, mop.blockX, mop.blockY, mop.blockZ);
|
||||
if(mop.typeOfHit == mop.typeOfHit.BLOCK) {
|
||||
|
||||
} else if(world.getBlock(mop.blockX, mop.blockY, mop.blockZ) instanceof ILookOverlay) {
|
||||
((ILookOverlay) world.getBlock(mop.blockX, mop.blockY, mop.blockZ)).printHook(event, world, mop.blockX, mop.blockY, mop.blockZ);
|
||||
if(player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ILookOverlay) {
|
||||
((ILookOverlay) player.getHeldItem().getItem()).printHook(event, world, mop.blockX, mop.blockY, mop.blockZ);
|
||||
|
||||
} else if(world.getBlock(mop.blockX, mop.blockY, mop.blockZ) instanceof ILookOverlay) {
|
||||
((ILookOverlay) world.getBlock(mop.blockX, mop.blockY, mop.blockZ)).printHook(event, world, mop.blockX, mop.blockY, mop.blockZ);
|
||||
}
|
||||
} else if(mop.typeOfHit == mop.typeOfHit.ENTITY) {
|
||||
Entity entity = mop.entityHit;
|
||||
|
||||
if(entity instanceof ILookOverlay) {
|
||||
((ILookOverlay) entity).printHook(event, world, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user