diff --git a/src/main/java/com/hbm/blocks/rail/RailStandardCurve.java b/src/main/java/com/hbm/blocks/rail/RailStandardCurve.java index 08b824df4..89658d741 100644 --- a/src/main/java/com/hbm/blocks/rail/RailStandardCurve.java +++ b/src/main/java/com/hbm/blocks/rail/RailStandardCurve.java @@ -57,11 +57,6 @@ public class RailStandardCurve extends BlockDummyable implements IRailNTM { ForgeDirection dir = ForgeDirection.getOrientation(meta); ForgeDirection rot = dir.getRotation(ForgeDirection.UP); - List context = new ArrayList(); - context.add("========================="); - - boolean debug = Math.abs(speed) < 2; - double turnRadius = 4.5D; Vec3 vec = Vec3.createVectorHelper(trainX, trainY, trainZ); @@ -78,16 +73,12 @@ public class RailStandardCurve extends BlockDummyable implements IRailNTM { return Vec3.createVectorHelper(axisX + dist.xCoord, y, axisZ + dist.zCoord); } - context.add("Speed: " + speed); double angleDeg = -Math.atan(dist.zCoord / dist.xCoord) * 180D / Math.PI; + if(dir == Library.NEG_X) angleDeg += 90; double length90Deg = turnRadius * Math.PI / 2D; double angularChange = speed / length90Deg * 90D; - context.add("angleDeg: " + angleDeg); - context.add("length90Deg: " + length90Deg); - context.add("angularChange: " + angularChange); - ForgeDirection moveDir = ForgeDirection.UNKNOWN; if(Math.abs(motionX) > Math.abs(motionZ)) { @@ -96,44 +87,31 @@ public class RailStandardCurve extends BlockDummyable implements IRailNTM { moveDir = motionZ > 0 ? Library.POS_Z : Library.NEG_Z; } - context.add("moveDir: " + moveDir); - - if(moveDir == dir || moveDir == rot) { + if(moveDir == dir || moveDir == rot.getOpposite()) { angularChange *= -1; } - context.add("angularChange: " + angularChange); - double effAngle = angleDeg + angularChange; - context.add("effAngle: " + effAngle); + if(Math.abs(speed) != 2)PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(new ChatComponentText(angleDeg + ""), 999, 3000), (EntityPlayerMP) world.playerEntities.get(0)); if(effAngle > 90) { double angleOvershoot = effAngle - 90D; double lengthOvershoot = angleOvershoot * length90Deg / 90D; - context.add("angleOvershoot: " + angleOvershoot); - context.add("lengthOvershoot: " + lengthOvershoot); - info.dist(lengthOvershoot).pos(new BlockPos(cX - dir.offsetX * 4 + rot.offsetX * 5, y, cZ - dir.offsetZ * 4 + rot.offsetZ * 5)); - if(debug) for(String s : context) System.out.println(s); + info.dist(-lengthOvershoot).pos(new BlockPos(cX - dir.offsetX * 4 + rot.offsetX * 5, y, cZ - dir.offsetZ * 4 + rot.offsetZ * 5)); return Vec3.createVectorHelper(axisX - dir.offsetX * turnRadius + rot.offsetX * turnRadius, y, axisZ - dir.offsetZ * turnRadius + rot.offsetZ * turnRadius); } if(effAngle < 0) { - double angleOvershoot = -effAngle; + double angleOvershoot = effAngle; double lengthOvershoot = angleOvershoot * length90Deg / 90D; - context.add("angleOvershoot: " + angleOvershoot); - context.add("lengthOvershoot: " + lengthOvershoot); info.dist(lengthOvershoot).pos(new BlockPos(cX + dir.offsetX , y, cZ + dir.offsetZ)); - ParticleUtil.spawnGasFlame(world, axisX + 0.5 + dir.offsetX * 0.5, y, axisZ * 0.5 + dir.offsetZ * 0.5, 0, 0.2, 0); - if(debug) for(String s : context) System.out.println(s); return Vec3.createVectorHelper(axisX + 0.5 + dir.offsetX * 0.5, y, axisZ * 0.5 + dir.offsetZ * 0.5); } double radianChange = angularChange * Math.PI / 180D; dist.rotateAroundY((float) radianChange); - context.add("radianChange: " + radianChange); - if(debug) for(String s : context) System.out.println(s); return Vec3.createVectorHelper(axisX + dist.xCoord, y, axisZ + dist.zCoord); } @@ -154,7 +132,6 @@ public class RailStandardCurve extends BlockDummyable implements IRailNTM { @Override public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { - int meta = world.getBlockMetadata(x, y, z); this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F); } diff --git a/src/main/java/com/hbm/blocks/rail/RailStandardStraight.java b/src/main/java/com/hbm/blocks/rail/RailStandardStraight.java index 512ca9aaa..d8a030009 100644 --- a/src/main/java/com/hbm/blocks/rail/RailStandardStraight.java +++ b/src/main/java/com/hbm/blocks/rail/RailStandardStraight.java @@ -41,7 +41,6 @@ public class RailStandardStraight extends BlockDummyable implements IRailNTM { @Override public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { - int meta = world.getBlockMetadata(x, y, z); this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F); } @@ -84,11 +83,11 @@ public class RailStandardStraight extends BlockDummyable implements IRailNTM { } else { targetX -= speed; } - vec.xCoord = MathHelper.clamp_double(targetX, x - 2, x + 3); + vec.xCoord = MathHelper.clamp_double(targetX, cX - 2, cX + 3); vec.yCoord = y; - vec.zCoord = z + 0.5; - info.dist(Math.abs(targetX - vec.xCoord)); - info.pos(new BlockPos(vec.xCoord + (motionX > 0 ? 1 : -1), y, z)); + vec.zCoord = cZ + 0.5; + info.dist(Math.abs(targetX - vec.xCoord) * -Math.signum(speed)); + info.pos(new BlockPos(cX + (motionX > 0 ? 3 : -3), y, cZ)); } else { double targetZ = trainZ; if(motionZ > 0) { @@ -96,11 +95,11 @@ public class RailStandardStraight extends BlockDummyable implements IRailNTM { } else { targetZ -= speed; } - vec.xCoord = x + 0.5; + vec.xCoord = cX + 0.5; vec.yCoord = y; - vec.zCoord = MathHelper.clamp_double(targetZ, z - 2, z + 3); - info.dist(Math.abs(targetZ - vec.zCoord)); - info.pos(new BlockPos(x, y, vec.zCoord + (motionZ > 0 ? 1 : -1))); + vec.zCoord = MathHelper.clamp_double(targetZ, cZ - 2,cZ + 3); + info.dist(Math.abs(targetZ - vec.zCoord) * -Math.signum(speed)); + info.pos(new BlockPos(cX, y, cZ + (motionZ > 0 ? 3 : -3))); } return vec; diff --git a/src/main/java/com/hbm/entity/train/EntityRailCarBase.java b/src/main/java/com/hbm/entity/train/EntityRailCarBase.java index 79df30ca0..1d76b8b12 100644 --- a/src/main/java/com/hbm/entity/train/EntityRailCarBase.java +++ b/src/main/java/com/hbm/entity/train/EntityRailCarBase.java @@ -3,6 +3,10 @@ package com.hbm.entity.train; import com.hbm.blocks.rail.IRailNTM; import com.hbm.blocks.rail.IRailNTM.RailLeaveInfo; import com.hbm.blocks.rail.IRailNTM.TrackGauge; +import com.hbm.main.MainRegistry; +import com.hbm.packet.PacketDispatcher; +import com.hbm.packet.PlayerInformPacket; +import com.hbm.util.ChatBuilder; import com.hbm.util.ParticleUtil; import com.hbm.util.fauxpointtwelve.BlockPos; @@ -10,7 +14,10 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.MathHelper; import net.minecraft.util.Vec3; import net.minecraft.world.World; @@ -60,9 +67,11 @@ public abstract class EntityRailCarBase extends Entity { --this.turnProgress; this.setPosition(x, y, z); this.setRotation(this.rotationYaw, this.rotationPitch); + this.setRotation((float)this.trainYaw, this.rotationPitch); } else { this.setPosition(this.posX, this.posY, this.posZ); this.setRotation(this.rotationYaw, this.rotationPitch); + this.setRotation((float)this.trainYaw, this.rotationPitch); } } else { @@ -84,15 +93,16 @@ public abstract class EntityRailCarBase extends Entity { if(frontPos == null || backPos == null) { this.derail(); } else { - //this.rotationYaw = generateYaw(frontPos, backPos); + this.rotationYaw = generateYaw(frontPos, backPos); } } + + PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(new ChatComponentText("Yaw: " + this.rotationYaw), 665, 3000), (EntityPlayerMP) worldObj.playerEntities.get(0)); } } public Vec3 getRelPosAlongRail(BlockPos anchor, double distanceToCover) { - double overshoot = 0; float yaw = this.rotationYaw; Vec3 next = Vec3.createVectorHelper(posX, posY, posZ); @@ -114,8 +124,7 @@ public abstract class EntityRailCarBase extends Entity { Block block = worldObj.getBlock(x, y, z); Vec3 rot = Vec3.createVectorHelper(0, 0, 1); - rot.rotateAroundY((float) (yaw * Math.PI / 180D)); - + rot.rotateAroundY((float) (-yaw * Math.PI / 180D)); if(block instanceof IRailNTM) { IRailNTM rail = (IRailNTM) block; @@ -124,9 +133,11 @@ public abstract class EntityRailCarBase extends Entity { RailLeaveInfo info = new RailLeaveInfo(); Vec3 prev = next; next = rail.getTravelLocation(worldObj, x, y, z, posX, posY, posZ, rot.xCoord, rot.yCoord, rot.zCoord, distanceToCover, info); - overshoot = info.overshoot; + distanceToCover = info.overshoot; anchor = info.pos; yaw = generateYaw(next, prev); + + //if(info.overshoot > 0) System.out.println("[" + (worldObj.getTotalWorldTime() % 100) + "] Left track " + ((Block) rail).getUnlocalizedName() + " with " + ((int)(info.overshoot * 100) / 100D) + "m more to go!"); } else { return null; @@ -135,7 +146,7 @@ public abstract class EntityRailCarBase extends Entity { return null; } - } while(overshoot != 0); //if there's still length to cover, keep going + } while(distanceToCover != 0); //if there's still length to cover, keep going return next; } diff --git a/src/main/java/com/hbm/entity/train/EntityRailCarRidable.java b/src/main/java/com/hbm/entity/train/EntityRailCarRidable.java index 615db63b0..95dd63367 100644 --- a/src/main/java/com/hbm/entity/train/EntityRailCarRidable.java +++ b/src/main/java/com/hbm/entity/train/EntityRailCarRidable.java @@ -31,7 +31,7 @@ public abstract class EntityRailCarRidable extends EntityRailCarBase { public void updateRiderPosition() { Vec3 offset = getRiderSeatPosition(); - offset.rotateAroundY((float) (this.rotationYaw * Math.PI / 180)); + offset.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180)); if(this.riddenByEntity != null) { this.riddenByEntity.setPosition(this.posX + offset.xCoord, this.posY + offset.yCoord, this.posZ + offset.zCoord); diff --git a/src/main/java/com/hbm/entity/train/TrainCargoTram.java b/src/main/java/com/hbm/entity/train/TrainCargoTram.java index 900f1026d..5f76989a4 100644 --- a/src/main/java/com/hbm/entity/train/TrainCargoTram.java +++ b/src/main/java/com/hbm/entity/train/TrainCargoTram.java @@ -69,7 +69,7 @@ public class TrainCargoTram extends EntityRailCarRidable { @Override public Vec3 getRiderSeatPosition() { - return Vec3.createVectorHelper(0.75, 1.75, 0.75); + return Vec3.createVectorHelper(0.375, 1.75, 0.5); } @Override diff --git a/src/main/java/com/hbm/items/tool/ItemWandD.java b/src/main/java/com/hbm/items/tool/ItemWandD.java index 9401b7b76..06b60dc0f 100644 --- a/src/main/java/com/hbm/items/tool/ItemWandD.java +++ b/src/main/java/com/hbm/items/tool/ItemWandD.java @@ -2,13 +2,24 @@ package com.hbm.items.tool; import java.util.List; +import com.hbm.blocks.rail.IRailNTM; +import com.hbm.blocks.rail.IRailNTM.RailLeaveInfo; import com.hbm.lib.Library; +import com.hbm.packet.PacketDispatcher; +import com.hbm.packet.PlayerInformPacket; +import com.hbm.util.ParticleUtil; +import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.world.feature.OilSpot; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; import net.minecraft.world.World; public class ItemWandD extends Item { @@ -23,6 +34,60 @@ public class ItemWandD extends Item { if(pos != null) { + float yaw = player.rotationYaw; + + Vec3 next = Vec3.createVectorHelper(pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord); + int it = 0; + + BlockPos anchor = new BlockPos(pos.blockX, pos.blockY, pos.blockZ); + + double distanceToCover = 2D; + + ParticleUtil.spawnGasFlame(world, pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord, 0, 0.2, 0); + + do { + + it++; + + if(it > 30) { + world.createExplosion(player, pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord, 5F, false); + return stack; + } + + int x = anchor.getX(); + int y = anchor.getY(); + int z = anchor.getZ(); + Block block = world.getBlock(x, y, z); + + Vec3 rot = Vec3.createVectorHelper(0, 0, 1); + rot.rotateAroundY((float) (-yaw * Math.PI / 180D)); + + if(block instanceof IRailNTM) { + IRailNTM rail = (IRailNTM) block; + + RailLeaveInfo info = new RailLeaveInfo(); + Vec3 prev = next; + next = rail.getTravelLocation(world, x, y, z, prev.xCoord, prev.yCoord, prev.zCoord, rot.xCoord, rot.yCoord, rot.zCoord, distanceToCover, info); + distanceToCover = info.overshoot; + anchor = info.pos; + + ParticleUtil.spawnGasFlame(world, next.xCoord, next.yCoord, next.zCoord, 0, 0.2 * it, 0); + + double deltaX = next.xCoord - prev.xCoord; + double deltaZ = next.zCoord - prev.zCoord; + double radians = -Math.atan2(deltaX, deltaZ); + yaw = (float) MathHelper.wrapAngleTo180_double(radians * 180D / Math.PI); + + PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(new ChatComponentText("Yaw: " + yaw), 0, 3000), (EntityPlayerMP) player); + + //if(info.overshoot > 0) System.out.println("[" + (worldObj.getTotalWorldTime() % 100) + "] Left track " + ((Block) rail).getUnlocalizedName() + " with " + ((int)(info.overshoot * 100) / 100D) + "m more to go!"); + + } else { + return stack; + } + + } while(distanceToCover != 0); //if there's still length to cover, keep going + /*TimeAnalyzer.startCount("setBlock"); world.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.dirt); TimeAnalyzer.startEndCount("getBlock"); @@ -58,8 +123,6 @@ public class ItemWandD extends Item { //MapGenStronghold.Start startS = new MapGenStronghold.Start(world, world.rand, pos.blockX >> 4, pos.blockZ >> 4); //startS.generateStructure(world, world.rand, new StructureBoundingBox(k - 124, l - 124, k + 15 + 124, l + 15 + 124)); - OilSpot.generateOilSpot(world, pos.blockX, pos.blockZ, 3, 50, true); - /*EntityNukeTorex torex = new EntityNukeTorex(world); torex.setPositionAndRotation(pos.blockX, pos.blockY + 1, pos.blockZ, 0, 0); torex.getDataWatcher().updateObject(10, 1.5F); diff --git a/src/main/java/com/hbm/render/entity/item/RenderTrainCargoTram.java b/src/main/java/com/hbm/render/entity/item/RenderTrainCargoTram.java index 660340f0f..5603c1d94 100644 --- a/src/main/java/com/hbm/render/entity/item/RenderTrainCargoTram.java +++ b/src/main/java/com/hbm/render/entity/item/RenderTrainCargoTram.java @@ -16,11 +16,11 @@ public class RenderTrainCargoTram extends Render { GL11.glPushMatrix(); GL11.glTranslated(x, y, z); - GL11.glRotated(180 - entity.rotationYaw, 0, 1, 0); + GL11.glRotated( -entity.rotationYaw, 0, 1, 0); GL11.glRotated(-entity.rotationPitch, 0, 0, 1); - MainRegistry.proxy.displayTooltip("Yaw: " + entity.rotationYaw, 666); - MainRegistry.proxy.displayTooltip("Pitch: " + entity.rotationPitch, 667); + MainRegistry.proxy.displayTooltip("Render Yaw: " + entity.rotationYaw, 666); + MainRegistry.proxy.displayTooltip("Render Pitch: " + entity.rotationPitch, 667); GL11.glDisable(GL11.GL_CULL_FACE); bindTexture(ResourceManager.universal);