mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
a curve that doesn't actually curve
This commit is contained in:
parent
abc4dc0cbf
commit
3983285c28
@ -11,6 +11,7 @@ import com.hbm.blocks.machine.*;
|
||||
import com.hbm.blocks.machine.pile.*;
|
||||
import com.hbm.blocks.machine.rbmk.*;
|
||||
import com.hbm.blocks.network.*;
|
||||
import com.hbm.blocks.rail.RailStandardCurve;
|
||||
import com.hbm.blocks.rail.RailStandardStraight;
|
||||
import com.hbm.blocks.siege.*;
|
||||
import com.hbm.blocks.test.*;
|
||||
@ -1085,8 +1086,9 @@ public class ModBlocks {
|
||||
public static Block rail_narrow;
|
||||
public static Block rail_highspeed;
|
||||
public static Block rail_booster;
|
||||
|
||||
|
||||
public static Block rail_large_straight;
|
||||
public static Block rail_large_curve;
|
||||
|
||||
public static Block statue_elb;
|
||||
public static Block statue_elb_g;
|
||||
@ -2113,6 +2115,7 @@ public class ModBlocks {
|
||||
rail_highspeed = new RailGeneric().setMaxSpeed(1F).setFlexible(false).setBlockName("rail_highspeed").setHardness(5.0F).setResistance(10.0F).setCreativeTab(CreativeTabs.tabTransport).setBlockTextureName(RefStrings.MODID + ":rail_highspeed");
|
||||
rail_booster = new RailBooster().setBlockName("rail_booster").setHardness(5.0F).setResistance(10.0F).setCreativeTab(CreativeTabs.tabTransport).setBlockTextureName(RefStrings.MODID + ":rail_booster");
|
||||
rail_large_straight = new RailStandardStraight().setBlockName("rail_large_straight").setHardness(5.0F).setResistance(10.0F).setCreativeTab(CreativeTabs.tabTransport).setBlockTextureName(RefStrings.MODID + ":block_steel");
|
||||
rail_large_curve = new RailStandardCurve().setBlockName("rail_large_curve").setHardness(5.0F).setResistance(10.0F).setCreativeTab(CreativeTabs.tabTransport).setBlockTextureName(RefStrings.MODID + ":block_steel");
|
||||
|
||||
crate = new BlockCrate(Material.wood).setBlockName("crate").setStepSound(Block.soundTypeWood).setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.consumableTab).setBlockTextureName(RefStrings.MODID + ":crate");
|
||||
crate_weapon = new BlockCrate(Material.wood).setBlockName("crate_weapon").setStepSound(Block.soundTypeWood).setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.consumableTab).setBlockTextureName(RefStrings.MODID + ":crate_weapon");
|
||||
@ -3331,6 +3334,7 @@ public class ModBlocks {
|
||||
GameRegistry.registerBlock(rail_highspeed, ItemBlockBase.class, rail_highspeed.getUnlocalizedName());
|
||||
GameRegistry.registerBlock(rail_booster, ItemBlockBase.class, rail_booster.getUnlocalizedName());
|
||||
register(rail_large_straight);
|
||||
register(rail_large_curve);
|
||||
|
||||
//Crate
|
||||
GameRegistry.registerBlock(crate, crate.getUnlocalizedName());
|
||||
|
||||
132
src/main/java/com/hbm/blocks/rail/RailStandardCurve.java
Normal file
132
src/main/java/com/hbm/blocks/rail/RailStandardCurve.java
Normal file
@ -0,0 +1,132 @@
|
||||
package com.hbm.blocks.rail;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.lib.Library;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class RailStandardCurve extends BlockDummyable implements IRailNTM {
|
||||
|
||||
public RailStandardCurve() {
|
||||
super(Material.iron);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3 getSnappingPos(World world, int x, int y, int z, double trainX, double trainY, double trainZ) {
|
||||
return snapAndMove(world, x, y, z, trainX, trainY, trainZ, 0, 0, 0, 0, new RailLeaveInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3 getTravelLocation(World world, int x, int y, int z, double trainX, double trainY, double trainZ, double motionX, double motionY, double motionZ, double speed, RailLeaveInfo info) {
|
||||
return snapAndMove(world, x, y, z, trainX, trainY, trainZ, motionX, motionY, motionZ, speed, info);
|
||||
}
|
||||
|
||||
/* Very simple function determining the snapping position and adding the motion value to it, if desired. */
|
||||
public Vec3 snapAndMove(World world, int x, int y, int z, double trainX, double trainY, double trainZ, double motionX, double motionY, double motionZ, double speed, RailLeaveInfo info) {
|
||||
int[] pos = this.findCore(world, x, y, z);
|
||||
if(pos == null) return Vec3.createVectorHelper(trainX, trainY, trainZ);
|
||||
int cX = pos[0];
|
||||
int cY = pos[1];
|
||||
int cZ = pos[2];
|
||||
int meta = world.getBlockMetadata(cX, cY, cZ) - this.offset;
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(meta);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
double turnRadius = 4.5D;
|
||||
|
||||
Vec3 vec = Vec3.createVectorHelper(trainX, trainY, trainZ);
|
||||
double axisX = cX + 0.5 + dir.offsetX * 0.5 + rot.offsetX * turnRadius;
|
||||
double axisZ = cZ + 0.5 + dir.offsetZ * 0.5 + rot.offsetZ * turnRadius;
|
||||
|
||||
Vec3 dist = Vec3.createVectorHelper(vec.xCoord - axisX, 0, vec.zCoord - axisZ);
|
||||
dist = dist.normalize();
|
||||
dist.xCoord *= turnRadius;
|
||||
dist.zCoord *= turnRadius;
|
||||
|
||||
if(speed == 0) {
|
||||
info.dist(0).pos(new BlockPos(x, y, z));
|
||||
return Vec3.createVectorHelper(axisX + dist.xCoord, y, axisZ + dist.zCoord);
|
||||
}
|
||||
|
||||
double angleDeg = -Math.atan(dist.zCoord / dist.xCoord) * 180D / Math.PI;
|
||||
double length90Deg = turnRadius * Math.PI / 2D;
|
||||
double angularChange = speed / length90Deg * 90D;
|
||||
|
||||
ForgeDirection moveDir = ForgeDirection.UNKNOWN;
|
||||
|
||||
if(Math.abs(motionX) > Math.abs(motionZ)) {
|
||||
moveDir = motionX > 0 ? Library.POS_X : Library.NEG_X;
|
||||
} else {
|
||||
moveDir = motionZ > 0 ? Library.POS_Z : Library.NEG_Z;
|
||||
}
|
||||
|
||||
if(moveDir == dir || moveDir == rot.getOpposite()) {
|
||||
angularChange *= -1;
|
||||
}
|
||||
|
||||
double effAngle = angleDeg + angularChange;
|
||||
|
||||
if(effAngle > 90) {
|
||||
double angleOvershoot = effAngle - 90D;
|
||||
double lengthOvershoot = angleOvershoot * length90Deg / 90D;
|
||||
info.dist(lengthOvershoot).pos(new BlockPos(cX - dir.offsetX * 4 + rot.offsetX * 4, y, cZ - dir.offsetZ * 4 + rot.offsetZ * 4));
|
||||
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 lengthOvershoot = angleOvershoot * length90Deg / 90D;
|
||||
info.dist(lengthOvershoot).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);
|
||||
}
|
||||
|
||||
double radianChange = angularChange * Math.PI / 180D;
|
||||
dist.rotateAroundY((float) -radianChange);
|
||||
|
||||
return Vec3.createVectorHelper(axisX + dist.xCoord, y, axisZ + dist.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackGauge getGauge(World world, int x, int y, int z) {
|
||||
return TrackGauge.STANDARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDimensions() {
|
||||
return new int[] {0, 0, 4, 0, 4, 0};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F);
|
||||
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ public class RailStandardStraight extends BlockDummyable implements IRailNTM {
|
||||
Vec3 vec = Vec3.createVectorHelper(trainX, trainY, trainZ);
|
||||
|
||||
if(speed == 0) {
|
||||
return vec;
|
||||
//return vec;
|
||||
}
|
||||
|
||||
if(dir == Library.POS_X || dir == Library.NEG_X) {
|
||||
|
||||
@ -75,7 +75,7 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
|
||||
anchor = this.getCurentAnchorPos(); //reset origin to new position
|
||||
Vec3 frontPos = getRelPosAlongRail(anchor, this.getLengthSpan());
|
||||
Vec3 backPos = getRelPosAlongRail(anchor, this.getLengthSpan());
|
||||
Vec3 backPos = getRelPosAlongRail(anchor, -this.getLengthSpan());
|
||||
|
||||
if(frontPos == null || backPos == null) {
|
||||
this.derail();
|
||||
@ -92,9 +92,17 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
float yaw = this.rotationYaw;
|
||||
|
||||
Vec3 next = Vec3.createVectorHelper(posX, posY, posZ);
|
||||
int it = 0;
|
||||
|
||||
do {
|
||||
|
||||
it++;
|
||||
|
||||
if(it > 30) {
|
||||
this.derail();
|
||||
return null;
|
||||
}
|
||||
|
||||
int x = anchor.getX();
|
||||
int y = anchor.getY();
|
||||
int z = anchor.getZ();
|
||||
|
||||
@ -4,6 +4,7 @@ import com.hbm.blocks.rail.IRailNTM.TrackGauge;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -26,10 +27,34 @@ public class TrainCargoTram extends EntityRailCarRidable {
|
||||
super(world);
|
||||
this.setSize(2F, 1F);
|
||||
}
|
||||
|
||||
public double speed = 0;
|
||||
public static final double maxSpeed = 0.5;
|
||||
public static final double acceleration = 0.01;
|
||||
public static final double deceleration = 0.75;
|
||||
|
||||
@Override
|
||||
public double getCurrentSpeed() {
|
||||
return this.riddenByEntity instanceof EntityPlayer ? ((EntityPlayer) this.riddenByEntity).moveForward * 0.125D : 0;
|
||||
public double getCurrentSpeed() { // in its current form, only call once per tick
|
||||
|
||||
if(this.riddenByEntity instanceof EntityPlayer) {
|
||||
|
||||
EntityPlayer player = (EntityPlayer) this.riddenByEntity;
|
||||
|
||||
if(player.moveForward > 0) {
|
||||
speed += acceleration;
|
||||
} else if(player.moveForward < 0) {
|
||||
speed -= acceleration;
|
||||
} else {
|
||||
speed *= deceleration;
|
||||
}
|
||||
|
||||
} else {
|
||||
speed *= deceleration;
|
||||
}
|
||||
|
||||
speed = MathHelper.clamp_double(speed, -maxSpeed, maxSpeed);
|
||||
|
||||
return speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user