9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-20 15:39:31 +00:00

Merge pull request #856 from VolmitSoftware/Development

Development
This commit is contained in:
Brian Fopiano
2022-08-16 13:06:00 -07:00
committed by GitHub
5 changed files with 139 additions and 199 deletions

View File

@@ -24,7 +24,7 @@ plugins {
id "de.undercouch.download" version "5.0.1" id "de.undercouch.download" version "5.0.1"
} }
version '2.2.9-1.19.2' // Needs to be version specific version '2.2.10-1.19.2' // Needs to be version specific
def nmsVersion = "1.19.2" def nmsVersion = "1.19.2"
def apiVersion = '1.19' def apiVersion = '1.19'
def spigotJarVersion = '1.19.1-R0.1-SNAPSHOT' def spigotJarVersion = '1.19.1-R0.1-SNAPSHOT'
@@ -38,7 +38,7 @@ registerCustomOutputTask('Psycho', 'D://Dan/MinecraftDevelopment/server/plugins'
registerCustomOutputTask('ArcaneArts', 'C://Users/arcane/Documents/development/server/plugins') registerCustomOutputTask('ArcaneArts', 'C://Users/arcane/Documents/development/server/plugins')
registerCustomOutputTask('Coco', 'D://Documents/MC/plugins') registerCustomOutputTask('Coco', 'D://Documents/MC/plugins')
registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins') registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins')
registerCustomOutputTask('Vatuu', 'D://Minecraft/Servers/1.19.1/plugins') registerCustomOutputTask('Vatuu', 'D://Minecraft/Servers/1.19.2/plugins')
// ========================== UNIX ============================== // ========================== UNIX ==============================
registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/development/server/plugins') registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/development/server/plugins')
registerCustomOutputTaskUnix('PsychoLT', '/Users/brianfopiano/Desktop/REMOTES/RemoteMinecraft/plugins') registerCustomOutputTaskUnix('PsychoLT', '/Users/brianfopiano/Desktop/REMOTES/RemoteMinecraft/plugins')

View File

