use of net.geforcemods.securitycraft.misc.CameraView 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.misc.CameraView in project SecurityCraft by Geforce132.
the class ItemCameraMonitor method getCameraPositions.
public ArrayList<CameraView> getCameraPositions(NBTTagCompound nbt) {
ArrayList<CameraView> list = new ArrayList<CameraView>();
for (int i = 1; i <= 30; i++) {
if (nbt != null && nbt.hasKey("Camera" + i)) {
String[] coords = nbt.getString("Camera" + i).split(" ");
list.add(new CameraView(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2]), (coords.length == 4 ? Integer.parseInt(coords[3]) : 0)));
} else
list.add(null);
}
return list;
}
use of net.geforcemods.securitycraft.misc.CameraView in project SecurityCraft by Geforce132.
the class EntitySecurityCamera method onUpdate.
@Override
public void onUpdate() {
if (worldObj.isRemote && riddenByEntity != null) {
if (screenshotCooldown > 0)
screenshotCooldown -= 1;
if (redstoneCooldown > 0)
redstoneCooldown -= 1;
if (toggleNightVisionCooldown > 0)
toggleNightVisionCooldown -= 1;
if (toggleLightCooldown > 0)
toggleLightCooldown -= 1;
if ((id == 0) && (((EntityPlayer) riddenByEntity).getCurrentEquippedItem() != null) && (((EntityPlayer) riddenByEntity).getCurrentEquippedItem().getItem() == SCContent.cameraMonitor))
id = ((ItemCameraMonitor) ((EntityPlayer) riddenByEntity).getCurrentEquippedItem().getItem()).getSlotFromPosition(((EntityPlayer) riddenByEntity).getCurrentEquippedItem().stackTagCompound, new CameraView((int) Math.floor(posX), (int) (posY - 1.0D), (int) Math.floor(posZ), riddenByEntity.dimension));
if (((EntityPlayer) riddenByEntity).rotationYaw != rotationYaw)
((EntityPlayer) riddenByEntity).rotationYaw = rotationYaw;
if (((EntityPlayer) riddenByEntity).rotationPitch != rotationPitch)
((EntityPlayer) riddenByEntity).rotationPitch = rotationPitch;
checkKeysPressed();
if ((Mouse.hasWheel()) && (Mouse.isButtonDown(2)) && (screenshotCooldown == 0)) {
screenshotCooldown = 30;
ClientUtils.takeScreenshot();
Minecraft.getMinecraft().theWorld.playSound(posX, posY, posZ, SCSounds.CAMERASNAP.path, 1.0F, 1.0F, true);
}
if ((riddenByEntity != null) && (shouldProvideNightVision))
SecurityCraft.network.sendToServer(new PacketGivePotionEffect(Potion.nightVision.id, 3, -1));
}
if (!worldObj.isRemote)
if (riddenByEntity == null | worldObj.getBlock(blockPosX, blockPosY, blockPosZ) != SCContent.securityCamera) {
setDead();
return;
}
}
use of net.geforcemods.securitycraft.misc.CameraView in project SecurityCraft by Geforce132.
the class ItemCameraMonitor method onItemUse.
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) {
if (!par3World.isRemote)
// When the mod is using the LookingGlass system.
if (SecurityCraft.instance.useLookingGlass()) {
if (par3World.getBlock(par4, par5, par6) instanceof BlockSecurityCamera) {
if (!((TileEntitySecurityCamera) par3World.getTileEntity(par4, par5, par6)).getOwner().isOwner(par2EntityPlayer)) {
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.cannotView"), EnumChatFormatting.RED);
return false;
}
if (par1ItemStack.getTagCompound() == null)
par1ItemStack.setTagCompound(new NBTTagCompound());
CameraView view = new CameraView(par4, par5, par6, par2EntityPlayer.dimension);
if (isCameraAdded(par1ItemStack.getTagCompound(), view)) {
par1ItemStack.getTagCompound().removeTag(getTagNameFromPosition(par1ItemStack.getTagCompound(), view));
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(view.x, view.y, view.z)), EnumChatFormatting.RED);
return true;
}
par1ItemStack.getTagCompound().setString("Camera1", view.toNBTString());
SecurityCraft.network.sendTo(new PacketCCreateLGView(view.x, view.y, view.z, view.dimension), (EntityPlayerMP) par2EntityPlayer);
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(view.x, view.y, view.z)), EnumChatFormatting.GREEN);
return true;
} else if (par3World.getBlock(par4, par5, par6) == SCContent.frame) {
if (!par1ItemStack.hasTagCompound() || !hasCameraAdded(par1ItemStack.getTagCompound()))
return false;
CameraView view = getCameraView(par1ItemStack.getTagCompound());
if (view == null)
return true;
((TileEntityFrame) par3World.getTileEntity(par4, par5, par6)).setCameraLocation(view.x, view.y, view.z, view.dimension);
SecurityCraft.network.sendToAll(new PacketCSetCameraLocation(par4, par5, par6, view.x, view.y, view.z, view.dimension));
par1ItemStack.stackSize--;
return true;
} else {
if (!par1ItemStack.hasTagCompound() || !hasCameraAdded(par1ItemStack.getTagCompound()))
return false;
CameraView view = getCameraView(par1ItemStack.getTagCompound());
if (view == null)
return true;
if (!(par3World.getBlock(view.x, view.y, view.z) instanceof BlockSecurityCamera)) {
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.noCamera").replace("#", Utils.getFormattedCoordinates(view.x, view.y, view.z)), EnumChatFormatting.RED);
return false;
}
if (SecurityCraft.instance.useLookingGlass())
SecurityCraft.network.sendTo(new PacketCCreateLGView(view.x, view.y, view.z, view.dimension), (EntityPlayerMP) par2EntityPlayer);
else
par2EntityPlayer.openGui(SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, par3World, par4, par5, par6);
return false;
}
} else if (par3World.getBlock(par4, par5, par6) == SCContent.securityCamera) {
if (!((IOwnable) par3World.getTileEntity(par4, par5, par6)).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(par4, par5, par6, 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(par4, par5, par6)), 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(par4, par5, par6)), EnumChatFormatting.GREEN);
break;
}
SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(par1ItemStack), (EntityPlayerMP) par2EntityPlayer);
return true;
}
return true;
}
use of net.geforcemods.securitycraft.misc.CameraView in project SecurityCraft by Geforce132.
the class GuiCameraMonitor method initGui.
@Override
public void initGui() {
super.initGui();
prevPageButton = new GuiButton(-1, width / 2 - 68, height / 2 + 40, 20, 20, "<");
nextPageButton = new GuiButton(0, width / 2 + 52, height / 2 + 40, 20, 20, ">");
buttonList.add(prevPageButton);
buttonList.add(nextPageButton);
cameraButtons[0] = new GuiButton(1, width / 2 - 38, height / 2 - 60 + 10, 20, 20, "#");
cameraButtons[1] = new GuiButton(2, width / 2 - 8, height / 2 - 60 + 10, 20, 20, "#");
cameraButtons[2] = new GuiButton(3, width / 2 + 22, height / 2 - 60 + 10, 20, 20, "#");
cameraButtons[3] = new GuiButton(4, width / 2 - 38, height / 2 - 30 + 10, 20, 20, "#");
cameraButtons[4] = new GuiButton(5, width / 2 - 8, height / 2 - 30 + 10, 20, 20, "#");
cameraButtons[5] = new GuiButton(6, width / 2 + 22, height / 2 - 30 + 10, 20, 20, "#");
cameraButtons[6] = new GuiButton(7, width / 2 - 38, height / 2 + 10, 20, 20, "#");
cameraButtons[7] = new GuiButton(8, width / 2 - 8, height / 2 + 10, 20, 20, "#");
cameraButtons[8] = new GuiButton(9, width / 2 + 22, height / 2 + 10, 20, 20, "#");
cameraButtons[9] = new GuiButton(10, width / 2 - 38, height / 2 + 40, 80, 20, "#");
unbindButtons[0] = new GuiButton(11, width / 2 - 19, height / 2 - 68 + 10, 8, 8, "x");
unbindButtons[1] = new GuiButton(12, width / 2 + 11, height / 2 - 68 + 10, 8, 8, "x");
unbindButtons[2] = new GuiButton(13, width / 2 + 41, height / 2 - 68 + 10, 8, 8, "x");
unbindButtons[3] = new GuiButton(14, width / 2 - 19, height / 2 - 38 + 10, 8, 8, "x");
unbindButtons[4] = new GuiButton(15, width / 2 + 11, height / 2 - 38 + 10, 8, 8, "x");
unbindButtons[5] = new GuiButton(16, width / 2 + 41, height / 2 - 38 + 10, 8, 8, "x");
unbindButtons[6] = new GuiButton(17, width / 2 - 19, height / 2 + 2, 8, 8, "x");
unbindButtons[7] = new GuiButton(18, width / 2 + 11, height / 2 + 2, 8, 8, "x");
unbindButtons[8] = new GuiButton(19, width / 2 + 41, height / 2 + 2, 8, 8, "x");
unbindButtons[9] = new GuiButton(20, width / 2 + 41, height / 2 + 32, 8, 8, "x");
for (int i = 0; i < 10; i++) {
GuiButton button = cameraButtons[i];
int camID = (button.id + ((page - 1) * 10));
ArrayList<CameraView> views = cameraMonitor.getCameraPositions(nbtTag);
CameraView view;
button.displayString += camID;
buttonList.add(button);
if ((view = views.get(camID - 1)) != null) {
if (view.dimension != Minecraft.getMinecraft().thePlayer.dimension) {
hoverCheckers[button.id - 1] = new HoverChecker(button, 20);
cameraViewDim[button.id - 1] = view.dimension;
}
if (BlockUtils.getBlock(Minecraft.getMinecraft().theWorld, view.getLocation()) != SCContent.securityCamera) {
button.enabled = false;
cameraTEs[button.id - 1] = null;
continue;
}
cameraTEs[button.id - 1] = (TileEntitySCTE) Minecraft.getMinecraft().theWorld.getTileEntity(view.getLocation());
hoverCheckers[button.id - 1] = new HoverChecker(button, 20);
} else {
button.enabled = false;
unbindButtons[button.id - 1].enabled = false;
cameraTEs[button.id - 1] = null;
continue;
}
}
for (int i = 0; i < 10; i++) buttonList.add(unbindButtons[i]);
if (page == 1)
prevPageButton.enabled = false;
if (page == 3 || cameraMonitor.getCameraPositions(nbtTag).size() < (page * 10) + 1)
nextPageButton.enabled = false;
for (int i = cameraMonitor.getCameraPositions(nbtTag).size() + 1; i <= (page * 10); i++) cameraButtons[(i - 1) - ((page - 1) * 10)].enabled = false;
}
Aggregations