mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-06 07:46:08 +00:00
Fix seed drift
This commit is contained in:
@@ -85,7 +85,7 @@ public class HeadlessWorld {
|
||||
public World load() {
|
||||
World w = new WorldCreator(worldName)
|
||||
.environment(dimension.getEnvironment())
|
||||
.seed(world.seed())
|
||||
.seed(world.getRawWorldSeed())
|
||||
.generator(new BukkitChunkGenerator(world, studio, dimension.getLoader().getDataFolder(),
|
||||
dimension.getLoadKey()))
|
||||
.createWorld();
|
||||
|
||||
@@ -28,6 +28,7 @@ public class IrisEngineData {
|
||||
private IrisEngineStatistics statistics = new IrisEngineStatistics();
|
||||
private KList<IrisEngineSpawnerCooldown> spawnerCooldowns = new KList<>();
|
||||
private KList<IrisEngineChunkData> chunks = new KList<>();
|
||||
private Long seed = null;
|
||||
|
||||
public void removeChunk(int x, int z) {
|
||||
long k = Cache.key(x, z);
|
||||
|
||||
@@ -109,7 +109,7 @@ public class IrisEntitySpawn implements IRare {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (rng.aquire(() -> new RNG(g.getTarget().getWorld().seed() + 4)).i(1, getRarity()) == 1) {
|
||||
if (rng.aquire(() -> new RNG(g.getSeedManager().getEntity())).i(1, getRarity()) == 1) {
|
||||
return spawn100(g, at);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class IrisEntitySpawn implements IRare {
|
||||
if (!irisEntity.getSurface().matches(at.clone().subtract(0, 1, 0).getBlock()))
|
||||
return null; //Make sure it can spawn on the block
|
||||
|
||||
Entity e = irisEntity.spawn(g, at.add(0.5, 0, 0.5), rng.aquire(() -> new RNG(g.getTarget().getWorld().seed() + 4)));
|
||||
Entity e = irisEntity.spawn(g, at.add(0.5, 0, 0.5), rng.aquire(() -> new RNG(g.getSeedManager().getEntity())));
|
||||
if (e != null) {
|
||||
Iris.debug("Spawned " + C.DARK_AQUA + "Entity<" + getEntity() + "> " + C.GREEN + e.getType() + C.LIGHT_PURPLE + " @ " + C.GRAY + e.getLocation().getX() + ", " + e.getLocation().getY() + ", " + e.getLocation().getZ());
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
|
||||
@Snippet("entity-spawn-override")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents an entity spawn")
|
||||
@Data
|
||||
public class IrisEntitySpawnOverride {
|
||||
@RegistryListResource(IrisEntity.class)
|
||||
@Required
|
||||
@Desc("The entity")
|
||||
private String entity = "";
|
||||
|
||||
@Required
|
||||
@Desc("If the following entity type spawns, spawn this entity. Set to unknown for any entity spawn")
|
||||
private EntityType trigger = EntityType.UNKNOWN;
|
||||
|
||||
@Desc("If the source is triggered, cancel spawning the original entity instead of ADDING a new entity.")
|
||||
private boolean cancelSourceSpawn = false;
|
||||
|
||||
@MinNumber(1)
|
||||
@Desc("The 1 in RARITY chance for this entity to spawn")
|
||||
private int rarity = 1;
|
||||
|
||||
private final transient AtomicCache<RNG> rng = new AtomicCache<>();
|
||||
private final transient AtomicCache<IrisEntity> ent = new AtomicCache<>();
|
||||
|
||||
|
||||
public Entity on(Engine g, Location at, EntityType t, EntitySpawnEvent ee) {
|
||||
if (!trigger.equals(EntityType.UNKNOWN)) {
|
||||
if (!trigger.equals(t)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Entity e = spawn(g, at);
|
||||
|
||||
if (e != null && isCancelSourceSpawn()) {
|
||||
ee.setCancelled(true);
|
||||
ee.getEntity().remove();
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
public Entity spawn(Engine g, Location at) {
|
||||
if (getRealEntity(g) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (rng.aquire(() -> new RNG(g.getTarget().getWorld().seed() + 4)).i(1, getRarity()) == 1) {
|
||||
return getRealEntity(g).spawn(g, at, rng.aquire(() -> new RNG(g.getTarget().getWorld().seed() + 4)));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IrisEntity getRealEntity(Engine g) {
|
||||
return ent.aquire(() -> g.getData().getEntityLoader().load(getEntity()));
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,7 @@ package com.volmit.iris.engine.object;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -42,6 +41,9 @@ public class IrisWorld {
|
||||
private static final KList<? extends Entity> NO_ENTITIES = new KList<>();
|
||||
private String name;
|
||||
private File worldFolder;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private long seed;
|
||||
private World.Environment environment;
|
||||
private World realWorld;
|
||||
@@ -55,13 +57,22 @@ public class IrisWorld {
|
||||
private static IrisWorld bindWorld(IrisWorld iw, World world) {
|
||||
return iw.name(world.getName())
|
||||
.worldFolder(world.getWorldFolder())
|
||||
.seed(world.getSeed())
|
||||
.minHeight(world.getMinHeight())
|
||||
.maxHeight(world.getMaxHeight())
|
||||
.realWorld(world)
|
||||
.environment(world.getEnvironment());
|
||||
}
|
||||
|
||||
public long getRawWorldSeed()
|
||||
{
|
||||
return seed;
|
||||
}
|
||||
|
||||
public void setRawWorldSeed(long seed)
|
||||
{
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public boolean tryGetRealWorld() {
|
||||
if (hasRealWorld()) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user