use of net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag in project SecurityCraft by Geforce132.
the class ItemMineRemoteAccessTool method onItemUse.
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) {
if (par3World.getBlock(par4, par5, par6) instanceof IExplosive) {
if (!isMineAdded(par1ItemStack, par3World, par4, par5, par6)) {
int availSlot = this.getNextAvaliableSlot(par1ItemStack);
if (availSlot == 0) {
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.noSlots"), EnumChatFormatting.RED);
return false;
}
if (par3World.getTileEntity(par4, par5, par6) instanceof IOwnable && !((IOwnable) par3World.getTileEntity(par4, par5, par6)).getOwner().isOwner(par2EntityPlayer)) {
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.cantBind"), EnumChatFormatting.RED);
return false;
}
if (par1ItemStack.stackTagCompound == null) {
par1ItemStack.stackTagCompound = new NBTTagCompound();
}
par1ItemStack.stackTagCompound.setIntArray(("mine" + availSlot), new int[] { par4, par5, par6 });
mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(par1ItemStack), (EntityPlayerMP) par2EntityPlayer);
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.bound").replace("#", Utils.getFormattedCoordinates(par4, par5, par6)), EnumChatFormatting.GREEN);
} else {
this.removeTagFromItemAndUpdate(par1ItemStack, par4, par5, par6, par2EntityPlayer);
PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.unbound").replace("#", Utils.getFormattedCoordinates(par4, par5, par6)), EnumChatFormatting.RED);
}
} else {
par2EntityPlayer.openGui(mod_SecurityCraft.instance, GuiHandler.MRAT_MENU_ID, par3World, (int) par2EntityPlayer.posX, (int) par2EntityPlayer.posY, (int) par2EntityPlayer.posZ);
}
}
return true;
}
use of net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag in project SecurityCraft by Geforce132.
the class ItemMineRemoteAccessTool method removeTagFromItemAndUpdate.
private void removeTagFromItemAndUpdate(ItemStack par1ItemStack, BlockPos pos, EntityPlayer par5EntityPlayer) {
if (par1ItemStack.getTagCompound() == null) {
return;
}
for (int i = 1; i <= 6; i++) {
if (par1ItemStack.getTagCompound().getIntArray("mine" + i).length > 0) {
int[] coords = par1ItemStack.getTagCompound().getIntArray("mine" + i);
if (coords[0] == pos.getX() && coords[1] == pos.getY() && coords[2] == pos.getZ()) {
par1ItemStack.getTagCompound().setIntArray("mine" + i, new int[] { 0, 0, 0 });
mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(par1ItemStack), (EntityPlayerMP) par5EntityPlayer);
return;
}
} else {
continue;
}
}
return;
}
use of net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag in project SecurityCraft by Geforce132.
the class ItemMineRemoteAccessTool 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) instanceof IExplosive) {
if (!isMineAdded(stack, worldIn, pos)) {
int availSlot = this.getNextAvaliableSlot(stack);
if (availSlot == 0) {
PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.noSlots"), TextFormatting.RED);
return EnumActionResult.FAIL;
}
if (worldIn.getTileEntity(pos) instanceof IOwnable && !((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.cantBind"), TextFormatting.RED);
return EnumActionResult.FAIL;
}
if (stack.getTagCompound() == null) {
stack.setTagCompound(new NBTTagCompound());
}
stack.getTagCompound().setIntArray(("mine" + availSlot), new int[] { BlockUtils.fromPos(pos)[0], BlockUtils.fromPos(pos)[1], BlockUtils.fromPos(pos)[2] });
mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
} else {
this.removeTagFromItemAndUpdate(stack, pos, playerIn);
PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.unbound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.RED);
}
} else {
playerIn.openGui(mod_SecurityCraft.instance, GuiHandler.MRAT_MENU_ID, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);
}
}
return EnumActionResult.SUCCESS;
}
Aggregations