Search in sources :

Example 1 with TileEntityLockableDoor

use of net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor in project BetterStorage by copygirl.

the class TileLockableDoor method getIcon.

@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int face) {
    int meta = world.getBlockMetadata(x, y, z);
    if (meta > 0)
        y -= 1;
    TileEntityLockableDoor lockable = WorldUtils.get(world, x, y, z, TileEntityLockableDoor.class);
    boolean flip = false;
    IIcon icon = iconUpper;
    if (meta == 0 || face == 1) {
        icon = iconLower;
    }
    switch(lockable.orientation) {
        case WEST:
            if (face == 3 && !lockable.isOpen)
                flip = true;
            else if (face == 2 && lockable.isOpen)
                flip = true;
            break;
        case EAST:
            if (face == 4 && !lockable.isOpen)
                flip = true;
            else if (face == 3 && lockable.isOpen)
                flip = true;
            break;
        case SOUTH:
            if (face == 2 && !lockable.isOpen)
                flip = true;
            else if (face == 4 && lockable.isOpen)
                flip = true;
            break;
        default:
            if (face == 3 && !lockable.isOpen)
                flip = true;
            else if (face == 5 && lockable.isOpen)
                flip = true;
            break;
    }
    icon = flip ? (icon == iconLower ? iconLowerFlipped : iconUpperFlipped) : icon;
    return icon;
}
Also used : IIcon(net.minecraft.util.IIcon) TileEntityLockableDoor(net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor)

Example 2 with TileEntityLockableDoor

use of net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor in project BetterStorage by copygirl.

the class TileLockableDoor method setBlockBoundsBasedOnState.

@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
    int metadata = world.getBlockMetadata(x, y, z);
    float offset = metadata == 0 ? 0F : -1F;
    TileEntityLockableDoor te = WorldUtils.get(world, x, y + (int) offset, z, TileEntityLockableDoor.class);
    if (te == null)
        return;
    switch(te.orientation) {
        case WEST:
            if (te.isOpen)
                setBlockBounds(0F, 0F, 0.005F / 16F, 1F, 1F, 2.995F / 16F);
            else
                setBlockBounds(0.005F / 16F, 0F, 0F, 2.995F / 16F, 1F, 1F);
            break;
        case EAST:
            if (te.isOpen)
                setBlockBounds(0F, 0F, 13.005F / 16F, 1F, 1F, 15.995F / 16F);
            else
                setBlockBounds(13.005F / 16F, 0F, 0F, 15.995F / 16F, 1F, 1F);
            break;
        case SOUTH:
            if (te.isOpen)
                setBlockBounds(0.005F / 16F, 0F, 0F, 2.995F / 16F, 1F, 1F);
            else
                setBlockBounds(0F, 0F, 13.005F / 16F, 1F, 1F, 15.995F / 16F);
            break;
        default:
            if (te.isOpen)
                setBlockBounds(13.005F / 16F, 0F, 0F, 15.995F / 16F, 1F, 1F);
            else
                setBlockBounds(0F, 0F, 0.005F / 16F, 1F, 1F, 2.995F / 16F);
            break;
    }
}
Also used : TileEntityLockableDoor(net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor)

Example 3 with TileEntityLockableDoor

use of net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor in project BetterStorage by copygirl.

the class CommonProxy method onPlayerInteract.

