use of net.minecraft.inventory.container.RepairContainer in project Arclight by IzzelAliz.
the class RepairContainerMixin method getBukkitView.
@Override
public CraftInventoryView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}
CraftInventory inventory = new CraftInventoryAnvil(((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation(), this.inputSlots, this.outputSlot, (RepairContainer) (Object) this);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
return bukkitEntity;
}
use of net.minecraft.inventory.container.RepairContainer in project TheAPI by TheDevTec.
the class v1_16_R3_Mohist method openAnvilGUI.
@Override
public void openAnvilGUI(Player player, Object con, String title, ItemStack[] items) {
RepairContainer container = (RepairContainer) con;
ServerPlayerEntity nmsPlayer = ((CraftPlayer) player).getHandle();
int id = container.field_75152_c;
net.minecraft.item.ItemStack[] nmsItems = new net.minecraft.item.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.item.ItemStack item = null;
container.func_75141_a(i, item = (net.minecraft.item.ItemStack) asNMSItem(is));
nmsItems[i] = item;
}
BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, "minecraft:anvil", 0, title));
int i = 0;
for (net.minecraft.item.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
nmsPlayer.field_71070_bA = (RepairContainer) container;
((RepairContainer) container).func_75134_a(nmsPlayer);
}
use of net.minecraft.inventory.container.RepairContainer in project TheAPI by TheDevTec.
the class v1_16_R3_Mohist method processInvClickPacket.
@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
CClickWindowPacket packet = (CClickWindowPacket) provPacket;
int slot = packet.func_149544_d();
if (slot == -999)
return false;
int id = packet.func_149548_c();
int mouseClick = packet.func_149543_e();
InventoryClickType type = InventoryClickType.valueOf(packet.func_186993_f().name());
Object container = gui.getContainer(player);
ItemStack item = asBukkitItem(packet.func_149546_g());
if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType().isAir()) && item.getType().isAir())
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(() -> ((RepairContainer) container).func_82846_b((PlayerEntity) getPlayer(player), slot));
}
return false;
}
use of net.minecraft.inventory.container.RepairContainer in project Magma-1.16.x by magmafoundation.
the class CraftContainer method setupSlots.
private void setupSlots(IInventory top, PlayerInventory bottom, PlayerEntity entityhuman) {
int windowId = -1;
switch(cachedType) {
case CREATIVE:
// TODO: This should be an error?
break;
case PLAYER:
case CHEST:
case ENDER_CHEST:
case BARREL:
delegate = new ChestContainer(ContainerType.GENERIC_9x3, windowId, bottom, top, top.getContainerSize() / 9);
break;
case DISPENSER:
case DROPPER:
delegate = new DispenserContainer(windowId, bottom, top);
break;
case FURNACE:
delegate = new FurnaceContainer(windowId, bottom, top, new IntArray(4));
break;
// TODO: This should be an error?
case CRAFTING:
case WORKBENCH:
// SPIGOT-3812 - manually set up slots so we can use the delegated inventory and not the automatically created one
setupWorkbench(top, bottom);
break;
case ENCHANTING:
delegate = new EnchantmentContainer(windowId, bottom);
break;
case BREWING:
delegate = new BrewingStandContainer(windowId, bottom, top, new IntArray(2));
break;
case HOPPER:
delegate = new HopperContainer(windowId, bottom, top);
break;
case ANVIL:
delegate = new RepairContainer(windowId, bottom);
break;
case SMITHING:
delegate = new SmokerContainer(windowId, bottom);
break;
case BEACON:
delegate = new BeaconContainer(windowId, bottom);
break;
case SHULKER_BOX:
delegate = new ShulkerBoxContainer(windowId, bottom, top);
break;
case BLAST_FURNACE:
delegate = new BlastFurnaceContainer(windowId, bottom, top, new IntArray(4));
break;
case LECTERN:
delegate = new LecternContainer(windowId, top, new IntArray(1), bottom);
break;
case SMOKER:
delegate = new SmokerContainer(windowId, bottom, top, new IntArray(4));
break;
case LOOM:
delegate = new LoomContainer(windowId, bottom);
break;
case CARTOGRAPHY:
delegate = new CartographyContainer(windowId, bottom);
break;
case GRINDSTONE:
delegate = new GrindstoneContainer(windowId, bottom);
break;
case STONECUTTER:
delegate = new StonecutterContainer(windowId, bottom);
break;
case MERCHANT:
delegate = new MerchantContainer(windowId, bottom);
break;
}
if (delegate != null) {
this.lastSlots = delegate.lastSlots;
this.slots = delegate.slots;
}
// SPIGOT-4598 - we should still delegate the shift click handler
if (cachedType == InventoryType.WORKBENCH) {
delegate = new WorkbenchContainer(windowId, bottom);
}
}
use of net.minecraft.inventory.container.RepairContainer in project Arclight by IzzelAliz.
the class RepairContainerMixin method updateRepairOutput.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void updateRepairOutput() {
ItemStack itemstack = this.inputSlots.getStackInSlot(0);
this.maximumCost.set(1);
int i = 0;
int j = 0;
int k = 0;
if (itemstack.isEmpty()) {
// this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY);
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY);
this.maximumCost.set(0);
} else {
ItemStack itemstack1 = itemstack.copy();
ItemStack itemstack2 = this.inputSlots.getStackInSlot(1);
Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(itemstack1);
j = j + itemstack.getRepairCost() + (itemstack2.isEmpty() ? 0 : itemstack2.getRepairCost());
this.materialCost = 0;
boolean flag = false;
if (!itemstack2.isEmpty()) {
if (!ForgeHooks.onAnvilChange((RepairContainer) (Object) this, itemstack, itemstack2, outputSlot, repairedItemName, j))
return;
flag = itemstack2.getItem() == Items.ENCHANTED_BOOK && !EnchantedBookItem.getEnchantments(itemstack2).isEmpty();
if (itemstack1.isDamageable() && itemstack1.getItem().getIsRepairable(itemstack, itemstack2)) {
int l2 = Math.min(itemstack1.getDamage(), itemstack1.getMaxDamage() / 4);
if (l2 <= 0) {
// this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY);
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY);
this.maximumCost.set(0);
return;
}
int i3;
for (i3 = 0; l2 > 0 && i3 < itemstack2.getCount(); ++i3) {
int j3 = itemstack1.getDamage() - l2;
itemstack1.setDamage(j3);
++i;
l2 = Math.min(itemstack1.getDamage(), itemstack1.getMaxDamage() / 4);
}
this.materialCost = i3;
} else {
if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.isDamageable())) {
// this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY);
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY);
this.maximumCost.set(0);
return;
}
if (itemstack1.isDamageable() && !flag) {
int l = itemstack.getMaxDamage() - itemstack.getDamage();
int i1 = itemstack2.getMaxDamage() - itemstack2.getDamage();
int j1 = i1 + itemstack1.getMaxDamage() * 12 / 100;
int k1 = l + j1;
int l1 = itemstack1.getMaxDamage() - k1;
if (l1 < 0) {
l1 = 0;
}
if (l1 < itemstack1.getDamage()) {
itemstack1.setDamage(l1);
i += 2;
}
}
Map<Enchantment, Integer> map1 = EnchantmentHelper.getEnchantments(itemstack2);
boolean flag2 = false;
boolean flag3 = false;
for (Enchantment enchantment1 : map1.keySet()) {
if (enchantment1 != null) {
int i2 = map.containsKey(enchantment1) ? map.get(enchantment1) : 0;
int j2 = map1.get(enchantment1);
j2 = i2 == j2 ? j2 + 1 : Math.max(j2, i2);
boolean flag1 = enchantment1.canApply(itemstack);
if (this.player.abilities.isCreativeMode || itemstack.getItem() == Items.ENCHANTED_BOOK) {
flag1 = true;
}
for (Enchantment enchantment : map.keySet()) {
if (enchantment != enchantment1 && !enchantment1.isCompatibleWith(enchantment)) {
flag1 = false;
++i;
}
}
if (!flag1) {
flag3 = true;
} else {
flag2 = true;
if (j2 > enchantment1.getMaxLevel()) {
j2 = enchantment1.getMaxLevel();
}
map.put(enchantment1, j2);
int k3 = 0;
switch(enchantment1.getRarity()) {
case COMMON:
k3 = 1;
break;
case UNCOMMON:
k3 = 2;
break;
case RARE:
k3 = 4;
break;
case VERY_RARE:
k3 = 8;
}
if (flag) {
k3 = Math.max(1, k3 / 2);
}
i += k3 * j2;
if (itemstack.getCount() > 1) {
i = 40;
}
}
}
}
if (flag3 && !flag2) {
// this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY);
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY);
this.maximumCost.set(0);
return;
}
}
}
if (StringUtils.isBlank(this.repairedItemName)) {
if (itemstack.hasDisplayName()) {
k = 1;
i += k;
itemstack1.clearCustomName();
}
} else if (!this.repairedItemName.equals(itemstack.getDisplayName().getString())) {
k = 1;
i += k;
itemstack1.setDisplayName(new StringTextComponent(this.repairedItemName));
}
if (flag && !itemstack1.isBookEnchantable(itemstack2))
itemstack1 = ItemStack.EMPTY;
this.maximumCost.set(j + i);
if (i <= 0) {
itemstack1 = ItemStack.EMPTY;
}
if (k == i && k > 0 && this.maximumCost.get() >= maximumRepairCost) {
this.maximumCost.set(maximumRepairCost - 1);
}
if (this.maximumCost.get() >= maximumRepairCost && !this.player.abilities.isCreativeMode) {
itemstack1 = ItemStack.EMPTY;
}
if (!itemstack1.isEmpty()) {
int k2 = itemstack1.getRepairCost();
if (!itemstack2.isEmpty() && k2 < itemstack2.getRepairCost()) {
k2 = itemstack2.getRepairCost();
}
if (k != i || k == 0) {
k2 = getNewRepairCost(k2);
}
itemstack1.setRepairCost(k2);
EnchantmentHelper.setEnchantments(map, itemstack1);
}
// this.outputSlot.setInventorySlotContents(0, itemstack1);
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1);
this.detectAndSendChanges();
}
}
Aggregations