本文整理汇总了Java中net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInteractEvent.EntityInteract方法的具体用法?Java PlayerInteractEvent.EntityInteract怎么用?Java PlayerInteractEvent.EntityInteract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.event.entity.player.PlayerInteractEvent
的用法示例。
在下文中一共展示了PlayerInteractEvent.EntityInteract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
}
示例2: 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);
}
}
}
}
}
示例3: playerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void playerInteract(PlayerInteractEvent.EntityInteract event){
Entity target = event.getTarget();
EntityPlayer player = event.getEntityPlayer();
if(target !=null && player !=null && !player.getEntityWorld().isRemote){
if(target instanceof EntityPlayer){
EntityPlayer tPlayer = (EntityPlayer) target;
tagPlayer(tPlayer.getName(), player.getName());
}
else if(target instanceof EntityLiving){
EntityLiving tEnt = (EntityLiving) target;
if(tEnt.hasCustomName()){
if(getData(tEnt.getCustomNameTag()) !=null)
tagPlayer(tEnt.getCustomNameTag(), player.getName());
}
}
}
}
示例4: onRightclickEntity
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onRightclickEntity(PlayerInteractEvent.EntityInteract event)
{
EntityPlayer player = event.getEntityPlayer();
ItemStack heldItem = player.inventory.getCurrentItem();
if(!event.getEntity().worldObj.isRemote && heldItem != null && heldItem.getItem() instanceof ItemMobCapsule)
{
if(heldItem.hasCapability(CapabilityEntityContainer.ENTITY_CONTAINER_CAPABILITY, EnumFacing.DOWN))
{
Entity e = event.getTarget();
if(e != null && !e.isDead)
{
IEntityContainer cap = heldItem.getCapability(CapabilityEntityContainer.ENTITY_CONTAINER_CAPABILITY, EnumFacing.DOWN);
if(cap.addEntity(new EntityStack(event.getTarget().serializeNBT())))
event.getTarget().setDead();
}
}
}
}
示例5: onPlayerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent.EntityInteract evt) {
if(evt.isCanceled()) return;
// If we're cancelling on this thread...
Boolean debounce = debounceEntityInteract.get();
if(debounce != null && debounce) {
debounceEntityInteract.set(false);
evt.setCanceled(true);
return;
}
// We don't care about offhands if we're not cancelling them...
if(evt.getHand() == EnumHand.OFF_HAND) return;
// If we pass the check, then we can allow the event to go through...
if(EntityRegistry.allowInteractionBetween(evt.getTarget(), evt.getEntityPlayer())) return;
// Otherwise, cancel, and debounce our off-hand click:
evt.setCanceled(true);
debounceEntityInteract.set(true);
}
示例6: onRightclickEntity
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onRightclickEntity(PlayerInteractEvent.EntityInteract event)
{
EntityPlayer player = event.getEntityPlayer();
ItemStack heldItem = player.inventory.getCurrentItem();
if(!event.getWorld().isRemote && heldItem != null && heldItem.getItem().equals(ModItems.mobCapsule))
{
if(heldItem.hasCapability(ENTITY_CONTAINER, EnumFacing.DOWN))
{
Entity e = event.getTarget();
if(e != null && !e.isDead)
{
IEntityContainer cap = heldItem.getCapability(ENTITY_CONTAINER, EnumFacing.DOWN);
if(cap != null)
{
if(cap.addEntity(new EntityStack(event.getTarget().serializeNBT())))
{
event.getTarget().setDead();
}
}
}
}
}
}
示例7: interactWith
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
/**TODO
* Patch over {@link EntityPlayer#interactOn(Entity,EnumHand)}, adapted for the dual wielding
* In battlemode, try to interact with {@link Entity#processInitialInteract(EntityPlayer, EnumHand)} in right hand, then left hand if no success
* then try to interact with {@link ItemStack#interactWithEntity(EntityPlayer, EntityLivingBase, EnumHand)} in the same order
* When necessary, hotswap the "current item" value to the offhand, then refresh the player attributes according to the newly selected item
* @return SUCCESS if any interaction happened, actually bypassing subsequent PlayerInteractEvent.Action.RIGHT_CLICK_AIR and PlayerControllerMP#sendUseItem on client side
*/
public static EnumActionResult interactWith(EntityPlayer entityPlayer, Entity entity, EnumHand hand){
if(hand == EnumHand.OFF_HAND && isPlayerInBattlemode(entityPlayer)){//No interaction with left hand item
PlayerInteractEvent.EntityInteract event = new PlayerInteractEvent.EntityInteract(entityPlayer, hand, entity);
PlayerEventChild.OffhandAttackEvent offAttackEvent = new PlayerEventChild.OffhandAttackEvent(event);
if(!MinecraftForge.EVENT_BUS.post(offAttackEvent)){
if (offAttackEvent.swingOffhand){
sendOffSwingEvent(event);
}
if (offAttackEvent.shouldAttack) {
((IBattlePlayer) entityPlayer).attackTargetEntityWithCurrentOffItem(offAttackEvent.getTarget());
}
if(offAttackEvent.cancelParent){
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.PASS;
}
示例8: onEntityRightClick
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onEntityRightClick(PlayerInteractEvent.EntityInteract event)
{
if(event.getEntityPlayer().getHeldItemMainhand().isItemEqual(new ItemStack(HarshenItems.GLASS_CONTAINER)) && event.getTarget().getClass() == EntityCow.class)
event.getEntityPlayer().setHeldItem(EnumHand.MAIN_HAND, GlassContainerValues.MILK.getStack());
}
示例9: onInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onInteract(PlayerInteractEvent.EntityInteract event)
{
if(event.getEntityPlayer().getActiveItemStack().getItem() instanceof ItemTorchGun)
{
event.setCanceled(true);
}
}
示例10: onPlayerEntityInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void onPlayerEntityInteract(PlayerInteractEvent.EntityInteract event)
{
// if the villager inventory gui is enabled, if the entity being interacted with is a villager, and if the player is sneaking...
if ((ModConfiguration.enableInventoryGui) && (event.getTarget() instanceof EntityVillager) && (EntityUtils.getFlag(event.getEntityPlayer(), 2)))
{
// if opening the gui requires the player to not be holding anything, check to ensure that the player isn't holding anything
if (!ModConfiguration.requireEmptyHand || (ModConfiguration.requireEmptyHand && event.getEntityPlayer().inventory.getCurrentItem().isEmpty()))
{
// if the event is running on the server
if (!event.getWorld().isRemote)
{
// cast the entity to type EntityVillager
EntityVillager villager = (EntityVillager)event.getTarget();
// get the entity id of the villager
int entityId = villager.getEntityId();
// and read it's profession and career from it's nbt data
NBTTagCompound compound = new NBTTagCompound();
villager.writeEntityToNBT(compound);
int professionId = compound.getInteger("Profession");
int careerId = compound.getInteger("Career");
// send a message to the client to tell it what the villager's career is
NETWORK.sendTo(new VillagerCareerMessage(entityId, careerId), (EntityPlayerMP)event.getEntityPlayer());
// open the inventory gui
FMLNetworkHandler.openGui(event.getEntityPlayer(), VillagerInventoryMod.INSTANCE, ModGuiHandler.GUI_VILLAGER_INVENTORY, event.getWorld(), entityId, professionId, careerId);
}
// cancel the event which would show the trading gui
event.setCanceled(true);
}
}
}
示例11: baconInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void baconInteract(PlayerInteractEvent.EntityInteract e) {
EntityPlayer player = e.getEntityPlayer();
if (!player.world.isRemote) {
if (e.getTarget() instanceof OinkBacon) {
if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && baconGlow) {
baconGlow = false;
} else if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && !baconGlow) {
baconGlow = true;
}
}
}
}
示例12: sausageInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void sausageInteract(PlayerInteractEvent.EntityInteract e) {
EntityPlayer player = e.getEntityPlayer();
if (!player.world.isRemote) {
if (e.getTarget() instanceof OinkSausage) {
if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && sausageGlow) {
sausageGlow = false;
} else if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && !sausageGlow) {
sausageGlow = true;
}
}
} else {
player.swingArm(EnumHand.MAIN_HAND);
}
}
示例13: stopUsing
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void stopUsing(PlayerInteractEvent.EntityInteract event) {
if (!TF2Util.canInteract(event.getEntityLiving())) {
event.setCanceled(true);
return;
}
if (WeaponsCapability.get(event.getEntity()).isDisguised() && !(event.getEntityPlayer().getHeldItem(event.getHand()).getItem() instanceof ItemFood)) {
disguise(event.getEntityPlayer(), false);
}
event.getEntityPlayer().removePotionEffect(TF2weapons.charging);
}
示例14: onInteractEntity
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onInteractEntity(PlayerInteractEvent.EntityInteract event)
{
if (event.getEntityPlayer() != null)
{
if (event.getEntityPlayer().isPotionActive(ExPPotions.stunned))
{
event.setCanceled(true);
}
}
}
示例15: onPlayerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent.EntityInteract event) {
if (event.getTarget() instanceof EntityWolf) {
@Nullable IWolfArmorCapability wolfArmorCapability = event.getTarget().getCapability(CapabilityWolfArmor.WOLF_ARMOR_CAPABILITY, null);
if (wolfArmorCapability != null) {
EntityPlayer player = event.getEntityPlayer();
EnumHand hand = event.getHand();
if (wolfArmorCapability.processInteract(player, hand)) {
event.setCanceled(true);
}
}
}
}