@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
    World world = event.entity.worldObj;
    int x = event.x;
    int y = event.y;
    int z = event.z;
    EntityPlayer player = event.entityPlayer;
    ItemStack holding = player.getCurrentEquippedItem();
    Block block = world.getBlock(x, y, z);
    boolean leftClick = (event.action == Action.LEFT_CLICK_BLOCK);
    boolean rightClick = (event.action == Action.RIGHT_CLICK_BLOCK);
    // Interact with attachments.
    if (leftClick || rightClick) {
        IHasAttachments hasAttachments = WorldUtils.get(world, x, y, z, IHasAttachments.class);
        if (hasAttachments != null) {
            EnumAttachmentInteraction interactionType = ((event.action == Action.LEFT_CLICK_BLOCK) ? EnumAttachmentInteraction.attack : EnumAttachmentInteraction.use);
            if (hasAttachments.getAttachments().interact(WorldUtils.rayTrace(player, 1.0F), player, interactionType)) {
                event.useBlock = Result.DENY;
                event.useItem = Result.DENY;
            }
        }
    }
    // Use cauldron to remove color from dyable items
    if (rightClick && (block == Blocks.cauldron)) {
        int metadata = world.getBlockMetadata(x, y, z);
        if (metadata > 0) {
            IDyeableItem dyeable = (((holding != null) && (holding.getItem() instanceof IDyeableItem)) ? (IDyeableItem) holding.getItem() : null);
            if ((dyeable != null) && (dyeable.canDye(holding))) {
                StackUtils.remove(holding, "display", "color");
                world.setBlockMetadataWithNotify(x, y, z, metadata - 1, 2);
                world.func_147453_f(x, y, z, block);
                event.useBlock = Result.DENY;
                event.useItem = Result.DENY;
            }
        }
    }
    // Prevent players from breaking blocks with broken cardboard items.
    if (leftClick && (holding != null) && (holding.getItem() instanceof ICardboardItem) && !ItemCardboardSheet.isEffective(holding))
        event.useItem = Result.DENY;
    // Attach locks to iron doors.
    if (!world.isRemote && BetterStorageTiles.lockableDoor != null && rightClick && block == Blocks.iron_door) {
        MovingObjectPosition target = WorldUtils.rayTrace(player, 1F);
        if (target != null && getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block) != null) {
            int meta = world.getBlockMetadata(x, y, z);
            boolean isMirrored;
            if (meta >= 8) {
                isMirrored = meta == 9;
                y -= 1;
                meta = world.getBlockMetadata(x, y, z);
            } else
                isMirrored = world.getBlockMetadata(x, y + 1, z) == 9;
            int rotation = meta & 3;
            ForgeDirection orientation = rotation == 0 ? ForgeDirection.WEST : rotation == 1 ? ForgeDirection.NORTH : rotation == 2 ? ForgeDirection.EAST : ForgeDirection.SOUTH;
            orientation = isMirrored ? (orientation == ForgeDirection.WEST ? ForgeDirection.SOUTH : orientation == ForgeDirection.NORTH ? ForgeDirection.WEST : orientation == ForgeDirection.EAST ? ForgeDirection.NORTH : ForgeDirection.EAST) : orientation;
            world.setBlock(x, y, z, BetterStorageTiles.lockableDoor, 0, SetBlockFlag.SEND_TO_CLIENT);
            world.setBlock(x, y + 1, z, BetterStorageTiles.lockableDoor, 8, SetBlockFlag.SEND_TO_CLIENT);
            TileEntityLockableDoor te = WorldUtils.get(world, x, y, z, TileEntityLockableDoor.class);
            te.orientation = orientation;
            te.isOpen = isMirrored;
            te.isMirrored = isMirrored;
            te.setLock(holding);
            player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
        }
    }
    // Prevent eating of slime buckets after capturing them.
    if (preventSlimeBucketUse) {
        event.setCanceled(true);
        preventSlimeBucketUse = false;
    }
}
Also used : IDyeableItem(net.mcft.copy.betterstorage.item.IDyeableItem) World(net.minecraft.world.World) TileEntityLockableDoor(net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) EnumAttachmentInteraction(net.mcft.copy.betterstorage.attachment.EnumAttachmentInteraction) IHasAttachments(net.mcft.copy.betterstorage.attachment.IHasAttachments) ICardboardItem(net.mcft.copy.betterstorage.item.cardboard.ICardboardItem) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 4 with TileEntityLockableDoor

use of net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor in project BetterStorage by copygirl.

the class TileLockableDoor method getExplosionResistance.

@Override
public float getExplosionResistance(Entity entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) {
    if (world.getBlockMetadata(x, y, z) > 0)
        y -= 1;
    float modifier = 1.0F;
    TileEntityLockableDoor lockable = WorldUtils.get(world, x, y, z, TileEntityLockableDoor.class);
    if (lockable != null) {
        int persistance = BetterStorageEnchantment.getLevel(lockable.getLock(), "persistance");
        if (persistance > 0)
            modifier += Math.pow(2, persistance);
    }
    return super.getExplosionResistance(entity) * modifier;
}
Also used : TileEntityLockableDoor(net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor)

Example 5 with TileEntityLockableDoor

use of net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor in project BetterStorage by copygirl.

the class TileLockableDoor method onBlockPreDestroy.

@Override
public void onBlockPreDestroy(World world, int x, int y, int z, int meta) {
    if (meta == 0) {
        TileEntityLockableDoor te = WorldUtils.get(world, x, y, z, TileEntityLockableDoor.class);
        WorldUtils.dropStackFromBlock(te, te.getLock());
        te.setLockWithUpdate(null);
    }
    super.onBlockPreDestroy(world, x, y, z, meta);
}
Also used : TileEntityLockableDoor(net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor)

Aggregations

TileEntityLockableDoor (net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 EnumAttachmentInteraction (net.mcft.copy.betterstorage.attachment.EnumAttachmentInteraction)1 IHasAttachments (net.mcft.copy.betterstorage.attachment.IHasAttachments)1 IDyeableItem (net.mcft.copy.betterstorage.item.IDyeableItem)1 ICardboardItem (net.mcft.copy.betterstorage.item.cardboard.ICardboardItem)1 Block (net.minecraft.block.Block)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 IIcon (net.minecraft.util.IIcon)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1 World (net.minecraft.world.World)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1