Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
//FAWE end
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ public BaseBlock getFullBlock(final Location location) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,34 @@ protected <T extends Future<T>> T internalCall(
entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch);
entity.setUUID(NbtUtils.uuid(nativeTag));
Runnable onError = () -> LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
id,
nmsWorld.getWorld().getName(),
x,
y,
z
);
if (!set.getSideEffectSet().shouldApply(SideEffect.ENTITY_EVENTS)) {
entity.spawnReason = CreatureSpawnEvent.SpawnReason.CUSTOM;
entity.generation = false;
if (PaperLib.isPaper()) {
if (!nmsWorld.getEntityLookup().addNewEntity(entity)) {
onError.run();
}
continue;
}
// Not paper
try {
PaperweightPlatformAdapter.getEntitySectionManager(nmsWorld).addNewEntity(entity);
continue;
} catch (IllegalAccessException e) {
// Fallback
LOGGER.warn("Error bypassing entity events on spawn on Spigot", e);
}
}
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
id,
nmsWorld.getWorld().getName(),
x,
y,
z
);
onError.run();
// Unsuccessful create should not be saved to history
iterator.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,22 @@ static List<Entity> getEntities(LevelChunk chunk) {
}
}
try {
//noinspection unchecked
return ((PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(chunk.level))).getEntities(chunk.getPos());
return getEntitySectionManager(chunk.level).getEntities(chunk.getPos());
} catch (IllegalAccessException e) {
collector.add(new RuntimeException("Failed to lookup entities [PAPER=false]", e));
}
collector.throwIfPresent();
return List.of();
}

/**
* Spigot only
*/
static PersistentEntitySectionManager<Entity> getEntitySectionManager(ServerLevel level) throws IllegalAccessException {
//noinspection unchecked
return (PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(level));
}

record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
//FAWE end
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ public BaseBlock getFullBlock(final Location location) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,34 @@ protected <T extends Future<T>> T internalCall(
entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch);
entity.setUUID(NbtUtils.uuid(nativeTag));
Runnable onError = () -> LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
id,
nmsWorld.getWorld().getName(),
x,
y,
z
);
if (!set.getSideEffectSet().shouldApply(SideEffect.ENTITY_EVENTS)) {
entity.spawnReason = CreatureSpawnEvent.SpawnReason.CUSTOM;
entity.generation = false;
if (PaperLib.isPaper()) {
if (!nmsWorld.getEntityLookup().addNewEntity(entity)) {
onError.run();
}
continue;
}
// Not paper
try {
PaperweightPlatformAdapter.getEntitySectionManager(nmsWorld).addNewEntity(entity);
continue;
} catch (IllegalAccessException e) {
// Fallback
LOGGER.warn("Error bypassing entity events on spawn on Spigot", e);
}
}
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
id,
nmsWorld.getWorld().getName(),
x,
y,
z
);
onError.run();
// Unsuccessful create should not be saved to history
iterator.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,22 @@ static List<Entity> getEntities(LevelChunk chunk) {
}
}
try {
//noinspection unchecked
return ((PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(chunk.level))).getEntities(chunk.getPos());
return getEntitySectionManager(chunk.level).getEntities(chunk.getPos());
} catch (IllegalAccessException e) {
collector.add(new RuntimeException("Failed to lookup entities [PAPER=false]", e));
}
collector.throwIfPresent();
return List.of();
}

/**
* Spigot only
*/
static PersistentEntitySectionManager<Entity> getEntitySectionManager(ServerLevel level) throws IllegalAccessException {
//noinspection unchecked
return (PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(level));
}

record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
//FAWE end
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ public BaseBlock getFullBlock(final Location location) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,34 @@ protected <T extends Future<T>> T internalCall(
entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch);
entity.setUUID(NbtUtils.uuid(nativeTag));
Runnable onError = () -> LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
id,
nmsWorld.getWorld().getName(),
x,
y,
z
);
if (!set.getSideEffectSet().shouldApply(SideEffect.ENTITY_EVENTS)) {
entity.spawnReason = CreatureSpawnEvent.SpawnReason.CUSTOM;
entity.generation = false;
if (PaperLib.isPaper()) {
if (!nmsWorld.getEntityLookup().addNewEntity(entity)) {
onError.run();
}
continue;
}
// Not paper
try {
PaperweightPlatformAdapter.getEntitySectionManager(nmsWorld).addNewEntity(entity);
continue;
} catch (IllegalAccessException e) {
// Fallback
LOGGER.warn("Error bypassing entity events on spawn on Spigot", e);
}
}
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
id,
nmsWorld.getWorld().getName(),
x,
y,
z
);
onError.run();
// Unsuccessful create should not be saved to history
iterator.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,22 @@ static List<Entity> getEntities(LevelChunk chunk) {
}
}
try {
//noinspection unchecked
return ((PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(chunk.level))).getEntities(chunk.getPos());
return getEntitySectionManager(chunk.level).getEntities(chunk.getPos());
} catch (IllegalAccessException e) {
collector.add(new RuntimeException("Failed to lookup entities [PAPER=false]", e));
}
collector.throwIfPresent();
return List.of();
}

/**
* Spigot only
*/
static PersistentEntitySectionManager<Entity> getEntitySectionManager(ServerLevel level) throws IllegalAccessException {
//noinspection unchecked
return (PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(level));
}

record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
//FAWE end
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ public BaseBlock getFullBlock(final Location location) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,15 +680,34 @@ protected <T extends Future<T>> T internalCall(
entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch);
entity.setUUID(NbtUtils.uuid(nativeTag));
Runnable onError = () -> LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
id,
nmsWorld.getWorld().getName(),
x,
y,
z
);
if (!set.getSideEffectSet().shouldApply(SideEffect.ENTITY_EVENTS)) {
entity.spawnReason = CreatureSpawnEvent.SpawnReason.CUSTOM;
entity.generation = false;
if (PaperLib.isPaper()) {
if (!nmsWorld.moonrise$getEntityLookup().addNewEntity(entity)) {
onError.run();
}
continue;
}
// Not paper
try {
PaperweightPlatformAdapter.getEntitySectionManager(nmsWorld).addNewEntity(entity);
continue;
} catch (IllegalAccessException e) {
// Fallback
LOGGER.warn("Error bypassing entity events on spawn on Spigot", e);
}
}
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
id,
nmsWorld.getWorld().getName(),
x,
y,
z
);
onError.run();
// Unsuccessful create should not be saved to history
iterator.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,13 +668,20 @@ static List<Entity> getEntities(LevelChunk chunk) {
}).orElse(Collections.emptyList());
}
try {
//noinspection unchecked
return ((PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(chunk.level))).getEntities(chunk.getPos());
return getEntitySectionManager(chunk.level).getEntities(chunk.getPos());
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to lookup entities [PAPER=false]", e);
}
}

/**
* Spigot only
*/
static PersistentEntitySectionManager<Entity> getEntitySectionManager(ServerLevel level) throws IllegalAccessException {
//noinspection unchecked
return (PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(level));
}

record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ public BaseBlock getFullBlock(final Location location) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.ENTITY_EVENTS
);

@Override
Expand Down
Loading
Loading