Search in sources :

Example 46 with ItemSword

use of net.minecraft.item.ItemSword in project Tropicraft by Tropicraft.

the class BlockEvents method handleCoconutBreakEvent.

@SubscribeEvent
public void handleCoconutBreakEvent(HarvestDropsEvent event) {
    World world = event.getWorld();
    Block block = event.getState().getBlock();
    int x = event.getPos().getX();
    int y = event.getPos().getY();
    int z = event.getPos().getZ();
    EntityPlayer player = event.getHarvester();
    if (world.isRemote)
        return;
    if (block != BlockRegistry.coconut)
        return;
    ItemStack handItemStack = player.getHeldItemMainhand();
    Item inHand;
    if (!handItemStack.isEmpty())
        inHand = handItemStack.getItem();
    else
        inHand = null;
    ItemStack drop = ItemStack.EMPTY;
    if (inHand != null && (inHand instanceof ItemSword || inHand.getItemUseAction(new ItemStack(inHand)) == EnumAction.BLOCK))
        drop = new ItemStack(ItemRegistry.coconutChunk);
    else
        drop = new ItemStack(block, 1, 0);
    int numDrops = drop.getItem() == ItemRegistry.coconutChunk ? world.rand.nextInt(3) + 2 : 1;
    world.setBlockToAir(event.getPos());
    for (int i = 0; i < numDrops; i++) dropBlockAsItem(world, x, y, z, drop);
}
Also used : ItemSword(net.minecraft.item.ItemSword) EntityItem(net.minecraft.entity.item.EntityItem) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 47 with ItemSword

use of net.minecraft.item.ItemSword in project Adventurers-Toolbox by the-realest-stu.

the class CommonProxy method processRecipes.

