use of net.minecraft.server.v1_10_R1.Slot in project PublicCrafters by BananaPuncher714.
the class CustomContainerWorkbench method shiftClick.
// Overrides 1.15.1
@Override
public ItemStack shiftClick(EntityHuman entityhuman, int i) {
ItemStack itemstack = ItemStack.b;
Slot slot = (Slot) this.slots.get(i);
if (slot != null && slot.hasItem()) {
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.cloneItemStack();
if (i == 0) {
this.containerAccess.a((world, blockposition) -> {
itemstack1.getItem().b(itemstack1, world, entityhuman);
});
if (!this.a(itemstack1, 10, 46, true)) {
return ItemStack.b;
}
slot.a(itemstack1, itemstack);
} else if (i >= 10 && i < 46 ? !this.a(itemstack1, 1, 10, false) && (i < 37 ? !this.a(itemstack1, 37, 46, false) : !this.a(itemstack1, 10, 37, false)) : !this.a(itemstack1, 10, 46, false)) {
return ItemStack.b;
}
if (itemstack1.isEmpty()) {
slot.set(ItemStack.b);
} else {
slot.d();
}
if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.b;
}
ItemStack itemstack2 = slot.a(entityhuman, itemstack1);
if (i == 0) {
entityhuman.drop(itemstack2, false);
}
}
return itemstack;
}
use of net.minecraft.server.v1_10_R1.Slot in project PublicCrafters by BananaPuncher714.
the class CustomContainerWorkbench method b.
/**
* The shift clicking method
*/
@Override
public ItemStack b(EntityHuman entityhuman, int i) {
ItemStack itemstack = null;
Slot slot = (Slot) this.c.get(i);
if ((slot != null) && (slot.hasItem())) {
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.cloneItemStack();
if (i == 0) {
itemstack1.getItem().b(itemstack1, world, entityhuman);
if (!a(itemstack1, 10, 46, true)) {
return null;
}
slot.a(itemstack1, itemstack);
} else if ((i >= 10) && (i < 37)) {
if (!a(itemstack1, 37, 46, false)) {
return null;
}
} else if ((i >= 37) && (i < 46)) {
if (!a(itemstack1, 10, 37, false)) {
return null;
}
} else if (!a(itemstack1, 10, 46, false)) {
return null;
}
slot.f();
if (itemstack1.count == itemstack.count) {
return null;
}
slot.a(entityhuman, itemstack1);
if (i == 0) {
entityhuman.drop(itemstack1, false);
}
}
return itemstack;
}
use of net.minecraft.server.v1_10_R1.Slot in project MechanicsMain by WeaponMechanics.
the class NBT_1_10_R1 method setAttribute.
@Nonnull
@Override
public void setAttribute(@Nonnull ItemStack bukkitItem, @Nonnull AttributeType attribute, @Nullable AttributeSlot slot, double value) {
net.minecraft.server.v1_10_R1.ItemStack nmsItem = getNMSStack(bukkitItem);
if (nmsItem.getTag() == null) {
nmsItem.setTag(new NBTTagCompound());
}
NBTTagCompound compound = nmsItem.getTag();
if (compound.hasKey("AttributeModifiers")) {
NBTTagList list = (NBTTagList) compound.get("AttributeModifiers");
// NBT lists don't have an indexOf method, so we need to loop
// through each attribute, and determine if it is one we want to
// modify. We want to modify an attribute if the attribute was
// set using MechanicsCore, and it's attribute type matches the
// parameter attribute type.
boolean isModifiedAttribute = false;
for (int i = 0; i < list.size(); i++) {
// 10 is the id for nbt lists
if (list.get(i).getTypeId() != 10) {
continue;
}
NBTTagCompound nbt = list.get(i);
String name = nbt.getString("Name");
String attributeName = nbt.getString("AttributeName");
// There is no offhand, or slot argument in 1_8_8.
if (!"MechanicsCoreAttribute".equals(name) || !attribute.getMinecraftName().equals(attributeName)) {
continue;
}
// Since this attribute already exists, we only need to modify
// the existing value. No need to set the name/uuid
nbt.setDouble("Amount", value);
isModifiedAttribute = true;
break;
}
if (!isModifiedAttribute) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("AttributeName", attribute.getMinecraftName());
nbt.setString("Name", "MechanicsCoreAttribute");
nbt.setDouble("Amount", value);
// 0 == add
nbt.setInt("Operation", 0);
nbt.setLong("UUIDLeast", attribute.getUUID().getLeastSignificantBits());
nbt.setLong("UUIDMost", attribute.getUUID().getMostSignificantBits());
if (slot != null) {
nbt.setString("Slot", slot.getSlotName());
}
}
}
bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsItem));
}
use of net.minecraft.server.v1_10_R1.Slot in project Citizens2 by CitizensDev.
the class EntityHumanNPC method updatePackets.
private void updatePackets(boolean navigating) {
updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
ItemStack cache = equipmentCache.get(slot);
if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
return;
updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
int i = 0;
for (EnumItemSlot slot : EnumItemSlot.values()) {
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
}
NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
use of net.minecraft.server.v1_10_R1.Slot in project Panilla by ds58.
the class InventoryCleaner method clean.
@Override
public void clean(IPanillaPlayer player) {
CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
Container container = craftPlayer.getHandle().activeContainer;
int containerSlotsSize = 0;
if (is_1_12_2) {
containerSlotsSize = container.slots.size();
} else {
try {
Field slotsField = Container.class.getField("c");
List<Slot> slots = (List<Slot>) slotsField.get(container);
containerSlotsSize = slots.size();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
for (int slot = 0; slot < containerSlotsSize; slot++) {
ItemStack itemStack = container.getSlot(slot).getItem();
if (itemStack == null || !itemStack.hasTag()) {
continue;
}
NBTTagCompound nmsTag = itemStack.getTag();
INbtTagCompound tag = new NbtTagCompound(nmsTag);
String itemName = itemStack.getItem().getName();
if (nmsTag == null || itemName == null) {
continue;
}
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.failsThreshold(failedNbt)) {
container.getSlot(slot).getItem().setTag(null);
} else if (FailedNbt.fails(failedNbt)) {
nmsTag.remove(failedNbt.key);
container.getSlot(slot).getItem().setTag(nmsTag);
}
}
}
Aggregations