add magic command, fix arg parser single digit negative numbers getting interpreted as flags

This commit is contained in:
Sen 2025-06-17 11:41:25 +02:00
parent f7bb1b0fe7
commit f579eee88b
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
26 changed files with 142 additions and 63 deletions

View file

@ -10,26 +10,23 @@ import common.entity.DamageSource;
import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.item.ItemStack;
import common.util.Displayable;
import common.util.Identifyable;
public abstract class Enchantment
public abstract class Enchantment implements Displayable, Identifyable
{
private static final String[] LEVELS = new String[] {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};
private static final Enchantment[] enchantmentsList = new Enchantment[256];
public static final Enchantment[] enchantmentsBookList;
private static final Map<String, Enchantment> locationEnchantments = Maps.<String, Enchantment>newHashMap();
private static final Enchantment[] LOOKUP = new Enchantment[256];
public static final Enchantment[] ENCHANTMENTS;
private static final Map<String, Enchantment> NAME_LOOKUP = Maps.<String, Enchantment>newHashMap();
public static final Enchantment protection = new EnchantmentProtection(0, "protection", 10, 0);
public static final Enchantment fireProtection = new EnchantmentProtection(1, "fire_protection", 5, 1);
public static final Enchantment featherFalling = new EnchantmentProtection(2, "feather_falling", 5, 2);
public static final Enchantment blastProtection = new EnchantmentProtection(3, "blast_protection", 2, 3);
public static final Enchantment projectileProtection = new EnchantmentProtection(4, "projectile_protection", 5, 4);
// public static final Enchantment respiration = new EnchantmentOxygen(5, "respiration", 2);
// public static final Enchantment aquaAffinity = new EnchantmentWaterWorker(6, "aqua_affinity", 2);
public static final Enchantment thorns = new EnchantmentThorns(7, "thorns", 1);
// public static final Enchantment depthStrider = new EnchantmentWaterWalker(8, "depth_strider", 2);
public static final Enchantment sharpness = new EnchantmentDamage(16, "sharpness", 10);
// public static final Enchantment smite = new EnchantmentDamage(17, "smite", 5, 1);
// public static final Enchantment baneOfArthropods = new EnchantmentDamage(18, "bane_of_arthropods", 5, 2);
public static final Enchantment knockback = new EnchantmentKnockback(19, "knockback", 5);
public static final Enchantment fireAspect = new EnchantmentFireAspect(20, "fire_aspect", 2);
public static final Enchantment looting = new EnchantmentLootBonus(21, "looting", 2, EnumEnchantmentType.WEAPON);
@ -43,40 +40,35 @@ public abstract class Enchantment
public static final Enchantment infinity = new EnchantmentArrowInfinite(51, "infinity", 1);
public static final Enchantment luckOfTheSea = new EnchantmentLootBonus(61, "luck_of_the_sea", 2, EnumEnchantmentType.FISHING_ROD);
public static final Enchantment lure = new EnchantmentFishingSpeed(62, "lure", 2, EnumEnchantmentType.FISHING_ROD);
public static final Enchantment draining = new EnchantmentDraining(64, "draining", 1);
public final int effectId;
private final String id;
private final int weight;
/** The EnumEnchantmentType given to this Enchantment. */
public EnumEnchantmentType type;
/** Used in localisation and stats. */
protected String name;
/**
* Retrieves an Enchantment from the enchantmentsList
*/
public static Enchantment getEnchantmentById(int enchID)
{
return enchID >= 0 && enchID < enchantmentsList.length ? enchantmentsList[enchID] : null;
return enchID >= 0 && enchID < LOOKUP.length ? LOOKUP[enchID] : null;
}
protected Enchantment(int enchID, String enchName, int enchWeight, EnumEnchantmentType enchType)
{
this.effectId = enchID;
this.id = enchName;
this.weight = enchWeight;
this.type = enchType;
if (enchantmentsList[enchID] != null)
if (LOOKUP[enchID] != null)
{
throw new IllegalArgumentException("Duplicate enchantment id!");
}
else
{
enchantmentsList[enchID] = this;
locationEnchantments.put(enchName, this);
LOOKUP[enchID] = this;
NAME_LOOKUP.put(enchName, this);
}
}
@ -85,12 +77,12 @@ public abstract class Enchantment
*/
public static Enchantment getEnchantmentByLocation(String location)
{
return locationEnchantments.get(location);
return NAME_LOOKUP.get(location);
}
public static Set<String> getNames()
{
return locationEnchantments.keySet();
return NAME_LOOKUP.keySet();
}
/**
@ -159,26 +151,27 @@ public abstract class Enchantment
return this != ench;
}
/**
* Sets the enchantment name
*/
public Enchantment setName(String enchName)
public Enchantment setDisplay(String enchName)
{
this.name = enchName;
return this;
}
public final String getName() {
return this.id;
}
/**
* Return the name of key of this enchantment.
*/
public String getName()
public String getDisplay()
{
return this.name;
}
public String getFormattedName(int level)
{
return this.getName() + " " + ((level >= 1 && level <= 10) ? LEVELS[level - 1] : "" + level);
return this.getDisplay() + " " + ((level >= 1 && level <= LEVELS.length) ? LEVELS[level - 1] : "" + level);
}
/**
@ -208,7 +201,7 @@ public abstract class Enchantment
{
List<Enchantment> list = Lists.<Enchantment>newArrayList();
for (Enchantment enchantment : enchantmentsList)
for (Enchantment enchantment : LOOKUP)
{
if (enchantment != null)
{
@ -216,6 +209,6 @@ public abstract class Enchantment
}
}
enchantmentsBookList = (Enchantment[])list.toArray(new Enchantment[list.size()]);
ENCHANTMENTS = (Enchantment[])list.toArray(new Enchantment[list.size()]);
}
}

View file

@ -7,7 +7,7 @@ public class EnchantmentArrowDamage extends Enchantment
public EnchantmentArrowDamage(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BOW);
this.setName("Stärke");
this.setDisplay("Stärke");
}
/**

View file

@ -7,7 +7,7 @@ public class EnchantmentArrowFire extends Enchantment
public EnchantmentArrowFire(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BOW);
this.setName("Flamme");
this.setDisplay("Flamme");
}
/**

View file

@ -7,7 +7,7 @@ public class EnchantmentArrowInfinite extends Enchantment
public EnchantmentArrowInfinite(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BOW);
this.setName("Unendlich");
this.setDisplay("Unendlich");
}
/**

View file

@ -7,7 +7,7 @@ public class EnchantmentArrowKnockback extends Enchantment
public EnchantmentArrowKnockback(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BOW);
this.setName("Schlag");
this.setDisplay("Schlag");
}
/**

View file

@ -9,7 +9,7 @@ public class EnchantmentDamage extends Enchantment
public EnchantmentDamage(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.WEAPON);
this.setName("Schärfe");
this.setDisplay("Schärfe");
}
/**

View file

@ -9,7 +9,7 @@ public class EnchantmentDigging extends Enchantment
protected EnchantmentDigging(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.DIGGER);
this.setName("Effizienz");
this.setDisplay("Effizienz");
}
/**

View file

@ -10,7 +10,7 @@ import common.item.ItemStack;
public class EnchantmentDraining extends Enchantment {
public EnchantmentDraining(int enchID, String enchName, int enchWeight) {
super(enchID, enchName, enchWeight, EnumEnchantmentType.WEAPON);
this.setName("Seelenentzug");
this.setDisplay("Seelenentzug");
}
public int getMinEnchantability(int enchantmentLevel) {

View file

@ -10,7 +10,7 @@ public class EnchantmentDurability extends Enchantment
protected EnchantmentDurability(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BREAKABLE);
this.setName("Haltbarkeit");
this.setDisplay("Haltbarkeit");
}
/**

View file

@ -7,7 +7,7 @@ public class EnchantmentFireAspect extends Enchantment
protected EnchantmentFireAspect(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.WEAPON);
this.setName("Verbrennung");
this.setDisplay("Verbrennung");
}
/**

View file

@ -7,7 +7,7 @@ public class EnchantmentFishingSpeed extends Enchantment
protected EnchantmentFishingSpeed(int enchID, String enchName, int enchWeight, EnumEnchantmentType enchType)
{
super(enchID, enchName, enchWeight, enchType);
this.setName("Köder");
this.setDisplay("Köder");
}
/**

View file

@ -483,7 +483,7 @@ public class EnchantmentHelper
Map<Integer, RngEnchantment> map = null;
boolean flag = p_77505_1_.getItem() == Items.book;
for (Enchantment enchantment : Enchantment.enchantmentsBookList)
for (Enchantment enchantment : Enchantment.ENCHANTMENTS)
{
if (enchantment != null && (enchantment.type.canEnchantItem(item) || flag))
{

View file

@ -7,7 +7,7 @@ public class EnchantmentKnockback extends Enchantment
protected EnchantmentKnockback(int p_i45768_1_, String p_i45768_2_, int p_i45768_3_)
{
super(p_i45768_1_, p_i45768_2_, p_i45768_3_, EnumEnchantmentType.WEAPON);
this.setName("Rückstoß");
this.setDisplay("Rückstoß");
}
/**

View file

@ -10,15 +10,15 @@ public class EnchantmentLootBonus extends Enchantment
if (p_i45767_4_ == EnumEnchantmentType.DIGGER)
{
this.setName("Glück");
this.setDisplay("Glück");
}
else if (p_i45767_4_ == EnumEnchantmentType.FISHING_ROD)
{
this.setName("Glück des Meeres");
this.setDisplay("Glück des Meeres");
}
else
{
this.setName("Plünderung");
this.setDisplay("Plünderung");
}
}

View file

@ -33,13 +33,8 @@ public class EnchantmentProtection extends Enchantment
public EnchantmentProtection(int id, String name, int weight, int type)
{
super(id, name, weight, EnumEnchantmentType.ARMOR);
super(id, name, weight, type == 2 ? EnumEnchantmentType.ARMOR_FEET : EnumEnchantmentType.ARMOR);
this.protectionType = type;
if (type == 2)
{
this.type = EnumEnchantmentType.ARMOR_FEET;
}
}
/**
@ -82,7 +77,7 @@ public class EnchantmentProtection extends Enchantment
}
}
public String getName()
public String getDisplay()
{
return NAMES[this.protectionType];
}

View file

@ -13,7 +13,7 @@ public class EnchantmentThorns extends Enchantment
public EnchantmentThorns(int p_i45764_1_, String p_i45764_2_, int p_i45764_3_)
{
super(p_i45764_1_, p_i45764_2_, p_i45764_3_, EnumEnchantmentType.ARMOR_TORSO);
this.setName("Dornen");
this.setDisplay("Dornen");
}
/**

View file

@ -9,7 +9,7 @@ public class EnchantmentUntouching extends Enchantment
protected EnchantmentUntouching(int p_i45763_1_, String p_i45763_2_, int p_i45763_3_)
{
super(p_i45763_1_, p_i45763_2_, p_i45763_3_, EnumEnchantmentType.DIGGER);
this.setName("Behutsamkeit");
this.setDisplay("Behutsamkeit");
}
/**

View file

@ -179,7 +179,7 @@ public abstract class TradeRegistry {
static class BookForGem implements ITradeList {
public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random) {
Enchantment enchantment = random.pick(Enchantment.enchantmentsBookList);
Enchantment enchantment = random.pick(Enchantment.ENCHANTMENTS);
int i = random.range(enchantment.getMinLevel(), enchantment.getMaxLevel());
ItemStack itemstack = Items.enchanted_book.getEnchantedItemStack(new RngEnchantment(enchantment, i));
int j = 2 + random.zrange(5 + i * 10) + 3 * i;

View file

@ -34,7 +34,7 @@ public class ItemEnchantedBook extends Item
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
{
for (Enchantment enchantment : Enchantment.enchantmentsBookList) {
for (Enchantment enchantment : Enchantment.ENCHANTMENTS) {
if(enchantment != null && enchantment.type != null)
subItems.add(Items.enchanted_book.getEnchantedItemStack(new RngEnchantment(enchantment, enchantment.getMaxLevel())));
}