Created
April 11, 2016 06:11
-
-
Save bloodmc/fad622f8a5928eda40da44f61cc9350a to your computer and use it in GitHub Desktop.
ItemEntityInteractionOverride
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.rwtema.extrautils2.eventhandlers; | |
import com.google.common.collect.Sets; | |
import java.util.HashSet; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.boss.EntityDragonPart; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraftforge.common.MinecraftForge; | |
import net.minecraftforge.event.entity.player.EntityInteractEvent; | |
import net.minecraftforge.fml.common.eventhandler.EventBus; | |
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | |
public class ItemEntityInteractionOverride | |
{ | |
public static final HashSet<Item> items = Sets.newHashSet(); | |
@SubscribeEvent | |
public void allowItemToInteract(EntityInteractEvent event) | |
{ | |
ItemStack itemstack = event.entityPlayer.getCurrentEquippedItem(); | |
if ((itemstack != null) && (items.contains(itemstack.getItem()))) { | |
Entity entity = event.target; | |
if ((entity instanceof EntityDragonPart)) { | |
entity = (Entity)((EntityDragonPart)entity).entityDragonObj; | |
} | |
if (((entity instanceof EntityLivingBase)) && | |
(itemstack.interactWithEntity(event.entityPlayer, (EntityLivingBase)entity))) { | |
if (itemstack.stackSize <= 0) { | |
event.entityPlayer.destroyCurrentEquippedItem(); | |
} | |
event.setCanceled(true); | |
} | |
} | |
} | |
static | |
{ | |
MinecraftForge.EVENT_BUS.register(new ItemEntityInteractionOverride()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment