use of net.minecraft.block.BlockButton in project Charset by CharsetMC.
the class ItemChisel method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (hand == EnumHand.OFF_HAND) {
return EnumActionResult.PASS;
}
if (!worldIn.isRemote) {
IBlockState state = worldIn.getBlockState(pos);
if (!state.getBlock().isAir(state, worldIn, pos)) {
ItemStack inputStack = state.getBlock().getPickBlock(state, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), facing, pos), worldIn, pos, playerIn);
if (!inputStack.isEmpty() && inputStack.getCount() == 1) {
ItemStack heldItem = playerIn.getHeldItem(EnumHand.MAIN_HAND);
ItemStack[] inputStacks = new ItemStack[9];
int inputMask = getBlockMask(heldItem);
int inputCount = 0;
for (int i = 0; i < 9; i++) {
if ((inputMask & (1 << i)) != 0) {
inputStacks[i] = inputStack;
inputCount++;
}
}
ItemStack result = FastRecipeLookup.getCraftingResult(RecipeUtils.getCraftingInventory(3, 3, RecipeUtils.defaultContainer(playerIn), inputStacks), worldIn);
if (result != null && !result.isEmpty() && !(result.getItem() instanceof ItemBlock && ((ItemBlock) result.getItem()).getBlock() instanceof BlockButton)) {
if (result.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) result.getItem()).getBlock();
if (block instanceof BlockButton) {
return EnumActionResult.FAIL;
}
if (block instanceof BlockStairs && (inputCount == 6 && result.getCount() >= 4 && result.getCount() <= 8)) {
result.setCount(inputCount);
}
}
if ((result.getCount() % inputCount) == 0) {
ItemStack resultCopy = result.copy();
resultCopy.setCount(1);
ActionResult<ItemStack> placeResult = ToolsUtils.placeBlockOrRollback(resultCopy, playerIn, worldIn, pos);
if (placeResult.getType() == EnumActionResult.FAIL) {
return EnumActionResult.FAIL;
}
if (result.getCount() > inputCount) {
ItemStack resultCopyRemainder = result.copy();
resultCopyRemainder.setCount((result.getCount() / inputCount) - 1);
Block.spawnAsEntity(worldIn, pos, resultCopyRemainder);
}
}
}
}
}
}
return EnumActionResult.SUCCESS;
}
use of net.minecraft.block.BlockButton in project Ceramics by KnightMiner.
the class BlockChannel method addExtra.
private IBlockState addExtra(IBlockState state, IBlockAccess world, BlockPos pos, PropertyEnum<ChannelConnectionState> prop, EnumFacing side) {
ChannelConnectionState connection = state.getValue(prop);
IBlockState offsetState = world.getBlockState(pos.offset(side));
Block block = offsetState.getBlock();
if (connection == ChannelConnectionState.OUT && block instanceof BlockBarrel) {
state = state.withProperty(prop, ChannelConnectionState.BARREL);
} else if (connection == ChannelConnectionState.NONE && (block instanceof BlockLever && offsetState.getValue(BlockLever.FACING).getFacing() == side || block instanceof BlockButton && offsetState.getValue(BlockButton.FACING) == side)) {
state = state.withProperty(prop, ChannelConnectionState.LEVER);
}
return state;
}
Aggregations