Search in sources :

Example 1 with Expander

use of omtteam.openmodularturrets.tileentity.Expander 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 Expander

use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretHeadUtil method getSpecificItemFromInvExpanders.

public static ItemStack getSpecificItemFromInvExpanders(World world, ItemStack itemStack, TurretBase base) {
    for (TileEntity tileEntity : WorldUtil.getTouchingTileEntities(world, base.getPos())) {
        if (tileEntity instanceof Expander && !((Expander) tileEntity).isPowerExpander()) {
            Expander exp = (Expander) tileEntity;
            ItemStack stack = deductFromInvExpander(itemStack, exp, base);
            if (stack != ItemStack.EMPTY) {
                return stack;
            }
        }
    }
    return ItemStack.EMPTY;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Expander(omtteam.openmodularturrets.tileentity.Expander) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Expander

use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretHeadUtil method getAmmoLevel.

public static int getAmmoLevel(TurretHead turret, TurretBase base) {
    int result = 0;
    ItemStack ammoStackRequired = turret.getAmmo();
    if (ammoStackRequired == null) {
        return base.getEnergyLevel(EnumFacing.DOWN) / turret.getTurretPowerUsage();
    }
    for (int i = 0; i <= 8; i++) {
        ItemStack ammoStack = base.getStackInSlot(i);
        if (ammoStack != ItemStack.EMPTY && getStackSize(ammoStack) > 0 && ammoStack.getItem() == ammoStackRequired.getItem() && ammoStack.getMetadata() == ammoStackRequired.getMetadata()) {
            result += ammoStack.getCount();
        }
    }
    for (TileEntity tileEntity : WorldUtil.getTouchingTileEntities(base.getWorld(), base.getPos())) {
        if (tileEntity instanceof Expander && !((Expander) tileEntity).isPowerExpander()) {
            Expander exp = (Expander) tileEntity;
            for (int i = 0; i < exp.getSizeInventory(); i++) {
                ItemStack ammoStack = exp.getStackInSlot(i);
                if (ammoStack != ItemStack.EMPTY && ammoStack.getItem() == ammoStackRequired.getItem()) {
                    result += ammoStack.getCount();
                }
            }
        }
    }
    return result;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Expander(omtteam.openmodularturrets.tileentity.Expander) ItemStack(net.minecraft.item.ItemStack)

Example 4 with Expander

use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.

the class BlockExpander method onBlockActivated.

@Override
public boolean onBlockActivated(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().isEmpty()) {
            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 5 with Expander

use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.

the class BlockExpander method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    Expander expander = (Expander) worldIn.getTileEntity(pos);
    if (expander != null) {
        expander.setOwnerName(expander.getBase().getOwnerName());
        expander.setOwner(expander.getBase().getOwner());
        expander.setSide();
    }
}
Also used : ItemBlockExpander(omtteam.openmodularturrets.items.blocks.ItemBlockExpander) Expander(omtteam.openmodularturrets.tileentity.Expander)

Aggregations

Expander (omtteam.openmodularturrets.tileentity.Expander)5 ItemBlockExpander (omtteam.openmodularturrets.items.blocks.ItemBlockExpander)3 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 TrustedPlayer (omtteam.omlib.util.TrustedPlayer)2 TurretBase (omtteam.openmodularturrets.tileentity.TurretBase)2