feat: integrate Beta 1.0.2.0 Pillager update with paid raid recovery
All checks were successful
DuneRealms Plugin CI / plugins (push) Successful in 3m8s
All checks were successful
DuneRealms Plugin CI / plugins (push) Successful in 3m8s
This commit is contained in:
parent
3485eec4a1
commit
c599b2b708
2 changed files with 4107 additions and 23 deletions
|
|
@ -38,6 +38,15 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
private static final String[] PLANETS = {"arrakis", "giedi_prime", "kaitain", "caladan", "sigma_draconis_iv"};
|
||||
|
||||
private NamespacedKey sietchLootIdKey;
|
||||
final SpiceDepositProvenance spiceProvenance=new SpiceDepositProvenance();
|
||||
public boolean isGeneratedSpiceDeposit(Block block){return block!=null&&block.getWorld().getName().equals("arrakis")&&SpiceDepositProvenance.authentic(block);}
|
||||
@EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void placedSpice(org.bukkit.event.block.BlockPlaceEvent event){if(event.getBlock().getWorld().getName().equals("arrakis")){SpiceDepositProvenance.forget(event.getBlock());SpiceDepositProvenance.invalidateBloom(event.getBlock());}}
|
||||
@EventHandler public void spiceChunkPopulated(org.bukkit.event.world.ChunkPopulateEvent event){if(event.getWorld().getName().equals("arrakis"))spiceProvenance.commitBloom(event.getChunk());}
|
||||
@EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void brokenBloom(org.bukkit.event.block.BlockBreakEvent event){if(event.getBlock().getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(event.getBlock());}
|
||||
@EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void movedBloom(org.bukkit.event.block.BlockPistonExtendEvent event){for(Block block:event.getBlocks())if(block.getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(block);}
|
||||
@EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void retractedBloom(org.bukkit.event.block.BlockPistonRetractEvent event){for(Block block:event.getBlocks())if(block.getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(block);}
|
||||
@EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void explodedBloom(org.bukkit.event.entity.EntityExplodeEvent event){for(Block block:event.blockList())if(block.getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(block);}
|
||||
@EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void changedBloom(org.bukkit.event.entity.EntityChangeBlockEvent event){if(event.getBlock().getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(event.getBlock());}
|
||||
private final Map<UUID, PersonalLoot> openSietchLoot = new HashMap<>();
|
||||
private record PersonalLoot(Inventory inventory, String id) {}
|
||||
|
||||
|
|
@ -124,6 +133,7 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
|
||||
private void detonateSpiceBlow(Block center) {
|
||||
if (center.getType() != Material.MAGMA_BLOCK) return;
|
||||
boolean authenticatedBloom=SpiceDepositProvenance.takeBloom(center);
|
||||
World world = center.getWorld();
|
||||
int x = center.getX(), z = center.getZ(), baseY = center.getY() - 1;
|
||||
for (int dx = -1; dx <= 1; dx++) for (int dz = -1; dz <= 1; dz++)
|
||||
|
|
@ -154,6 +164,7 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
for (Block block : candidates) {
|
||||
if (placed >= targetDeposits) break;
|
||||
block.setType(Material.SUSPICIOUS_SAND, false);
|
||||
if(authenticatedBloom)SpiceDepositProvenance.mark(block.getState());
|
||||
placed++;
|
||||
}
|
||||
announceSpiceBloom(center.getLocation());
|
||||
|
|
@ -367,7 +378,7 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
PlanetChunkGenerator(DuneTerrain plugin, String planet) { this.plugin = plugin; this.planet = planet; }
|
||||
@Override public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||
return planet.equals("arrakis") && world.getName().equalsIgnoreCase("arrakis")
|
||||
? List.of(new SietchPopulator(plugin), new SpiceBlowPopulator(plugin), new DesertVillages(plugin), new HarkonnenFortress(plugin)) : List.of();
|
||||
? List.of(new SietchPopulator(plugin), new SpiceBlowPopulator(plugin), new DesertVillages(plugin), new HarkonnenFortress(plugin),plugin.spiceProvenance) : List.of();
|
||||
}
|
||||
@Override public void generateNoise(WorldInfo world, Random random, int chunkX, int chunkZ, ChunkData data) {
|
||||
if(TemperateLandscape.enabled(planet)){
|
||||
|
|
@ -420,10 +431,11 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
}
|
||||
boolean arrakisWorld = planet.equals("arrakis") && world.getName().equalsIgnoreCase("arrakis");
|
||||
if (arrakisWorld) placeOasisTree(data, chunkX, chunkZ, heights, minY, maxY);
|
||||
var emittedSpice=new ArrayList<SpiceDepositProvenance.Position>();
|
||||
if (arrakisWorld) {
|
||||
placeDarkstoneIsland(data, chunkX, chunkZ, heights, minY, maxY);
|
||||
placeSpiceDeposits(data, heights, random, minY, maxY);
|
||||
placeRandomSpicePatch(data, chunkX, chunkZ, heights);
|
||||
placeSpiceDeposits(data, heights, random, minY, maxY,emittedSpice);
|
||||
placeRandomSpicePatch(data, chunkX, chunkZ, heights,emittedSpice);
|
||||
if (plugin.getConfig().getBoolean("dense-spice.enabled", true)) {
|
||||
int spacing = Math.max(128, plugin.getConfig().getInt("dense-spice.spacing", 512));
|
||||
for (int x=0;x<16;x++) for(int z=0;z<16;z++)
|
||||
|
|
@ -432,6 +444,7 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
}
|
||||
}
|
||||
placeOres(data, random, path, minY, maxY);
|
||||
if(arrakisWorld&&plugin.spiceProvenance!=null)plugin.spiceProvenance.capture(world,chunkX,chunkZ,emittedSpice,data);
|
||||
}
|
||||
@Override public BiomeProvider getDefaultBiomeProvider(WorldInfo worldInfo) {
|
||||
return new PlanetBiomeProvider(plugin, planet);
|
||||
|
|
@ -548,16 +561,16 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
Material material = Material.matchMaterial(name == null ? "" : name);
|
||||
return material == null ? fallback : material;
|
||||
}
|
||||
private void placeSpiceDeposits(ChunkData data, int[][] heights, Random random, int minY, int maxY) {
|
||||
private void placeSpiceDeposits(ChunkData data, int[][] heights, Random random, int minY, int maxY,List<SpiceDepositProvenance.Position> emitted) {
|
||||
int count = Math.max(0, plugin.getConfig().getInt("spice-deposits.per-chunk", 2));
|
||||
for (int i = 0; i < count; i++) {
|
||||
int x = random.nextInt(16), z = random.nextInt(16), y = heights[x][z];
|
||||
Material surface = data.getType(x, y, z);
|
||||
if (y + 1 < maxY && y > minY && (surface == Material.SAND || surface == Material.RED_SAND))
|
||||
data.setBlock(x, y, z, Material.SUSPICIOUS_SAND);
|
||||
if (y + 1 < maxY && y > minY && (surface == Material.SAND || surface == Material.RED_SAND)){
|
||||
data.setBlock(x, y, z, Material.SUSPICIOUS_SAND);emitted.add(new SpiceDepositProvenance.Position(x,y,z));}
|
||||
}
|
||||
}
|
||||
private void placeRandomSpicePatch(ChunkData data, int chunkX, int chunkZ, int[][] heights) {
|
||||
private void placeRandomSpicePatch(ChunkData data, int chunkX, int chunkZ, int[][] heights,List<SpiceDepositProvenance.Position> emitted) {
|
||||
String path = "spice-deposits.patches.";
|
||||
if (!plugin.getConfig().getBoolean(path + "enabled", true)) return;
|
||||
int spacing = Math.max(128, plugin.getConfig().getInt(path + "region-spacing", 600));
|
||||
|
|
@ -585,7 +598,7 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
if (hashUnit(blockSeed) >= density) continue;
|
||||
int y = heights[x][z];
|
||||
if (data.getType(x, y, z) == Material.SAND || data.getType(x, y, z) == Material.RED_SAND)
|
||||
data.setBlock(x, y, z, Material.SUSPICIOUS_SAND);
|
||||
{data.setBlock(x, y, z, Material.SUSPICIOUS_SAND);emitted.add(new SpiceDepositProvenance.Position(x,y,z));}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -947,6 +960,7 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
|
|||
for (int dx = -1; dx <= 1; dx++) for (int dz = -1; dz <= 1; dz++)
|
||||
if (region.isInRegion(x + dx, y, z + dz)) region.setType(x + dx, y, z + dz, Material.MAGMA_BLOCK);
|
||||
if (region.isInRegion(x, y + 1, z)) region.setType(x, y + 1, z, Material.MAGMA_BLOCK);
|
||||
if(plugin.spiceProvenance!=null)plugin.spiceProvenance.bloom(world,chunkX,chunkZ,new SpiceDepositProvenance.Position(x,y+1,z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package com.example.duneterrain;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.generator.*;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
/** Marks only coordinates actually emitted by our spice generator or authenticated bloom. */
|
||||
final class SpiceDepositProvenance extends BlockPopulator {
|
||||
static final NamespacedKey KEY=new NamespacedKey("dunerealms","generated_spice_deposit");
|
||||
record Position(int x,int y,int z){}
|
||||
private record ChunkKey(UUID world,int x,int z){}
|
||||
private final Map<ChunkKey,Set<Position>> pending=new ConcurrentHashMap<>();
|
||||
private final Map<ChunkKey,Position> blooms=new ConcurrentHashMap<>();
|
||||
void bloom(WorldInfo world,int cx,int cz,Position position){if(world.getUID()!=null&&blooms.size()<4096)blooms.put(new ChunkKey(world.getUID(),cx,cz),position);}
|
||||
void commitBloom(Chunk chunk){
|
||||
Position p=blooms.remove(new ChunkKey(chunk.getWorld().getUID(),chunk.getX(),chunk.getZ()));if(p==null)return;
|
||||
if(chunk.getBlock(p.x()&15,p.y(),p.z()&15).getType()==Material.MAGMA_BLOCK)chunk.getPersistentDataContainer().set(bloomKey(p.x(),p.y(),p.z()),PersistentDataType.BYTE,(byte)1);
|
||||
}
|
||||
private static NamespacedKey bloomKey(int x,int y,int z){return new NamespacedKey("dunerealms","generated_spice_bloom_"+(x&15)+"_"+y+"_"+(z&15));}
|
||||
static boolean takeBloom(Block center){
|
||||
var data=center.getChunk().getPersistentDataContainer();var key=bloomKey(center.getX(),center.getY(),center.getZ());
|
||||
boolean authentic=Byte.valueOf((byte)1).equals(data.get(key,PersistentDataType.BYTE));data.remove(key);return authentic;
|
||||
}
|
||||
static void invalidateBloom(Block changed){
|
||||
World world=changed.getWorld();for(int dx=-1;dx<=1;dx++)for(int dz=-1;dz<=1;dz++)for(int dy=-1;dy<=1;dy++){
|
||||
int x=changed.getX()+dx,z=changed.getZ()+dz;if(!world.isChunkLoaded(x>>4,z>>4))continue;
|
||||
world.getChunkAt(x>>4,z>>4).getPersistentDataContainer().remove(bloomKey(x,changed.getY()+dy,z));
|
||||
}
|
||||
}
|
||||
void capture(WorldInfo world,int cx,int cz,Collection<Position> positions,ChunkGenerator.ChunkData data){
|
||||
if(world.getUID()==null||pending.size()>=4096)return; // Fail closed; never grow an unbounded generation cache.
|
||||
Set<Position> actual=new HashSet<>();
|
||||
for(Position p:positions)if(data.getType(p.x(),p.y(),p.z())==Material.SUSPICIOUS_SAND)actual.add(new Position(cx*16+p.x(),p.y(),cz*16+p.z()));
|
||||
if(!actual.isEmpty())pending.put(new ChunkKey(world.getUID(),cx,cz),Set.copyOf(actual));
|
||||
}
|
||||
@Override public void populate(WorldInfo world,Random random,int cx,int cz,LimitedRegion region){
|
||||
Set<Position> positions=pending.remove(new ChunkKey(world.getUID(),cx,cz));if(positions==null)return;
|
||||
for(Position p:positions)if(region.isInRegion(p.x(),p.y(),p.z())&®ion.getType(p.x(),p.y(),p.z())==Material.SUSPICIOUS_SAND){
|
||||
BlockState state=region.getBlockState(p.x(),p.y(),p.z());mark(state);
|
||||
}
|
||||
}
|
||||
static boolean mark(BlockState state){
|
||||
if(state.getType()!=Material.SUSPICIOUS_SAND||!(state instanceof BrushableBlock tile)||tile.getLootTable()!=null||tile.getItem()!=null&&!tile.getItem().isEmpty())return false;
|
||||
tile.getPersistentDataContainer().set(KEY,PersistentDataType.BYTE,(byte)1);return tile.update(true,false);
|
||||
}
|
||||
static boolean authentic(Block block){
|
||||
if(block.getType()!=Material.SUSPICIOUS_SAND||!(block.getState() instanceof BrushableBlock tile)||tile.getLootTable()!=null||tile.getItem()!=null&&!tile.getItem().isEmpty())return false;
|
||||
return Byte.valueOf((byte)1).equals(tile.getPersistentDataContainer().get(KEY,PersistentDataType.BYTE));
|
||||
}
|
||||
static void forget(Block block){if(block.getState() instanceof TileState tile){tile.getPersistentDataContainer().remove(KEY);tile.update(false,false);}}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff