2020-04-29 17:27:58 +02:00
|
|
|
package net.minestom.server.inventory.type;
|
|
|
|
|
2021-06-30 01:19:17 +02:00
|
|
|
import net.kyori.adventure.text.Component;
|
2020-04-29 17:27:58 +02:00
|
|
|
import net.minestom.server.inventory.Inventory;
|
2020-08-01 10:33:06 +02:00
|
|
|
import net.minestom.server.inventory.InventoryProperty;
|
2020-04-29 17:27:58 +02:00
|
|
|
import net.minestom.server.inventory.InventoryType;
|
2020-08-01 10:33:06 +02:00
|
|
|
import net.minestom.server.item.Enchantment;
|
2021-06-30 01:19:17 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-04-29 17:27:58 +02:00
|
|
|
|
|
|
|
public class EnchantmentTableInventory extends Inventory {
|
|
|
|
|
2020-10-22 12:55:53 +02:00
|
|
|
private final short[] levelRequirements = new short[EnchantmentSlot.values().length];
|
2020-08-01 10:33:06 +02:00
|
|
|
private short seed;
|
2020-10-22 12:55:53 +02:00
|
|
|
private final short[] enchantmentShown = new short[EnchantmentSlot.values().length];
|
|
|
|
private final short[] enchantmentLevel = new short[EnchantmentSlot.values().length];
|
2020-08-01 10:33:06 +02:00
|
|
|
|
2021-06-30 01:19:17 +02:00
|
|
|
public EnchantmentTableInventory(@NotNull Component title) {
|
|
|
|
super(InventoryType.ENCHANTMENT, title);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EnchantmentTableInventory(@NotNull String title) {
|
2020-04-29 17:27:58 +02:00
|
|
|
super(InventoryType.ENCHANTMENT, title);
|
|
|
|
}
|
2020-08-01 10:33:06 +02:00
|
|
|
|
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Gets the level requirement in a slot.
|
2020-08-01 10:33:06 +02:00
|
|
|
*
|
|
|
|
* @param enchantmentSlot the slot to check the level requirement
|
|
|
|
* @return the level requirement of the slot
|
|
|
|
*/
|
|
|
|
public short getLevelRequirement(EnchantmentSlot enchantmentSlot) {
|
|
|
|
return levelRequirements[enchantmentSlot.ordinal()];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Sets the level requirement of a slot.
|
2020-08-01 10:33:06 +02:00
|
|
|
*
|
|
|
|
* @param enchantmentSlot the slot
|
|
|
|
* @param level the level
|
|
|
|
*/
|
|
|
|
public void setLevelRequirement(EnchantmentSlot enchantmentSlot, short level) {
|
|
|
|
switch (enchantmentSlot) {
|
|
|
|
case TOP:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_LEVEL_REQUIREMENT_TOP, level);
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_LEVEL_REQUIREMENT_MIDDLE, level);
|
|
|
|
break;
|
|
|
|
case BOTTOM:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_LEVEL_REQUIREMENT_BOTTOM, level);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.levelRequirements[enchantmentSlot.ordinal()] = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Gets the enchantment seed.
|
2020-08-01 10:33:06 +02:00
|
|
|
*
|
|
|
|
* @return the enchantment seed
|
|
|
|
*/
|
|
|
|
public short getSeed() {
|
|
|
|
return seed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Sets the enchantment seed.
|
2020-08-01 10:33:06 +02:00
|
|
|
*
|
|
|
|
* @param seed the enchantment seed
|
|
|
|
*/
|
|
|
|
public void setSeed(short seed) {
|
|
|
|
this.seed = seed;
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_SEED, seed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Gets the enchantment shown in a slot.
|
2020-08-01 10:33:06 +02:00
|
|
|
*
|
|
|
|
* @param enchantmentSlot the enchantment slot
|
|
|
|
* @return the enchantment shown in the slot, null if it is hidden
|
|
|
|
*/
|
|
|
|
public Enchantment getEnchantmentShown(EnchantmentSlot enchantmentSlot) {
|
|
|
|
final short id = enchantmentShown[enchantmentSlot.ordinal()];
|
|
|
|
if (id == -1)
|
|
|
|
return null;
|
|
|
|
return Enchantment.fromId(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Sets the enchantment shown in a slot.
|
2020-08-01 10:33:06 +02:00
|
|
|
* <p>
|
2020-10-15 21:16:31 +02:00
|
|
|
* Can be set to null to hide it.
|
2020-08-01 10:33:06 +02:00
|
|
|
*
|
|
|
|
* @param enchantmentSlot the enchantment slot
|
|
|
|
* @param enchantment the enchantment
|
|
|
|
*/
|
|
|
|
public void setEnchantmentShown(EnchantmentSlot enchantmentSlot, Enchantment enchantment) {
|
2021-07-28 13:27:49 +02:00
|
|
|
final short id = enchantment == null ? -1 : (short) enchantment.id();
|
2020-08-01 10:33:06 +02:00
|
|
|
switch (enchantmentSlot) {
|
|
|
|
case TOP:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_ENCH_ID_TOP, id);
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_ENCH_ID_MIDDLE, id);
|
|
|
|
break;
|
|
|
|
case BOTTOM:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_ENCH_ID_BOTTOM, id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.enchantmentShown[enchantmentSlot.ordinal()] = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Gets the enchantment level shown on mouse hover.
|
2020-08-01 10:33:06 +02:00
|
|
|
*
|
|
|
|
* @param enchantmentSlot the enchantment slot
|
|
|
|
* @return the level shown, -1 if no enchant
|
|
|
|
*/
|
|
|
|
public short getEnchantmentLevel(EnchantmentSlot enchantmentSlot) {
|
|
|
|
return enchantmentLevel[enchantmentSlot.ordinal()];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Sets the enchantment level shown on mouse hover.
|
2020-08-01 10:33:06 +02:00
|
|
|
* <p>
|
2020-10-15 21:16:31 +02:00
|
|
|
* Can be set to -1 if no enchant.
|
2020-08-01 10:33:06 +02:00
|
|
|
*
|
|
|
|
* @param enchantmentSlot the enchantment slot
|
|
|
|
* @param level the level shown
|
|
|
|
*/
|
|
|
|
public void setEnchantmentLevel(EnchantmentSlot enchantmentSlot, short level) {
|
|
|
|
switch (enchantmentSlot) {
|
|
|
|
case TOP:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_ENCH_LEVEL_TOP, level);
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_ENCH_LEVEL_MIDDLE, level);
|
|
|
|
break;
|
|
|
|
case BOTTOM:
|
|
|
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_ENCH_LEVEL_BOTTOM, level);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.enchantmentLevel[enchantmentSlot.ordinal()] = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum EnchantmentSlot {
|
|
|
|
TOP, MIDDLE, BOTTOM
|
|
|
|
}
|
|
|
|
|
2020-04-29 17:27:58 +02:00
|
|
|
}
|