gateway world gen freeze band-aid fix
This commit is contained in:
parent
3e87d79b09
commit
2f9c994b42
3 changed files with 28 additions and 8 deletions
|
@ -1,13 +1,21 @@
|
|||
package org.dimdev.dimdoors.api.util;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerTask;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public enum BlockPlacementType {
|
||||
// TODO: do we need some update fluids only option?
|
||||
SECTION_NO_UPDATE(true, false, "section_no_update"),
|
||||
SECTION_UPDATE(true, true, "section_update"),
|
||||
SET_BLOCK_STATE(false, false, "set_block_state");
|
||||
SECTION_NO_UPDATE_QUEUE_BLOCK_ENTITY("section_no_update_queue_block_entity", true, false, BlockPlacementType::queueBlockEntity),
|
||||
SECTION_NO_UPDATE("section_no_update", true, false, World::addBlockEntity),
|
||||
SECTION_UPDATE("section_update", true, true, World::addBlockEntity),
|
||||
SET_BLOCK_STATE("set_block_state", false, false, World::addBlockEntity),
|
||||
SET_BLOCK_STATE_QUEUE_BLOCK_ENTITY("set_block_state_queue_block_entity", false, false, BlockPlacementType::queueBlockEntity);
|
||||
|
||||
private final static Map<String, BlockPlacementType> idMap = new HashMap<>();
|
||||
|
||||
|
@ -17,14 +25,17 @@ public enum BlockPlacementType {
|
|||
}
|
||||
}
|
||||
|
||||
final String id;
|
||||
final boolean useSection;
|
||||
final boolean markForUpdate;
|
||||
final String id;
|
||||
final BiConsumer<World, BlockEntity> blockEntityPlacer;
|
||||
|
||||
BlockPlacementType(boolean useSection, boolean markForUpdate, String id) {
|
||||
|
||||
BlockPlacementType(String id, boolean useSection, boolean markForUpdate, BiConsumer<World, BlockEntity> blockEntityPlacer) {
|
||||
this.id = id;
|
||||
this.useSection = useSection;
|
||||
this.markForUpdate = markForUpdate;
|
||||
this.id = id;
|
||||
this.blockEntityPlacer = blockEntityPlacer;
|
||||
}
|
||||
|
||||
public boolean useSection() {
|
||||
|
@ -35,6 +46,10 @@ public enum BlockPlacementType {
|
|||
return markForUpdate;
|
||||
}
|
||||
|
||||
public BiConsumer<World, BlockEntity> getBlockEntityPlacer() {
|
||||
return blockEntityPlacer;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -42,4 +57,9 @@ public enum BlockPlacementType {
|
|||
public static BlockPlacementType getFromId(String id) {
|
||||
return idMap.get(id);
|
||||
}
|
||||
|
||||
private static void queueBlockEntity(World world, BlockEntity blockEntity) {
|
||||
MinecraftServer server = world.getServer();
|
||||
server.send(new ServerTask(server.getTicks(), () -> world.addBlockEntity(blockEntity)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public abstract class SchematicGateway implements Gateway, BiPredicate<Structure
|
|||
TemplateUtils.replacePlaceholders(this.schematic, world);
|
||||
this.replaced = true;
|
||||
}
|
||||
SchematicPlacer.place(this.schematic, world, pos, BlockPlacementType.SECTION_NO_UPDATE);
|
||||
SchematicPlacer.place(this.schematic, world, pos, BlockPlacementType.SECTION_NO_UPDATE_QUEUE_BLOCK_ENTITY);
|
||||
this.generateRandomBits(world, pos);
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
|
|||
|
||||
BlockEntity blockEntity = BlockEntity.createFromNbt(actualPos, this.getBlockState(pos), nbt);
|
||||
if (blockEntity != null) {
|
||||
world.toServerWorld().addBlockEntity(blockEntity);
|
||||
placementType.getBlockEntityPlacer().accept(world.toServerWorld(), blockEntity);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<NbtCompound, Vec3d> entry : this.entityContainer.entrySet()) {
|
||||
|
|
Loading…
Reference in a new issue