use of net.minecraft.entity.player.EntityPlayerMP in project NyaSamaRailway by NSDN.
the class ItemPierBuilder 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 (player.isSneaking()) {
endBlock = block;
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.endBlock", endBlock.getLocalizedName()));
} else {
if (endBlock == null)
return false;
if (!(block instanceof BlockPierTag))
return false;
else {
world.setBlock(x, y, z, Blocks.air);
block = world.getBlock(x, y + 1, z);
}
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.begin"));
// dy = -1 to use pier tag
for (int dy = -1; !reachesEndBlock(world, x, y - dy - 1, z); dy++) {
traversalCounter = 0;
TraversalBlocks(world, block, x, y - dy, z);
if (traversalCounter > TRAVERSAL_MAX) {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.abort"));
break;
}
}
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.finish"));
}
return !world.isRemote;
}
use of net.minecraft.entity.player.EntityPlayerMP in project NyaSamaRailway by NSDN.
the class NGTPacketHandler method onMessage.
@Override
public IMessage onMessage(NGTPacket packet, MessageContext context) {
EntityPlayerMP serverPlayer = context.getServerHandler().playerEntity;
NBTTagCompound tagCompound = packet.stack.getTagCompound();
if (serverPlayer.getCurrentEquippedItem() != null)
serverPlayer.getCurrentEquippedItem().setTagCompound(tagCompound);
return null;
}
use of net.minecraft.entity.player.EntityPlayerMP in project NyaSamaRailway by NSDN.
the class Connector 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 (!world.isRemote) {
if (player.isSneaking()) {
UUID uuid = player.getUniqueID();
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityTransceiver) {
TileEntityTransceiver railSender = (TileEntityTransceiver) tileEntity;
if (tmpRails.containsKey(uuid)) {
tmpRails.remove(uuid);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.abort"));
} else {
tmpRails.put(uuid, railSender);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.begin"));
}
return true;
} else if (tileEntity instanceof TileEntityReceiver) {
TileEntityReceiver railReceiver = (TileEntityReceiver) tileEntity;
if (tmpRails.containsKey(uuid)) {
if (railReceiver.getSender() != tmpRails.get(uuid)) {
if (tmpRails.get(uuid).getTransceiver() == null) {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
} else {
railReceiver.setSender(tmpRails.get(uuid));
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
updateTileEntity(tmpRails.get(uuid));
updateTileEntity(railReceiver);
}
tmpRails.remove(uuid);
} else {
if (railReceiver.getSender() == tmpRails.get(uuid)) {
railReceiver.setSender(null);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
updateTileEntity(tmpRails.get(uuid));
updateTileEntity(railReceiver);
tmpRails.remove(uuid);
}
}
} else {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
}
return true;
}
} else {
UUID uuid = player.getUniqueID();
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityMultiSender) {
TileEntityMultiSender sender = (TileEntityMultiSender) tileEntity;
if (senderRails.containsKey(uuid)) {
if (senderRails.get(uuid) instanceof TileEntityMultiSender) {
if (senderRails.get(uuid) == sender) {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.abort"));
} else {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
}
} else {
if (sender.getTransceiver() == senderRails.get(uuid)) {
sender.getTransceiver().setTransceiver(null);
sender.setTransceiver(null);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
updateTileEntity(senderRails.get(uuid));
updateTileEntity(sender);
} else {
sender.setTransceiver(senderRails.get(uuid));
sender.getTransceiver().setTransceiver(sender);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
updateTileEntity(senderRails.get(uuid));
updateTileEntity(sender);
}
}
senderRails.remove(uuid);
} else {
if (receiverRails.containsKey(uuid)) {
// Here is actuator to transceiver, 1 to 1
if (receiverRails.get(uuid) instanceof TileEntityActuator) {
TileEntityActuator actuator = (TileEntityActuator) receiverRails.get(uuid);
if (actuator.getTarget() != sender) {
actuator.setTarget(sender);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
updateTileEntity(actuator);
updateTileEntity(sender);
} else {
actuator.setTarget(null);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
updateTileEntity(actuator);
updateTileEntity(sender);
}
} else {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
}
receiverRails.remove(uuid);
} else {
senderRails.put(uuid, sender);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.begin"));
}
}
return true;
} else if (tileEntity instanceof TileEntityTransceiver) {
TileEntityTransceiver transceiver = (TileEntityTransceiver) tileEntity;
if (senderRails.containsKey(uuid)) {
if (senderRails.get(uuid) instanceof TileEntityMultiSender) {
if (transceiver.getTransceiver() == senderRails.get(uuid)) {
transceiver.getTransceiver().setTransceiver(null);
transceiver.setTransceiver(null);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
updateTileEntity(senderRails.get(uuid));
updateTileEntity(transceiver);
} else {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
}
} else {
// Here is blocking rail, link with 1n4148 instead of this item, it may be dangerous
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.abort"));
}
senderRails.remove(uuid);
} else {
senderRails.put(uuid, transceiver);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.begin"));
}
return true;
} else if (tileEntity instanceof TileEntityReceiver) {
TileEntityReceiver receiver = (TileEntityReceiver) tileEntity;
if (senderRails.containsKey(uuid)) {
if (receiver.getSender() != senderRails.get(uuid)) {
receiver.setSender(senderRails.get(uuid));
if (senderRails.get(uuid) instanceof TileEntityMultiSender) {
((TileEntityMultiSender) senderRails.get(uuid)).incTarget();
}
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
updateTileEntity(senderRails.get(uuid));
updateTileEntity(receiver);
} else {
receiver.setSender(null);
if (senderRails.get(uuid) instanceof TileEntityMultiSender) {
((TileEntityMultiSender) senderRails.get(uuid)).decTarget();
}
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
updateTileEntity(senderRails.get(uuid));
updateTileEntity(receiver);
}
senderRails.remove(uuid);
} else {
if (receiverRails.containsKey(uuid)) {
if (receiverRails.get(uuid) instanceof TileEntityActuator) {
TileEntityActuator actuator = (TileEntityActuator) receiverRails.get(uuid);
if (actuator == receiver) {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.abort"));
} else if (actuator.getTarget() != receiver) {
actuator.setTarget(receiver);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
updateTileEntity(actuator);
updateTileEntity(receiver);
} else {
actuator.setTarget(null);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
updateTileEntity(actuator);
updateTileEntity(receiver);
}
} else if (receiver instanceof TileEntityActuator) {
if (((TileEntityActuator) receiver).getTarget() != receiverRails.get(uuid)) {
((TileEntityActuator) receiver).setTarget(receiverRails.get(uuid));
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
updateTileEntity(receiverRails.get(uuid));
updateTileEntity(receiver);
} else {
((TileEntityActuator) receiver).setTarget(null);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
updateTileEntity(receiverRails.get(uuid));
updateTileEntity(receiver);
}
}
receiverRails.remove(uuid);
} else {
if (receiver instanceof TileEntityPassiveReceiver) {
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
} else {
receiverRails.put(uuid, receiver);
if (player instanceof EntityPlayerMP)
player.addChatComponentMessage(new ChatComponentTranslation("info.signal.begin"));
}
}
}
return true;
} else {
onConnectorUseLast(player, uuid, tileEntity);
}
}
}
return false;
}
use of net.minecraft.entity.player.EntityPlayerMP in project NyaSamaRailway by NSDN.
the class BlockRailReception method onMinecartPass.
@Override
public void onMinecartPass(World world, EntityMinecart cart, int x, int y, int z) {
boolean playerDetectable = false;
boolean hasPlayer = false;
EntityPlayer player = null;
if (!checkNearbySameRail(world, x, y, z))
playerDetectable = true;
if (cart.riddenByEntity instanceof EntityPlayer) {
player = (EntityPlayer) cart.riddenByEntity;
ItemStack stack = ((EntityPlayer) cart.riddenByEntity).getCurrentEquippedItem();
if (stack != null) {
if (stack.getItem() instanceof ItemNTP8Bit || stack.getItem() instanceof ItemNTP32Bit) {
return;
}
}
hasPlayer = true;
} else if (cart.riddenByEntity instanceof EntityMinecart) {
EntityMinecart ncart = (EntityMinecart) cart.riddenByEntity;
if (ncart.riddenByEntity instanceof EntityPlayer) {
player = (EntityPlayer) ncart.riddenByEntity;
ItemStack stack = ((EntityPlayer) ncart.riddenByEntity).getCurrentEquippedItem();
if (stack != null) {
if (stack.getItem() instanceof ItemNTP8Bit || stack.getItem() instanceof ItemNTP32Bit) {
return;
}
}
hasPlayer = true;
}
}
double maxV;
if (!playerDetectable) {
maxV = 0.1;
if (isRailPowered(world, x, y, z)) {
if (getRailDirection(world, x, y, z) == RailDirection.NS) {
if (cart.motionZ > maxV) {
// cart.motionZ > maxV
if (cart.motionZ < maxV * 1.5)
cart.motionZ = maxV * 1.5;
} else {
if (cart.motionZ >= 0)
cart.motionZ = -0.005;
if (cart.motionZ > -maxV)
cart.motionZ = -Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionZ), 0.1, 1.0, 0.1, 0.02);
}
} else {
if (cart.motionX < -maxV) {
// cart.motionX < -maxV
if (cart.motionX > -maxV * 1.5)
cart.motionX = -maxV * 1.5;
} else {
if (cart.motionX <= 0)
cart.motionX = 0.005;
if (cart.motionX < maxV)
cart.motionX = Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionX), 0.1, 1.0, 0.1, 0.02);
}
}
} else {
if (Math.abs(cart.motionX) > maxV || Math.abs(cart.motionZ) > maxV) {
cart.motionX = Math.signum(cart.motionX) * Dynamics.LocoMotions.calcVelocityDown(Math.abs(cart.motionX), 0.1, 1.0, 1.0, 1.0, 0.05, 0.02);
cart.motionZ = Math.signum(cart.motionZ) * Dynamics.LocoMotions.calcVelocityDown(Math.abs(cart.motionZ), 0.1, 1.0, 1.0, 1.0, 0.05, 0.02);
} else {
if (getRailDirection(world, x, y, z) == RailDirection.NS) {
cart.motionZ = 0.0D;
} else {
cart.motionX = 0.0D;
}
}
}
} else {
maxV = 0.2;
TileEntityRailReception rail = null;
if (world.getTileEntity(x, y, z) instanceof TileEntityRailReception) {
rail = (TileEntityRailReception) world.getTileEntity(x, y, z);
}
if (rail != null) {
if (rail.cartType.equals("loco")) {
return;
}
if (rail.cartType.isEmpty() && (cart.motionX * cart.motionX + cart.motionZ * cart.motionZ == 0))
registerCart(rail, cart);
if (!world.isBlockIndirectlyGettingPowered(x, y, z)) {
if (hasPlayer) {
if ((cart.motionX * cart.motionX + cart.motionZ * cart.motionZ > 0) && !rail.enable) {
if ((Math.abs(cart.motionX) > maxV / 2) || (Math.abs(cart.motionZ) > maxV / 2)) {
cart.motionX = (Math.signum(cart.motionX) * Dynamics.LocoMotions.calcVelocityDown(Math.abs(cart.motionX), 0.1D, 1.0D, 1.0D, 1.0D, 0.05D, 0.02D));
cart.motionZ = (Math.signum(cart.motionZ) * Dynamics.LocoMotions.calcVelocityDown(Math.abs(cart.motionZ), 0.1D, 1.0D, 1.0D, 1.0D, 0.05D, 0.02D));
} else {
rail.enable = true;
if (getRailDirection(world, x, y, z) == RailDirection.NS) {
cart.motionZ = 0.0D;
} else {
cart.motionX = 0.0D;
}
cart.setPosition(x + 0.5, y + 0.5, z + 0.5);
if (player instanceof EntityPlayerMP) {
player.addChatComponentMessage(new ChatComponentTranslation("info.reception.pause", DELAY_TIME));
world.playSoundAtEntity(cart, "nyasamarailway:info.reception.pause", 0.5F, 1.0F);
}
}
} else {
if (rail.delay < DELAY_TIME * 20 && rail.enable) {
boolean isEnabled = false;
if (world.getTileEntity(x, y, z) instanceof TileEntityReceiver) {
TileEntityReceiver railReceiver = (TileEntityReceiver) world.getTileEntity(x, y, z);
if (railReceiver.senderIsPowered())
isEnabled = true;
}
if (!isEnabled)
rail.delay += 1;
else {
rail.count += 1;
if (rail.delay + rail.count == DELAY_TIME * 15) {
rail.delay = DELAY_TIME * 15 - 1;
rail.count += 1;
if (player instanceof EntityPlayerMP) {
player.addChatComponentMessage(new ChatComponentTranslation("info.reception.delay"));
world.playSoundAtEntity(cart, "nyasamarailway:info.reception.delay", 0.5F, 1.0F);
}
}
}
if (rail.delay == DELAY_TIME * 15) {
rail.count = 0;
if (player instanceof EntityPlayerMP) {
player.addChatComponentMessage(new ChatComponentTranslation("info.reception.ready"));
world.playSoundAtEntity(cart, "nyasamarailway:info.reception.ready", 0.5F, 1.0F);
}
}
cart.motionX = 0.0D;
cart.motionZ = 0.0D;
cart.setPosition(x + 0.5, y + 0.5, z + 0.5);
} else {
if (getRailDirection(world, x, y, z) == RailDirection.NS) {
if (cart.motionZ > maxV) {
if (cart.motionZ < maxV * 1.5D)
cart.motionZ = (maxV * 1.5D);
} else {
if (cart.motionZ >= 0.0D)
cart.motionZ = -0.005D;
if (cart.motionZ > -maxV) {
cart.motionZ = -Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionZ), 0.1D, 1.0D, 0.1D, 0.02D);
}
}
} else {
if (cart.motionX < -maxV) {
if (cart.motionX > -maxV * 1.5D)
cart.motionX = (-maxV * 1.5D);
} else {
if (cart.motionX <= 0.0D)
cart.motionX = 0.005D;
if (cart.motionX < maxV) {
cart.motionX = Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionX), 0.1D, 1.0D, 0.1D, 0.02D);
}
}
}
}
}
} else {
cart.motionX = 0.0D;
cart.motionZ = 0.0D;
cart.setPosition(x + 0.5, y + 0.5, z + 0.5);
rail.delay = 0;
rail.count = 0;
rail.enable = false;
}
} else {
if (cart.motionX * cart.motionX + cart.motionZ * cart.motionZ > 0) {
if (getRailDirection(world, x, y, z) == RailDirection.NS) {
if (cart.posZ - 0.5 > z) {
cart.killMinecart(new DamageSource("nsr"));
}
} else {
if (cart.posX - 0.5 < x) {
cart.killMinecart(new DamageSource("nsr"));
}
}
}
}
}
}
}
use of net.minecraft.entity.player.EntityPlayerMP in project malmo by Microsoft.
the class RewardForDiscardingItemImplementation method onTossItem.
@SubscribeEvent
public void onTossItem(ItemTossEvent event) {
if (event.getEntityItem() != null && event.getPlayer() instanceof EntityPlayerMP) {
ItemStack stack = event.getEntityItem().getEntityItem();
sendItemStackToClient((EntityPlayerMP) event.getPlayer(), MalmoMessageType.SERVER_DISCARDITEM, stack);
}
}
Aggregations