Search in sources :

Example 1 with TurretBase

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;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) ItemBlockExpander(omtteam.openmodularturrets.items.blocks.ItemBlockExpander) Expander(omtteam.openmodularturrets.tileentity.Expander) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with TurretBase

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;
}
Also used : LeverTileEntity(omtteam.openmodularturrets.tileentity.LeverTileEntity) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) TurretHeadUtil.getTurretBase(omtteam.openmodularturrets.util.TurretHeadUtil.getTurretBase) OMEnergyStorage(omtteam.omlib.power.OMEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with TurretBase

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());
        }
    }
}
Also used : TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 4 with TurretBase

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;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) UsableMetaItem(omtteam.openmodularturrets.items.UsableMetaItem) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) Block(net.minecraft.block.Block) IHasItemBlock(omtteam.omlib.api.IHasItemBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) IHasItemBlock(omtteam.omlib.api.IHasItemBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TurretBase (omtteam.openmodularturrets.tileentity.TurretBase)4 TextComponentString (net.minecraft.util.text.TextComponentString)2 TrustedPlayer (omtteam.omlib.util.TrustedPlayer)2 ItemBlockTurretBase (omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase)2 Block (net.minecraft.block.Block)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 IHasItemBlock (omtteam.omlib.api.IHasItemBlock)1 OMEnergyStorage (omtteam.omlib.power.OMEnergyStorage)1 UsableMetaItem (omtteam.openmodularturrets.items.UsableMetaItem)1 ItemBlockExpander (omtteam.openmodularturrets.items.blocks.ItemBlockExpander)1 Expander (omtteam.openmodularturrets.tileentity.Expander)1 LeverTileEntity (omtteam.openmodularturrets.tileentity.LeverTileEntity)1 TurretHeadUtil.getTurretBase (omtteam.openmodularturrets.util.TurretHeadUtil.getTurretBase)1