use of omtteam.openmodularturrets.items.UsableMetaItem in project OpenModularTurrets by OpenModularTurretsTeam.
the class BlockTurretBase method clOnBlockActivated.
@Override
protected boolean clOnBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
ItemStack heldItem = player.getHeldItemMainhand();
TurretBase base = (TurretBase) world.getTileEntity(pos);
if (player.isSneaking() && ConfigHandler.isAllowBaseCamo() && heldItem == ItemStackTools.getEmptyStack()) {
if (base != null) {
if (player.getUniqueID().toString().equals(base.getOwner())) {
base.setCamoState(state);
world.notifyBlockUpdate(pos, state, state, 3);
} else {
addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
}
}
}
Block heldItemBlock = null;
if (heldItem != ItemStackTools.getEmptyStack()) {
heldItemBlock = Block.getBlockFromItem(heldItem.getItem());
}
if (!player.isSneaking() && ConfigHandler.isAllowBaseCamo() && heldItem != ItemStackTools.getEmptyStack() && heldItem.getItem() instanceof ItemBlock && heldItemBlock.isNormalCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && Block.getBlockFromItem(heldItem.getItem()).isOpaqueCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && !(Block.getBlockFromItem(heldItem.getItem()) instanceof BlockTurretBase)) {
if (base != null) {
if (player.getUniqueID().toString().equals(base.getOwner())) {
base.setCamoState(heldItemBlock.getStateFromMeta(heldItem.getItemDamage()));
world.notifyBlockUpdate(pos, state, state, 3);
} else {
addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
}
}
} else if (player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStackTools.getEmptyStack() && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2) {
((UsableMetaItem) player.getHeldItemMainhand().getItem()).setDataStored(player.getHeldItemMainhand(), base.writeMemoryCardNBT());
} else if (!player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStackTools.getEmptyStack() && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2 && ((UsableMetaItem) player.getHeldItemMainhand().getItem()).hasDataStored(player.getHeldItemMainhand())) {
base.readMemoryCardNBT(((UsableMetaItem) player.getHeldItemMainhand().getItem()).getDataStored(player.getHeldItemMainhand()));
} else if (!player.isSneaking() && base != null) {
TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(player, base);
if (trustedPlayer != null && trustedPlayer.canOpenGUI) {
world.notifyBlockUpdate(pos, state, state, 6);
player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
return true;
} else if (PlayerUtil.isPlayerOwner(player, base)) {
world.notifyBlockUpdate(pos, state, state, 6);
player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
} else {
addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
}
}
}
return true;
}
Aggregations