Search in sources :

Example 56 with ItemSword

use of net.minecraft.item.ItemSword in project clientcommands by Earthcomputer.

the class ToolDamageManager method registerEvents.

public static void registerEvents() {
    EventManager.addOutboundPacketPreListener(e -> {
        Iterator<Class<? extends Packet<?>>> packetItr = packetsToBlock.iterator();
        while (packetItr.hasNext()) {
            if (packetItr.next().isInstance(e.getPacket())) {
                e.setCanceled(true);
                packetItr.remove();
                return;
            }
        }
    });
    EventManager.addPlayerTickListener(e -> {
        EntityPlayer player = e.player;
        if (player.isElytraFlying()) {
            ItemStack elytra = player.inventory.armorItemInSlot(2);
            if (!elytra.isEmpty() && elytra.getItem() == Items.ELYTRA) {
                if (postToolDamaged(player, elytra, 1)) {
                    NetUtils.sendPacket(new CPacketEntityAction(player, CPacketEntityAction.Action.START_FALL_FLYING));
                }
            }
        }
    });
    EventManager.addUseBlockListener(e -> {
        ItemStack stack = e.getItemStack();
        if (stack.isEmpty()) {
            return;
        }
        Item item = stack.getItem();
        IBlockState state = e.getWorld().getBlockState(e.getPos());
        if (state.getBlock() == Blocks.TNT) {
            if (item == Items.FLINT_AND_STEEL) {
                if (postToolDamaged(e.getEntityPlayer(), stack, 1)) {
                    e.setCanceled(true);
                    packetsToBlock.add(CPacketPlayerTryUseItemOnBlock.class);
                }
                return;
            }
        }
        if (e.getEntityPlayer().canPlayerEdit(e.getPos().offset(e.getFace()), e.getFace(), stack)) {
            if (item instanceof ItemHoe) {
                boolean usedHoe = false;
                if (state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.GRASS_PATH) {
                    usedHoe = true;
                } else if (state.getBlock() == Blocks.DIRT) {
                    BlockDirt.DirtType variant = state.getValue(BlockDirt.VARIANT);
                    usedHoe = variant == BlockDirt.DirtType.DIRT || variant == BlockDirt.DirtType.COARSE_DIRT;
                }
                if (usedHoe) {
                    if (postToolDamaged(e.getEntityPlayer(), stack, 1)) {
                        e.setCanceled(true);
                        packetsToBlock.add(CPacketPlayerTryUseItemOnBlock.class);
                    }
                }
                return;
            } else if (item == Items.FLINT_AND_STEEL) {
                if (postToolDamaged(e.getEntityPlayer(), stack, 1)) {
                    e.setCanceled(true);
                    packetsToBlock.add(CPacketPlayerTryUseItemOnBlock.class);
                }
                return;
            } else if (item instanceof ItemSpade) {
                // creating a grass path
                if (e.getFace() != EnumFacing.DOWN && e.getWorld().getBlockState(e.getPos().up()).getMaterial() == Material.AIR && e.getWorld().getBlockState(e.getPos()).getBlock() == Blocks.GRASS) {
                    if (postToolDamaged(e.getEntityPlayer(), stack, 1)) {
                        e.setCanceled(true);
                        packetsToBlock.add(CPacketPlayerTryUseItemOnBlock.class);
                    }
                    return;
                }
            }
        }
    });
    EventManager.addAttackBlockListener(e -> {
        if (!Minecraft.getMinecraft().playerController.isInCreativeMode()) {
            IBlockState hitState = e.getWorld().getBlockState(e.getPos());
            int damage = getDestroyBlockDamage(e.getWorld(), e.getPos(), e.getEntityPlayer());
            if (damage != 0) {
                if (postToolDamagedPre(e.getEntityPlayer(), e.getItemStack(), damage)) {
                    e.setCanceled(true);
                    packetsToBlock.add(CPacketPlayerDigging.class);
                } else if (hitState.getMaterial() != Material.AIR && hitState.getPlayerRelativeBlockHardness(e.getEntityPlayer(), e.getWorld(), e.getPos()) >= 1) {
                    // handle end of instant-mine
                    postToolDamagedPost(e.getEntityPlayer(), e.getItemStack(), damage);
                }
            }
        }
    });
    // need to listen for the packet since it's dispatched before the normal event
    EventManager.addOutboundPacketPreListener(e -> {
        Packet<?> packet = e.getPacket();
        if (packet instanceof CPacketPlayerTryUseItem) {
            CPacketPlayerTryUseItem useItem = (CPacketPlayerTryUseItem) packet;
            EntityPlayer player = Minecraft.getMinecraft().player;
            ItemStack stack = player.getHeldItem(useItem.getHand());
            if (stack.isEmpty()) {
                return;
            }
            Item item = stack.getItem();
            if (player.getCooldownTracker().hasCooldown(item)) {
                return;
            }
            if (item == Items.CARROT_ON_A_STICK) {
                if (postToolDamaged(player, stack, 7)) {
                    e.setCanceled(true);
                    timesToBlockUseItem++;
                }
                return;
            } else if (item instanceof ItemFishingRod) {
                if (postToolDamaged(player, stack, 5)) {
                    // assume 5 (max in vanilla)
                    e.setCanceled(true);
                    timesToBlockUseItem++;
                }
                return;
            }
        } else if (packet instanceof CPacketUseEntity) {
            CPacketUseEntity useEntity = (CPacketUseEntity) packet;
            if (Minecraft.getMinecraft().playerController.isSpectator()) {
                return;
            }
            if (useEntity.getAction() == CPacketUseEntity.Action.ATTACK) {
                EntityPlayer player = Minecraft.getMinecraft().player;
                ItemStack stack = player.getHeldItemMainhand();
                if (stack.isEmpty()) {
                    return;
                }
                Item item = stack.getItem();
                int damage = 0;
                if (item instanceof ItemSword || item instanceof ItemHoe) {
                    damage = 1;
                } else if (item instanceof ItemTool) {
                    damage = 2;
                }
                if (damage != 0) {
                    if (postToolDamaged(player, stack, damage)) {
                        e.setCanceled(true);
                        timesToBlockAttackEntity++;
                    }
                }
            } else if (useEntity.getAction() == CPacketUseEntity.Action.INTERACT) {
                boolean isDamagingItem = false;
                EntityPlayer player = Minecraft.getMinecraft().player;
                ItemStack stack = player.getHeldItem(useEntity.getHand());
                if (stack.isEmpty()) {
                    return;
                }
                Item item = stack.getItem();
                Entity target = useEntity.getEntityFromWorld(Minecraft.getMinecraft().world);
                if (item instanceof ItemShears) {
                    if (target instanceof IShearable) {
                        if (((IShearable) target).isShearable(stack, target.world, new BlockPos(target))) {
                            // shearing sheep, snow golems
                            isDamagingItem = true;
                        }
                    }
                } else if (item == Items.FLINT_AND_STEEL) {
                    if (target instanceof EntityCreeper) {
                        isDamagingItem = true;
                    }
                }
                if (isDamagingItem) {
                    if (postToolDamaged(player, stack, 1)) {
                        e.setCanceled(true);
                        timesToBlockUseEntity++;
                    }
                    return;
                }
            }
        } else if (packet instanceof CPacketPlayerDigging) {
            CPacketPlayerDigging playerDigging = (CPacketPlayerDigging) packet;
            if (playerDigging.getAction() == CPacketPlayerDigging.Action.RELEASE_USE_ITEM) {
                EntityPlayer player = Minecraft.getMinecraft().player;
                if (player.capabilities.isCreativeMode) {
                    return;
                }
                ItemStack stack = player.getActiveItemStack();
                if (stack.isEmpty()) {
                    return;
                }
                Item item = stack.getItem();
                if (item instanceof ItemBow) {
                    boolean hasAmmo = false;
                    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                        ItemStack arrow = player.inventory.getStackInSlot(i);
                        if (!arrow.isEmpty() && arrow.getItem() instanceof ItemArrow) {
                            hasAmmo = true;
                            break;
                        }
                    }
                    int charge = stack.getMaxItemUseDuration() - player.getItemInUseCount();
                    if (hasAmmo && ItemBow.getArrowVelocity(charge) >= 0.1) {
                        if (postToolDamaged(player, stack, 1)) {
                            e.setCanceled(true);
                            timesToBlockStopUseItem++;
                        }
                    }
                }
            } else if (playerDigging.getAction() == CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK) {
                // the player has completed mining a block
                Minecraft mc = Minecraft.getMinecraft();
                int damage = getDestroyBlockDamage(mc.world, playerDigging.getPosition(), mc.player);
                if (damage != 0) {
                    postToolDamagedPost(mc.player, mc.player.getHeldItemMainhand(), damage);
                }
            }
        }
    });
    EventManager.addUseItemListener(e -> {
        if (timesToBlockUseItem > 0) {
            timesToBlockUseItem--;
            e.setCanceled(true);
        }
    });
    EventManager.addStopUseItemListener(e -> {
        if (timesToBlockStopUseItem > 0) {
            timesToBlockStopUseItem--;
            e.setCanceled(true);
        }
    });
    EventManager.addAttackEntityListener(e -> {
        if (timesToBlockAttackEntity > 0) {
            timesToBlockAttackEntity--;
            e.setCanceled(true);
        }
    });
    EventManager.addUseEntityListener(e -> {
        if (timesToBlockUseEntity > 0) {
            timesToBlockUseEntity--;
            e.setCanceled(true);
        }
    });
}
Also used : CPacketPlayerDigging(net.minecraft.network.play.client.CPacketPlayerDigging) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Entity(net.minecraft.entity.Entity) ItemBow(net.minecraft.item.ItemBow) Item(net.minecraft.item.Item) CPacketPlayerTryUseItem(net.minecraft.network.play.client.CPacketPlayerTryUseItem) ItemHoe(net.minecraft.item.ItemHoe) ItemSpade(net.minecraft.item.ItemSpade) IShearable(net.minecraftforge.common.IShearable) ItemShears(net.minecraft.item.ItemShears) BlockPos(net.minecraft.util.math.BlockPos) ItemSword(net.minecraft.item.ItemSword) Packet(net.minecraft.network.Packet) ItemTool(net.minecraft.item.ItemTool) IBlockState(net.minecraft.block.state.IBlockState) ItemFishingRod(net.minecraft.item.ItemFishingRod) Minecraft(net.minecraft.client.Minecraft) CPacketPlayerTryUseItemOnBlock(net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock) CPacketPlayerTryUseItem(net.minecraft.network.play.client.CPacketPlayerTryUseItem) CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow)

