use of omtteam.openmodularturrets.tileentity.TurretBase in project OpenModularTurrets by OpenModularTurretsTeam.
the class BlockExpander method clOnBlockActivated.
@Override
protected boolean clOnBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hand.equals(EnumHand.OFF_HAND))
return true;
Expander expander = (Expander) worldIn.getTileEntity(pos);
if (expander == null) {
return true;
}
TurretBase base = expander.getBase();
if (base == null) {
worldIn.destroyBlock(pos, true);
return true;
}
TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(playerIn, base);
if (trustedPlayer != null) {
if (base.getTrustedPlayer(playerIn.getUniqueID()).canOpenGUI && state.getValue(META) < 5) {
playerIn.openGui(OpenModularTurrets.instance, 7, worldIn, pos.getX(), pos.getY(), pos.getZ());
return true;
}
}
if (PlayerUtil.isPlayerOwner(playerIn, base)) {
if (playerIn.isSneaking() && playerIn.getHeldItemMainhand() == null) {
worldIn.destroyBlock(pos, true);
} else if (state.getValue(META) < 5) {
playerIn.openGui(OpenModularTurrets.instance, 7, worldIn, pos.getX(), pos.getY(), pos.getZ());
} else {
return true;
}
} else {
addChatMessage(playerIn, new TextComponentString(safeLocalize("status.ownership")));
}
return true;
}
use of omtteam.openmodularturrets.tileentity.TurretBase in project OpenModularTurrets by OpenModularTurretsTeam.
the class LeverBlock method clOnBlockActivated.
@Override
protected boolean clOnBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (TurretHeadUtil.getTurretBaseFacing(worldIn, pos) == EnumFacing.DOWN || TurretHeadUtil.getTurretBaseFacing(worldIn, pos) == EnumFacing.UP) {
return true;
}
TurretBase base = getTurretBase(worldIn, pos);
LeverTileEntity lever = (LeverTileEntity) worldIn.getTileEntity(pos);
OMEnergyStorage storage = (OMEnergyStorage) base.getCapability(CapabilityEnergy.ENERGY, EnumFacing.DOWN);
if (storage == null) {
return true;
}
if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 0 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)))) {
base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1));
if (base != null) {
lever.isTurning = true;
if (lever.rotation == 0F) {
//worldIn.playSound(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
storage.receiveEnergy(50, false);
}
}
}
if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 90 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())))) {
base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()));
if (base != null) {
lever.isTurning = true;
if (lever.rotation == 0F) {
//worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
storage.receiveEnergy(50, false);
}
}
}
if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 180 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)))) {
base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1));
if (base != null) {
lever.isTurning = true;
if (lever.rotation == 0F) {
//worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
storage.receiveEnergy(50, false);
}
}
}
if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 270 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())))) {
base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ()));
if (base != null) {
lever.isTurning = true;
if (lever.rotation == 0F) {
//worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
storage.receiveEnergy(50, false);
}
}
}
return true;
}
use of omtteam.openmodularturrets.tileentity.TurretBase in project OpenModularTurrets by OpenModularTurretsTeam.
the class BlockTurretBase method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
if (!worldIn.isRemote && worldIn.getTileEntity(pos) instanceof TurretBase) {
EntityPlayerMP player = (EntityPlayerMP) placer;
TurretBase base = (TurretBase) worldIn.getTileEntity(pos);
if (base == null) {
return;
}
base.setCamoState(state);
base.setOwner(player.getUniqueID().toString());
if (worldIn.isBlockIndirectlyGettingPowered(pos) > 0) {
base.setRedstone(true);
} else if (worldIn.isBlockIndirectlyGettingPowered(pos) == 0) {
base.setRedstone(false);
}
base.markDirty();
switch(state.getValue(TIER)) {
case 1:
this.setResistance(ConfigHandler.getBaseTierOneBlastResistance());
this.setHardness(ConfigHandler.getBaseTierOneHardness());
break;
case 2:
this.setResistance(ConfigHandler.getBaseTierTwoBlastResistance());
this.setHardness(ConfigHandler.getBaseTierTwoHardness());
break;
case 3:
this.setResistance(ConfigHandler.getBaseTierThreeBlastResistance());
this.setHardness(ConfigHandler.getBaseTierThreeHardness());
break;
case 4:
this.setResistance(ConfigHandler.getBaseTierFourBlastResistance());
this.setHardness(ConfigHandler.getBaseTierFourHardness());
break;
case 5:
this.setResistance(ConfigHandler.getBaseTierFiveBlastResistance());
this.setHardness(ConfigHandler.getBaseTierFiveHardness());
}
}
}
use of omtteam.openmodularturrets.tileentity.TurretBase 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