mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-30 12:29:20 +00:00
Loot
This commit is contained in:
21
src/main/java/com/volmit/iris/object/InventorySlotType.java
Normal file
21
src/main/java/com/volmit/iris/object/InventorySlotType.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.volmit.iris.object;
|
||||
|
||||
import com.volmit.iris.util.DontObfuscate;
|
||||
|
||||
public enum InventorySlotType
|
||||
{
|
||||
@DontObfuscate
|
||||
STORAGE,
|
||||
|
||||
@DontObfuscate
|
||||
FUEL,
|
||||
|
||||
@DontObfuscate
|
||||
FURNACE,
|
||||
|
||||
@DontObfuscate
|
||||
BLAST_FURNACE,
|
||||
|
||||
@DontObfuscate
|
||||
SMOKER,
|
||||
}
|
||||
@@ -45,6 +45,10 @@ public class IrisBiome extends IrisRegistrant implements IRare
|
||||
@Desc("This changes the dispersion of the biome colors if multiple derivatives are chosen.")
|
||||
private IrisGeneratorStyle biomeStyle = NoiseStyle.SIMPLEX.style();
|
||||
|
||||
@DontObfuscate
|
||||
@Desc("Reference loot tables in this area")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
|
||||
@MinNumber(0.0001)
|
||||
@DontObfuscate
|
||||
@DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"})
|
||||
|
||||
@@ -174,21 +174,14 @@ public class IrisBiomeDecorator
|
||||
return getBlockData().get(0);
|
||||
}
|
||||
|
||||
return getVarianceGenerator(
|
||||
|
||||
rng.nextParallelRNG(44)
|
||||
|
||||
)
|
||||
|
||||
.fit(
|
||||
|
||||
getBlockData()
|
||||
|
||||
,
|
||||
|
||||
xx,
|
||||
|
||||
zz);
|
||||
CNG v = getVarianceGenerator(rng.nextParallelRNG(44));
|
||||
|
||||
if(v == null)
|
||||
{
|
||||
getBlockData().get(0);
|
||||
}
|
||||
|
||||
v.fit(getBlockData(), xx, zz);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -42,6 +42,10 @@ public class IrisDimension extends IrisRegistrant
|
||||
@Desc("The human readable name of this dimension")
|
||||
private String name = "A Dimension";
|
||||
|
||||
@DontObfuscate
|
||||
@Desc("Reference loot tables in this area")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
|
||||
@Required
|
||||
@MinNumber(0)
|
||||
@DontObfuscate
|
||||
|
||||
115
src/main/java/com/volmit/iris/object/IrisLoot.java
Normal file
115
src/main/java/com/volmit/iris/object/IrisLoot.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package com.volmit.iris.object;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.gen.atomics.AtomicCache;
|
||||
import com.volmit.iris.noise.CNG;
|
||||
import com.volmit.iris.util.B;
|
||||
import com.volmit.iris.util.Desc;
|
||||
import com.volmit.iris.util.DontObfuscate;
|
||||
import com.volmit.iris.util.Form;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.MaxNumber;
|
||||
import com.volmit.iris.util.MinNumber;
|
||||
import com.volmit.iris.util.RNG;
|
||||
import com.volmit.iris.util.Required;
|
||||
|
||||
import lombok.Data;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
@Desc("Represents a loot entry")
|
||||
@Data
|
||||
public class IrisLoot
|
||||
{
|
||||
@DontObfuscate
|
||||
@Desc("The target inventory slot types to fill this loot with")
|
||||
private InventorySlotType slotTypes = InventorySlotType.STORAGE;
|
||||
|
||||
@MinNumber(1)
|
||||
@DontObfuscate
|
||||
@Desc("The sub rarity of this loot. Calculated after this loot table has been picked.")
|
||||
private int rarity = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@DontObfuscate
|
||||
@Desc("Minimum amount of this loot")
|
||||
private int minAmount = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@DontObfuscate
|
||||
@Desc("Maximum amount of this loot")
|
||||
private int maxAmount = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@DontObfuscate
|
||||
@Desc("Minimum durability percent")
|
||||
private double minDurability = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@DontObfuscate
|
||||
@Desc("Maximum durability percent")
|
||||
private double maxDurability = 1;
|
||||
|
||||
@Required
|
||||
@Desc("This is the item or block type. Does not accept minecraft:*. Only materials such as DIAMOND_SWORD or DIRT.")
|
||||
private String type = "";
|
||||
|
||||
private transient AtomicCache<CNG> chance = new AtomicCache<>();
|
||||
|
||||
public IrisLoot()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Material getType()
|
||||
{
|
||||
return B.getMaterial(type);
|
||||
}
|
||||
|
||||
public ItemStack get(boolean debug, IrisLootTable table, RNG rng, int x, int y, int z)
|
||||
{
|
||||
if(debug)
|
||||
{
|
||||
chance.reset();
|
||||
}
|
||||
|
||||
if(chance.aquire(() -> NoiseStyle.STATIC.create(rng)).fit(1, rarity * table.getRarity(), x, y, z) == 1)
|
||||
{
|
||||
if(getType() == null)
|
||||
{
|
||||
Iris.warn("Cant find item type " + type);
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack is = new ItemStack(getType(), Math.max(1, rng.i(getMinAmount(), getMaxAmount())));
|
||||
ItemMeta m = is.getItemMeta();
|
||||
|
||||
if(getType().getMaxDurability() > 0 && m instanceof Damageable)
|
||||
{
|
||||
Damageable d = (Damageable) m;
|
||||
int max = getType().getMaxDurability();
|
||||
d.setDamage((int) Math.round(Math.max(0, Math.min(max, rng.d(getMinDurability(), getMaxDurability()) * max))));
|
||||
}
|
||||
|
||||
KList<String> lore = new KList<>();
|
||||
|
||||
if(debug)
|
||||
{
|
||||
lore.add("From Table: " + table.getName() + " (" + Form.pc(1D / table.getRarity(), 5) + ")");
|
||||
lore.add(ChatColor.GRAY + "1 in " + (table.getRarity() * getRarity()) + " Chance (" + Form.pc(1D / (table.getRarity() * getRarity()), 5) + ")");
|
||||
}
|
||||
|
||||
m.setLore(lore);
|
||||
is.setItemMeta(m);
|
||||
return is;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
48
src/main/java/com/volmit/iris/object/IrisLootReference.java
Normal file
48
src/main/java/com/volmit/iris/object/IrisLootReference.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.volmit.iris.object;
|
||||
|
||||
import com.volmit.iris.gen.DimensionChunkGenerator;
|
||||
import com.volmit.iris.gen.atomics.AtomicCache;
|
||||
import com.volmit.iris.util.ArrayType;
|
||||
import com.volmit.iris.util.Desc;
|
||||
import com.volmit.iris.util.DontObfuscate;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.RegistryListLoot;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Desc("Represents a loot entry")
|
||||
@Data
|
||||
public class IrisLootReference
|
||||
{
|
||||
@DontObfuscate
|
||||
@Desc("Add = add on top of parent tables, Replace = clear first then add these. Clear = Remove all and dont add loot from this or parent.")
|
||||
private LootMode mode = LootMode.ADD;
|
||||
|
||||
@DontObfuscate
|
||||
@RegistryListLoot
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("Add loot table registries here")
|
||||
private KList<String> tables = new KList<>();
|
||||
|
||||
private transient AtomicCache<KList<IrisLootTable>> tt = new AtomicCache<>();
|
||||
|
||||
public IrisLootReference()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public KList<IrisLootTable> getLootTables(DimensionChunkGenerator g)
|
||||
{
|
||||
return tt.aquire(() ->
|
||||
{
|
||||
KList<IrisLootTable> t = new KList<>();
|
||||
|
||||
for(String i : tables)
|
||||
{
|
||||
t.add(g.getData().getLootLoader().load(i));
|
||||
}
|
||||
|
||||
return t;
|
||||
});
|
||||
}
|
||||
}
|
||||
63
src/main/java/com/volmit/iris/object/IrisLootTable.java
Normal file
63
src/main/java/com/volmit/iris/object/IrisLootTable.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package com.volmit.iris.object;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.volmit.iris.util.ArrayType;
|
||||
import com.volmit.iris.util.Desc;
|
||||
import com.volmit.iris.util.DontObfuscate;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.MinNumber;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Desc("Represents a loot table. Biomes, Regions & Objects can add or replace the virtual table with these loot tables")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisLootTable extends IrisRegistrant
|
||||
{
|
||||
@Desc("The name of this loot table")
|
||||
@DontObfuscate
|
||||
@MinNumber(2)
|
||||
private String name;
|
||||
|
||||
@MinNumber(1)
|
||||
@DontObfuscate
|
||||
@Desc("The rarity as in 1 in X chance")
|
||||
private int rarity = 1;
|
||||
|
||||
@DontObfuscate
|
||||
@Desc("The loot in this table")
|
||||
@ArrayType(min = 1, type = IrisLoot.class)
|
||||
private KList<IrisLoot> loot = new KList<>();
|
||||
|
||||
public KList<ItemStack> getLoot(boolean debug, RNG rng, InventorySlotType slot, int x, int y, int z)
|
||||
{
|
||||
KList<ItemStack> lootf = new KList<>();
|
||||
|
||||
int m = 0;
|
||||
|
||||
for(IrisLoot i : loot)
|
||||
{
|
||||
if(i.getSlotTypes().equals(slot))
|
||||
{
|
||||
ItemStack item = i.get(debug, this, rng.nextParallelRNG(294788 + x + y - z * z + (m * -4125)), x, y, z);
|
||||
|
||||
if(item != null)
|
||||
{
|
||||
lootf.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
m++;
|
||||
}
|
||||
|
||||
return lootf;
|
||||
}
|
||||
|
||||
public IrisLootTable()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -309,7 +309,7 @@ public class IrisObject extends IrisRegistrant
|
||||
int yy = y + (int) Math.round(i.getY());
|
||||
int zz = z + (int) Math.round(i.getZ());
|
||||
|
||||
if(config.getMode().equals(ObjectPlaceMode.PAINT))
|
||||
if(config.getMode().equals(ObjectPlaceMode.PAINT) && paintmap != null)
|
||||
{
|
||||
yy = (int) Math.round(i.getY()) + Math.floorDiv(h, 2) + paintmap.compute(new ChunkPosition(xx, zz), (k, v) ->
|
||||
{
|
||||
|
||||
@@ -52,6 +52,10 @@ public class IrisRegion extends IrisRegistrant implements IRare
|
||||
@Desc("The min shore height")
|
||||
private double shoreHeightMin = 1.2;
|
||||
|
||||
@DontObfuscate
|
||||
@Desc("Reference loot tables in this area")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
|
||||
@MinNumber(0)
|
||||
@DontObfuscate
|
||||
@Desc("The the max shore height")
|
||||
|
||||
@@ -38,6 +38,10 @@ public class IrisStructure extends IrisRegistrant
|
||||
@Desc("This is the x and z size of each grid cell")
|
||||
private int gridSize = 11;
|
||||
|
||||
@DontObfuscate
|
||||
@Desc("Reference loot tables in this area")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
|
||||
@Required
|
||||
@MinNumber(1)
|
||||
@MaxNumber(255)
|
||||
|
||||
@@ -17,6 +17,10 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisStructureTile
|
||||
{
|
||||
@DontObfuscate
|
||||
@Desc("Reference loot tables in this area")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
|
||||
@Required
|
||||
@DontObfuscate
|
||||
@Desc("Is this structure allowed to place if there is supposed to be a ceiling?")
|
||||
|
||||
15
src/main/java/com/volmit/iris/object/LootMode.java
Normal file
15
src/main/java/com/volmit/iris/object/LootMode.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.volmit.iris.object;
|
||||
|
||||
import com.volmit.iris.util.DontObfuscate;
|
||||
|
||||
public enum LootMode
|
||||
{
|
||||
@DontObfuscate
|
||||
ADD,
|
||||
|
||||
@DontObfuscate
|
||||
CLEAR,
|
||||
|
||||
@DontObfuscate
|
||||
REPLACE;
|
||||
}
|
||||
Reference in New Issue
Block a user