Skip to content

Commit

Permalink
Upgrade minestom
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Sep 26, 2024
1 parent 880e8f2 commit 69387b9
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 90 deletions.
2 changes: 1 addition & 1 deletion minestom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(21)

dependencies {
api project(':common')
compileOnly 'com.github.Minestom:Minestom:e63c9def24'
compileOnly 'com.github.Minestom:Minestom:d0754f2a15'
// https://mvnrepository.com/artifact/dev.hollowcube/minestom-ce-extensions
compileOnly 'dev.hollowcube:minestom-ce-extensions:1.2.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
import com.elikill58.negativity.api.item.Material;
import com.elikill58.negativity.minestom.impl.item.MinestomItemStack;

import net.minestom.server.inventory.ContainerInventory;
import net.minestom.server.inventory.PlayerInventory;

public class MinestomInventory extends Inventory {

private net.minestom.server.inventory.Inventory inv;
Expand All @@ -28,62 +25,58 @@ public MinestomInventory(String inventoryName, int size, NegativityHolder holder
net.minestom.server.inventory.InventoryType type = net.minestom.server.inventory.InventoryType.CHEST_6_ROW;
if(size % 9 == 0)
type = net.minestom.server.inventory.InventoryType.valueOf("CHEST_" + (size / 9) + "_ROW");
this.inv = new net.minestom.server.inventory.ContainerInventory(type, inventoryName);
this.inv = new net.minestom.server.inventory.Inventory(type, inventoryName);
this.holder = holder;
HolderById.add(inv.getWindowId(), holder);
}

@Override
public InventoryType getType() {
if(inv instanceof PlayerInventory)
switch(inv.getInventoryType()) {
case ANVIL:
return InventoryType.ANVIL;
case BEACON:
return InventoryType.BEACON;
case BLAST_FURNACE:
return InventoryType.BLAST_FURNACE;
case BREWING_STAND:
return InventoryType.BREWING;
case CARTOGRAPHY:
return InventoryType.CARTOGRAPHY;
case CHEST_1_ROW:
case CHEST_2_ROW:
case CHEST_3_ROW:
case CHEST_4_ROW:
case CHEST_5_ROW:
case CHEST_6_ROW:
return InventoryType.CHEST;
case CRAFTING:
return InventoryType.CRAFTING;
case ENCHANTMENT:
return InventoryType.ENCHANTING;
case FURNACE:
return InventoryType.FURNACE;
case GRINDSTONE:
return InventoryType.GRINDSTONE;
case HOPPER:
return InventoryType.HOPPER;
case LECTERN:
return InventoryType.LECTERN;
case LOOM:
return InventoryType.LOOM;
case MERCHANT:
return InventoryType.MERCHANT;
case SHULKER_BOX:
return InventoryType.SHULKER_BOX;
case SMITHING:
return InventoryType.SMITHING;
case SMOKER:
return InventoryType.SMOKER;
case STONE_CUTTER:
return InventoryType.STONECUTTER;
case CRAFTER_3X3:
case WINDOW_3X3:
return InventoryType.PLAYER;
if(inv instanceof ContainerInventory ci) {
switch(ci.getInventoryType()) {
case ANVIL:
return InventoryType.ANVIL;
case BEACON:
return InventoryType.BEACON;
case BLAST_FURNACE:
return InventoryType.BLAST_FURNACE;
case BREWING_STAND:
return InventoryType.BREWING;
case CARTOGRAPHY:
return InventoryType.CARTOGRAPHY;
case CHEST_1_ROW:
case CHEST_2_ROW:
case CHEST_3_ROW:
case CHEST_4_ROW:
case CHEST_5_ROW:
case CHEST_6_ROW:
return InventoryType.CHEST;
case CRAFTING:
return InventoryType.CRAFTING;
case ENCHANTMENT:
return InventoryType.ENCHANTING;
case FURNACE:
return InventoryType.FURNACE;
case GRINDSTONE:
return InventoryType.GRINDSTONE;
case HOPPER:
return InventoryType.HOPPER;
case LECTERN:
return InventoryType.LECTERN;
case LOOM:
return InventoryType.LOOM;
case MERCHANT:
return InventoryType.MERCHANT;
case SHULKER_BOX:
return InventoryType.SHULKER_BOX;
case SMITHING:
return InventoryType.SMITHING;
case SMOKER:
return InventoryType.SMOKER;
case STONE_CUTTER:
return InventoryType.STONECUTTER;
case CRAFTER_3X3:
case WINDOW_3X3:
return InventoryType.PLAYER;
}
}
return InventoryType.CHEST;
}
Expand Down Expand Up @@ -120,9 +113,7 @@ public int getSize() {

@Override
public String getInventoryName() {
if(inv instanceof ContainerInventory ci)
return ci.getTitle().examinableName();
return null;
return inv.getTitle().examinableName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public MinestomPlayerInventory(Player p) {
}

private Optional<ItemStack> getArmorItem(EquipmentSlot slot) {
net.minestom.server.item.ItemStack i = inv.getEquipment(slot, slot.armorSlot());
net.minestom.server.item.ItemStack i = inv.getEquipment(slot);
return i == null || i.material().equals(net.minestom.server.item.Material.AIR) ? Optional.empty() : Optional.of(new MinestomItemStack(i));
}

Expand All @@ -46,9 +46,9 @@ public ItemStack[] getArmorContent() {
@Override
public void setArmorContent(ItemStack[] items) {
setHelmet(items[0]);
setChestplate(items[0]);
setLegging(items[0]);
setBoot(items[0]);
setChestplate(items[1]);
setLegging(items[2]);
setBoot(items[3]);
}

@Override
Expand Down Expand Up @@ -107,7 +107,7 @@ public Object getDefault() {
}

private void setArmorItem(EquipmentSlot slot, ItemStack item) {
inv.setEquipment(slot, slot.armorSlot(), (net.minestom.server.item.@NotNull ItemStack) item.getDefault());
inv.setEquipment(slot, (net.minestom.server.item.@NotNull ItemStack) item.getDefault());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,93 @@
package com.elikill58.negativity.minestom.impl.item;

import com.elikill58.negativity.api.item.Enchantment;
import org.jetbrains.annotations.NotNull;

import net.minestom.server.item.enchant.Enchantment;
import net.minestom.server.registry.DynamicRegistry;

public class MinestomEnchants {

public static net.minestom.server.item.enchant.Enchantment getEnchant(Enchantment enchant) {
return net.minestom.server.item.enchant.Enchantment.fromNamespaceId(enchant.getId());
public static @NotNull DynamicRegistry.Key<Enchantment> getEnchant(com.elikill58.negativity.api.item.Enchantment enchant) {
switch (enchant) {
case AQUA_AFFINITY:
return Enchantment.AQUA_AFFINITY;
case BANE_OF_ARTHROPODS:
return Enchantment.BANE_OF_ARTHROPODS;
case BINDING_CURSE:
return Enchantment.BINDING_CURSE;
case BLAST_PROTECTION:
return Enchantment.BLAST_PROTECTION;
case CHANNELING:
return Enchantment.CHANNELING;
case DEPTH_STRIDER:
return Enchantment.DEPTH_STRIDER;
case EFFICIENCY:
return Enchantment.EFFICIENCY;
case FEATHER_FALLING:
return Enchantment.FEATHER_FALLING;
case FIRE_ASPECT:
return Enchantment.FIRE_ASPECT;
case FIRE_PROTECTION:
return Enchantment.FIRE_PROTECTION;
case FLAME:
return Enchantment.FLAME;
case FORTUNE:
return Enchantment.FORTUNE;
case FROST_WALKER:
return Enchantment.FROST_WALKER;
case IMPALING:
return Enchantment.IMPALING;
case INFINITY:
return Enchantment.INFINITY;
case KNOCKBACK:
return Enchantment.KNOCKBACK;
case LOOTING:
return Enchantment.LOOTING;
case LOYALTY:
return Enchantment.LOYALTY;
case LUCK_OF_THE_SEA:
return Enchantment.LUCK_OF_THE_SEA;
case LURE:
return Enchantment.LURE;
case MENDING:
return Enchantment.MENDING;
case MULTISHOT:
return Enchantment.MULTISHOT;
case PIERCING:
return Enchantment.PIERCING;
case POWER:
return Enchantment.POWER;
case PROJECTILE_PROTECTION:
return Enchantment.PROJECTILE_PROTECTION;
case PROTECTION:
return Enchantment.PROTECTION;
case PUNCH:
return Enchantment.PUNCH;
case QUICK_CHARGE:
return Enchantment.QUICK_CHARGE;
case RESPIRATION:
return Enchantment.RESPIRATION;
case RIPTIDE:
return Enchantment.RIPTIDE;
case SHARPNESS:
return Enchantment.SHARPNESS;
case SILK_TOUCH:
return Enchantment.SILK_TOUCH;
case SMITE:
return Enchantment.SMITE;
case SOUL_SPEED:
return Enchantment.SOUL_SPEED;
case SWEEPING:
return Enchantment.SWEEPING_EDGE;
case SWIFT_SNEAK:
return Enchantment.SWIFT_SNEAK;
case THORNS:
return Enchantment.THORNS;
case UNBREAKING:
return Enchantment.UNBREAKING;
case VANISHING_CURSE:
return Enchantment.VANISHING_CURSE;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minestom.server.item.component.EnchantmentList;
import net.minestom.server.item.component.HeadProfile;
import net.minestom.server.item.component.Unbreakable;
import net.minestom.server.registry.DynamicRegistry;

public class MinestomItemBuilder extends ItemBuilder {

Expand All @@ -30,7 +31,7 @@ public class MinestomItemBuilder extends ItemBuilder {
public MinestomItemBuilder(ItemStack def) {
net.minestom.server.item.ItemStack i = (net.minestom.server.item.ItemStack) def.getDefault();
this.item = net.minestom.server.item.ItemStack.builder(i.material());
for(DataComponent dc : DataComponent.values()) {
for(DataComponent dc : ItemComponent.values()) {
Object obj = i.get(dc);
if(obj != null)
this.item.set(dc, obj);
Expand Down Expand Up @@ -65,7 +66,7 @@ public ItemBuilder unenchant(Enchantment enchantment) {

@Override
public ItemBuilder enchant(Enchantment enchantment, int level) {
Map<net.minestom.server.item.enchant.Enchantment, Integer> enchantments = new HashMap<>();
Map<DynamicRegistry.Key<net.minestom.server.item.enchant.Enchantment>, Integer> enchantments = new HashMap<>();
enchantments.put(MinestomEnchants.getEnchant(enchantment), level);
item.set(ItemComponent.ENCHANTMENTS, new EnchantmentList(enchantments, false));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public Difficulty getDifficulty() {

@Override
public int getMaxHeight() {
return w.getDimensionType().getMaxY();
return w.getCachedDimensionType().maxY();
}

@Override
public int getMinHeight() {
return w.getDimensionType().getMinY();
return w.getCachedDimensionType().minY();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.minestom.server.event.Event;
import net.minestom.server.event.EventNode;
import net.minestom.server.event.inventory.InventoryCloseEvent;
import net.minestom.server.inventory.click.Click;
import net.minestom.server.inventory.click.ClickType;

public class InventoryListeners {

Expand All @@ -30,33 +30,44 @@ public void onInventoryOpen(net.minestom.server.event.inventory.InventoryOpenEve
}

public void onInventoryClick(net.minestom.server.event.inventory.InventoryClickEvent e) {
if(e.getInventory() == null || e.getChanges().isEmpty())
if(e.getInventory() == null || e.getClickedItem() == null)
return;
e.getChanges().forEach(c -> {
if(c instanceof Click.Change.Container cc)
EventManager.callEvent(new InventoryClickEvent(MinestomEntityManager.getPlayer(e.getPlayer()), getAction(e.getClickInfo()), cc.slot(), new MinestomItemStack(cc.item()), new MinestomInventory(e.getInventory())));
if(c instanceof Click.Change.Player cc)
EventManager.callEvent(new InventoryClickEvent(MinestomEntityManager.getPlayer(e.getPlayer()), getAction(e.getClickInfo()), cc.slot(), new MinestomItemStack(cc.item()), new MinestomInventory(e.getInventory())));
});
EventManager.callEvent(new InventoryClickEvent(MinestomEntityManager.getPlayer(e.getPlayer()), getAction(e.getClickType()), e.getSlot(), new MinestomItemStack(e.getClickedItem()), new MinestomInventory(e.getInventory())));
}

private InventoryAction getAction(Click.Info type) {
if(type instanceof Click.Info.DropSlot)
return InventoryAction.DROP;
if(type instanceof Click.Info.Double)
private InventoryAction getAction(ClickType type) {
switch(type) {
case CHANGE_HELD:
break;
case DOUBLE_CLICK:
return InventoryAction.DOUBLE;
if(type instanceof Click.Info.Right)
return InventoryAction.RIGHT;
if(type instanceof Click.Info.Left)
case DROP:
return InventoryAction.DROP;
case END_LEFT_DRAGGING:
break;
case END_RIGHT_DRAGGING:
break;
case LEFT_CLICK:
return InventoryAction.LEFT;
if(type instanceof Click.Info.RightShift)
return InventoryAction.RIGHT_SHIFT;
if(type instanceof Click.Info.LeftShift)
case LEFT_DRAGGING:
break;
case RIGHT_CLICK:
return InventoryAction.RIGHT;
case RIGHT_DRAGGING:
break;
case SHIFT_CLICK:
return InventoryAction.LEFT_SHIFT;
if(type instanceof Click.Info.CreativeDropItem || type instanceof Click.Info.CreativeSetItem)
return InventoryAction.CREATIVE;
if(type instanceof Click.Info.Middle || type instanceof Click.Info.MiddleDrag || type instanceof Click.Info.MiddleDropCursor)
return InventoryAction.MIDDLE;
case START_DOUBLE_CLICK:
break;
case START_LEFT_DRAGGING:
break;
case START_RIGHT_DRAGGING:
break;
case START_SHIFT_CLICK:
break;
default:
break;
}
return InventoryAction.UNKNOWN;
}

Expand Down

0 comments on commit 69387b9

Please sign in to comment.