straightened the straights, rail debugger

This commit is contained in:
Bob 2023-05-06 12:43:32 +02:00
parent 4433726af2
commit a558b1d83b
5 changed files with 85 additions and 79 deletions

View File

@ -15,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@ -76,6 +77,8 @@ public class RailStandardCurve extends BlockDummyable implements IRailNTM {
double angleDeg = -Math.atan(dist.zCoord / dist.xCoord) * 180D / Math.PI;
if(dir == Library.NEG_X) angleDeg += 90;
if(dir == Library.POS_X) angleDeg -= 90;
angleDeg = MathHelper.wrapAngleTo180_double(angleDeg);
double length90Deg = turnRadius * Math.PI / 2D;
double angularChange = speed / length90Deg * 90D;
@ -92,20 +95,19 @@ public class RailStandardCurve extends BlockDummyable implements IRailNTM {
}
double effAngle = angleDeg + angularChange;
if(Math.abs(speed) != 2)PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(new ChatComponentText(angleDeg + ""), 999, 3000), (EntityPlayerMP) world.playerEntities.get(0));
effAngle = MathHelper.wrapAngleTo180_double(effAngle);
if(effAngle > 90) {
double angleOvershoot = effAngle - 90D;
double lengthOvershoot = angleOvershoot * length90Deg / 90D;
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);
info.dist(lengthOvershoot * Math.signum(speed * angularChange)).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, y, axisZ - dir.offsetZ * turnRadius);
}
if(effAngle < 0) {
double angleOvershoot = effAngle;
double angleOvershoot = -effAngle;
double lengthOvershoot = angleOvershoot * length90Deg / 90D;
info.dist(lengthOvershoot).pos(new BlockPos(cX + dir.offsetX , y, cZ + dir.offsetZ));
info.dist(-lengthOvershoot * Math.signum(speed * angularChange)).pos(new BlockPos(cX + dir.offsetX , y, cZ + dir.offsetZ));
return Vec3.createVectorHelper(axisX + 0.5 + dir.offsetX * 0.5, y, axisZ * 0.5 + dir.offsetZ * 0.5);
}

View File

@ -86,8 +86,8 @@ public class RailStandardStraight extends BlockDummyable implements IRailNTM {
vec.xCoord = MathHelper.clamp_double(targetX, cX - 2, cX + 3);
vec.yCoord = y;
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));
info.dist(Math.abs(targetX - vec.xCoord) * Math.signum(speed));
info.pos(new BlockPos(cX + (motionX * speed > 0 ? 3 : -3), y, cZ));
} else {
double targetZ = trainZ;
if(motionZ > 0) {
@ -98,8 +98,8 @@ public class RailStandardStraight extends BlockDummyable implements IRailNTM {
vec.xCoord = cX + 0.5;
vec.yCoord = y;
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)));
info.dist(Math.abs(targetZ - vec.zCoord) * Math.signum(speed));
info.pos(new BlockPos(cX, y, cZ + (motionZ * speed > 0 ? 3 : -3)));
}
return vec;

View File

