use of club.nsdn.nyasamarailway.block.rail.special.BlockRailReception in project NyaSamaRailway by NSDN.
the class MinecartBase method func_145821_a.
// applyPush()
@Override
protected void func_145821_a(int x, int y, int z, double maxVel, double slopeAdj, Block block, int meta) {
// applyPush
if (block instanceof BlockRailReception) {
BlockRailReception.TileEntityRailReception tile = (BlockRailReception.TileEntityRailReception) worldObj.getTileEntity(x, y, z);
if (!((BlockRailReception) block).checkNearbySameRail(worldObj, x, y, z))
if (riddenByEntity == null && !tile.cartType.isEmpty()) {
if (!tile.cartType.equals("loco"))
return;
}
}
if (block instanceof BlockRailReceptionAnti) {
BlockRailReceptionAnti.TileEntityRailReceptionAnti tile = (BlockRailReceptionAnti.TileEntityRailReceptionAnti) worldObj.getTileEntity(x, y, z);
if (!((BlockRailReceptionAnti) block).checkNearbySameRail(worldObj, x, y, z))
if (riddenByEntity == null && !tile.cartType.isEmpty()) {
if (!tile.cartType.equals("loco"))
return;
}
}
if (block instanceof RailMonoMagnetReception) {
RailMonoMagnetReception.TileEntityRail tile = (RailMonoMagnetReception.TileEntityRail) worldObj.getTileEntity(x, y, z);
if (!((RailMonoMagnetReception) block).checkNearbySameRail(worldObj, x, y, z))
if (riddenByEntity == null && !tile.cartType.isEmpty())
return;
}
if (block instanceof RailMonoMagnetReceptionAnti) {
RailMonoMagnetReceptionAnti.TileEntityRail tile = (RailMonoMagnetReceptionAnti.TileEntityRail) worldObj.getTileEntity(x, y, z);
if (!((RailMonoMagnetReceptionAnti) block).checkNearbySameRail(worldObj, x, y, z))
if (riddenByEntity == null && !tile.cartType.isEmpty())
return;
}
/* ******************************** MAIN FUNC ******************************** */
this.fallDistance = 0.0F;
Vec3 vec3 = this.func_70489_a(this.posX, this.posY, this.posZ);
this.posY = (double) y;
boolean isRailPowered = false;
boolean slowDown = false;
if (block == Blocks.golden_rail) {
// Stock Powered Rail, Push-Brake
isRailPowered = (this.worldObj.getBlockMetadata(x, y, z) & 8) != 0;
slowDown = !isRailPowered;
}
if (((BlockRailBase) block).isPowered()) {
meta &= 7;
}
if (meta >= 2 && meta <= 5) {
this.posY = (double) (y + 1);
}
if (meta == 2) {
this.motionX -= slopeAdj;
}
if (meta == 3) {
this.motionX += slopeAdj;
}
if (meta == 4) {
this.motionZ += slopeAdj;
}
if (meta == 5) {
this.motionZ -= slopeAdj;
}
int[][] aint = matrix[meta];
double d2 = (double) (aint[1][0] - aint[0][0]);
double d3 = (double) (aint[1][2] - aint[0][2]);
double d4 = Math.sqrt(d2 * d2 + d3 * d3);
double d5 = this.motionX * d2 + this.motionZ * d3;
if (d5 < 0.0D) {
d2 = -d2;
d3 = -d3;
}
double vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (vel > getMaxCartSpeedOnRail()) {
vel = getMaxCartSpeedOnRail();
}
this.motionX = vel * d2 / d4;
this.motionZ = vel * d3 / d4;
double d7;
double d8;
double d9;
double d10;
if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase) {
d7 = (double) ((EntityLivingBase) this.riddenByEntity).moveForward;
if (d7 > 0.0D) {
d8 = -Math.sin((double) (this.riddenByEntity.rotationYaw * 3.1415927F / 180.0F));
d9 = Math.cos((double) (this.riddenByEntity.rotationYaw * 3.1415927F / 180.0F));
d10 = this.motionX * this.motionX + this.motionZ * this.motionZ;
if (d10 < 0.01D) {
this.motionX += d8 * 0.1D;
this.motionZ += d9 * 0.1D;
slowDown = false;
}
}
}
if (slowDown && this.shouldDoRailFunctions()) {
d7 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (d7 < 0.03D) {
this.motionX *= 0.0D;
this.motionY *= 0.0D;
this.motionZ *= 0.0D;
} else {
this.motionX *= 0.5D;
this.motionY *= 0.0D;
this.motionZ *= 0.5D;
}
}
d7 = 0.0D;
d8 = (double) x + 0.5D + (double) aint[0][0] * 0.5D;
d9 = (double) z + 0.5D + (double) aint[0][2] * 0.5D;
d10 = (double) x + 0.5D + (double) aint[1][0] * 0.5D;
double d11 = (double) z + 0.5D + (double) aint[1][2] * 0.5D;
d2 = d10 - d8;
d3 = d11 - d9;
if (d2 == 0.0D) {
this.posX = (double) x + 0.5D;
d7 = this.posZ - (double) z;
} else if (d3 == 0.0D) {
this.posZ = (double) z + 0.5D;
d7 = this.posX - (double) x;
} else {
double d12 = this.posX - d8;
double d13 = this.posZ - d9;
d7 = (d12 * d2 + d13 * d3) * 2.0D;
}
this.posX = d8 + d2 * d7;
this.posZ = d9 + d3 * d7;
this.setPosition(this.posX, this.posY + (double) this.yOffset, this.posZ);
this.moveMinecartOnRail(x, y, z, maxVel);
if (aint[0][1] != 0 && MathHelper.floor_double(this.posX) - x == aint[0][0] && MathHelper.floor_double(this.posZ) - z == aint[0][2]) {
this.setPosition(this.posX, this.posY + (double) aint[0][1], this.posZ);
} else if (aint[1][1] != 0 && MathHelper.floor_double(this.posX) - x == aint[1][0] && MathHelper.floor_double(this.posZ) - z == aint[1][2]) {
this.setPosition(this.posX, this.posY + (double) aint[1][1], this.posZ);
}
this.applyDrag();
Vec3 vec31 = this.func_70489_a(this.posX, this.posY, this.posZ);
if (vec31 != null && vec3 != null) {
double d14 = (vec3.yCoord - vec31.yCoord) * 0.05D;
vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (vel > 0.0D) {
this.motionX = this.motionX / vel * (vel + d14);
this.motionZ = this.motionZ / vel * (vel + d14);
}
this.setPosition(this.posX, vec31.yCoord, this.posZ);
}
/**
* HOLY SHIT! THE CODE CAUSES BUG!
* int pX = MathHelper.floor_double(this.posX);
* int pZ = MathHelper.floor_double(this.posZ);
* if (pX != x || pZ != z) {
* vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
* this.motionX = vel * (double)(pX - x);
* this.motionZ = vel * (double)(pZ - z);
* }
*/
if (this.shouldDoRailFunctions()) {
((BlockRailBase) block).onMinecartPass(this.worldObj, this, x, y, z);
}
if (isRailPowered && this.shouldDoRailFunctions()) {
double d15 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (d15 > 0.01D) {
double d16 = 0.06D;
this.motionX += this.motionX / d15 * d16;
this.motionZ += this.motionZ / d15 * d16;
} else if (meta == 1) {
if (this.worldObj.getBlock(x - 1, y, z).isNormalCube()) {
this.motionX = 0.02D;
} else if (this.worldObj.getBlock(x + 1, y, z).isNormalCube()) {
this.motionX = -0.02D;
}
} else if (meta == 0) {
if (this.worldObj.getBlock(x, y, z - 1).isNormalCube()) {
this.motionZ = 0.02D;
} else if (this.worldObj.getBlock(x, y, z + 1).isNormalCube()) {
this.motionZ = -0.02D;
}
}
}
}
use of club.nsdn.nyasamarailway.block.rail.special.BlockRailReception in project NyaSamaRailway by NSDN.
the class Item1N4148 method onItemUseFirst.
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
Block block = world.getBlock(x, y, z);
if (block == null)
return false;
if (block instanceof IRailDirectional) {
if (player.isSneaking()) {
TileEntity rail = world.getTileEntity(x, y, z);
if (rail == null)
return false;
if (rail instanceof BlockRailReception.TileEntityRailReception) {
if (((BlockRailReception.TileEntityRailReception) rail).cartType.isEmpty()) {
((BlockRailReception.TileEntityRailReception) rail).cartType = "loco";
say(player, "info.reception.loco");
} else {
if (((BlockRailReception.TileEntityRailReception) rail).cartType.equals("loco")) {
((BlockRailReception.TileEntityRailReception) rail).cartType = "";
say(player, "info.reception.reset");
} else {
((BlockRailReception.TileEntityRailReception) rail).cartType = "";
((BlockRailReception.TileEntityRailReception) rail).extInfo = "";
;
say(player, "info.reception.cleared");
}
}
return !world.isRemote;
} else if (rail instanceof BlockRailReceptionAnti.TileEntityRailReceptionAnti) {
if (((BlockRailReceptionAnti.TileEntityRailReceptionAnti) rail).cartType.isEmpty()) {
((BlockRailReceptionAnti.TileEntityRailReceptionAnti) rail).cartType = "loco";
say(player, "info.reception.loco");
} else {
if (((BlockRailReceptionAnti.TileEntityRailReceptionAnti) rail).cartType.equals("loco")) {
((BlockRailReceptionAnti.TileEntityRailReceptionAnti) rail).cartType = "";
say(player, "info.reception.reset");
} else {
((BlockRailReceptionAnti.TileEntityRailReceptionAnti) rail).cartType = "";
((BlockRailReceptionAnti.TileEntityRailReceptionAnti) rail).extInfo = "";
say(player, "info.reception.cleared");
}
}
return !world.isRemote;
} else if (rail instanceof RailMonoMagnetReception.TileEntityRail) {
if (((RailMonoMagnetReception.TileEntityRail) rail).cartType.isEmpty()) {
((RailMonoMagnetReception.TileEntityRail) rail).cartType = "loco";
say(player, "info.reception.loco");
} else {
if (((RailMonoMagnetReception.TileEntityRail) rail).cartType.equals("loco")) {
((RailMonoMagnetReception.TileEntityRail) rail).cartType = "";
say(player, "info.reception.reset");
} else {
((RailMonoMagnetReception.TileEntityRail) rail).cartType = "";
((RailMonoMagnetReception.TileEntityRail) rail).extInfo = "";
say(player, "info.reception.cleared");
}
}
return !world.isRemote;
} else if (rail instanceof RailMonoMagnetReceptionAnti.TileEntityRail) {
if (((RailMonoMagnetReceptionAnti.TileEntityRail) rail).cartType.isEmpty()) {
((RailMonoMagnetReceptionAnti.TileEntityRail) rail).cartType = "loco";
say(player, "info.reception.loco");
} else {
if (((RailMonoMagnetReceptionAnti.TileEntityRail) rail).cartType.equals("loco")) {
((RailMonoMagnetReceptionAnti.TileEntityRail) rail).cartType = "";
say(player, "info.reception.reset");
} else {
((RailMonoMagnetReceptionAnti.TileEntityRail) rail).cartType = "";
((RailMonoMagnetReceptionAnti.TileEntityRail) rail).extInfo = "";
say(player, "info.reception.cleared");
}
}
return !world.isRemote;
}
}
if (((IRailDirectional) block).isForward()) {
if (block instanceof BlockRailReception)
world.setBlock(x, y, z, BlockLoader.blockRailReceptionAnti);
if (block instanceof BlockRailProtectHead) {
int meta = world.getBlockMetadata(x, y, z);
world.setBlock(x, y, z, BlockLoader.blockRailProtectHeadAnti);
world.setBlockMetadataWithNotify(x, y, z, meta, 1);
}
if ((block instanceof BlockRailDirectional))
world.setBlock(x, y, z, BlockLoader.blockRailDirectionalAnti);
if (block instanceof RailMonoMagnetReception)
world.setBlock(x, y, z, BlockLoader.railMonoMagnetReceptionAnti);
if ((block instanceof RailMonoMagnetDirectional))
world.setBlock(x, y, z, BlockLoader.railMonoMagnetDirectionalAnti);
} else {
if (block instanceof BlockRailReceptionAnti)
world.setBlock(x, y, z, BlockLoader.blockRailReception);
if (block instanceof BlockRailProtectHeadAnti) {
int meta = world.getBlockMetadata(x, y, z);
world.setBlock(x, y, z, BlockLoader.blockRailProtectHead);
world.setBlockMetadataWithNotify(x, y, z, meta, 1);
}
if ((block instanceof BlockRailDirectionalAnti))
world.setBlock(x, y, z, BlockLoader.blockRailDirectional);
if (block instanceof RailMonoMagnetReceptionAnti)
world.setBlock(x, y, z, BlockLoader.railMonoMagnetReception);
if ((block instanceof RailMonoMagnetDirectionalAnti))
world.setBlock(x, y, z, BlockLoader.railMonoMagnetDirectional);
}
return !world.isRemote;
} else if (block instanceof BlockRailDetectorBase && !(block instanceof IRailNoDelay)) {
int nowDelay = ((BlockRailDetectorBase) block).getDelaySecond();
if (block instanceof BlockRailStoneSleeperDetector) {
switch(nowDelay) {
case 0:
world.setBlock(x, y, z, BlockLoader.blockRailStoneSleeperDetector5s);
break;
case 5:
world.setBlock(x, y, z, BlockLoader.blockRailStoneSleeperDetector15s);
break;
case 15:
world.setBlock(x, y, z, BlockLoader.blockRailStoneSleeperDetector30s);
break;
case 30:
world.setBlock(x, y, z, BlockLoader.blockRailStoneSleeperDetector);
break;
}
} else if (block instanceof BlockRailNoSleeperDetector) {
switch(nowDelay) {
case 0:
world.setBlock(x, y, z, BlockLoader.blockRailNoSleeperDetector5s);
break;
case 5:
world.setBlock(x, y, z, BlockLoader.blockRailNoSleeperDetector15s);
break;
case 15:
world.setBlock(x, y, z, BlockLoader.blockRailNoSleeperDetector30s);
break;
case 30:
world.setBlock(x, y, z, BlockLoader.blockRailNoSleeperDetector);
break;
}
}
nowDelay = ((BlockRailDetectorBase) world.getBlock(x, y, z)).getDelaySecond();
say(player, "info.1N4148.delay", nowDelay);
return !world.isRemote;
} else if (block instanceof RailMonoMagnetDetector && !(block instanceof IRailNoDelay)) {
int nowDelay = ((RailMonoMagnetDetector) block).getDelaySecond();
switch(nowDelay) {
case 0:
world.setBlock(x, y, z, BlockLoader.railMonoMagnetDetector5s);
break;
case 5:
world.setBlock(x, y, z, BlockLoader.railMonoMagnetDetector15s);
break;
case 15:
world.setBlock(x, y, z, BlockLoader.railMonoMagnetDetector30s);
break;
case 30:
world.setBlock(x, y, z, BlockLoader.railMonoMagnetDetector);
break;
}
nowDelay = ((RailMonoMagnetDetector) world.getBlock(x, y, z)).getDelaySecond();
say(player, "info.1N4148.delay", nowDelay);
return !world.isRemote;
}
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity == null)
return false;
if (player.isSneaking()) {
if (tileEntity instanceof BlockCoinBlock.CoinBlock) {
BlockCoinBlock.CoinBlock coinBlock = (BlockCoinBlock.CoinBlock) tileEntity;
if (coinBlock.value <= 0)
coinBlock.value = 1;
switch(coinBlock.value) {
case 1:
coinBlock.value = 5;
break;
case 5:
coinBlock.value = 10;
break;
case 10:
coinBlock.value = 20;
break;
case 20:
coinBlock.value = 50;
break;
case 50:
coinBlock.value = 1;
break;
}
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.coin.value", coinBlock.value));
} else if (tileEntity instanceof BlockTicketBlockOnce.TicketBlock) {
BlockTicketBlockOnce.TicketBlock ticketBlock = (BlockTicketBlockOnce.TicketBlock) tileEntity;
switch(ticketBlock.setOver) {
case 1:
ticketBlock.setOver = 5;
break;
case 5:
ticketBlock.setOver = 10;
break;
case 10:
ticketBlock.setOver = 20;
break;
case 20:
ticketBlock.setOver = 50;
break;
case 50:
ticketBlock.setOver = 1;
break;
}
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.ticket.over", ticketBlock.setOver));
} else if (tileEntity instanceof BlockGateFront.GateFront) {
BlockGateFront.GateFront gateFront = (BlockGateFront.GateFront) tileEntity;
switch(gateFront.setOver) {
case 1:
gateFront.setOver = 5;
break;
case 5:
gateFront.setOver = 10;
break;
case 10:
gateFront.setOver = 20;
break;
case 20:
gateFront.setOver = 50;
break;
case 50:
gateFront.setOver = 1;
break;
}
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.gate.over", gateFront.setOver));
}
}
if (tileEntity instanceof TileEntityTransceiver) {
TileEntityTransceiver thisRail = (TileEntityTransceiver) tileEntity;
if (player.isSneaking() && !world.isRemote) {
UUID uuid = player.getUniqueID();
if (tmpRails.containsKey(uuid)) {
if (tmpRails.get(uuid) == thisRail) {
thisRail.setTransceiver(null);
say(player, "info.blocking.abort");
} else {
if (thisRail.getTransceiver() == tmpRails.get(uuid)) {
thisRail.getTransceiver().setTransceiver(null);
thisRail.setTransceiver(null);
say(player, "info.blocking.disconnected");
} else {
thisRail.setTransceiver(tmpRails.get(uuid));
thisRail.getTransceiver().setTransceiver(thisRail);
say(player, "info.blocking.connected");
}
}
tmpRails.remove(uuid);
} else {
tmpRails.put(uuid, thisRail);
say(player, "info.blocking.begin");
}
return true;
}
} else if (tileEntity instanceof BlockTriStateSignalBox.TileEntityTriStateSignalBox) {
BlockTriStateSignalBox.TileEntityTriStateSignalBox signalBox = (BlockTriStateSignalBox.TileEntityTriStateSignalBox) tileEntity;
if (player.isSneaking()) {
signalBox.prevInverterEnabled = signalBox.inverterEnabled;
if (signalBox.inverterEnabled) {
signalBox.inverterEnabled = false;
say(player, "info.signal.box.inverter.off");
} else {
signalBox.inverterEnabled = true;
say(player, "info.signal.box.inverter.on");
}
} else {
signalBox.prevTriStateIsNeg = signalBox.triStateIsNeg;
if (signalBox.triStateIsNeg) {
signalBox.triStateIsNeg = false;
say(player, "info.signal.box.triState.pos");
} else {
signalBox.triStateIsNeg = true;
say(player, "info.signal.box.triState.neg");
}
}
return !world.isRemote;
} else if (tileEntity instanceof BlockSignalBox.TileEntitySignalBox) {
BlockSignalBox.TileEntitySignalBox signalBox = (BlockSignalBox.TileEntitySignalBox) tileEntity;
if (player.isSneaking()) {
if (signalBox.inverterEnabled) {
signalBox.inverterEnabled = false;
say(player, "info.signal.box.inverter.off");
} else {
signalBox.inverterEnabled = true;
say(player, "info.signal.box.inverter.on");
}
}
return !world.isRemote;
} else if (tileEntity instanceof club.nsdn.nyasamarailway.tileblock.signal.TileEntitySignalLight) {
club.nsdn.nyasamarailway.tileblock.signal.TileEntitySignalLight signalLight = (club.nsdn.nyasamarailway.tileblock.signal.TileEntitySignalLight) tileEntity;
if (player.isSneaking()) {
signalLight.prevLightType = signalLight.lightType;
switch(signalLight.lightType) {
case "none":
signalLight.lightType = "red&off";
say(player, "info.signal.light.mode.red_off");
break;
case "red&off":
signalLight.lightType = "yellow&off";
say(player, "info.signal.light.mode.yellow_off");
break;
case "yellow&off":
signalLight.lightType = "green&off";
say(player, "info.signal.light.mode.green_off");
break;
case "green&off":
signalLight.lightType = "white&off";
say(player, "info.signal.light.mode.white_off");
break;
case "white&off":
signalLight.lightType = "blue&off";
say(player, "info.signal.light.mode.blue_off");
break;
case "blue&off":
signalLight.lightType = "purple&off";
say(player, "info.signal.light.mode.purple_off");
break;
case "purple&off":
signalLight.lightType = "red&yellow";
say(player, "info.signal.light.mode.red_yellow");
break;
case "red&yellow":
signalLight.lightType = "red&green";
say(player, "info.signal.light.mode.red_green");
break;
case "red&green":
signalLight.lightType = "yellow&green";
say(player, "info.signal.light.mode.yellow_green");
break;
case "yellow&green":
signalLight.lightType = "white&blue";
say(player, "info.signal.light.mode.white_blue");
break;
case "white&blue":
signalLight.lightType = "yellow&purple";
say(player, "info.signal.light.mode.yellow_purple");
break;
case "yellow&purple":
signalLight.lightType = "none";
say(player, "info.signal.light.mode.none");
break;
default:
break;
}
} else {
if (signalLight.isBlinking) {
signalLight.isBlinking = false;
say(player, "info.signal.light.blink.off");
} else {
signalLight.isBlinking = true;
say(player, "info.signal.light.blink.on");
}
}
return !world.isRemote;
}
return false;
}
Aggregations