Example 57 with ItemSword

use of net.minecraft.item.ItemSword in project BapeClient by BapeDeveloperTeam.

the class MurderMystery method o.

@SubscribeEvent
public void o(final RenderWorldLastEvent ev) {
    if (MurderMystery.mc.thePlayer.getWorldScoreboard() != null && MurderMystery.mc.thePlayer.getWorldScoreboard().getObjectiveInDisplaySlot(1) != null) {
        final String d = MurderMystery.mc.thePlayer.getWorldScoreboard().getObjectiveInDisplaySlot(1).getDisplayName();
        if (d.contains("MURDER") || d.contains("MYSTERY")) {
            for (final EntityPlayer en : MurderMystery.mc.theWorld.playerEntities) {
                if (en != MurderMystery.mc.thePlayer && !en.isInvisible() && !AntiBot.isServerBot(en)) {
                    if (en.getHeldItem() != null && en.getHeldItem().hasDisplayName()) {
                        final Item i = en.getHeldItem().getItem();
                        if (i instanceof ItemSword || i instanceof ItemAxe || en.getHeldItem().getDisplayName().replaceAll("ยง", "").equals("aKnife")) {
                            if (!MurderMystery.m.contains(en)) {
                                MurderMystery.m.add(en);
                                MurderMystery.mc.thePlayer.playSound("note.pling", 1.0f, 1.0f);
                                Helper.sendMessage(en.getName() + " is the murderer!");
                                if (this.Murder.getValue()) {
                                    mc.thePlayer.sendChatMessage(en.getName() + " is the murderer!");
                                }
                            }
                        } else if (i instanceof ItemBow && !MurderMystery.bw.contains(en)) {
                            MurderMystery.bw.add(en);
                            Helper.sendMessage("[WARNING]" + en.getName() + " have bow! he maybe will kill you.");
                            if (this.Bow.getValue()) {
                                mc.thePlayer.sendChatMessage(en.getName() + " have bow.");
                            }
                        }
                    }
                    int rgb = Color.green.getRGB();
                    if ((MurderMystery.m.contains(en) && !MurderMystery.bw.contains(en)) || (MurderMystery.m.contains(en) && MurderMystery.bw.contains(en))) {
                        rgb = Color.red.getRGB();
                    }
                    if (!MurderMystery.m.contains(en) && MurderMystery.bw.contains(en)) {
                        rgb = Color.orange.getRGB();
                    }
                }
            }
        } else {
            this.c();
        }
    } else {
        this.c();
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) Item(net.minecraft.item.Item) ItemAxe(net.minecraft.item.ItemAxe) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemBow(net.minecraft.item.ItemBow) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 58 with ItemSword

use of net.minecraft.item.ItemSword in project Lands-of-Icaria by Axanthic-Game-Studios.

the class ClientProxy method onWeaponBreaks.

public void onWeaponBreaks(LivingAttackEvent event) {
    DamageSource source = event.getSource();
    if (source instanceof EntityDamageSource) {
        EntityDamageSource damageSource = (EntityDamageSource) source;
        Entity entitySource = damageSource.getTrueSource();
        if (entitySource instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entitySource;
            for (int slot = 0; slot < 9; slot++) {
                ItemStack totem = player.inventory.getStackInSlot(slot);
                if (totem.getItem().equals(Resources.totem_unshattering)) {
                    ItemStack tools = player.getHeldItemMainhand();
                    if (tools.getItem() instanceof ItemTool || tools.getItem() instanceof ItemHoe || tools.getItem() instanceof ItemSword) {
                        if (tools.getItem().getMaxDamage(tools) - tools.getItem().getDamage(tools) < tools.getItem().getMaxDamage(tools) * 0.1) {
                            tools.setItemDamage((int) (tools.getItem().getMaxDamage(tools) * 0.1));
                            ((ItemTotem) totem.getItem()).animationTotemUnshattering(player);
                            totem.shrink(1);
                        }
                    }
                }
            }
            ItemStack totem = player.inventory.getStackInSlot(40);
            if (totem.getItem().equals(Resources.totem_unshattering)) {
                ItemStack tools = player.getHeldItemMainhand();
                if (tools.getItem() instanceof ItemTool || tools.getItem() instanceof ItemHoe || tools.getItem() instanceof ItemSword) {
                    if (tools.getItem().getMaxDamage(tools) - tools.getItem().getDamage(tools) < tools.getItem().getMaxDamage(tools) * 0.1) {
                        tools.setItemDamage((int) (tools.getItem().getMaxDamage(tools) * 0.1));
                        ((ItemTotem) totem.getItem()).animationTotemUnshattering(player);
                        totem.shrink(1);
                    }
                }
            }
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) Entity(net.minecraft.entity.Entity) ItemHoe(net.minecraft.item.ItemHoe) ItemTool(net.minecraft.item.ItemTool) EntityDamageSource(net.minecraft.util.EntityDamageSource) DamageSource(net.minecraft.util.DamageSource) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemTotem(com.axanthic.loi.items.ItemTotem) ItemStack(net.minecraft.item.ItemStack) EntityDamageSource(net.minecraft.util.EntityDamageSource)

Example 59 with ItemSword

use of net.minecraft.item.ItemSword in project Lands-of-Icaria by Axanthic-Game-Studios.

the class ClientProxy method registerModels.

@SubscribeEvent
public void registerModels(ModelRegistryEvent event) {
    for (ItemBlock block : Resources.blocks) {
        if (block.getBlock() instanceof BlockFlower || block.getBlock() instanceof BlockTallGrass || block.getBlock() instanceof BlockHerb) {
            for (int i = 0; i < ((IBlockMeta) block.getBlock()).getNames().length; i++) {
                ModelLoader.setCustomModelResourceLocation(block, i, new ModelResourceLocation(block.getRegistryName() + "_inv", "type=" + ((IBlockMeta) block.getBlock()).getNames()[i]));
            }
        } else if (block.getBlock() instanceof BlockLeafOlives) {
            // olive leaves are weird
            ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "check_decay=false,decayable=false,type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(0)));
            ModelLoader.setCustomModelResourceLocation(block, 1, new ModelResourceLocation(block.getRegistryName(), "check_decay=false,decayable=false,type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(1)));
        } else if (block instanceof ItemBlockMeta) {
            ModelLoader.setCustomMeshDefinition(block, new ItemMeshDefinition() {

                @Override
                public ModelResourceLocation getModelLocation(ItemStack stack) {
                    return new ModelResourceLocation(block.getRegistryName(), "type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(stack.getMetadata()));
                }
            });
        } else if (block.getBlock() instanceof BlockLeaf || block.getBlock() instanceof BlockSapling || block.getBlock() instanceof BlockCustomWorkbench) {
            String[] path = block.getRegistryName().getResourcePath().split("_");
            if (block.getBlock() instanceof BlockSapling)
                ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), "inv_" + path[0]));
            else
                ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), path[0]));
            ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {

                @Override
                public ModelResourceLocation getModelResourceLocation(IBlockState state) {
                    return new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), path[0]);
                }
            });
        } else if (block.getBlock() instanceof BlockLog) {
            String[] path = block.getRegistryName().getResourcePath().split("_");
            ResourceLocation loc = new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]);
            ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(loc, path[0] + "_y"));
            ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {

                @Override
                public ModelResourceLocation getModelResourceLocation(IBlockState state) {
                    String axis = "bark";
                    int meta = ((BlockLog) block.getBlock()).getMetaFromState(state);
                    if (meta == 0) {
                        axis = "y";
                    } else if (meta == 4) {
                        axis = "x";
                    } else if (meta == 8) {
                        axis = "z";
                    }
                    return new ModelResourceLocation(loc, path[0] + "_" + axis);
                }
            });
        } else if (block.getBlock() instanceof BlockFluidCustom) {
            ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "normal"));
            ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {

                @Override
                public ModelResourceLocation getModelResourceLocation(IBlockState state) {
                    return new ModelResourceLocation(block.getRegistryName(), "normal");
                }
            });
        } else
            ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));
    }
    for (Item item : Resources.items) {
        if (item instanceof IItemMeta) {
            for (int i = 0; i < ((IItemMeta) item).getNames().length; i++) {
                ModelLoader.setCustomModelResourceLocation(item, i, new ModelResourceLocation(item.getRegistryName(), "type=" + ((IItemMeta) item).getNames()[i]));
            }
        } else if (item instanceof ItemTool || item instanceof ItemSword || item instanceof ItemCustomArmor) {
            String[] path = item.getRegistryName().getResourcePath().split("_");
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "tool_" + path[1]), path[0]));
        } else if (item instanceof ItemSpell) {
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "spell"), ((ItemSpell) item).getName()));
        } else if (item instanceof ItemScroll) {
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "spell_scroll"), ((ItemScroll) item).getName()));
        } else if (item instanceof ItemConcoctionFlask) {
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "concoction_flask_filled"), "inventory"));
        } else
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
    }
    // register special item renderers here
    Resources.saltedFood.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.grinder.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadRevenant.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadArachne.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadArachneDrone.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadMyrmeke.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadCerver.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadArganHound.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagPlane.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagPopulus.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagCypress.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagFir.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagOlive.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagLaurel.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagDroughtroot.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadAeternae.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadCatoblepas.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadSow.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    for (ItemScroll scroll : Resources.scrolls) scroll.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
}
Also used : StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) BlockLeaf(com.axanthic.loi.blocks.BlockLeaf) IBlockMeta(com.axanthic.loi.blocks.IBlockMeta) BlockLeafOlives(com.axanthic.loi.blocks.BlockLeafOlives) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) BlockCustomWorkbench(com.axanthic.loi.blocks.BlockCustomWorkbench) Item(net.minecraft.item.Item) ItemSpell(com.axanthic.loi.items.ItemSpell) BlockSapling(com.axanthic.loi.blocks.BlockSapling) BlockHerb(com.axanthic.loi.blocks.BlockHerb) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemConcoctionFlask(com.axanthic.loi.items.ItemConcoctionFlask) ItemSword(net.minecraft.item.ItemSword) ItemTool(net.minecraft.item.ItemTool) IBlockState(net.minecraft.block.state.IBlockState) BlockLog(com.axanthic.loi.blocks.BlockLog) IItemMeta(com.axanthic.loi.items.IItemMeta) ItemBlock(net.minecraft.item.ItemBlock) BlockFlower(com.axanthic.loi.blocks.BlockFlower) ItemCustomArmor(com.axanthic.loi.items.ItemCustomArmor) ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) BlockTallGrass(com.axanthic.loi.blocks.BlockTallGrass) ItemBlockMeta(com.axanthic.loi.items.ItemBlockMeta) ItemStack(net.minecraft.item.ItemStack) ItemScroll(com.axanthic.loi.items.ItemScroll) BlockFluidCustom(com.axanthic.loi.blocks.BlockFluidCustom) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 60 with ItemSword