@ -136,8 +136,6 @@ public abstract class EntityRailCarBase extends Entity {
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;
@ -154,8 +152,8 @@ public abstract class EntityRailCarBase extends Entity {
public float generateYaw(Vec3 front, Vec3 back) {
double deltaX = front.xCoord - back.xCoord;
double deltaZ = front.zCoord - back.zCoord;
double radians = Math.atan(deltaZ / deltaX);
return (float) MathHelper.wrapAngleTo180_double(radians * 180D / Math.PI - 90);
double radians = -Math.atan2(deltaX, deltaZ);
return (float) MathHelper.wrapAngleTo180_double(radians * 180D / Math.PI);
}
/** Returns the amount of blocks that the train should move per tick */

View File

@ -34,60 +34,6 @@ 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");

View File

@ -12,6 +12,8 @@ import org.lwjgl.opengl.GL11;
import com.hbm.blocks.ILookOverlay;
import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.generic.BlockAshes;
import com.hbm.blocks.rail.IRailNTM;
import com.hbm.blocks.rail.IRailNTM.RailLeaveInfo;
import com.hbm.config.GeneralConfig;
import com.hbm.entity.effect.EntityNukeTorex;
import com.hbm.entity.mob.EntityHunterChopper;
@ -42,6 +44,7 @@ import com.hbm.lib.RefStrings;
import com.hbm.packet.AuxButtonPacket;
import com.hbm.packet.GunButtonPacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.PlayerInformPacket;
import com.hbm.packet.SyncButtonsPacket;
import com.hbm.render.anim.HbmAnimations;
import com.hbm.render.anim.HbmAnimations.Animation;
@ -64,12 +67,14 @@ import com.hbm.tileentity.machine.TileEntityNukeFurnace;
import com.hbm.util.I18nUtil;
import com.hbm.util.ItemStackUtil;
import com.hbm.util.LoggingUtil;
import com.hbm.util.ParticleUtil;
import com.hbm.wiaj.GuiWorldInAJar;
import com.hbm.wiaj.cannery.CanneryBase;
import com.hbm.wiaj.cannery.Jars;
import com.hbm.util.ArmorRegistry;
import com.hbm.util.ArmorUtil;
import com.hbm.util.ArmorRegistry.HazardClass;
import com.hbm.util.fauxpointtwelve.BlockPos;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import api.hbm.item.IButtonReceiver;
@ -98,6 +103,7 @@ import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
@ -105,6 +111,7 @@ import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
@ -203,17 +210,70 @@ public class ModEventHandlerClient {
}*/
List<String> text = new ArrayList();
text.add("YAW: " + player.rotationYaw);
text.add("PITCH: " + player.rotationPitch);
int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
int j = 0;
if(i == 0) j = 2;
if(i == 1) j = 5;
if(i == 2) j = 3;
if(i == 3) j = 4;
ForgeDirection dir = ForgeDirection.getOrientation(j).getOpposite();
text.add("x: " + dir.offsetX + " z: " + dir.offsetZ);
ILookOverlay.printGeneric(event, "DEBUG", 0xffff00, 0x4040000, text);
MovingObjectPosition pos = Library.rayTrace(player, 500, 1, false, true, false);
for(int i = 0; i < 2; i++) if(pos != null && pos.typeOfHit == pos.typeOfHit.BLOCK) {
float yaw = player.rotationYaw;
Vec3 next = Vec3.createVectorHelper(pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord);
Vec3 first = next;
int it = 0;
BlockPos anchor = new BlockPos(pos.blockX, pos.blockY, pos.blockZ);
double distanceToCover = 4D * (i == 0 ? 1 : -1);
do {
it++;
if(it > 30) {
world.createExplosion(player, pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord, 5F, false);
break;
}
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();
boolean flip = distanceToCover < 0;
if(it == 1) {
Vec3 snap = rail.getTravelLocation(world, x, y, z, next.xCoord, next.yCoord, next.zCoord, rot.xCoord, rot.yCoord, rot.zCoord, 0, info);
if(i == 0) world.spawnParticle("reddust", snap.xCoord, snap.yCoord + 0.25, snap.zCoord, 0.1, 1, 0.1);
}
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;
if(i == 0) world.spawnParticle("reddust", next.xCoord, next.yCoord + 0.25, next.zCoord, 0, distanceToCover != 0 ? 0.5 : 0, 0);
else world.spawnParticle("reddust", next.xCoord, next.yCoord + 0.25, next.zCoord, 0, distanceToCover != 0 ? 0.5 : 0, 1);
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 + (flip ? 180 : 0));
text.add(it + ": " + distanceToCover);
} else {
break;
}
} while(distanceToCover != 0);
ILookOverlay.printGeneric(event, "DEBUG", 0xffff00, 0x4040000, text);
}
}
/// HANLDE ANIMATION BUSES ///