use of reborncore.api.IToolDrop in project RebornCore by TechReborn.
the class BlockMachineBase method onBlockActivated.
/*
* Right-click should open GUI for all non-wrench items
* Shift-Right-click should apply special action, like fill\drain bucket, install upgrade, etc.
*/
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (fillBlockWithFluid(worldIn, pos, playerIn)) {
return true;
}
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos);
// We extended BlockTileBase. Thus we should always have tile entity. I hope.
if (tileEntity == null) {
return false;
}
if (!stack.isEmpty()) {
if (ToolManager.INSTANCE.canHandleTool(stack)) {
if (ToolManager.INSTANCE.handleTool(stack, pos, worldIn, playerIn, side, false)) {
if (playerIn.isSneaking()) {
if (tileEntity instanceof IToolDrop) {
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(playerIn);
if (drop == null) {
return false;
}
if (!drop.isEmpty()) {
spawnAsEntity(worldIn, pos, drop);
}
if (!worldIn.isRemote) {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
return true;
}
} else {
rotateBlock(worldIn, pos, side);
return true;
}
}
} else if (stack.getItem() instanceof IUpgrade && tileEntity instanceof IUpgradeable) {
IUpgradeable upgradeableEntity = (IUpgradeable) tileEntity;
if (upgradeableEntity.canBeUpgraded()) {
if (InventoryHelper.testInventoryInsertion(upgradeableEntity.getUpgradeInvetory(), stack, null) > 0) {
InventoryHelper.insertItemIntoInventory(upgradeableEntity.getUpgradeInvetory(), stack);
playerIn.setHeldItem(EnumHand.MAIN_HAND, stack);
return true;
}
}
}
}
if (getGui() != null && !playerIn.isSneaking()) {
getGui().open(playerIn, pos, worldIn);
return true;
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
use of reborncore.api.IToolDrop in project TechReborn by TechReborn.
the class BlockPlayerDetector method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity == null) {
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
String type = state.getValue(TYPE);
String newType = type;
TextFormatting color = TextFormatting.GREEN;
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
if (ToolManager.INSTANCE.handleTool(stack, pos, worldIn, playerIn, side, false)) {
if (playerIn.isSneaking()) {
if (tileEntity instanceof IToolDrop) {
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(playerIn);
if (drop == null) {
return false;
}
if (!drop.isEmpty()) {
spawnAsEntity(worldIn, pos, drop);
}
if (!worldIn.isRemote) {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
return true;
}
} else {
if (type.equals("all")) {
newType = "others";
color = TextFormatting.RED;
} else if (type.equals("others")) {
newType = "you";
color = TextFormatting.BLUE;
} else if (type.equals("you")) {
newType = "all";
}
worldIn.setBlockState(pos, state.withProperty(TYPE, newType));
}
}
}
if (worldIn.isRemote) {
ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID, new TextComponentString(TextFormatting.GRAY + I18n.format("techreborn.message.detects") + " " + color + StringUtils.toFirstCapital(newType)));
}
return true;
}
use of reborncore.api.IToolDrop in project TechReborn by TechReborn.
the class BlockEnergyStorage method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack heldStack = player.getHeldItem(hand);
if (ToolManager.INSTANCE.canHandleTool(heldStack)) {
if (ToolManager.INSTANCE.handleTool(heldStack, pos, world, player, side, true)) {
if (player.isSneaking()) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IToolDrop) {
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player);
if (drop == null) {
return false;
}
if (!drop.isEmpty()) {
spawnAsEntity(world, pos, drop);
}
world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.BLOCK_DISMANTLE, SoundCategory.BLOCKS, 0.6F, 1F);
if (!world.isRemote) {
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
return true;
}
} else {
EnumFacing facing2 = state.getValue(BlockEnergyStorage.FACING);
if (facing2.getOpposite() == side) {
facing2 = side;
} else {
facing2 = side.getOpposite();
}
world.setBlockState(pos, state.withProperty(BlockEnergyStorage.FACING, facing2));
return true;
}
}
} else if (!player.isSneaking()) {
player.openGui(Core.INSTANCE, guiID, world, pos.getX(), pos.getY(), pos.getZ());
return true;
}
return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
use of reborncore.api.IToolDrop in project TechReborn by TechReborn.
the class BlockTransformer method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack) && !world.isRemote) {
if (ToolManager.INSTANCE.handleTool(stack, pos, world, player, side, true) && state.getBlock() instanceof BlockTransformer) {
if (player.isSneaking()) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IToolDrop) {
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player);
if (drop == null) {
return false;
}
if (!drop.isEmpty()) {
spawnAsEntity(world, pos, drop);
}
world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.BLOCK_DISMANTLE, SoundCategory.BLOCKS, 0.6F, 1F);
if (!world.isRemote) {
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
return true;
}
} else {
EnumFacing facing2 = state.getValue(BlockTransformer.FACING);
if (facing2.getOpposite() == side) {
facing2 = side;
} else {
facing2 = side.getOpposite();
}
world.setBlockState(pos, state.withProperty(BlockTransformer.FACING, facing2));
return true;
}
}
}
return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
Aggregations