本文整理匯總了Java中net.minecraftforge.event.entity.player.PlayerInteractEvent類的典型用法代碼示例。如果您正苦於以下問題:Java PlayerInteractEvent類的具體用法?Java PlayerInteractEvent怎麽用?Java PlayerInteractEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PlayerInteractEvent類屬於net.minecraftforge.event.entity.player包,在下文中一共展示了PlayerInteractEvent類的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: entityInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
@SubscribeEvent
public void entityInteract(EntityInteract event) {
if (event.getEntityPlayer().getEntityData().hasKey("renderViewCamera")) {
event.setCanceled(true);
if (event.getSide().isClient() && event.getHand().equals(EnumHand.MAIN_HAND)
&& event.getItemStack() == null) {
System.out.println("EntityInteract,HandType=" + event.getHand());
ActiveTripod(Minecraft.getMinecraft().thePlayer.getName(),
((EntityTripod) event.getWorld()
.getEntityByID(event.getEntityPlayer().getEntityData().getInteger("renderViewCamera")))
.getDelay());
}
return;
}
if (event.getTarget() instanceof EntityTripod) {
Entity target = ((PlayerInteractEvent.EntityInteract) event).getTarget();
EntityPlayer player = event.getEntityPlayer();
if (!player.isSneaking()) {
if (player.inventory.armorInventory[3] != null
&& player.inventory.armorInventory[3].getItem() instanceof ItemGlassesHelmet) {
if (player.getEntityWorld().isRemote) {
// System.out.println("123");
Minecraft.getMinecraft().setRenderViewEntity(target);
Minecraft.getMinecraft().ingameGUI.setRecordPlaying(new TextComponentTranslation("chat.tripod.info"), false);
}
player.getEntityData().setInteger("renderViewCamera", target.getEntityId());
}else if(!event.getWorld().isRemote&&event.getHand().equals(EnumHand.MAIN_HAND)){
player.addChatComponentMessage(new TextComponentTranslation("chat.tripod.mustuseglass"));
}
} else {
player.getEntityData().setInteger("usingGui", target.getEntityId());
player.openGui(MineCamera.instance, GuiElementLoader.GUI_TRIPOD_CAMERA, target.getEntityWorld(),
(int) target.posX, (int) target.posY, (int) target.posZ);
}
}
}
示例3: playerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
@SubscribeEvent
public void playerInteract(PlayerInteractEvent event) {
// System.out.println(event.toString());
// System.out.println("PlayerInteractEvent,HandType="+event.getHand()+",PlayerAciveHand="+event.getEntityPlayer().getActiveHand());
if (event.isCancelable() && event.getEntityPlayer().getEntityData().hasKey("renderViewCamera")) {
event.setCanceled(true);
return;
}
/*
* if(event instanceof
* PlayerInteractEvent.EntityInteract&&((PlayerInteractEvent.
* EntityInteract) event).getTarget() instanceof EntityTripod){ Entity
* target=((PlayerInteractEvent.EntityInteract) event).getTarget();
* EntityPlayer player =event.getEntityPlayer(); if
* (!player.isSneaking()) { if (player.getEntityWorld().isRemote) {
* System.out.println("123");
* Minecraft.getMinecraft().setRenderViewEntity(target); }
* player.getEntityData().setInteger("renderViewCamera",
* target.getEntityId()); }else{
* player.getEntityData().setInteger("usingGui", target.getEntityId());
* player.openGui(MineCamera.instance,
* GuiElementLoader.GUI_TRIPOD_CAMERA, target.getEntityWorld(),
* (int)target.posX, (int)target.posY, (int)target.posZ); } }
*/
}
示例4: 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;
}
示例5: onEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
public void onEvent(Event event) {
ISensorSetting sensor = SensorHandler.getInstance().getSensorFromPath(sensorSetting);
if (sensor != null && sensor instanceof IEventSensorSetting && getPressure() > PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR) {
int newRedstoneStrength = ((IEventSensorSetting) sensor).emitRedstoneOnEvent(event, this, getRange(), sensorGuiText);
if (newRedstoneStrength != 0) eventTimer = ((IEventSensorSetting) sensor).getRedstonePulseLength();
if (invertedRedstone) newRedstoneStrength = 15 - newRedstoneStrength;
if (eventTimer > 0 && ThirdPartyManager.computerCraftLoaded) {
if (event instanceof PlayerInteractEvent) {
PlayerInteractEvent e = (PlayerInteractEvent) event;
notifyComputers(newRedstoneStrength, e.getPos().getX(), e.getPos().getY(), e.getPos().getZ());
} else {
notifyComputers(newRedstoneStrength);
}
}
if (newRedstoneStrength != redstoneStrength) {
redstoneStrength = newRedstoneStrength;
updateNeighbours();
}
}
}
示例6: 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);
}
}
示例7: dueProcess
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
private void dueProcess(PlayerInteractEvent event, BiFunction<RegionSelector<?, ?>, Vector3i, String> selector) {
if (event.getWorld().isRemote) {
// don't process on client
// perhaps we can cancel on client if we do config sync
return;
}
if (event.getItemStack().getItem() == HardVoxConfig.getSelectionWand()) {
// cancel event, fire selection
event.setCanceled(true);
WorldServer ws = (WorldServer) event.getWorld();
SessionManager.getInstance()
.getSession(ws.getMinecraftServer(), event.getEntityPlayer())
.performRegionCommand(sel -> selector.apply(sel, VecBridge.toFlow(event.getPos())));
// send an update to the player so the block re-appears?
ws.getPlayerChunkMap().markBlockForUpdate(event.getPos());
}
}
示例8: rightClickEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
@SubscribeEvent
public void rightClickEvent(PlayerInteractEvent.RightClickItem e)
{
EntityPlayer player = e.getEntityPlayer();
ItemStack RunicItem = null;
if(EnchantmentHelper.getEnchantmentLevel(ModEnchantment.runicenchantment, player.getHeldItem(EnumHand.MAIN_HAND) )>0)
RunicItem = player.getHeldItem(EnumHand.MAIN_HAND);
else if(EnchantmentHelper.getEnchantmentLevel(ModEnchantment.runicenchantment, player.getHeldItem(EnumHand.OFF_HAND) )>0)
RunicItem = player.getHeldItem(EnumHand.OFF_HAND);
else return;
CompiledSymbol[] script = ModDust.getScriptFromItem(RunicItem);
if(script==null)return;
if(player.isSneaking())
new ScriptExecutor(script, player, RunicItem, ScriptExecutor.StartPoint.SNEAK_RIGHT);
else
new ScriptExecutor(script, player, RunicItem, ScriptExecutor.StartPoint.RIGHT_CLICK);
}
示例9: animalsSheared
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
@SubscribeEvent
public static void animalsSheared(PlayerInteractEvent.EntityInteract event)
{
Entity target = event.getTarget();
if (target instanceof EntityMooshroom && !target.isDead && ((EntityMooshroom) target).hurtTime == 0)
{
if (isUsingShears(event.getEntityPlayer()))
{
World world = event.getWorld();
if (!world.isRemote)
{
EntityItem item = new EntityItem(event.getEntity().getEntityWorld(), target.posX, target.posY, target.posZ, new ItemStack(ModItems.meatshroom));
world.spawnEntity(item);
}
}
}
}
示例10: 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);
}
}
}
示例11: 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);
}
}
示例12: onPlayerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
public static void onPlayerInteract(PlayerInteractEvent event) {
if (EtFuturum.enableGrassPath)
if (event.entityPlayer != null) {
World world = event.entityPlayer.worldObj;
if (event.action == Action.RIGHT_CLICK_BLOCK)
if (world.getBlock(event.x, event.y, event.z) == Blocks.grass) {
ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
if (stack != null && (stack.getItem() instanceof ItemSpade || isTinkersShovel(stack))) {
world.setBlock(event.x, event.y, event.z, ModBlocks.grass_path);
event.entityPlayer.swingItem();
stack.damageItem(1, event.entityPlayer);
world.playSoundEffect(event.x + 0.5F, event.y + 0.5F, event.z + 0.5F, Block.soundTypeGravel.getStepResourcePath(), 1.0F, 0.8F);
}
}
}
}
示例13: onEntityInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
@SubscribeEvent
public void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
EntityPlayer player = event.getEntityPlayer();
if (!player.worldObj.isRemote && event.getHand() == EnumHand.MAIN_HAND) {
if (event.getTarget() instanceof EntityLivingBase && !(event.getTarget() instanceof EntityPlayer) && player.isSneaking()) {
ItemStack head = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if ((head != null && head.getItem() instanceof ItemPossessiveHelmet) || PossessHandler.isPossessing(player)) {
EntityLivingBase target = (EntityLivingBase) event.getTarget();
if (!(target instanceof EntityLiving && ((EntityLiving) target).isAIDisabled())) {
PossessHandler.possess(player, target);
}
}
} else if (event.getTarget() instanceof EntityPlayer) {
PossessivePlayer possessivePlayer = PossessHandler.get((EntityPlayer) event.getTarget());
if (possessivePlayer != null) {
ItemStack stack = event.getItemStack();
EntityLivingBase possessing = possessivePlayer.getPossessing();
EnumHand hand = event.getHand();
if ((stack != null && stack.getItem().itemInteractionForEntity(stack, player, possessing, hand)) || (possessing.processInitialInteract(player, stack, hand))) {
event.setCanceled(true);
}
}
}
}
}
示例14: onRightClick
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入依賴的package包/類
@SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickItem e)
{
if (e.getItemStack() != null && e.getItemStack().getItem() instanceof ItemGlassBottle && e.getEntityPlayer().isSneaking() && (e.getEntityPlayer().experienceLevel >= 1 || e.getEntityPlayer().isCreative())) {
EntityPlayer player = e.getEntityPlayer();
Vector3 origin = Vector3.fromEntity(player).add(0, player.getEyeHeight(), 0);
Vector3 look = new Vector3(player.getLookVec());
Vector3 end = origin.copy().add(look.copy().normalize().multiply(5));
RayTraceResult rtr = player.worldObj.rayTraceBlocks(origin.toVec3D(), end.toVec3D(), true);
IBlockState hitBlockState = null;
if (rtr != null) hitBlockState = e.getWorld().getBlockState(rtr.getBlockPos());
if (hitBlockState == null || hitBlockState.getBlock() != Blocks.water) {
e.getItemStack().stackSize--;
if (e.getItemStack().stackSize <= 0)
e.getEntityPlayer().inventory.deleteStack(e.getItemStack());
e.getEntityPlayer().inventory.addItemStackToInventory(new ItemStack(Items.experience_bottle));
e.getEntityPlayer().removeExperienceLevel(1);
}
}
}
示例15: 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);
}
}
}
}