Search in sources :

Example 1 with IDisruptable

use of de.sanandrew.mods.claysoldiers.api.IDisruptable in project ClaySoldiersMod by SanAndreasP.

the class ItemDisruptor method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    ItemStack itemStackIn = playerIn.getHeldItem(hand);
    NBTTagCompound nbt = itemStackIn.getOrCreateSubCompound("disruptor");
    long lastTimeMillis = nbt.getLong("lastActivated");
    long currTimeMillis = System.currentTimeMillis();
    if (lastTimeMillis + 2_000 < currTimeMillis) {
        if (!worldIn.isRemote) {
            AxisAlignedBB aabb = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 64.0D, 64.0D, 64.0D).offset(playerIn.posX, playerIn.posY, playerIn.posZ).offset(-32.0D, -32.0D, -32.0D);
            worldIn.getEntitiesWithinAABB(EntityCreature.class, aabb).stream().filter(entity -> entity instanceof IDisruptable).map(entity -> (IDisruptable) entity).collect(Collectors.toList()).forEach(IDisruptable::disrupt);
            nbt.setLong("lastActivated", currTimeMillis);
            if (itemStackIn.isItemStackDamageable()) {
                itemStackIn.damageItem(1, playerIn);
            }
        }
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemStackIn);
    } else {
        return super.onItemRightClick(worldIn, playerIn, hand);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IItemPropertyGetter(net.minecraft.item.IItemPropertyGetter) Arrays(java.util.Arrays) Item(net.minecraft.item.Item) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Constants(net.minecraftforge.common.util.Constants) EnumHand(net.minecraft.util.EnumHand) ItemStack(net.minecraft.item.ItemStack) OreDictionary(net.minecraftforge.oredict.OreDictionary) CsmConstants(de.sanandrew.mods.claysoldiers.api.CsmConstants) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) CsmCreativeTabs(de.sanandrew.mods.claysoldiers.util.CsmCreativeTabs) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CsmConfiguration(de.sanandrew.mods.claysoldiers.util.CsmConfiguration) World(net.minecraft.world.World) Collectors(java.util.stream.Collectors) ActionResult(net.minecraft.util.ActionResult) ItemRegistry(de.sanandrew.mods.claysoldiers.registry.ItemRegistry) IDisruptable(de.sanandrew.mods.claysoldiers.api.IDisruptable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) ResourceLocation(net.minecraft.util.ResourceLocation) EntityCreature(net.minecraft.entity.EntityCreature) Configuration(net.minecraftforge.common.config.Configuration) ItemStackUtils(de.sanandrew.mods.sanlib.lib.util.ItemStackUtils) IDisruptable(de.sanandrew.mods.claysoldiers.api.IDisruptable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityCreature(net.minecraft.entity.EntityCreature)

Aggregations

CsmConstants (de.sanandrew.mods.claysoldiers.api.CsmConstants)1 IDisruptable (de.sanandrew.mods.claysoldiers.api.IDisruptable)1 ItemRegistry (de.sanandrew.mods.claysoldiers.registry.ItemRegistry)1 CsmConfiguration (de.sanandrew.mods.claysoldiers.util.CsmConfiguration)1 CsmCreativeTabs (de.sanandrew.mods.claysoldiers.util.CsmCreativeTabs)1 ItemStackUtils (de.sanandrew.mods.sanlib.lib.util.ItemStackUtils)1 Arrays (java.util.Arrays)1 Collectors (java.util.stream.Collectors)1 CreativeTabs (net.minecraft.creativetab.CreativeTabs)1 EntityCreature (net.minecraft.entity.EntityCreature)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 IItemPropertyGetter (net.minecraft.item.IItemPropertyGetter)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 EnumHand (net.minecraft.util.EnumHand)1 NonNullList (net.minecraft.util.NonNullList)1 ResourceLocation (net.minecraft.util.ResourceLocation)1