mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-14 19:32:17 +01:00
Updated inventory types
This commit is contained in:
parent
930c222953
commit
d980b3f56c
@ -6,11 +6,28 @@ import net.minestom.server.inventory.InventoryType;
|
|||||||
|
|
||||||
public class AnvilInventory extends Inventory {
|
public class AnvilInventory extends Inventory {
|
||||||
|
|
||||||
|
private short repairCost;
|
||||||
|
|
||||||
public AnvilInventory(String title) {
|
public AnvilInventory(String title) {
|
||||||
super(InventoryType.ANVIL, title);
|
super(InventoryType.ANVIL, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the anvil repair cost
|
||||||
|
*
|
||||||
|
* @return the repair cost
|
||||||
|
*/
|
||||||
|
public short getRepairCost() {
|
||||||
|
return repairCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the anvil repair cost
|
||||||
|
*
|
||||||
|
* @param cost the new anvil repair cost
|
||||||
|
*/
|
||||||
public void setRepairCost(short cost) {
|
public void setRepairCost(short cost) {
|
||||||
|
this.repairCost = repairCost;
|
||||||
sendProperty(InventoryProperty.ANVIL_REPAIR_COST, cost);
|
sendProperty(InventoryProperty.ANVIL_REPAIR_COST, cost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,68 @@ import net.minestom.server.potion.PotionType;
|
|||||||
|
|
||||||
public class BeaconInventory extends Inventory {
|
public class BeaconInventory extends Inventory {
|
||||||
|
|
||||||
|
private short powerLevel;
|
||||||
|
private PotionType firstPotionEffect;
|
||||||
|
private PotionType secondPotionEffect;
|
||||||
|
|
||||||
public BeaconInventory(String title) {
|
public BeaconInventory(String title) {
|
||||||
super(InventoryType.BEACON, title);
|
super(InventoryType.BEACON, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the beacon power level
|
||||||
|
*
|
||||||
|
* @return the power level
|
||||||
|
*/
|
||||||
|
public short getPowerLevel() {
|
||||||
|
return powerLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the beacon power level
|
||||||
|
*
|
||||||
|
* @param powerLevel the new beacon power level
|
||||||
|
*/
|
||||||
public void setPowerLevel(short powerLevel) {
|
public void setPowerLevel(short powerLevel) {
|
||||||
|
this.powerLevel = powerLevel;
|
||||||
sendProperty(InventoryProperty.BEACON_POWER_LEVEL, powerLevel);
|
sendProperty(InventoryProperty.BEACON_POWER_LEVEL, powerLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the first potion effect
|
||||||
|
*
|
||||||
|
* @return the first potion effect, can be null
|
||||||
|
*/
|
||||||
|
public PotionType getFirstPotionEffect() {
|
||||||
|
return firstPotionEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the first potion effect
|
||||||
|
*
|
||||||
|
* @param firstPotionEffect the new first potion effect, can be null
|
||||||
|
*/
|
||||||
public void setFirstPotionEffect(PotionType firstPotionEffect) {
|
public void setFirstPotionEffect(PotionType firstPotionEffect) {
|
||||||
|
this.firstPotionEffect = firstPotionEffect;
|
||||||
sendProperty(InventoryProperty.BEACON_FIRST_POTION, (short) firstPotionEffect.getId());
|
sendProperty(InventoryProperty.BEACON_FIRST_POTION, (short) firstPotionEffect.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the second potion effect
|
||||||
|
*
|
||||||
|
* @return the second potion effect, can be null
|
||||||
|
*/
|
||||||
|
public PotionType getSecondPotionEffect() {
|
||||||
|
return secondPotionEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the second potion effect
|
||||||
|
*
|
||||||
|
* @param secondPotionEffect the new second potion effect, can be null
|
||||||
|
*/
|
||||||
public void setSecondPotionEffect(PotionType secondPotionEffect) {
|
public void setSecondPotionEffect(PotionType secondPotionEffect) {
|
||||||
|
this.secondPotionEffect = secondPotionEffect;
|
||||||
sendProperty(InventoryProperty.BEACON_SECOND_POTION, (short) secondPotionEffect.getId());
|
sendProperty(InventoryProperty.BEACON_SECOND_POTION, (short) secondPotionEffect.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,15 +6,48 @@ import net.minestom.server.inventory.InventoryType;
|
|||||||
|
|
||||||
public class BrewingStandInventory extends Inventory {
|
public class BrewingStandInventory extends Inventory {
|
||||||
|
|
||||||
|
private short brewTime;
|
||||||
|
private short fuelTime;
|
||||||
|
|
||||||
public BrewingStandInventory(String title) {
|
public BrewingStandInventory(String title) {
|
||||||
super(InventoryType.BREWING_STAND, title);
|
super(InventoryType.BREWING_STAND, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the brewing stand brew time
|
||||||
|
*
|
||||||
|
* @return the brew time in tick
|
||||||
|
*/
|
||||||
|
public short getBrewTime() {
|
||||||
|
return brewTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the brew time
|
||||||
|
*
|
||||||
|
* @param brewTime the new brew time in tick
|
||||||
|
*/
|
||||||
public void setBrewTime(short brewTime) {
|
public void setBrewTime(short brewTime) {
|
||||||
|
this.brewTime = brewTime;
|
||||||
sendProperty(InventoryProperty.BREWING_STAND_BREW_TIME, brewTime);
|
sendProperty(InventoryProperty.BREWING_STAND_BREW_TIME, brewTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the brewing stand fuel time
|
||||||
|
*
|
||||||
|
* @return the fuel time in tick
|
||||||
|
*/
|
||||||
|
public short getFuelTime() {
|
||||||
|
return fuelTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the fuel time
|
||||||
|
*
|
||||||
|
* @param fuelTime the new fuel time in tick
|
||||||
|
*/
|
||||||
public void setFuelTime(short fuelTime) {
|
public void setFuelTime(short fuelTime) {
|
||||||
|
this.fuelTime = fuelTime;
|
||||||
sendProperty(InventoryProperty.BREWING_STAND_FUEL_TIME, fuelTime);
|
sendProperty(InventoryProperty.BREWING_STAND_FUEL_TIME, fuelTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,143 @@
|
|||||||
package net.minestom.server.inventory.type;
|
package net.minestom.server.inventory.type;
|
||||||
|
|
||||||
import net.minestom.server.inventory.Inventory;
|
import net.minestom.server.inventory.Inventory;
|
||||||
|
import net.minestom.server.inventory.InventoryProperty;
|
||||||
import net.minestom.server.inventory.InventoryType;
|
import net.minestom.server.inventory.InventoryType;
|
||||||
|
import net.minestom.server.item.Enchantment;
|
||||||
|
|
||||||
public class EnchantmentTableInventory extends Inventory {
|
public class EnchantmentTableInventory extends Inventory {
|
||||||
|
|
||||||
|
private short[] levelRequirements = new short[EnchantmentSlot.values().length];
|
||||||
|
private short seed;
|
||||||
|
private short[] enchantmentShown = new short[EnchantmentSlot.values().length];
|
||||||
|
private short[] enchantmentLevel = new short[EnchantmentSlot.values().length];
|
||||||
|
|
||||||
public EnchantmentTableInventory(String title) {
|
public EnchantmentTableInventory(String title) {
|
||||||
super(InventoryType.ENCHANTMENT, title);
|
super(InventoryType.ENCHANTMENT, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the level requirement in a slot
|
||||||
|
*
|
||||||
|
* @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()];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the level requirement of a slot
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the enchantment seed
|
||||||
|
*
|
||||||
|
* @return the enchantment seed
|
||||||
|
*/
|
||||||
|
public short getSeed() {
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the enchantment seed
|
||||||
|
*
|
||||||
|
* @param seed the enchantment seed
|
||||||
|
*/
|
||||||
|
public void setSeed(short seed) {
|
||||||
|
this.seed = seed;
|
||||||
|
sendProperty(InventoryProperty.ENCHANTMENT_TABLE_SEED, seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the enchantment shown in a slot
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the enchantment shown in a slot
|
||||||
|
* <p>
|
||||||
|
* Can be set to null to hide it
|
||||||
|
*
|
||||||
|
* @param enchantmentSlot the enchantment slot
|
||||||
|
* @param enchantment the enchantment
|
||||||
|
*/
|
||||||
|
public void setEnchantmentShown(EnchantmentSlot enchantmentSlot, Enchantment enchantment) {
|
||||||
|
final short id = enchantment == null ? -1 : (short) enchantment.getId();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the enchantment level shown on mouse hover
|
||||||
|
*
|
||||||
|
* @param enchantmentSlot the enchantment slot
|
||||||
|
* @return the level shown, -1 if no enchant
|
||||||
|
*/
|
||||||
|
public short getEnchantmentLevel(EnchantmentSlot enchantmentSlot) {
|
||||||
|
return enchantmentLevel[enchantmentSlot.ordinal()];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the enchantment level shown on mouse hover
|
||||||
|
* <p>
|
||||||
|
* Can be set to -1 if no enchant
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,28 +6,58 @@ import net.minestom.server.inventory.InventoryType;
|
|||||||
|
|
||||||
public class FurnaceInventory extends Inventory {
|
public class FurnaceInventory extends Inventory {
|
||||||
|
|
||||||
|
private short remainingFuelTick;
|
||||||
|
private short maximumFuelBurnTime;
|
||||||
|
private short progressArrow;
|
||||||
|
private short maximumProgress;
|
||||||
|
|
||||||
public FurnaceInventory(String title) {
|
public FurnaceInventory(String title) {
|
||||||
super(InventoryType.FURNACE, title);
|
super(InventoryType.FURNACE, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represent the amount of tick until the fire icon come empty`
|
* Represent the amount of tick until the fire icon come empty
|
||||||
|
*
|
||||||
|
* @return the amount of tick until the fire icon come empty
|
||||||
|
*/
|
||||||
|
public short getRemainingFuelTick() {
|
||||||
|
return remainingFuelTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represent the amount of tick until the fire icon come empty
|
||||||
*
|
*
|
||||||
* @param remainingFuelTick
|
* @param remainingFuelTick
|
||||||
*/
|
*/
|
||||||
public void setRemainingFuelTick(short remainingFuelTick) {
|
public void setRemainingFuelTick(short remainingFuelTick) {
|
||||||
|
this.remainingFuelTick = remainingFuelTick;
|
||||||
sendProperty(InventoryProperty.FURNACE_FIRE_ICON, remainingFuelTick);
|
sendProperty(InventoryProperty.FURNACE_FIRE_ICON, remainingFuelTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public short getMaximumFuelBurnTime() {
|
||||||
|
return maximumFuelBurnTime;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMaximumFuelBurnTime(short maximumFuelBurnTime) {
|
public void setMaximumFuelBurnTime(short maximumFuelBurnTime) {
|
||||||
|
this.maximumFuelBurnTime = maximumFuelBurnTime;
|
||||||
sendProperty(InventoryProperty.FURNACE_MAXIMUM_FUEL_BURN_TIME, maximumFuelBurnTime);
|
sendProperty(InventoryProperty.FURNACE_MAXIMUM_FUEL_BURN_TIME, maximumFuelBurnTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public short getProgressArrow() {
|
||||||
|
return progressArrow;
|
||||||
|
}
|
||||||
|
|
||||||
public void setProgressArrow(short progressArrow) {
|
public void setProgressArrow(short progressArrow) {
|
||||||
|
this.progressArrow = progressArrow;
|
||||||
sendProperty(InventoryProperty.FURNACE_PROGRESS_ARROW, progressArrow);
|
sendProperty(InventoryProperty.FURNACE_PROGRESS_ARROW, progressArrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public short getMaximumProgress() {
|
||||||
|
return maximumProgress;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMaximumProgress(short maximumProgress) {
|
public void setMaximumProgress(short maximumProgress) {
|
||||||
|
this.maximumProgress = maximumProgress;
|
||||||
sendProperty(InventoryProperty.FURNACE_MAXIMUM_PROGRESS, maximumProgress);
|
sendProperty(InventoryProperty.FURNACE_MAXIMUM_PROGRESS, maximumProgress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class VillagerInventory extends Inventory {
|
|||||||
|
|
||||||
public void addTrade(TradeListPacket.Trade trade) {
|
public void addTrade(TradeListPacket.Trade trade) {
|
||||||
TradeListPacket.Trade[] oldTrades = getTrades();
|
TradeListPacket.Trade[] oldTrades = getTrades();
|
||||||
int length = oldTrades.length + 1;
|
final int length = oldTrades.length + 1;
|
||||||
TradeListPacket.Trade[] trades = new TradeListPacket.Trade[length];
|
TradeListPacket.Trade[] trades = new TradeListPacket.Trade[length];
|
||||||
System.arraycopy(oldTrades, 0, trades, 0, oldTrades.length);
|
System.arraycopy(oldTrades, 0, trades, 0, oldTrades.length);
|
||||||
trades[length] = trade;
|
trades[length] = trade;
|
||||||
@ -30,7 +30,7 @@ public class VillagerInventory extends Inventory {
|
|||||||
|
|
||||||
public void removeTrade(int index) {
|
public void removeTrade(int index) {
|
||||||
TradeListPacket.Trade[] oldTrades = getTrades();
|
TradeListPacket.Trade[] oldTrades = getTrades();
|
||||||
int length = oldTrades.length - 1;
|
final int length = oldTrades.length - 1;
|
||||||
TradeListPacket.Trade[] trades = new TradeListPacket.Trade[length];
|
TradeListPacket.Trade[] trades = new TradeListPacket.Trade[length];
|
||||||
ArrayUtils.removeElement(trades, index);
|
ArrayUtils.removeElement(trades, index);
|
||||||
this.tradeListPacket.trades = trades;
|
this.tradeListPacket.trades = trades;
|
||||||
|
Loading…
Reference in New Issue
Block a user