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)));
}
}
}
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);
}
}
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;
}
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;
}
}
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--;
}
}
Aggregations