use of net.minecraft.server.v1_11_R1.Slot in project MyPet by xXKeyleXx.
the class IconMenuInventory method update.
@Override
public void update(IconMenu menu) {
for (int slot = 0; slot < size; slot++) {
IconMenuItem menuItem = menu.getOption(slot);
if (menuItem != null) {
ItemStack item = createItemStack(menuItem);
minecraftInventory.setItem(slot, item);
} else {
minecraftInventory.setItem(slot, ItemStack.a);
}
}
}
use of net.minecraft.server.v1_11_R1.Slot in project X-Road by nordic-institute.
the class HardwareModuleWorker method listTokens.
@Override
protected List<TokenType> listTokens() throws Exception {
log.trace("Listing tokens on module '{}'", module.getType());
Slot[] slots = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
if (slots.length == 0) {
log.warn("Did not get any slots from module '{}'. Reinitializing module.", module.getType());
// Error code doesn't really matter as long as it's PKCS11Exception
throw new PKCS11Exception(PKCS11Constants.CKR_GENERAL_ERROR);
}
log.info("Module '{}' got {} slots", module.getType(), slots.length);
for (int i = 0; i < slots.length; i++) {
log.debug("Module '{}' Slot {} ID: {} (0x{})", module.getType(), i, slots[i].getSlotID(), Functions.toHexString(slots[i].getSlotID()));
}
// HSM slot ids defined in module data
Set<Long> slotIds = module.getSlotIds();
log.debug("Slot configuration for module '{}' defined as {}", module.getType(), slotIds.toString());
Map<String, TokenType> tokens = new HashMap<>();
for (int slotIndex = 0; slotIndex < slots.length; slotIndex++) {
if (slotIds.isEmpty() || slotIds.contains(slots[slotIndex].getSlotID())) {
TokenType token = createToken(slots, slotIndex);
TokenType previous = tokens.putIfAbsent(token.getId(), token);
if (previous == null) {
log.info("Module '{}' slot #{} has token with ID '{}': {}", module.getType(), slotIndex, token.getId(), token);
} else {
log.info("Module '{}' slot #{} has token with ID '{}' but token with that ID is " + " already registered", module.getType(), slotIndex, token.getId());
}
}
}
return new ArrayList<>(tokens.values());
}
use of net.minecraft.server.v1_11_R1.Slot in project MechanicsMain by WeaponMechanics.
the class NBT_1_11_R1 method setAttribute.
@Nonnull
@Override
public void setAttribute(@Nonnull ItemStack bukkitItem, @Nonnull AttributeType attribute, @Nullable AttributeSlot slot, double value) {
net.minecraft.server.v1_11_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_11_R1.Slot in project TheAPI by TheDevTec.
the class v1_11_R1 method processInvClickPacket.
@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
PacketPlayInWindowClick packet = (PacketPlayInWindowClick) provPacket;
int slot = packet.b();
if (slot == -999)
return false;
int id = packet.a();
int mouseClick = packet.c();
net.minecraft.server.v1_11_R1.InventoryClickType nmsType = packet.f();
InventoryClickType type = InventoryClickType.valueOf(nmsType.name());
Object container = gui.getContainer(player);
ItemStack item = asBukkitItem(packet.e());
if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType() == Material.AIR) && item.getType() == Material.AIR)
item = asBukkitItem(getSlotItem(container, slot));
boolean cancel = false;
if (InventoryClickType.SWAP == type) {
item = player.getInventory().getItem(mouseClick);
mouseClick = 0;
cancel = true;
}
if (item == null)
item = new ItemStack(Material.AIR);
ItemStack before = player.getItemOnCursor();
ClickType clickType = BukkitLoader.buildClick(item, type, slot, mouseClick);
if (!cancel)
cancel = BukkitLoader.useItem(player, item, gui, slot, clickType);
if (!gui.isInsertable())
cancel = true;
int gameSlot = slot > gui.size() - 1 ? InventoryUtils.convertToPlayerInvSlot(slot - gui.size()) : slot;
if (!cancel)
cancel = gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
else
gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
int position = 0;
if (!cancel && type == InventoryClickType.QUICK_MOVE) {
ItemStack[] contents = slot < gui.size() ? player.getInventory().getStorageContents() : gui.getInventory().getStorageContents();
List<Integer> modified = slot < gui.size() ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI ? DestinationType.PLAYER_INV_ANVIL : DestinationType.PLAYER_INV_CUSTOM_INV, null, contents, item) : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.CUSTOM_INV, gui.getNotInterableSlots(player), contents, item);
if (!modified.isEmpty()) {
if (slot < gui.size()) {
boolean canRemove = !modified.contains(-1);
player.getInventory().setStorageContents(contents);
if (canRemove) {
gui.remove(gameSlot);
} else {
gui.getInventory().setItem(gameSlot, item);
}
} else {
boolean canRemove = !modified.contains(-1);
gui.getInventory().setStorageContents(contents);
if (canRemove) {
player.getInventory().setItem(gameSlot, null);
} else {
player.getInventory().setItem(gameSlot, item);
}
}
}
return true;
}
if (cancel) {
// MOUSE
BukkitLoader.getPacketHandler().send(player, packetSetSlot(-1, -1, asNMSItem(before)));
switch(type) {
case CLONE:
return true;
case SWAP:
case QUICK_MOVE:
case PICKUP_ALL:
// TOP
for (ItemStack cItem : gui.getInventory().getContents()) {
BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
}
// BUTTON
player.updateInventory();
return true;
default:
BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, slot, getSlotItem(container, slot)));
if (gui instanceof AnvilGUI) {
// TOP
for (ItemStack cItem : gui.getInventory().getContents()) {
if (position != slot)
BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
}
// BUTTON
player.updateInventory();
}
return true;
}
} else {
if (gui instanceof AnvilGUI && slot == 2)
postToMainThread(() -> ((ContainerAnvil) container).b((EntityPlayer) getPlayer(player), slot));
}
return false;
}
use of net.minecraft.server.v1_11_R1.Slot in project PublicCrafters by BananaPuncher714.
the class CustomContainerWorkbench method shiftClick.
// Overrides 1.12.2
public ItemStack shiftClick(EntityHuman entityhuman, int i) {
ItemStack itemstack = ItemStack.a;
Slot slot = (Slot) theseSlots.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 ItemStack.a;
}
slot.a(itemstack1, itemstack);
} else if ((i >= 10) && (i < 37)) {
if (!a(itemstack1, 37, 46, false)) {
return ItemStack.a;
}
} else if ((i >= 37) && (i < 46)) {
if (!a(itemstack1, 10, 37, false)) {
return ItemStack.a;
}
} else if (!a(itemstack1, 10, 46, false)) {
return ItemStack.a;
}
if (itemstack1.isEmpty()) {
slot.set(ItemStack.a);
} else {
slot.f();
}
if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.a;
}
ItemStack itemstack2 = slot.a(entityhuman, itemstack1);
if (i == 0) {
entityhuman.drop(itemstack2, false);
}
}
return itemstack;
}
Aggregations