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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations