Search in sources :

Example 16 with EntityEquipmentSlot

use of net.minecraft.inventory.EntityEquipmentSlot in project SpongeCommon by SpongePowered.

the class MixinEntityPlayer method onSetItemStackToSlot.

@Inject(method = "setItemStackToSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/NonNullList;set(ILjava/lang/Object;)Ljava/lang/Object;"))
private void onSetItemStackToSlot(EntityEquipmentSlot slotIn, ItemStack stack, CallbackInfo ci) {
    if (((IMixinInventoryPlayer) this.inventory).capturesTransactions()) {
        if (slotIn == EntityEquipmentSlot.MAINHAND) {
            ItemStack orig = this.inventory.mainInventory.get(this.inventory.currentItem);
            Slot slot = ((PlayerInventory) this.inventory).getMain().getHotbar().getSlot(SlotIndex.of(this.inventory.currentItem)).get();
            ((IMixinInventoryPlayer) this.inventory).getCapturedTransactions().add(new SlotTransaction(slot, ItemStackUtil.snapshotOf(orig), ItemStackUtil.snapshotOf(stack)));
        } else if (slotIn == EntityEquipmentSlot.OFFHAND) {
            ItemStack orig = this.inventory.offHandInventory.get(0);
            Slot slot = ((PlayerInventory) this.inventory).getOffhand();
            ((IMixinInventoryPlayer) this.inventory).getCapturedTransactions().add(new SlotTransaction(slot, ItemStackUtil.snapshotOf(orig), ItemStackUtil.snapshotOf(stack)));
        } else if (slotIn.getSlotType() == EntityEquipmentSlot.Type.ARMOR) {
            ItemStack orig = this.inventory.armorInventory.get(slotIn.getIndex());
            Slot slot = ((PlayerInventory) this.inventory).getEquipment().getSlot(SlotIndex.of(slotIn.getIndex())).get();
            ((IMixinInventoryPlayer) this.inventory).getCapturedTransactions().add(new SlotTransaction(slot, ItemStackUtil.snapshotOf(orig), ItemStackUtil.snapshotOf(stack)));
        }
    }
}
Also used : IMixinInventoryPlayer(org.spongepowered.common.interfaces.entity.player.IMixinInventoryPlayer) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) Slot(org.spongepowered.api.item.inventory.Slot) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) ItemStack(net.minecraft.item.ItemStack) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 17 with EntityEquipmentSlot

use of net.minecraft.inventory.EntityEquipmentSlot in project Charset by CharsetMC.

the class CharsetTweakMobEqualizer method upgradeMob.

@SubscribeEvent(priority = EventPriority.LOW)
public void upgradeMob(LivingSpawnEvent.SpecialSpawn event) {
    EnumDifficulty difficulty = event.getWorld().getDifficulty();
    if (difficulty == null || difficulty.getDifficultyId() <= 1) {
        return;
    }
    if (!(event.getEntityLiving() instanceof EntityMob)) {
        return;
    }
    EntityMob ent = (EntityMob) event.getEntityLiving();
    // 2) Should we add more granular setups (like only some elements of armor, but at a higher frequency)?
    if (event.getWorld().rand.nextInt(400) > difficulty.getDifficultyId()) {
        return;
    }
    if (!ent.canPickUpLoot())
        return;
    EntityPlayer template = pickNearPlayer(event);
    if (template == null) {
        return;
    }
    int equipmentCount = 0;
    ItemStack[] equipmentCopies = new ItemStack[6];
    boolean copyArmor = event.getEntity() instanceof IRangedAttackMob || event.getWorld().rand.nextBoolean();
    boolean copyWeapon = !(event.getEntity() instanceof IRangedAttackMob) || event.getWorld().rand.nextBoolean();
    for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
        if (slot.getSlotType() == EntityEquipmentSlot.Type.ARMOR && copyArmor) {
            ItemStack is = template.getItemStackFromSlot(slot);
            if (!is.isEmpty() && is.getItem().isValidArmor(is, slot, ent)) {
                equipmentCopies[slot.ordinal()] = is.copy();
                equipmentCount++;
            } else {
                equipmentCopies[slot.ordinal()] = ItemStack.EMPTY;
            }
        }
    }
    List<ItemStack> carriedWeapons = new ArrayList<ItemStack>();
    if (copyWeapon) {
        ItemStack currentWeapon = ent.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
        double currentWeaponDmg = ItemUtils.getAttributeValue(EntityEquipmentSlot.MAINHAND, currentWeapon, SharedMonsterAttributes.ATTACK_DAMAGE);
        for (int i = 0; i < 9; i++) {
            ItemStack playerWeapon = template.inventory.getStackInSlot(i);
            if (playerWeapon.isEmpty() || playerWeapon.getCount() != 1 || playerWeapon.getMaxStackSize() != 1) {
                continue;
            }
            EnumAction act = playerWeapon.getItemUseAction();
            if (act != EnumAction.BLOCK && act != EnumAction.NONE && act != EnumAction.BOW) {
                continue;
            }
            double playerWeaponDmg = ItemUtils.getAttributeValue(EntityEquipmentSlot.MAINHAND, playerWeapon, SharedMonsterAttributes.ATTACK_DAMAGE);
            if (playerWeaponDmg > currentWeaponDmg) {
                carriedWeapons.add(playerWeapon.copy());
            }
        }
    }
    if (!carriedWeapons.isEmpty()) {
        equipmentCopies[0] = carriedWeapons.get(event.getWorld().rand.nextInt(carriedWeapons.size())).copy();
        equipmentCount++;
    }
    if (equipmentCount <= 0) {
        return;
    }
    event.setCanceled(true);
    ent.onInitialSpawn(ent.world.getDifficultyForLocation(new BlockPos(event.getEntity())), null);
    // We need to cancel the event so that we can call this before the below happens
    ent.setCanPickUpLoot(false);
    for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
        if (equipmentCopies[slot.ordinal()] != null) {
            ent.setItemStackToSlot(slot, equipmentCopies[slot.ordinal()]);
        }
        ent.setDropChance(slot, 0);
    }
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ArrayList(java.util.ArrayList) IRangedAttackMob(net.minecraft.entity.IRangedAttackMob) EnumAction(net.minecraft.item.EnumAction) EntityMob(net.minecraft.entity.monster.EntityMob) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EnumDifficulty(net.minecraft.world.EnumDifficulty) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 18 with EntityEquipmentSlot

use of net.minecraft.inventory.EntityEquipmentSlot in project BuildCraft by BuildCraft.

the class ListMatchHandlerArmor method getArmorTypes.

private static EnumSet<EntityEquipmentSlot> getArmorTypes(ItemStack stack) {
    EntityPlayer player = BCLibProxy.getProxy().getClientPlayer();
    if (player == null) {
        player = BuildCraftAPI.fakePlayerProvider.getBuildCraftPlayer(DimensionManager.getWorld(0));
    }
    EnumSet<EntityEquipmentSlot> types = EnumSet.noneOf(EntityEquipmentSlot.class);
    for (EntityEquipmentSlot e : EntityEquipmentSlot.values()) {
        if (e.getSlotType() == EntityEquipmentSlot.Type.ARMOR) {
            if (stack.getItem().isValidArmor(stack, e, player)) {
                types.add(e);
            }
        }
    }
    return types;
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 19 with EntityEquipmentSlot

use of net.minecraft.inventory.EntityEquipmentSlot in project EnderIO by SleepyTrousers.

the class ItemLocationPrintout method getGuiElement.

@Override
@Nullable
public Object getGuiElement(boolean server, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable EnumFacing facing, int ID, int handID, int param3) {
    if (server) {
        return null;
    } else if (GUI_ID_LOCATION_PRINTOUT_CREATE == ID) {
        int foundPaper = -1;
        for (int paperIndex = 0; paperIndex < player.inventoryContainer.inventorySlots.size() && foundPaper < 0; paperIndex++) {
            ItemStack invItem = player.inventoryContainer.inventorySlots.get(paperIndex).getStack();
            if (invItem.getItem() == Items.PAPER) {
                foundPaper = paperIndex;
            }
        }
        if (foundPaper < 0) {
            player.sendMessage(Lang.PRINTOUT_NOPAPER.toChat());
            return null;
        }
        TelepadTarget target = new TelepadTarget(pos, world.provider.getDimension());
        ItemStack stack = new ItemStack(this);
        target.writeToNBT(stack);
        return new GuiLocationPrintout(target, stack, foundPaper);
    } else if (GUI_ID_LOCATION_PRINTOUT == ID) {
        EnumHand hand = handID == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
        EntityEquipmentSlot slot = hand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND;
        TelepadTarget target = TelepadTarget.readFromNBT(player.getItemStackFromSlot(slot));
        if (target != null) {
            return new GuiLocationPrintout(target, player, slot);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) EnumHand(net.minecraft.util.EnumHand) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 20 with EntityEquipmentSlot

use of net.minecraft.inventory.EntityEquipmentSlot in project BloodMagic by WayofTime.

the class LivingArmourUpgradeRepairing method onTick.

@Override
public void onTick(World world, EntityPlayer player, ILivingArmour livingArmour) {
    if (delay <= 0) {
        delay = repairDelay[this.level];
        EntityEquipmentSlot randomSlot = EntityEquipmentSlot.values()[2 + world.rand.nextInt(4)];
        ItemStack repairStack = player.getItemStackFromSlot(randomSlot);
        if (!repairStack.isEmpty()) {
            if (repairStack.isItemStackDamageable() && repairStack.isItemDamaged()) {
                int toRepair = Math.min(maxRepair, repairStack.getItemDamage());
                if (toRepair > 0) {
                    repairStack.setItemDamage(repairStack.getItemDamage() - toRepair);
                }
            }
        }
    } else {
        delay--;
    }
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)23 ItemStack (net.minecraft.item.ItemStack)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 ArrayList (java.util.ArrayList)3 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)3 ItemArmor (net.minecraft.item.ItemArmor)3 BlockPos (net.minecraft.util.math.BlockPos)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 IGuiTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile)2 IGuiItem (blusunrize.immersiveengineering.common.items.IEItemInterfaces.IGuiItem)2 IDarkSteelItem (crazypants.enderio.api.upgrades.IDarkSteelItem)2 IDarkSteelUpgrade (crazypants.enderio.api.upgrades.IDarkSteelUpgrade)2 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 Item (net.minecraft.item.Item)2 TileEntity (net.minecraft.tileentity.TileEntity)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 IBullet (blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet)1 TileEntityAlloySmelter (blusunrize.immersiveengineering.common.blocks.stone.TileEntityAlloySmelter)1