protected void processRecipes() {
    if (ForgeRegistries.RECIPES instanceof IForgeRegistryModifiable) {
        IForgeRegistryModifiable registry = (IForgeRegistryModifiable) ForgeRegistries.RECIPES;
        Entry<ResourceLocation, IRecipe>[] recipeEntries = ForgeRegistries.RECIPES.getEntries().toArray(new Entry[ForgeRegistries.RECIPES.getEntries().size()]);
        for (int recipeIndex = 0; recipeIndex < recipeEntries.length; recipeIndex++) {
            Entry<ResourceLocation, IRecipe> recipeEntry = recipeEntries[recipeIndex];
            IRecipe recipe = recipeEntry.getValue();
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            Item output = recipe.getRecipeOutput().getItem();
            String rp = output.getRegistryName().getResourcePath();
            boolean exception = false;
            for (String s : Config.REMOVAL_EXCEPTIONS) {
                if (output.getRegistryName().toString().contains(s)) {
                    exception = true;
                }
            }
            if (exception == false && (output instanceof ItemHoe || output instanceof ItemAxe || output instanceof ItemSpade || output instanceof ItemPickaxe || output instanceof ItemSword) || (output instanceof ItemTool && (rp.contains("pick") || rp.contains("axe") || rp.contains("shovel") || rp.contains("spade"))) || (output instanceof ItemTool && (output.getRegistryName().getResourceDomain().equals("thermalfoundation") && rp.contains("hammer")))) {
                String materialName = output instanceof ItemHoe ? ((ItemHoe) output).getMaterialName() : output instanceof ItemSword ? ((ItemSword) output).getToolMaterialName() : ((ItemTool) output).getToolMaterialName();
                if (Materials.canReplaceMaterial(materialName, recipe.getRecipeOutput())) {
                    // System.out.println(materialName);
                    registry.remove(recipeEntry.getKey());
                    registry.register(new IRecipe() {

                        private ResourceLocation registryName;

                        @Override
                        public IRecipe setRegistryName(ResourceLocation name) {
                            this.registryName = name;
                            return this;
                        }

                        @Override
                        public ResourceLocation getRegistryName() {
                            return this.registryName;
                        }

                        @Override
                        public Class<IRecipe> getRegistryType() {
                            return IRecipe.class;
                        }

                        @Override
                        public boolean matches(InventoryCrafting inv, World worldIn) {
                            return false;
                        }

                        @Override
                        public ItemStack getCraftingResult(InventoryCrafting inv) {
                            return ItemStack.EMPTY;
                        }

                        @Override
                        public boolean canFit(int width, int height) {
                            return false;
                        }

                        @Override
                        public ItemStack getRecipeOutput() {
                            return ItemStack.EMPTY;
                        }
                    }.setRegistryName(recipeEntry.getKey()));
                    removed_recipes.add(recipeEntry.getKey());
                } else {
                    System.out.println(output.getRegistryName() + " -> " + materialName);
                }
            } else {
                for (int i = 0; i < ingredients.size(); i++) {
                    ItemStack[] matchingStacks = ingredients.get(i).getMatchingStacks();
                    boolean flag = false;
                    Item ingredientItem = null;
                    for (int j = 0; j < matchingStacks.length && !flag; j++) {
                        Item item = matchingStacks[j].getItem();
                        if (!getToolReplacement(item).isEmpty()) {
                            ingredientItem = item;
                            flag = true;
                        }
                    }
                    if (flag && ingredientItem != null && !getToolReplacement(ingredientItem).isEmpty()) {
                        ingredients.set(i, new IngredientNBT(getToolReplacement(ingredientItem)) {
                        });
                    }
                }
            }
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) ItemAxe(net.minecraft.item.ItemAxe) IForgeRegistryModifiable(net.minecraftforge.registries.IForgeRegistryModifiable) ItemTool(net.minecraft.item.ItemTool) IngredientNBT(net.minecraftforge.common.crafting.IngredientNBT) IRecipe(net.minecraft.item.crafting.IRecipe) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) World(net.minecraft.world.World) Item(net.minecraft.item.Item) ItemHoe(net.minecraft.item.ItemHoe) ResearchEntry(thaumcraft.api.research.ResearchEntry) Entry(java.util.Map.Entry) Ingredient(net.minecraft.item.crafting.Ingredient) ItemSpade(net.minecraft.item.ItemSpade) ResourceLocation(net.minecraft.util.ResourceLocation) ItemPickaxe(net.minecraft.item.ItemPickaxe) ItemStack(net.minecraft.item.ItemStack)

Example 48 with ItemSword

use of net.minecraft.item.ItemSword in project Adventurers-Toolbox by the-realest-stu.

the class SpecialToolAbilityHandler method onAttack.

@SubscribeEvent
public void onAttack(AttackEntityEvent event) {
    EntityPlayer player = event.getEntityPlayer();
    Entity targetEntity = event.getTarget();
    ItemStack weapon = player.getHeldItemMainhand();
    if (targetEntity instanceof EntityLivingBase) {
        EntityLivingBase target = (EntityLivingBase) targetEntity;
        if (!player.world.isRemote && isVoidTool(weapon)) {
            target.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, weapon.getItem() instanceof ItemSword ? 60 : 80));
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) Entity(net.minecraft.entity.Entity) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 49 with ItemSword

use of net.minecraft.item.ItemSword in project Wurst-MC-1.12 by Wurst-Imperium.

the class AutoSwordMod method setSlot.

public void setSlot() {
    // check if active
    if (!isActive())
        return;
    // wait for AutoEat
    if (wurst.mods.autoEatMod.isEating())
        return;
    // find best weapon
    float bestDamage = 0;
    int bestSlot = -1;
    for (int i = 0; i < 9; i++) {
        // skip empty slots
        if (InventoryUtils.isSlotEmpty(i))
            continue;
        Item item = WMinecraft.getPlayer().inventory.getStackInSlot(i).getItem();
        // get damage
        float damage = 0;
        if (item instanceof ItemSword)
            damage = ((ItemSword) item).attackDamage;
        else if (item instanceof ItemTool)
            damage = ((ItemTool) item).damageVsEntity;
        // compare with previous best weapon
        if (damage > bestDamage) {
            bestDamage = damage;
            bestSlot = i;
        }
    }
    // check if any weapon was found
    if (bestSlot == -1)
        return;
    // save old slot
    if (oldSlot == -1)
        oldSlot = WMinecraft.getPlayer().inventory.currentItem;
    // set slot
    WMinecraft.getPlayer().inventory.currentItem = bestSlot;
    // start timer
    timer = 4;
    wurst.events.add(UpdateListener.class, this);
}
Also used : ItemSword(net.minecraft.item.ItemSword) Item(net.minecraft.item.Item) ItemTool(net.minecraft.item.ItemTool)

Example 50 with ItemSword

use of net.minecraft.item.ItemSword in project Wurst-MC-1.12 by Wurst-Imperium.

the class AutoToolMod method setSlot.

public void setSlot(BlockPos pos) {
    // check if active
    if (!isActive())
        return;
    // check gamemode
    EntityPlayer player = WMinecraft.getPlayer();
    if (player.capabilities.isCreativeMode)
        return;
    // check if block can be clicked
    if (!WBlock.canBeClicked(pos))
        return;
    // initialize speed & slot
    IBlockState state = WBlock.getState(pos);
    float bestSpeed = getDestroySpeed(player.getHeldItemMainhand(), state);
    int bestSlot = -1;
    // find best tool
    for (int slot = 0; slot < 9; slot++) {
        if (slot == player.inventory.currentItem)
            continue;
        ItemStack stack = player.inventory.getStackInSlot(slot);
        float speed = getDestroySpeed(stack, state);
        if (speed <= bestSpeed)
            continue;
        if (!useSwords.isChecked() && stack.getItem() instanceof ItemSword)
            continue;
        bestSpeed = speed;
        bestSlot = slot;
    }
    // check if any tool was found
    if (bestSlot == -1)
        return;
    // save old slot
    if (oldSlot == -1)
        oldSlot = player.inventory.currentItem;
    // set slot
    player.inventory.currentItem = bestSlot;
    // save position
    this.pos = pos;
    // start timer
    timer = 4;
}
Also used : ItemSword(net.minecraft.item.ItemSword) IBlockState(net.minecraft.block.state.IBlockState) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemSword (net.minecraft.item.ItemSword)76 ItemStack (net.minecraft.item.ItemStack)53 Item (net.minecraft.item.Item)25 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)23 EntityPlayer (net.minecraft.entity.player.EntityPlayer)22 ItemTool (net.minecraft.item.ItemTool)21 ItemHoe (net.minecraft.item.ItemHoe)18 IBlockState (net.minecraft.block.state.IBlockState)17 ItemBow (net.minecraft.item.ItemBow)15 Entity (net.minecraft.entity.Entity)13 Block (net.minecraft.block.Block)9 EntityLivingBase (net.minecraft.entity.EntityLivingBase)8 ItemAxe (net.minecraft.item.ItemAxe)8 ItemBlock (net.minecraft.item.ItemBlock)8 World (net.minecraft.world.World)7 ItemArmor (net.minecraft.item.ItemArmor)6 ItemFishingRod (net.minecraft.item.ItemFishingRod)6 DamageSource (net.minecraft.util.DamageSource)6 ItemDoor (net.minecraft.item.ItemDoor)5 ItemShield (net.minecraft.item.ItemShield)5