下面列出了net.minecraft.util.text.event.HoverEvent#net.minecraft.util.EnumHand 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBlueprintArchive)
{
/*if (player.isCreative() && player.isSneaking())
{
TileEntityScanner scanner = ((TileEntityScanner) tileentity);
scanner.ticks = CyberwareConfig.SCANNER_TIME - 200;
}*/
player.openGui(Cyberware.INSTANCE, 4, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
public boolean place(IBlockState state, EnumFacing direction, EnumHand hand) {
if (!world.isBlockLoaded(blockPos)) return false;
if (spawnProtection) {
if (!world.isBlockModifiable(player, blockPos)) return false;
}
final BlockSnapshot snapshot = BlockSnapshot.getBlockSnapshot(world, blockPos);
if (!world.setBlockState(blockPos, state, blockPlaceFlags)) return false;
if (ForgeEventFactory.onPlayerBlockPlace(player, snapshot, direction, hand).isCanceled()) {
world.restoringBlockSnapshots = true;
snapshot.restore(true, false);
world.restoringBlockSnapshots = false;
return false;
}
return true;
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.isRemote) {
return true;
} else {
int age = state.getValue(STAGE).intValue();
if (age == 3) {
IBlockState back = state.withProperty(STAGE, 1);
worldIn.setBlockState(pos, back, 2);
spawnAsEntity(worldIn, pos, new ItemStack(ItemLoader.foodsetContain, 1, 14));
}
return true;
}
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItem = playerIn.getHeldItem(hand);
//if (isStructureComplete(worldIn, pos)) {
TileHaloInfuser infuser = getTE(worldIn, pos);
if (infuser == null) return heldItem.isEmpty();
if (!infuser.getHalo().isEmpty()) {
playerIn.setHeldItem(hand, infuser.extractHalo());
playerIn.openContainer.detectAndSendChanges();
} else if (heldItem.getItem() == ModItems.FAKE_HALO) {
infuser.setHalo(heldItem);
playerIn.setHeldItem(hand, ItemStack.EMPTY);
playerIn.openContainer.detectAndSendChanges();
}
//}
return heldItem.isEmpty();
}
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itemstack = player.getHeldItem(hand);
IBlockState state = worldIn.getBlockState(pos);
if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, itemstack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up()))
{
worldIn.setBlockState(pos.up(), content.plant.createState());
if (player instanceof EntityPlayerMP)
{
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos.up(), itemstack);
}
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
} else
{
return EnumActionResult.FAIL;
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
if (world.isRemote == false)
{
// These two lines are to fix the UUID being missing the first time the GUI opens,
// if the item is grabbed from the creative inventory or from JEI or from /give
NBTUtils.getUUIDFromItemStack(stack, "UUID", true);
player.openContainer.detectAndSendChanges();
player.openGui(EnderUtilities.instance, ReferenceGuiIds.GUI_ID_PICKUP_MANAGER, world,
(int)player.posX, (int)player.posY, (int)player.posZ);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
public static EnumActionResult tryParseCoords(IGTCoordinateTile coordTile, World world, EntityPlayer player,
EnumHand hand) {
NBTTagCompound nbt = StackUtil.getNbtData(player.getHeldItem(hand));
if (nbt.getIntArray(POS).length == 4) {
int[] posArr = nbt.getIntArray(POS);
if (!coordTile.isInterdimensional() && posArr[3] != world.provider.getDimension()) {
IC2.platform.messagePlayer(player, "This machine does not support interdimensional communication");
return EnumActionResult.SUCCESS;
}
ItemStack playerStack = player.getHeldItem(hand);
if (coordTile.insertSensorStick(playerStack)) {
coordTile.applyCoordinates(new BlockPos(posArr[0], posArr[1], posArr[2]), posArr[3]);
player.getHeldItem(hand).shrink(1);
IC2.platform.messagePlayer(player, "Sensor Stick successfully installed into machine!");
return EnumActionResult.SUCCESS;
} else {
IC2.platform.messagePlayer(player, "Sensor Stick already found in machine");
return EnumActionResult.SUCCESS;
}
}
IC2.platform.messagePlayer(player, "Sensor Card cannot be installed in this!");
return EnumActionResult.SUCCESS;
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (player.isSneaking())
{
TileEntity te = world.getTileEntity(pos);
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
{
IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
if (world.isRemote == false && inv != null)
{
this.swapInventory(player.getHeldItem(hand), inv, player);
}
return EnumActionResult.SUCCESS;
}
}
return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) {
super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY);
if(playerIn.getHeldItemMainhand()==null) {
TileEntity target = worldIn.getTileEntity(pos);
if(target instanceof TileBasicPipe) {
if(((TileBasicPipe) target).hasNetwork()) {
//Add Debug routing on Activation
return true;
}
}
}
return false;
}
protected boolean tryApplyCamouflage(EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (this.hasCamouflageAbility() && player.getHeldItemMainhand().isEmpty())
{
// Sneaking with an empty hand, clear the camo block
if (player.isSneaking() && this.camoState != null)
{
this.removeCamouflage();
return true;
}
ItemStack stackOffHand = player.getHeldItemOffhand();
// Apply camouflage when right clicking with an empty main hand, and a block in the off hand
if (stackOffHand.isEmpty() == false && stackOffHand.getItem() instanceof ItemBlock)
{
return this.applyCamouflage(player, stackOffHand, side, hitX, hitY, hitZ);
}
}
return false;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
if (world.isRemote == false)
{
// These two lines are to fix the UUID being missing the first time the GUI opens,
// if the item is grabbed from the creative inventory or from JEI or from /give
NBTUtils.getUUIDFromItemStack(stack, "UUID", true);
player.openContainer.detectAndSendChanges();
player.openGui(EnderUtilities.instance, ReferenceGuiIds.GUI_ID_HANDY_BAG_RIGHT_CLICK, world,
(int)player.posX, (int)player.posY, (int)player.posZ);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) {
super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY);
if(playerIn.getHeldItemMainhand()==null) {
TileEntity target = worldIn.getTileEntity(pos);
if(target instanceof TileBasicPipe) {
if(((TileBasicPipe) target).hasNetwork()) {
//Add Debug routing on Activation
return true;
}
}
}
return false;
}
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
ItemStack stack = playerIn.getHeldItem(hand);
if(!worldIn.isRemote) {
TileEntity te = worldIn.getTileEntity(pos);
if(te instanceof TileEntityRailLinkBase && playerIn.isSneaking()) {
TileEntityRailLinkBase railLinkBase = (TileEntityRailLinkBase)te;
MCPos railPos = getLinkedRail(stack);
if(railPos != null) {
if(railLinkBase.setLinkedPos(railPos, playerIn)) {
playerIn.sendMessage(new TextComponentString("Linked to " + railPos));
}
}
} else {
IBlockState state = worldIn.getBlockState(pos);
IRail r = RailManager.getInstance().getRail(worldIn, pos, state);
if(r != null) {
setLinkedRail(stack, new MCPos(worldIn, pos));
playerIn.sendMessage(new TextComponentString("Pos: " + pos));
}
}
}
return super.onItemUse(playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
public static boolean doClickableFluidContainerFillThings(EntityPlayer player, EnumHand hand, World world,
BlockPos pos, IC2Tank tank) {
ItemStack playerStack = player.getHeldItem(hand);
if (!playerStack.isEmpty()) {
FluidActionResult result = FluidUtil.tryFillContainer(playerStack, tank, tank.getCapacity(), player, true);
if (result.isSuccess()) {
playerStack.shrink(1);
ItemStack resultStack = result.getResult();
if (!resultStack.isEmpty()) {
if (!player.inventory.addItemStackToInventory(resultStack)) {
player.dropItem(resultStack, false);
}
}
return true;
}
}
return false;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
ItemStack itemStackIn = playerIn.getHeldItem(handIn);
if(itemStackIn.getCount() < 5)
{
return new ActionResult(EnumActionResult.FAIL, itemStackIn);
}
PlayerInfo pi = PlayerManagerTFC.getInstance().getPlayerInfoFromPlayer(playerIn);
pi.specialCraftingType = new ItemStack(itemStackIn.getItem());
pi.specialCraftingTypeAlternate = new ItemStack(itemStackIn.getItem());
if(!worldIn.isRemote)
playerIn.openGui(TFC.instance, 0, worldIn, playerIn.getPosition().getX(), playerIn.getPosition().getY(), playerIn.getPosition().getZ());
return new ActionResult(EnumActionResult.PASS, itemStackIn);
}
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack stack = playerIn.getHeldItem(hand);
if(worldIn.isRemote)
return EnumActionResult.FAIL;
IBlockState soil = worldIn.getBlockState(pos);
if(facing == EnumFacing.UP && soil.getBlock() == TFCBlocks.Farmland && worldIn.isAirBlock(pos.up()))
{
//worldIn.setBlockState(pos.up(), TFCBlocks.Crop.getDefaultState());
TileCrop tc = (TileCrop) worldIn.getTileEntity(pos.up());
tc.setCropType(cropToPlant[stack.getItemDamage()]);
tc.setFarmerID(playerIn);
}
return EnumActionResult.SUCCESS;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (player.getHeldItem(hand).getItem() == Items.STICK) {
BlockSuperchest.toggleMultiBlock(world, pos, state, player);
return true;
}
// Only work if the block is formed
if (state.getBlock() == ModBlocks.blockSuperchestPart && state.getValue(FORMED) != SuperchestPartIndex.UNFORMED) {
// Find the controller
BlockPos controllerPos = BlockSuperchest.getControllerPos(world, pos);
if (controllerPos != null) {
IBlockState controllerState = world.getBlockState(controllerPos);
return controllerState.getBlock().onBlockActivated(world, controllerPos, controllerState, player, hand, facing, hitX, hitY, hitZ);
}
}
return false;
}
@Override
@SideOnly(Side.CLIENT)
public void onInventoryButtonPressed(int buttonId) {
ItemStack stack = Minecraft.getMinecraft().player.getHeldItem(EnumHand.MAIN_HAND);
if(stack != null && stack.getItem() == this) {
setBiomeId(stack, buttonId);
PacketHandler.sendToServer(new PacketItemModifcation(this, Minecraft.getMinecraft().player, (byte)(buttonId == -1 ? -1 : 0)));
}
}
public boolean useHoeToPlant(ItemStack toolStack, EntityPlayer player, EnumHand hand,
World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (UtilItemModular.useEnderCharge(toolStack, ENDER_CHARGE_COST, true) == false)
{
return false;
}
IItemHandler inv = this.getLinkedInventoryWithChecks(toolStack, player);
if (inv != null)
{
for (int slot = 0; slot < inv.getSlots(); slot++)
{
if (this.plantItemFromInventorySlot(world, player, hand, inv, slot, pos, side, hitX, hitY, hitZ))
{
// Use Ender Charge if planting from a remote inventory
if (DropsMode.fromStack(toolStack) == DropsMode.REMOTE)
{
UtilItemModular.useEnderCharge(toolStack, ENDER_CHARGE_COST, false);
}
Effects.addItemTeleportEffects(world, pos);
return true;
}
}
}
return false;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
player.openGui(AgriCraft.instance, GuiHandler.SEED_STORAGE_GUI_ID, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
@Override
public boolean processInitialInteract(EntityPlayer player,
EnumHand hand) {
if(!world.isRemote && tile != null) {
tile.selectSystem(properties.getId());
}
return true;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX,
float hitY, float hitZ) {
if (!world.isRemote) {
player.openGui(Minecoprocessors.INSTANCE, MinecoprocessorGuiHandler.MINECOPROCESSOR_ENTITY_GUI, world, pos.getX(), pos.getY(),
pos.getZ());
}
return true;
}
private boolean tryApplyLabel(EntityPlayer player, EnumHand hand, EnumFacing side)
{
if (this.labels.contains(side) == false && side != this.getFacing() &&
this.tryApplyUpgrade(player, hand, 0, EnderUtilitiesItems.ENDER_PART, 70))
{
this.labels.add(side);
this.updateLabels(false);
return true;
}
return false;
}
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
ItemStack itemstack = playerIn.getHeldItem(handIn);
if (playerIn.canEat(false))
{
playerIn.setActiveHand(handIn);
return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
}
else
{
return new ActionResult<>(EnumActionResult.FAIL, itemstack);
}
}
/**
* see PlayerInteractionManager.tryHarvestBlock
*/
public boolean breakBlock(EntityPlayerMP player, BlockPos pos) {
World world = player.world;
IBlockState state = world.getBlockState(pos);
TileEntity te = world.getTileEntity(pos);
if (state.getBlockHardness(world, pos) < 0 || !state.getBlock().canHarvestBlock(world, pos, player))
{
return false;
}
else {
ItemStack stack = player.getHeldItemMainhand();
if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;
world.playEvent(player, 2001, pos, Block.getStateId(state));
ItemStack itemHand = player.getHeldItemMainhand();
ItemStack itemHandCopy = itemHand.isEmpty() ? ItemStack.EMPTY : itemHand.copy();
boolean canHarvest = state.getBlock().canHarvestBlock(world, pos, player);
if (!itemHand.isEmpty()) {
itemHand.onBlockDestroyed(world, state, pos, player);
if (itemHand.isEmpty()) {
ForgeEventFactory.onPlayerDestroyItem(player, itemHandCopy, EnumHand.MAIN_HAND);
}
}
boolean didRemove = removeBlock(player, pos, canHarvest);
if (didRemove && canHarvest) {
state.getBlock().harvestBlock(world, player, pos, state, te, itemHandCopy);
}
return didRemove;
}
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (world.isRemote == false)
{
// Returns the "id" of the pointed element of this block the player is currently looking at.
// The target selection buttons are ids 0..7, the middle button is 8 and the base of the panel is 9.
Integer id = this.getPointedElementId(world, pos, state.getValue(FACING), player);
if (id != null && id >= 0 && id <= 8)
{
TileEntityPortalPanel te = getTileEntitySafely(world, pos, TileEntityPortalPanel.class);
if (te != null)
{
if (id == 8)
{
te.tryTogglePortal();
}
else
{
te.setActiveTargetId(id);
world.notifyBlockUpdate(pos, state, state, 3);
}
world.playSound(null, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.MASTER, 0.5f, 1.0f);
}
return true;
}
}
return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (playerIn.getHeldItem(hand).getItem() == Items.BUCKET && hasSoy(state)) {
if (playerIn.getHeldItem(hand).getCount() > 1) {
playerIn.getHeldItem(hand).shrink(1);
playerIn.inventory.addItemStackToInventory(FluidUtil.getFilledBucket(new FluidStack(BlockLoader.SOYSAUCE_FLUID, 1000)));
} else {
playerIn.setHeldItem(hand, FluidUtil.getFilledBucket(new FluidStack(BlockLoader.SOYSAUCE_FLUID, 1000)));
}
worldIn.setBlockState(pos, this.withFerm(8), 2);
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
@Override
public boolean onInputAction(int keyMask, EntityPlayer player, RayTraceResult trace, World world, BlockPos pos)
{
if (EnumKey.MIDDLE_CLICK.matches(keyMask, HotKeys.MOD_NONE, HotKeys.MOD_SHIFT))
{
Vec3d hit = trace.hitVec;
return this.tryApplyCamouflage(player, EnumHand.OFF_HAND, trace.sideHit, (float) hit.x, (float) hit.y, (float) hit.z);
}
return false;
}
@Override
@SideOnly(Side.CLIENT)
protected PlayerInventoryHolder readHolderFromSyncData(PacketBuffer syncData) {
EntityPlayer entityPlayer = Minecraft.getMinecraft().player;
EnumHand enumHand = EnumHand.values()[syncData.readByte()];
ItemStack itemStack;
try {
itemStack = syncData.readItemStack();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
return new PlayerInventoryHolder(entityPlayer, enumHand, itemStack);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing face, float par7, float par8, float par9){
if(player.isSneaking() || getGuiID() == null) return false;
else {
if(!world.isRemote) {
TileEntity te = world.getTileEntity(pos);
if(te != null) {
player.openGui(Signals.instance, getGuiID().ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}
return true;
}
}