@@ -22,17 +22,7 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.core.loader.IrisRegistrant;
import com.volmit.iris.core.loader.ResourceLoader; import com.volmit.iris.core.loader.ResourceLoader;
import com.volmit.iris.engine.object.annotations.ArrayType; import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.engine.object.annotations.MaxNumber;
import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.RegistryListBlockType;
import com.volmit.iris.engine.object.annotations.RegistryListFont;
import com.volmit.iris.engine.object.annotations.RegistryListItemType;
import com.volmit.iris.engine.object.annotations.RegistryListResource;
import com.volmit.iris.engine.object.annotations.RegistryListSpecialEntity;
import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.data.B; import com.volmit.iris.util.data.B;
@@ -52,7 +42,7 @@ public class SchemaBuilder {
private static final String SYMBOL_LIMIT__N = "*"; private static final String SYMBOL_LIMIT__N = "*";
private static final String SYMBOL_TYPE__N = ""; private static final String SYMBOL_TYPE__N = "";
private static final JSONArray POTION_TYPES = getPotionTypes(); private static final JSONArray POTION_TYPES = getPotionTypes();
private static final JSONArray ENCHANT_TYPES = getEnchantmentTypes(); private static final JSONArray ENCHANT_TYPES = getEnchantTypes();
private static final JSONArray ITEM_TYPES = new JSONArray(B.getItemTypes()); private static final JSONArray ITEM_TYPES = new JSONArray(B.getItemTypes());
private static final JSONArray FONT_TYPES = new JSONArray(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); private static final JSONArray FONT_TYPES = new JSONArray(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
private final KMap<String, JSONObject> definitions; private final KMap<String, JSONObject> definitions;
@@ -67,16 +57,6 @@ public class SchemaBuilder {
this.root = root; this.root = root;
} }
private static JSONArray getEnchantmentTypes() {
JSONArray a = new JSONArray();
for(Field gg : Enchantment.class.getDeclaredFields()) {
a.put(gg.getName());
}
return a;
}
private static JSONArray getPotionTypes() { private static JSONArray getPotionTypes() {
JSONArray a = new JSONArray(); JSONArray a = new JSONArray();
@@ -87,6 +67,14 @@ public class SchemaBuilder {
return a; return a;
} }
private static JSONArray getEnchantTypes() {
JSONArray array = new JSONArray();
for(Enchantment e : Enchantment.values()) {
array.put(e.getKey().getKey());
}
return array;
}
public JSONObject construct() { public JSONObject construct() {
JSONObject schema = new JSONObject(); JSONObject schema = new JSONObject();
schema.put("$schema", "http://json-schema.org/draft-07/schema#"); schema.put("$schema", "http://json-schema.org/draft-07/schema#");
@@ -309,7 +297,7 @@ public class SchemaBuilder {
prop.put("$ref", "#/definitions/" + key); prop.put("$ref", "#/definitions/" + key);
description.add(SYMBOL_TYPE__N + " Must be a valid Font Family (use ctrl+space for auto complete!)"); description.add(SYMBOL_TYPE__N + " Must be a valid Font Family (use ctrl+space for auto complete!)");
} else if(k.getType().equals(Enchantment.class)) { } else if(k.isAnnotationPresent(RegistryListEnchantment.class)) {
String key = "enum-enchantment"; String key = "enum-enchantment";
if(!definitions.containsKey(key)) { if(!definitions.containsKey(key)) {
@@ -483,7 +471,7 @@ public class SchemaBuilder {
items.put("$ref", "#/definitions/" + key); items.put("$ref", "#/definitions/" + key);
prop.put("items", items); prop.put("items", items);
description.add(SYMBOL_TYPE__N + " Must be a valid Font Family (use ctrl+space for auto complete!)"); description.add(SYMBOL_TYPE__N + " Must be a valid Font Family (use ctrl+space for auto complete!)");
} else if(t.type().equals(Enchantment.class)) { } else if(k.isAnnotationPresent(RegistryListEnchantment.class)) {
fancyType = "List of Enchantment Types"; fancyType = "List of Enchantment Types";
String key = "enum-enchantment"; String key = "enum-enchantment";

View File

@@ -19,21 +19,17 @@
package com.volmit.iris.engine.object; package com.volmit.iris.engine.object;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.annotations.Desc; import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.engine.object.annotations.MaxNumber;
import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.lang.reflect.Field;
@Snippet("enchantment") @Snippet("enchantment")
@Accessors(chain = true) @Accessors(chain = true)
@@ -43,8 +39,9 @@ import java.lang.reflect.Field;
@Data @Data
public class IrisEnchantment { public class IrisEnchantment {
@Required @Required
@RegistryListEnchantment
@Desc("The enchantment") @Desc("The enchantment")
private String enchantment = ""; private String enchantment;
@MinNumber(1) @MinNumber(1)
@Desc("Minimum amount of this loot") @Desc("Minimum amount of this loot")
@@ -61,12 +58,17 @@ public class IrisEnchantment {
public void apply(RNG rng, ItemMeta meta) { public void apply(RNG rng, ItemMeta meta) {
try { try {
Enchantment enchant = Enchantment.getByKey(NamespacedKey.minecraft(getEnchantment()));
if(enchant == null) {
Iris.warn("Unknown Enchantment: " + getEnchantment());
return;
}
if(rng.nextDouble() < chance) { if(rng.nextDouble() < chance) {
if(meta instanceof EnchantmentStorageMeta) { if(meta instanceof EnchantmentStorageMeta) {
((EnchantmentStorageMeta) meta).addStoredEnchant(getEnchant(), getLevel(rng), true); ((EnchantmentStorageMeta) meta).addStoredEnchant(enchant, getLevel(rng), true);
return; return;
} }
meta.addEnchant(getEnchant(), getLevel(rng), true); meta.addEnchant(enchant, getLevel(rng), true);
} }
} catch(Throwable e) { } catch(Throwable e) {
Iris.reportError(e); Iris.reportError(e);
@@ -74,21 +76,6 @@ public class IrisEnchantment {
} }
} }
public Enchantment getEnchant() {
for(Field i : Enchantment.class.getDeclaredFields()) {
if(i.getType().equals(Enchantment.class) && i.getName().equals(getEnchantment())) {
try {
return (Enchantment) i.get(null);
} catch(IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
Iris.reportError(e);
}
}
}
return null;
}
public int getLevel(RNG rng) { public int getLevel(RNG rng) {
return rng.i(getMinLevel(), getMaxLevel()); return rng.i(getMinLevel(), getMaxLevel());
} }

View File

@@ -105,7 +105,7 @@ public class IrisLoot {
private KList<String> lore = new KList<>(); private KList<String> lore = new KList<>();
@RegistryListItemType @RegistryListItemType
@Required @Required
@Desc("This is the item or block type. Does not accept minecraft:*. Only materials such as DIAMOND_SWORD or DIRT.") @Desc("This is the item or block type. Does not accept minecraft:*, only materials such as DIAMOND_SWORD or DIRT. The exception are modded materials, as they require a namespace.")
private String type = ""; private String type = "";
@Desc("The dye color") @Desc("The dye color")
private DyeColor dyeColor = null; private DyeColor dyeColor = null;
@@ -120,89 +120,15 @@ public class IrisLoot {
public ItemStack get(boolean debug, RNG rng) { public ItemStack get(boolean debug, RNG rng) {
try { try {
ItemStack is; ItemStack is = getItemStack(rng);
if(!type.startsWith("minecraft:") && type.contains(":")) { if(is == null)
Optional<ItemStack> opt = Iris.service(ExternalDataSVC.class).getItemStack(NamespacedKey.fromString(type)); return new ItemStack(Material.AIR);
if(opt.isEmpty()) { is.setItemMeta(applyProperties(is, rng, debug, null));
//TODO Better third party provider
Iris.warn("Unknown Material: " + type);
return null;
}
is = opt.get();
is.setAmount(Math.max(1, rng.i(getMinAmount(), getMaxAmount())));
} else {
is = new ItemStack(getType(), Math.max(1, rng.i(getMinAmount(), getMaxAmount())));
}
ItemMeta m = is.getItemMeta();
if(is.getType().getMaxDurability() > 0 && m instanceof Damageable d) {
int max = is.getType().getMaxDurability();
d.setDamage((int) Math.round(Math.max(0, Math.min(max, (1D - rng.d(getMinDurability(), getMaxDurability())) * max))));
}
for(IrisEnchantment i : getEnchantments()) {
i.apply(rng, m);
}
for(IrisAttributeModifier i : getAttributes()) {
i.apply(rng, m);
}
try {
m.setCustomModelData(getCustomModel());
} catch(Throwable e) {
Iris.reportError(e);
}
m.setLocalizedName(C.translateAlternateColorCodes('&', displayName));
m.setDisplayName(C.translateAlternateColorCodes('&', displayName));
m.setUnbreakable(isUnbreakable());
for(ItemFlag i : getItemFlags()) {
m.addItemFlags(i);
}
KList<String> lore = new KList<>();
getLore().forEach((i) ->
{
String mf = C.translateAlternateColorCodes('&', i);
if(mf.length() > 24) {
for(String g : Form.wrapWords(mf, 24).split("\\Q\n\\E")) {
lore.add(g.trim());
}
} else {
lore.add(mf);
}
});
if(debug) {
if(lore.isNotEmpty()) {
lore.add(C.GRAY + "--------------------");
}
lore.add(C.GRAY + "1 in " + (getRarity()) + " Chance (" + Form.pc(1D / (getRarity()), 5) + ")");
}
m.setLore(lore);
if(getLeatherColor() != null && m instanceof LeatherArmorMeta) {
Color c = Color.decode(getLeatherColor());
((LeatherArmorMeta) m).setColor(org.bukkit.Color.fromRGB(c.getRed(), c.getGreen(), c.getBlue()));
}
if(getDyeColor() != null && m instanceof Colorable) {
((Colorable) m).setColor(getDyeColor());
}
is.setItemMeta(m);
return applyCustomNbt(is); return applyCustomNbt(is);
} catch(Throwable e) { } catch(Throwable e) {
Iris.reportError(e); Iris.reportError(e);
return new ItemStack(Material.AIR);
} }
return new ItemStack(Material.AIR);
} }
public ItemStack get(boolean debug, boolean giveSomething, IrisLootTable table, RNG rng, int x, int y, int z) { public ItemStack get(boolean debug, boolean giveSomething, IrisLootTable table, RNG rng, int x, int y, int z) {
@@ -212,75 +138,10 @@ public class IrisLoot {
if(giveSomething || chance.aquire(() -> NoiseStyle.STATIC.create(rng)).fit(1, rarity * table.getRarity(), x, y, z) == 1) { if(giveSomething || chance.aquire(() -> NoiseStyle.STATIC.create(rng)).fit(1, rarity * table.getRarity(), x, y, z) == 1) {
try { try {
ItemStack is; ItemStack is = getItemStack(rng);
if(!type.startsWith("minecraft:") && type.contains(":")) { if(is == null)
Optional<ItemStack> opt = Iris.service(ExternalDataSVC.class).getItemStack(NamespacedKey.fromString(type)); return null;
if(opt.isEmpty()) { is.setItemMeta(applyProperties(is, rng, debug, table));
Iris.warn("Unknown Material: " + type);
return null;
}
is = opt.get();
is.setAmount(Math.max(1, rng.i(getMinAmount(), getMaxAmount())));
return is;
} else {
is = new ItemStack(getType(), Math.max(1, rng.i(getMinAmount(), getMaxAmount())));
}
ItemMeta m = is.getItemMeta();
if(is.getType().getMaxDurability() > 0 && m instanceof Damageable d) {
int max = is.getType().getMaxDurability();
d.setDamage((int) Math.round(Math.max(0, Math.min(max, (1D - rng.d(getMinDurability(), getMaxDurability())) * max))));
}
for(IrisEnchantment i : getEnchantments()) {
i.apply(rng, m);
}
for(IrisAttributeModifier i : getAttributes()) {
i.apply(rng, m);
}
try {
m.setCustomModelData(getCustomModel());
} catch(Throwable e) {
Iris.reportError(e);
}
m.setLocalizedName(C.translateAlternateColorCodes('&', displayName));
m.setDisplayName(C.translateAlternateColorCodes('&', displayName));
m.setUnbreakable(isUnbreakable());
for(ItemFlag i : getItemFlags()) {
m.addItemFlags(i);
}
KList<String> lore = new KList<>();
getLore().forEach((i) ->
{
String mf = C.translateAlternateColorCodes('&', i);
if(mf.length() > 24) {
for(String g : Form.wrapWords(mf, 24).split("\\Q\n\\E")) {
lore.add(g.trim());
}
} else {
lore.add(mf);
}
});
if(debug) {
if(lore.isNotEmpty()) {
lore.add(C.GRAY + "--------------------");
}
lore.add(C.GRAY + "From: " + table.getName() + " (" + Form.pc(1D / table.getRarity(), 5) + ")");
lore.add(C.GRAY + "1 in " + (table.getRarity() * getRarity()) + " Chance (" + Form.pc(1D / (table.getRarity() * getRarity()), 5) + ")");
}
m.setLore(lore);
is.setItemMeta(m);
return applyCustomNbt(is); return applyCustomNbt(is);
} catch(Throwable e) { } catch(Throwable e) {
//Iris.reportError(e); //Iris.reportError(e);
@@ -291,6 +152,98 @@ public class IrisLoot {
return null; return null;
} }
// TODO Better Third Party Item Acquisition
private ItemStack getItemStack(RNG rng) {
if(!type.startsWith("minecraft:") && type.contains(":")) {
Optional<ItemStack> opt = Iris.service(ExternalDataSVC.class).getItemStack(NamespacedKey.fromString(type));
if(opt.isEmpty()) {
Iris.warn("Unknown Material: " + type);
return null;
}
ItemStack is = opt.get();
is.setAmount(Math.max(1, rng.i(getMinAmount(), getMaxAmount())));
return is;
}
return new ItemStack(getType(), Math.max(1, rng.i(getMinAmount(), getMaxAmount())));
}
private ItemMeta applyProperties(ItemStack is, RNG rng, boolean debug, IrisLootTable table) {
ItemMeta m = is.getItemMeta();
if(m == null) {
return null;
}
for(IrisEnchantment i : getEnchantments()) {
i.apply(rng, m);
}
for(IrisAttributeModifier i : getAttributes()) {
i.apply(rng, m);
}
m.setUnbreakable(isUnbreakable());
for(ItemFlag i : getItemFlags()) {
m.addItemFlags(i);
}
if(getCustomModel() != null) {
m.setCustomModelData(getCustomModel());
}
if(is.getType().getMaxDurability() > 0 && m instanceof Damageable d) {
int max = is.getType().getMaxDurability();
d.setDamage((int) Math.round(Math.max(0, Math.min(max, (1D - rng.d(getMinDurability(), getMaxDurability())) * max))));
}
if(getLeatherColor() != null && m instanceof LeatherArmorMeta leather) {
Color c = Color.decode(getLeatherColor());
leather.setColor(org.bukkit.Color.fromRGB(c.getRed(), c.getGreen(), c.getBlue()));
}
if(getDyeColor() != null && m instanceof Colorable colorable) {
colorable.setColor(getDyeColor());
}
m.setLocalizedName(C.translateAlternateColorCodes('&', displayName));
m.setDisplayName(C.translateAlternateColorCodes('&', displayName));
KList<String> lore = new KList<>();
getLore().forEach((i) ->
{
String mf = C.translateAlternateColorCodes('&', i);
if(mf.length() > 24) {
for(String g : Form.wrapWords(mf, 24).split("\\Q\n\\E")) {
lore.add(g.trim());
}
} else {
lore.add(mf);
}
});
if(debug) {
if(table == null) {
if(lore.isNotEmpty()) {
lore.add(C.GRAY + "--------------------");
}
lore.add(C.GRAY + "1 in " + (getRarity()) + " Chance (" + Form.pc(1D / (getRarity()), 5) + ")");
} else {
if(lore.isNotEmpty()) {
lore.add(C.GRAY + "--------------------");
}
lore.add(C.GRAY + "From: " + table.getName() + " (" + Form.pc(1D / table.getRarity(), 5) + ")");
lore.add(C.GRAY + "1 in " + (table.getRarity() * getRarity()) + " Chance (" + Form.pc(1D / (table.getRarity() * getRarity()), 5) + ")");
}
}
m.setLore(lore);
return m;
}
private ItemStack applyCustomNbt(ItemStack stack) throws CommandSyntaxException { private ItemStack applyCustomNbt(ItemStack stack) throws CommandSyntaxException {
if(customNbt == null || customNbt.isEmpty()) if(customNbt == null || customNbt.isEmpty())
return stack; return stack;

View File

@@ -0,0 +1,12 @@
package com.volmit.iris.engine.object.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
@Target({PARAMETER, TYPE, FIELD})
public @interface RegistryListEnchantment {
}