Search in sources :

Example 1 with ArmorStandEquipHandler

use of net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler in project BetterStorage by copygirl.

the class TileEntityArmorStand method dropContents.

@Override
public void dropContents() {
    ItemStack item;
    for (EnumArmorStandRegion region : EnumArmorStandRegion.values()) for (ArmorStandEquipHandler handler : BetterStorageArmorStand.getEquipHandlers(region)) if ((item = getItem(handler)) != null)
        WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, item);
    clearItems();
}
Also used : ArmorStandEquipHandler(net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler) EnumArmorStandRegion(net.mcft.copy.betterstorage.api.stand.EnumArmorStandRegion) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ArmorStandEquipHandler

use of net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler in project BetterStorage by copygirl.

the class TileEntityArmorStand method onBlockActivated.

@Override
public boolean onBlockActivated(EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    if (worldObj.isRemote)
        return true;
    int slot = Math.max(0, Math.min(3, (int) (hitY * 2)));
    EnumArmorStandRegion region = EnumArmorStandRegion.values()[slot];
    for (ArmorStandEquipHandler handler : BetterStorageArmorStand.getEquipHandlers(region)) {
        ItemStack item = getItem(handler);
        if (player.isSneaking()) {
            // Swap player's equipped armor with armor stand's.
            ItemStack equipped = handler.getEquipment(player);
            if (((item == null) && (equipped == null)) || ((item != null) && !handler.isValidItem(player, item)) || ((equipped != null) && !handler.isValidItem(player, equipped)) || !handler.canSetEquipment(player, item))
                continue;
            setItem(handler, equipped);
            handler.setEquipment(player, item);
        } else {
            // Swap player's held item with armor stand's.
            ItemStack holding = player.getCurrentEquippedItem();
            if (((item == null) && (holding == null)) || ((holding != null) && !handler.isValidItem(player, holding)))
                continue;
            setItem(handler, holding);
            player.setCurrentItemOrArmor(EquipmentSlot.HELD, item);
            break;
        }
    }
    return true;
}
Also used : ArmorStandEquipHandler(net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler) EnumArmorStandRegion(net.mcft.copy.betterstorage.api.stand.EnumArmorStandRegion) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ArmorStandEquipHandler

use of net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler in project BetterStorage by copygirl.

the class ClientProxy method getArmorStandHighlightBox.

private AxisAlignedBB getArmorStandHighlightBox(EntityPlayer player, World world, int x, int y, int z, Vec3 hitVec) {
    int metadata = world.getBlockMetadata(x, y, z);
    if (metadata > 0)
        y -= 1;
    TileEntityArmorStand armorStand = WorldUtils.get(world, x, y, z, TileEntityArmorStand.class);
    if (armorStand == null)
        return null;
    int slot = Math.max(0, Math.min(3, (int) ((hitVec.yCoord - y) * 2)));
    double minX = x + 2 / 16.0;
    double minY = y + slot / 2.0;
    double minZ = z + 2 / 16.0;
    double maxX = x + 14 / 16.0;
    double maxY = y + slot / 2.0 + 0.5;
    double maxZ = z + 14 / 16.0;
    EnumArmorStandRegion region = EnumArmorStandRegion.values()[slot];
    for (ArmorStandEquipHandler handler : BetterStorageArmorStand.getEquipHandlers(region)) {
        ItemStack item = armorStand.getItem(handler);
        if (player.isSneaking()) {
            // Check if we can swap the player's equipped armor with armor stand's.
            ItemStack equipped = handler.getEquipment(player);
            if (((item == null) && (equipped == null)) || ((item != null) && !handler.isValidItem(player, item)) || ((equipped != null) && !handler.isValidItem(player, equipped)) || !handler.canSetEquipment(player, item))
                continue;
            return AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
        } else {
            // Check if we can swap the player's held item with armor stand's.
            ItemStack holding = player.getCurrentEquippedItem();
            if (((item == null) && (holding == null)) || ((holding != null) && !handler.isValidItem(player, holding)))
                continue;
            return AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
        }
    }
    return AxisAlignedBB.getBoundingBox(minX, y, minZ, maxX, y + 2, maxZ);
}
Also used : TileEntityArmorStand(net.mcft.copy.betterstorage.tile.stand.TileEntityArmorStand) ArmorStandEquipHandler(net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler) EnumArmorStandRegion(net.mcft.copy.betterstorage.api.stand.EnumArmorStandRegion) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ArmorStandEquipHandler

use of net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler in project BetterStorage by copygirl.

the class TileEntityArmorStand method write.

public void write(NBTTagCompound compound) {
    compound.setByte("rotation", (byte) rotation);
    NBTTagCompound items = new NBTTagCompound();
    for (EnumArmorStandRegion region : EnumArmorStandRegion.values()) {
        NBTTagCompound regionCompound = new NBTTagCompound();
        ItemStack item;
        for (ArmorStandEquipHandler handler : BetterStorageArmorStand.getEquipHandlers(region)) if ((item = getItem(handler)) != null)
            regionCompound.setTag(handler.id, item.writeToNBT(new NBTTagCompound()));
        items.setTag(region.toString(), regionCompound);
    }
    compound.setTag("Items", items);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArmorStandEquipHandler(net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler) EnumArmorStandRegion(net.mcft.copy.betterstorage.api.stand.EnumArmorStandRegion) ItemStack(net.minecraft.item.ItemStack)

Example 5 with ArmorStandEquipHandler

use of net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler in project BetterStorage by copygirl.

the class TileEntityArmorStand method onPickBlock.

@Override
public ItemStack onPickBlock(ItemStack block, MovingObjectPosition target) {
    int slot = Math.max(0, Math.min(3, (int) ((target.hitVec.yCoord - yCoord) * 2)));
    EnumArmorStandRegion region = EnumArmorStandRegion.values()[slot];
    ItemStack item;
    for (ArmorStandEquipHandler handler : BetterStorageArmorStand.getEquipHandlers(region)) if ((item = getItem(handler)) != null)
        return item;
    return block;
}
Also used : ArmorStandEquipHandler(net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler) EnumArmorStandRegion(net.mcft.copy.betterstorage.api.stand.EnumArmorStandRegion) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ArmorStandEquipHandler (net.mcft.copy.betterstorage.api.stand.ArmorStandEquipHandler)6 EnumArmorStandRegion (net.mcft.copy.betterstorage.api.stand.EnumArmorStandRegion)6 ItemStack (net.minecraft.item.ItemStack)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 Set (java.util.Set)1 TileEntityArmorStand (net.mcft.copy.betterstorage.tile.stand.TileEntityArmorStand)1 NBTBase (net.minecraft.nbt.NBTBase)1 NBTTagList (net.minecraft.nbt.NBTTagList)1