use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project TheAPI by TheDevTec.
the class v1_15_R1 method openGUI.
@Override
public void openGUI(Player player, Object container, String legacy, int size, String title, ItemStack[] items) {
EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
int id = ((Container) container).windowId;
net.minecraft.server.v1_15_R1.ItemStack[] nmsItems = new net.minecraft.server.v1_15_R1.ItemStack[items.length];
for (int i = 0; i < items.length; ++i) {
ItemStack is = items[i];
if (is == null || is.getType() == Material.AIR)
continue;
net.minecraft.server.v1_15_R1.ItemStack item = null;
((Container) container).setItem(i, item = (net.minecraft.server.v1_15_R1.ItemStack) asNMSItem(is));
nmsItems[i] = item;
}
BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, legacy, size, title));
int i = 0;
for (net.minecraft.server.v1_15_R1.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
nmsPlayer.activeContainer.transferTo((Container) container, (CraftPlayer) player);
nmsPlayer.activeContainer = (Container) container;
((Container) container).addSlotListener(nmsPlayer);
((Container) container).checkReachable = false;
}
use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project WLib by WizardlyBump17.
the class PacketListener method entityMetadata.
@SuppressWarnings("unchecked")
@SneakyThrows
private void entityMetadata(World world, PacketContainer packet, PacketPlayOutEntityMetadata handle) {
final Entity entity = packet.getEntityModifier(world).read(0);
if (!(entity instanceof org.bukkit.entity.Item))
return;
final ItemStack itemStack = ((org.bukkit.entity.Item) entity).getItemStack().clone();
if (isInvalid(itemStack))
return;
final Field field = handle.getClass().getDeclaredField("b");
field.setAccessible(true);
List<DataWatcher.Item<?>> items = new ArrayList<>((List<DataWatcher.Item<?>>) field.get(handle));
final DataWatcher.Item<?> item;
int index;
if (items.size() == 8)
// new item
item = items.get(index = 6).d();
else
// item merge
item = items.get(index = 0).d();
final Field itemField = item.getClass().getDeclaredField("b");
itemField.setAccessible(true);
itemField.set(item, CraftItemStack.asNMSCopy(fixItem(itemStack)));
items.set(index, item);
field.set(handle, items);
}
use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project solinia3-core by mixxit.
the class ItemStackUtils method ConvertItemStackToJsonRegular.
public static String ConvertItemStackToJsonRegular(ItemStack itemStack) {
// First we convert the item stack into an NMS itemstack
net.minecraft.server.v1_15_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound compound = new NBTTagCompound();
compound = nmsItemStack.save(compound);
return compound.toString();
}
use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project solinia3-core by mixxit.
the class ItemStackUtils method getWeaponDamageFromItemStack.
public static int getWeaponDamageFromItemStack(ItemStack itemStack, EnumItemSlot itemSlot) {
double attackDamage = 1.0;
UUID uuid = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF");
net.minecraft.server.v1_15_R1.ItemStack craftItemStack = CraftItemStack.asNMSCopy(itemStack);
net.minecraft.server.v1_15_R1.Item item = craftItemStack.getItem();
if (item instanceof net.minecraft.server.v1_15_R1.ItemSword || item instanceof net.minecraft.server.v1_15_R1.ItemTool || item instanceof net.minecraft.server.v1_15_R1.ItemHoe) {
Multimap<String, AttributeModifier> map = item.a(itemSlot);
Collection<AttributeModifier> attributes = map.get(GenericAttributes.ATTACK_DAMAGE.getName());
if (!attributes.isEmpty()) {
for (AttributeModifier am : attributes) {
if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.ADDITION)
attackDamage += am.getAmount();
}
double y = 1;
for (AttributeModifier am : attributes) {
if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_BASE)
y += am.getAmount();
}
attackDamage *= y;
for (AttributeModifier am : attributes) {
if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_TOTAL)
attackDamage *= (1 + am.getAmount());
}
}
}
Long rounded = Math.round(attackDamage);
if (rounded > Integer.MAX_VALUE)
rounded = (long) Integer.MAX_VALUE;
int damage = Integer.valueOf(rounded.intValue());
return damage;
}
use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project solinia3-core by mixxit.
the class SoliniaLivingEntity method getItemBonusesTuple.
public Tuple<Integer, Integer> getItemBonusesTuple(SpellEffectType spellEffectType, SpellResistType filterResistType) {
List<ISoliniaItem> equippedItems = this.getEquippedSoliniaItems();
int highest = 0;
int highest2 = 0;
// Check if item focus effect exists for the client.
if (equippedItems.size() > 0) {
ISoliniaItem TempItem = null;
// item focus
for (ISoliniaItem item : equippedItems) {
TempItem = item;
if (TempItem == null)
continue;
if (TempItem.getFocusEffectId() < 1) {
continue;
}
ISoliniaSpell spell = null;
try {
spell = StateManager.getInstance().getConfigurationManager().getSpell(item.getFocusEffectId());
if (spell == null)
continue;
if (!filterResistType.equals(SpellResistType.RESIST_NONE))
if (spell.isEffectInSpell(SpellEffectType.LimitResist)) {
try {
// For spells like Pet Focus where the spell type has type limits (ie fire resist = fire pet)
int resistTypeId = spell.getSpellEffectBase(SpellEffectType.LimitResist);
if (SpellUtils.getSpellResistType(resistTypeId) != filterResistType)
continue;
} catch (Exception e) {
e.printStackTrace();
}
}
if (!spell.isEffectInSpell(spellEffectType))
continue;
Tuple<Integer, Integer> spellBonuses = ApplySpellsBonuses(spell.getId(), getBukkitLivingEntity(), getBukkitLivingEntity(), spell.getSpellEffect(spellEffectType), getMentorLevel(), 0, 0);
if (spellBonuses.a() > highest) {
highest = spellBonuses.a();
highest2 = spellBonuses.b();
}
} catch (CoreStateInitException e) {
}
}
}
return new Tuple<Integer, Integer>(highest, highest2);
}
Aggregations