use of net.geforcemods.securitycraft.entity.EntitySecurityCamera in project SecurityCraft by Geforce132.
the class ItemCameraMonitor method onItemUse.
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
if (BlockUtils.getBlock(worldIn, pos) == SCContent.securityCamera) {
if (!((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.cannotView"), TextFormatting.RED);
return EnumActionResult.SUCCESS;
}
if (playerIn.inventory.getCurrentItem().getTagCompound() == null)
playerIn.inventory.getCurrentItem().setTagCompound(new NBTTagCompound());
CameraView view = new CameraView(pos, playerIn.dimension);
if (isCameraAdded(playerIn.inventory.getCurrentItem().getTagCompound(), view)) {
playerIn.inventory.getCurrentItem().getTagCompound().removeTag(getTagNameFromPosition(playerIn.inventory.getCurrentItem().getTagCompound(), view));
PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.RED);
return EnumActionResult.SUCCESS;
}
for (int i = 1; i <= 30; i++) if (!playerIn.inventory.getCurrentItem().getTagCompound().hasKey("Camera" + i)) {
playerIn.inventory.getCurrentItem().getTagCompound().setString("Camera" + i, view.toNBTString());
PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
break;
}
SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
return EnumActionResult.SUCCESS;
}
} else if (worldIn.isRemote && BlockUtils.getBlock(worldIn, pos) != SCContent.securityCamera) {
if (playerIn.getRidingEntity() != null && playerIn.getRidingEntity() instanceof EntitySecurityCamera)
return EnumActionResult.SUCCESS;
if (stack.getTagCompound() == null || stack.getTagCompound().hasNoTags()) {
PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.rightclickToView"), TextFormatting.RED);
return EnumActionResult.SUCCESS;
}
playerIn.openGui(SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
return EnumActionResult.SUCCESS;
}
return EnumActionResult.SUCCESS;
}
use of net.geforcemods.securitycraft.entity.EntitySecurityCamera in project SecurityCraft by Geforce132.
the class ItemCameraMonitor method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(hand);
if (!worldIn.isRemote) {
if (BlockUtils.getBlock(worldIn, pos) == SCContent.securityCamera) {
if (!((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.cannotView"), TextFormatting.RED);
return EnumActionResult.SUCCESS;
}
if (playerIn.inventory.getCurrentItem().getTagCompound() == null)
playerIn.inventory.getCurrentItem().setTagCompound(new NBTTagCompound());
CameraView view = new CameraView(pos, playerIn.dimension);
if (isCameraAdded(playerIn.inventory.getCurrentItem().getTagCompound(), view)) {
playerIn.inventory.getCurrentItem().getTagCompound().removeTag(getTagNameFromPosition(playerIn.inventory.getCurrentItem().getTagCompound(), view));
PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.RED);
return EnumActionResult.SUCCESS;
}
for (int i = 1; i <= 30; i++) if (!playerIn.inventory.getCurrentItem().getTagCompound().hasKey("Camera" + i)) {
playerIn.inventory.getCurrentItem().getTagCompound().setString("Camera" + i, view.toNBTString());
PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
break;
}
SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
return EnumActionResult.SUCCESS;
}
} else if (worldIn.isRemote && BlockUtils.getBlock(worldIn, pos) != SCContent.securityCamera) {
if (playerIn.getRidingEntity() != null && playerIn.getRidingEntity() instanceof EntitySecurityCamera)
return EnumActionResult.SUCCESS;
if (stack.getTagCompound() == null || stack.getTagCompound().hasNoTags()) {
PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.rightclickToView"), TextFormatting.RED);
return EnumActionResult.SUCCESS;
}
playerIn.openGui(SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
return EnumActionResult.SUCCESS;
}
return EnumActionResult.SUCCESS;
}
use of net.geforcemods.securitycraft.entity.EntitySecurityCamera in project SecurityCraft by Geforce132.
the class ItemCameraMonitor method onItemUse.
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, BlockPos pos, EnumFacing side, float par8, float par9, float par10) {
if (!par3World.isRemote) {
if (BlockUtils.getBlock(par3World, pos) == SCContent.securityCamera) {
if (!((IOwnable) par3World.getTileEntity(pos)).getOwner().isOwner(par2EntityPlayer)) {
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.cannotView"), EnumChatFormatting.RED);
return true;
}
if (par2EntityPlayer.getCurrentEquippedItem().getTagCompound() == null)
par2EntityPlayer.getCurrentEquippedItem().setTagCompound(new NBTTagCompound());
CameraView view = new CameraView(pos, par2EntityPlayer.dimension);
if (isCameraAdded(par2EntityPlayer.getCurrentEquippedItem().getTagCompound(), view)) {
par2EntityPlayer.getCurrentEquippedItem().getTagCompound().removeTag(getTagNameFromPosition(par2EntityPlayer.getCurrentEquippedItem().getTagCompound(), view));
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(pos)), EnumChatFormatting.RED);
return true;
}
for (int i = 1; i <= 30; i++) if (!par2EntityPlayer.getCurrentEquippedItem().getTagCompound().hasKey("Camera" + i)) {
par2EntityPlayer.getCurrentEquippedItem().getTagCompound().setString("Camera" + i, view.toNBTString());
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(pos)), EnumChatFormatting.GREEN);
break;
}
SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(par1ItemStack), (EntityPlayerMP) par2EntityPlayer);
return true;
}
} else if (par3World.isRemote && BlockUtils.getBlock(par3World, pos) != SCContent.securityCamera) {
if (par2EntityPlayer.ridingEntity != null && par2EntityPlayer.ridingEntity instanceof EntitySecurityCamera)
return true;
if (par1ItemStack.getTagCompound() == null || par1ItemStack.getTagCompound().hasNoTags()) {
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.rightclickToView"), EnumChatFormatting.RED);
return true;
}
par2EntityPlayer.openGui(SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, par3World, pos.getX(), pos.getY(), pos.getZ());
return true;
}
return true;
}
use of net.geforcemods.securitycraft.entity.EntitySecurityCamera in project SecurityCraft by Geforce132.
the class BlockSecurityCamera method mountCamera.
public void mountCamera(World world, int par2, int par3, int par4, int par5, EntityPlayer player) {
if (!world.isRemote && player.ridingEntity == null)
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("tile.securityCamera.name"), StatCollector.translateToLocal("messages.securityCamera.mounted"), EnumChatFormatting.GREEN);
if (player.ridingEntity != null && player.ridingEntity instanceof EntitySecurityCamera) {
EntitySecurityCamera dummyEntity = new EntitySecurityCamera(world, par2, par3, par4, par5, (EntitySecurityCamera) player.ridingEntity);
world.spawnEntityInWorld(dummyEntity);
player.mountEntity(dummyEntity);
return;
}
EntitySecurityCamera dummyEntity = new EntitySecurityCamera(world, par2, par3, par4, par5, player);
world.spawnEntityInWorld(dummyEntity);
player.mountEntity(dummyEntity);
for (Object e : world.loadedEntityList) if (e instanceof EntityLiving)
if (((EntityLiving) e).getAttackTarget() == player)
((EntityLiving) e).setAttackTarget(null);
}
Aggregations