use of net.minecraft.item.ItemSword in project Lands-of-Icaria by Axanthic-Game-Studios.

the class CommonProxy method onToolBreaksMainhand.

public void onToolBreaksMainhand(PlayerInteractEvent event) {
    EntityPlayer player = event.getEntityPlayer();
    for (int slot = 0; slot < 9; slot++) {
        ItemStack totem = player.inventory.getStackInSlot(slot);
        if (totem.getItem().equals(Resources.totem_unshattering)) {
            ItemStack tools = player.getHeldItemMainhand();
            if (tools.getItem() instanceof ItemTool || tools.getItem() instanceof ItemHoe || tools.getItem() instanceof ItemSword || tools.getItem() instanceof ItemBow || tools.getItem() instanceof ItemFishingRod || tools.getItem() instanceof ItemFlintAndSteel || tools.getItem() instanceof ItemShears || tools.getItem() instanceof ItemShield) {
                if (tools.getItem().getMaxDamage(tools) - tools.getItem().getDamage(tools) < tools.getItem().getMaxDamage(tools) * 0.1) {
                    tools.setItemDamage((int) (tools.getItem().getMaxDamage(tools) * 0.1));
                    totem.shrink(1);
                }
            }
        }
    }
    ItemStack totem = player.inventory.getStackInSlot(40);
    if (totem.getItem().equals(Resources.totem_unshattering)) {
        ItemStack tools = player.getHeldItemMainhand();
        if (tools.getItem() instanceof ItemTool || tools.getItem() instanceof ItemHoe || tools.getItem() instanceof ItemSword || tools.getItem() instanceof ItemBow || tools.getItem() instanceof ItemFishingRod || tools.getItem() instanceof ItemFlintAndSteel || tools.getItem() instanceof ItemShears || tools.getItem() instanceof ItemShield) {
            if (tools.getItem().getMaxDamage(tools) - tools.getItem().getDamage(tools) < tools.getItem().getMaxDamage(tools) * 0.1) {
                tools.setItemDamage((int) (tools.getItem().getMaxDamage(tools) * 0.1));
                totem.shrink(1);
            }
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) ItemHoe(net.minecraft.item.ItemHoe) ItemTool(net.minecraft.item.ItemTool) ItemShield(net.minecraft.item.ItemShield) ItemFishingRod(net.minecraft.item.ItemFishingRod) ItemFlintAndSteel(net.minecraft.item.ItemFlintAndSteel) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemShears(net.minecraft.item.ItemShears) ItemStack(net.minecraft.item.ItemStack) ItemBow(net.minecraft.item.ItemBow)

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