use of reborncore.api.tile.IUpgrade 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.tile.IUpgrade in project TechReborn by TechReborn.
the class UpgradeSlot method handleRightClick.
@Override
public boolean handleRightClick(int slotID, EntityPlayer player, BuiltContainer container) {
if (inventory instanceof Inventory) {
Inventory inv = (Inventory) inventory;
TileEntity tileEntity = inv.getTileBase();
if (tileEntity instanceof IUpgradeable) {
IUpgradeable upgradeable = (IUpgradeable) tileEntity;
if (upgradeable.canBeUpgraded()) {
ItemStack stack = upgradeable.getUpgradeInvetory().getStackInSlot(slotID);
if (!stack.isEmpty() && stack.getItem() instanceof IUpgrade) {
if (player.world.isRemote) {
((IUpgrade) stack.getItem()).handleRightClick(tileEntity, stack, container, slotID);
}
}
}
}
}
return true;
}
Aggregations