Search in sources :

Example 1 with TileEntityHPBase

use of se.gory_moon.horsepower.tileentity.TileEntityHPBase in project HorsePower by GoryMoon.

the class BlockHPBase method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = playerIn.getHeldItem(hand);
    TileEntityHPBase te = (TileEntityHPBase) worldIn.getTileEntity(pos);
    TileEntityHPHorseBase teH = null;
    if (te == null)
        return false;
    if (te instanceof TileEntityHPHorseBase)
        teH = (TileEntityHPHorseBase) te;
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    EntityCreature creature = null;
    if (teH != null) {
        ArrayList<Class<? extends EntityCreature>> clazzes = Utils.getCreatureClasses();
        search: for (Class<? extends Entity> clazz : clazzes) {
            for (Object entity : worldIn.getEntitiesWithinAABB(clazz, new AxisAlignedBB((double) x - 7.0D, (double) y - 7.0D, (double) z - 7.0D, (double) x + 7.0D, (double) y + 7.0D, (double) z + 7.0D))) {
                if (entity instanceof EntityCreature) {
                    EntityCreature tmp = (EntityCreature) entity;
                    if ((tmp.getLeashed() && tmp.getLeashHolder() == playerIn)) {
                        creature = tmp;
                        break search;
                    }
                }
            }
        }
    }
    if (teH != null && ((stack.getItem() instanceof ItemLead && creature != null) || creature != null)) {
        if (!teH.hasWorker()) {
            creature.clearLeashed(true, false);
            teH.setWorker(creature);
            onWorkerAttached(playerIn, creature);
            return true;
        } else {
            return false;
        }
    } else if (!stack.isEmpty() && te.isItemValidForSlot(0, stack)) {
        ItemStack itemStack = te.getStackInSlot(0);
        boolean flag = false;
        if (itemStack.isEmpty()) {
            te.setInventorySlotContents(0, stack.copy());
            stack.setCount(stack.getCount() - te.getInventoryStackLimit(stack));
            flag = true;
        } else if (TileEntityHPBase.canCombine(itemStack, stack)) {
            int i = Math.min(te.getInventoryStackLimit(stack), stack.getMaxStackSize()) - itemStack.getCount();
            int j = Math.min(stack.getCount(), i);
            stack.shrink(j);
            itemStack.grow(j);
            flag = j > 0;
        }
        if (flag)
            return true;
    }
    int slot = getSlot(state.getBlock().getExtendedState(state, worldIn, pos), hitX, hitY, hitZ);
    ItemStack result = ItemStack.EMPTY;
    if (slot > -1) {
        result = te.removeStackFromSlot(slot);
    } else if (slot > -2) {
        result = te.removeStackFromSlot(1);
        if (result.isEmpty()) {
            result = te.removeStackFromSlot(2);
            if (result.isEmpty() && stack.isEmpty() && hand != EnumHand.OFF_HAND) {
                result = te.removeStackFromSlot(0);
            }
        }
        if (!result.isEmpty())
            emptiedOutput(worldIn, pos);
    }
    if (result.isEmpty()) {
        if (!stack.isEmpty())
            return false;
        if (teH != null)
            teH.setWorkerToPlayer(playerIn);
    }
    if (!result.isEmpty())
        ItemHandlerHelper.giveItemToPlayer(playerIn, result, EntityEquipmentSlot.MAINHAND.getSlotIndex());
    te.markDirty();
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TileEntityHPBase(se.gory_moon.horsepower.tileentity.TileEntityHPBase) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ItemLead(net.minecraft.item.ItemLead) ItemStack(net.minecraft.item.ItemStack) EntityCreature(net.minecraft.entity.EntityCreature) TileEntityHPHorseBase(se.gory_moon.horsepower.tileentity.TileEntityHPHorseBase)

Example 2 with TileEntityHPBase

use of se.gory_moon.horsepower.tileentity.TileEntityHPBase in project HorsePower by GoryMoon.

the class BlockHPChoppingBase method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
    TileEntityHPBase tile = getTileEntity(worldIn, pos);
    if (tile == null)
        return;
    NBTTagCompound baseTag = tag != null ? tag.getCompoundTag("textureBlock") : new NBTTagCompound();
    tile.getTileData().setTag("textureBlock", baseTag);
}
Also used : TileEntityHPBase(se.gory_moon.horsepower.tileentity.TileEntityHPBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with TileEntityHPBase

use of se.gory_moon.horsepower.tileentity.TileEntityHPBase in project HorsePower by GoryMoon.

the class BlockPress method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
    TileEntityHPBase tile = getTileEntity(worldIn, pos);
    if (tile == null)
        return;
    tile.setForward(placer.getHorizontalFacing().getOpposite());
    super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}
Also used : TileEntityHPBase(se.gory_moon.horsepower.tileentity.TileEntityHPBase)

Example 4 with TileEntityHPBase

use of se.gory_moon.horsepower.tileentity.TileEntityHPBase in project HorsePower by GoryMoon.

the class BlockHPChoppingBase method getExtendedState.

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
    IExtendedBlockState extendedState = (IExtendedBlockState) state;
    TileEntityHPBase tile = getTileEntity(world, pos);
    if (tile != null) {
        return getExtendedState(tile, tile.getExtendedState(extendedState));
    }
    return super.getExtendedState(state, world, pos);
}
Also used : TileEntityHPBase(se.gory_moon.horsepower.tileentity.TileEntityHPBase) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState)

Example 5 with TileEntityHPBase

use of se.gory_moon.horsepower.tileentity.TileEntityHPBase in project HorsePower by GoryMoon.

the class BlockChopper method onBlockPlacedBy.

public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
    TileEntityHPBase tile = getTileEntity(worldIn, pos);
    if (tile == null)
        return;
    tile.setForward(placer.getHorizontalFacing().getOpposite());
    super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}
Also used : TileEntityHPBase(se.gory_moon.horsepower.tileentity.TileEntityHPBase)

Aggregations

TileEntityHPBase (se.gory_moon.horsepower.tileentity.TileEntityHPBase)5 Entity (net.minecraft.entity.Entity)1 EntityCreature (net.minecraft.entity.EntityCreature)1 ItemLead (net.minecraft.item.ItemLead)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1 TileEntityHPHorseBase (se.gory_moon.horsepower.tileentity.TileEntityHPHorseBase)1