本文整理匯總了Java中net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock方法的典型用法代碼示例。如果您正苦於以下問題:Java PlayerInteractEvent.RightClickBlock方法的具體用法?Java PlayerInteractEvent.RightClickBlock怎麽用?Java PlayerInteractEvent.RightClickBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraftforge.event.entity.player.PlayerInteractEvent
的用法示例。
在下文中一共展示了PlayerInteractEvent.RightClickBlock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleBlockRightClick
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void handleBlockRightClick(PlayerInteractEvent.RightClickBlock evt) {
TileEntity entity = evt.getEntityPlayer().getEntityWorld().getTileEntity(evt.getPos());
SecurityServerEntity securityServer;
if (entity instanceof SecurityServerEntity) {
securityServer = (SecurityServerEntity)entity;
if (!securityServer.canPlayerOpen(evt.getEntityPlayer())) {
evt.setCanceled(true);
}
return;
}
CableNetwork network = new CableNetwork(evt.getEntityPlayer().getEntityWorld(), evt.getPos(), RezolveMod.ETHERNET_CABLE_BLOCK);
securityServer = network.getSecurityServer();
if (securityServer != null) {
if (!securityServer.canPlayerUse(evt.getEntityPlayer(), evt.getPos())) {
evt.setCanceled(true);
}
}
}
示例2: onPlayerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public boolean onPlayerInteract(PlayerInteractEvent.RightClickBlock event) {
if (isListeningToCoordTrackerSetting) {
isListeningToCoordTrackerSetting = false;
EnumFacing dir = event.getFace();
reset();
ItemStack stack = event.getEntityPlayer().getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if (!stack.isEmpty()) {
NBTTagCompound tag = NBTUtil.getCompoundTag(stack, "CoordTracker");
tag.setInteger("dimID", event.getEntity().world.provider.getDimension());
NBTUtil.setPos(tag, event.getPos().offset(dir));
}
assert dir != null;
NetworkHandler.sendToServer(new PacketCoordTrackUpdate(event.getEntity().world, event.getPos().offset(dir)));
}
return false;
}
示例3: onInteraction
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onInteraction(PlayerInteractEvent.RightClickBlock event) {
ItemStack curItem = event.getEntityPlayer().getHeldItemMainhand();
if (!event.getWorld().isRemote && event.getHand() == EnumHand.MAIN_HAND) {
if (curItem.getItem() instanceof ISemiBlockItem) {
boolean success = interact(event, curItem, event.getPos());
//If the block can't be placed in the pos, then try to place it next to the block.
if(!success && event.getFace() != null)
success = interact(event, curItem, event.getPos().offset(event.getFace()));
if(success) event.setCanceled(true);
}
} else if (event.getWorld().isRemote && curItem.getItem() instanceof ISemiBlockItem) {
event.setCancellationResult(EnumActionResult.SUCCESS);
event.setCanceled(true);
}
}
示例4: placeKiln
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority=EventPriority.HIGH)
public void placeKiln(PlayerInteractEvent.RightClickBlock event){
if(event.getWorld().getBlockState(event.getPos()).getBlock()==BlocksRegistry.potteryKiln){
event.setUseBlock(Result.ALLOW);
}else if(!event.isCanceled()&&event.getEntityPlayer().isSneaking()&&PotteryKilnRecipe.isValidInput(event.getItemStack())){
if(event.getFace()==EnumFacing.UP&&event.getWorld().getBlockState(event.getPos()).isSideSolid(event.getWorld(), event.getPos(), EnumFacing.UP)&&
event.getWorld().getBlockState(event.getPos().offset(EnumFacing.UP)).getBlock().isReplaceable(event.getWorld(), event.getPos().offset(EnumFacing.UP))){
if(!event.getWorld().isRemote){
event.getWorld().setBlockState(event.getPos().offset(EnumFacing.UP), BlocksRegistry.potteryKiln.getDefaultState());
TilePotteryKiln tile=((TilePotteryKiln)event.getWorld().getTileEntity(event.getPos().offset(EnumFacing.UP)));
event.getEntityPlayer().setHeldItem(event.getHand(), tile.pottery.insertItem(0, event.getItemStack(), false));
event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_GRAVEL_PLACE, SoundCategory.BLOCKS, 1F, 1F);
event.getWorld().notifyBlockUpdate(event.getPos().offset(EnumFacing.UP), BlocksRegistry.potteryKiln.getDefaultState(), BlocksRegistry.potteryKiln.getDefaultState(), 2);
}
event.setUseBlock(Result.DENY);
event.setUseItem(Result.DENY);
}
}
}
示例5: onPlayerClickBlock
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onPlayerClickBlock(PlayerInteractEvent.RightClickBlock event) {
if (event.getEntityPlayer() == null || !event.getEntityPlayer().isSneaking()) {
return;
}
if (event.getItemStack().getItem() == ModItems.hammer && !event.getEntityPlayer().getCooldownTracker().hasCooldown(ModItems.hammer)) {
if (!event.getWorld().isRemote) {
BlockPos pos = event.getPos().offset(event.getFace());
event.getWorld().createExplosion(event.getEntityPlayer(), pos.getX() + 0.5, pos.getY() + 0.5,
pos.getZ() + 0.5, 3, false);
}
event.getEntityPlayer().swingArm(event.getHand());
event.getEntityPlayer().setActiveHand(event.getHand());
event.getEntityPlayer().getCooldownTracker().setCooldown(ModItems.hammer, 200);
ModItems.hammer.setDamage(event.getItemStack(), ModItems.hammer.getDamage(event.getItemStack()) - 10);
event.setCancellationResult(EnumActionResult.SUCCESS);
event.setResult(Event.Result.ALLOW);
event.setCanceled(true);
}
}
示例6: onRightClick
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickBlock e)
{
if (!e.getWorld().isRemote) {
BlockPos pos = e.getPos();
IBlockState state = e.getWorld().getBlockState(pos);
if (state.getBlock() instanceof BlockCrops) {
BlockCrops block = (BlockCrops) state.getBlock();
if ((block == Blocks.wheat || block == Blocks.carrots || block == Blocks.potatoes) && state.getValue(BlockCrops.AGE) == 7) {
performAction(e.getWorld(), e.getPos(), state, BlockCrops.AGE);
} else if (block == Blocks.beetroots && state.getValue(BlockBeetroot.BEETROOT_AGE) == 3) {
performAction(e.getWorld(), e.getPos(), state, BlockBeetroot.BEETROOT_AGE);
}
}
}
}
示例7: handleInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SuppressWarnings("static-access")
@SubscribeEvent
public static void handleInteract(PlayerInteractEvent.RightClickBlock event) throws NullPointerException
{
ItemStack item = event.getEntityPlayer().getActiveItemStack();
AchievementPage page = ARKCraftAchievements.page;
Achievement achievement = ARKCraftAchievements.achievementMichaelBay;
EntityPlayer player = event.getEntityPlayer();
if (!AchievementHelper.containsAchievement(page, achievement)) {
if (item != null && item.getItem() == ARKCraftRangedWeapons.rocket_propelled_grenade) {
if (item.getDisplayName().equals("Michael_Bay") && player.isSneaking()) {
double x = player.posX;
double y = player.posY;
double z = player.posZ;
Easter.MICHAEL_BAY.createExplosionNoDamage(player, event.getWorld(), 5.0F, x, y, z, 0, 1, 0);
AchievementHelper.registerAndDisplay(player, achievement);
}
}
}
}
示例8: onPlayerInteractEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteractEvent(PlayerInteractEvent.RightClickBlock evt) {
// Called when right clicking on a block (potentially with something...)
if(evt.isCanceled()) return;
// Check if we're cancelling, or if our interaction handler says we should cancel:
if (!ItemRegistry.instance.shouldCancelUse(evt) && BlockRegistry.instance.handleInteraction(evt)) return;
evt.setUseItem(Event.Result.DENY);
evt.setUseBlock(Event.Result.ALLOW);
evt.setCanceled(true);
// The game ends up firing the RightClickItem event as well; we set this here to make sure
// we don't end up doing all the checks/callbacks a second time in that event:
debounceItemRightClick.set(true);
}
示例9: handleInteraction
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
/**
* Handles checking for any interactions we need to run for the given block.
* @param evt The event to handle
* @return True if the interaction should continue, false otherwise.
*/
public boolean handleInteraction(PlayerInteractEvent.RightClickBlock evt) {
// Figure out what we clicked...
IBlockState targetBlock = evt.getWorld().getBlockState(evt.getPos());
// Get our handlers...
Collection<BlockInteractionHandler> handlers = interactionHandlers.get(targetBlock);
// Bail early if we can:
if(handlers.size() <= 0) return true;
// Simulate the harvest drops event:
// TODO: Abstract block drops from general block matchers so we don't have to do this...
BlockEvent.HarvestDropsEvent simulatedEvt = new BlockEvent.HarvestDropsEvent(evt.getWorld(), evt.getPos(),
targetBlock, 0, 0.0f, new ArrayList<>(), evt.getEntityPlayer(), false);
// ... and process them
for (BlockInteractionHandler handler : handlers) {
// Check if we should cancel:
if(!handler.handle(evt, simulatedEvt)) return false;
}
// If we made it here, we can tell the parent handler it can continue:
return true;
}
示例10: handle
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
/**
* Handle the event, returning if processing should continue
*
* @param evt The event to handle
* @param simulatedEvt A simulated drop event to pass on to the matchers
* @return True if processing should continue; false to cancel the underlying event.
*/
public boolean handle(PlayerInteractEvent.RightClickBlock evt, BlockEvent.HarvestDropsEvent simulatedEvt) {
List<Runnable> matcherCallbacks = new ArrayList<>();
// Check our matchers:
for (IBlockDropMatcher matcher : matchers) {
BaseMatchResult result = matcher.isMatch(simulatedEvt, dummy);
if (!result.isMatch()) return true;
if (result.getCallback() != null) matcherCallbacks.add(result.getCallback());
}
// Run our matcher callbacks:
for (Runnable matcherCallback : matcherCallbacks) {
matcherCallback.run();
}
// Run our callbacks, only for the main hand:
// TODO: Consider moving this to the event handler to prevent going through everything else...
if(evt.getHand() == EnumHand.MAIN_HAND) {
MobTickRegistry.addCallbackSet(evt.getEntity(), callbacks, new BaseEntityMatcherData(evt.getEntity()));
}
return !cancelAfterMatch;
}
示例11: onPlayerTryToSleep
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
@SuppressWarnings("unused")
public void onPlayerTryToSleep(PlayerInteractEvent.RightClickBlock event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState state = world.getBlockState(pos);
if(!(state.getBlock() instanceof BlockBed)) {
return;
}
if(isBedOccupied(world, pos, state)) {
event.setCanceled(true);
event.setUseBlock(Event.Result.DENY);
event.setUseItem(Event.Result.DENY);
event.getEntityPlayer().sendMessage(new TextComponentString("Occupied"));
}
}
示例12: vanillaRightClickCropsHarvesting
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void vanillaRightClickCropsHarvesting(PlayerInteractEvent.RightClickBlock event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState state = event.getWorld().getBlockState(pos);
Block block = world.getBlockState(pos).getBlock();
if (block instanceof BlockCrops && !(block instanceof BlockCrop) && !(block instanceof BlockBeetroot)) {
int age = state.getValue(BlockCrops.AGE);
if (age >= 7) {
block.dropBlockAsItem(world, pos, state, 0);
world.setBlockState(pos, state.withProperty(BlockCrop.AGE, 0), 2);
}
} else if (block instanceof BlockNetherWart || block instanceof BlockBeetroot) {
int age3 = state.getValue(BlockNetherWart.AGE);
if (age3 >= 3) {
block.dropBlockAsItem(world, pos, state, 0);
world.setBlockState(pos, state.withProperty(BlockNetherWart.AGE, 0), 2);
}
}
}
示例13: interact
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
private boolean interact(PlayerInteractEvent.RightClickBlock event, ItemStack curItem, BlockPos pos){
ISemiBlock newBlock = ((ISemiBlockItem) curItem.getItem()).getSemiBlock(event.getWorld(), pos, curItem);
newBlock.initialize(event.getWorld(), pos);
newBlock.prePlacement(event.getEntityPlayer(), curItem, event.getFace());
Stream<ISemiBlock> existingSemiblocks = getSemiBlocks(event.getWorld(), pos);
List<ISemiBlock> collidingBlocks = existingSemiblocks.filter(s -> !s.canCoexistInSameBlock(newBlock)).collect(Collectors.toList());
if (!collidingBlocks.isEmpty()) {
for(ISemiBlock collidingBlock : collidingBlocks){
if (event.getEntityPlayer().capabilities.isCreativeMode) {
removeSemiBlock(collidingBlock);
} else {
breakSemiBlock(collidingBlock, event.getEntityPlayer());
}
}
return true;
} else {
if (newBlock.canPlace(event.getFace())) {
addSemiBlock(event.getWorld(), pos, newBlock);
newBlock.onPlaced(event.getEntityPlayer(), curItem, event.getFace());
event.getWorld().playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundType.GLASS.getPlaceSound(), SoundCategory.BLOCKS,
(SoundType.GLASS.getVolume() + 1.0F) / 2.0F, SoundType.GLASS.getPitch() * 0.8F,
false);
if (!event.getEntityPlayer().capabilities.isCreativeMode) {
curItem.shrink(1);
if (curItem.getCount() <= 0) event.getEntityPlayer().setHeldItem(event.getHand(), ItemStack.EMPTY);
}
return true;
}
}
return false;
}
示例14: onInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public static void onInteract(PlayerInteractEvent.RightClickBlock e)
{
if(e.getEntityPlayer() instanceof EntityPlayerMP)
{
EntityPlayerMP mp = (EntityPlayerMP) e.getEntityPlayer();
for (Pair<IfEntry, IRSBlockInteract> pair : PurMag.INSTANCE.getIfRegistry().getAllResearchableSteps(IRSBlockInteract.class, mp))
{
if(pair.getRight().apply(mp, e.getHand(), e.getPos(), e.getFace(), e.getHitVec(), e.getWorld()))
{
mp.getCapability(CapabilityRegistry.ENTRY_STORE_CAP, null).unlockStepAndSync(pair.getLeft().getId(), mp);
}
}
}
}
示例15: onRightClickBlock
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
EntityPlayer player = event.getEntityPlayer();
World world = event.getWorld();
BlockPos pos = event.getPos();
EnumFacing face = event.getFace();
ItemStack stack = event.getItemStack();
Item item = stack.getItem();
if (item instanceof ItemSpade) {
if (player.canPlayerEdit(pos.offset(face), face, stack)) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (face != EnumFacing.DOWN && world.isAirBlock(pos.up()) && block == GenesisBlocks.HUMUS) {
world.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (!world.isRemote) {
IBlockState path = GenesisBlocks.HUMUS_PATH.getDefaultState();
world.setBlockState(pos, path, WorldFlags.UPDATE_BLOCK_AND_CLIENT_AND_RERENDER_ON_MAIN);
stack.damageItem(1, player);
}
event.setCanceled(true);
}
}
}
}