use of com.wuest.prefab.structures.base.Structure in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method onServerTick.
/**
* This event is primarily used to build 100 blocks for any queued structures for all players.
*
* @param event The event object.
*/
@SubscribeEvent
public static void onServerTick(ServerTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
ArrayList<Player> playersToRemove = new ArrayList<>();
if (StructureEventHandler.entitiesToGenerate.size() > 0) {
StructureEventHandler.ticksSinceLastEntitiesGenerated++;
if (StructureEventHandler.ticksSinceLastEntitiesGenerated > 40) {
// Process any entities.
StructureEventHandler.processStructureEntities();
StructureEventHandler.ticksSinceLastEntitiesGenerated = 0;
}
}
if (StructureEventHandler.structuresToBuild.size() > 0) {
for (Entry<Player, ArrayList<Structure>> entry : StructureEventHandler.structuresToBuild.entrySet()) {
ArrayList<Structure> structuresToRemove = new ArrayList<>();
// Build the first 100 blocks of each structure for this player.
for (Structure structure : entry.getValue()) {
if (!structure.entitiesRemoved) {
// If there is a player there...they will probably die anyways.....
for (BlockPos clearedPos : structure.clearedBlockPos) {
AABB axisPos = Shapes.block().bounds().move(clearedPos);
List<Entity> list = structure.world.getEntities(null, axisPos);
if (!list.isEmpty()) {
for (Entity entity : list) {
// Don't kill living entities.
if (!(entity instanceof LivingEntity)) {
if (entity instanceof HangingEntity) {
structure.BeforeHangingEntityRemoved((HangingEntity) entity);
}
structure.world.removeEntity(entity, false);
}
}
}
}
structure.entitiesRemoved = true;
}
if (structure.airBlocks.size() > 0) {
structure.hasAirBlocks = true;
}
for (int i = 0; i < 10; i++) {
i = StructureEventHandler.setBlock(i, structure, structuresToRemove);
}
// After building the blocks for this tick, find waterlogged blocks and remove them.
StructureEventHandler.removeWaterLogging(structure);
}
// Update the list of structures to remove this structure since it's done building.
StructureEventHandler.removeStructuresFromList(structuresToRemove, entry);
if (entry.getValue().size() == 0) {
playersToRemove.add(entry.getKey());
}
}
}
// Remove each player that has their structure's built.
for (Player player : playersToRemove) {
StructureEventHandler.structuresToBuild.remove(player);
}
}
}
use of com.wuest.prefab.structures.base.Structure in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method removeStructuresFromList.
private static void removeStructuresFromList(ArrayList<Structure> structuresToRemove, Entry<Player, ArrayList<Structure>> entry) {
for (Structure structure : structuresToRemove) {
StructureEventHandler.removeWaterLogging(structure);
for (BuildEntity buildEntity : structure.entities) {
Optional<EntityType<?>> entityType = EntityType.byString(buildEntity.getEntityResourceString());
if (entityType.isPresent()) {
StructureEventHandler.entitiesToGenerate.add(new Tuple<>(structure, buildEntity));
}
}
// This structure is done building.
entry.getValue().remove(structure);
}
}
use of com.wuest.prefab.structures.base.Structure in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method processStructureEntities.
private static void processStructureEntities() {
for (Tuple<Structure, BuildEntity> entityRecords : StructureEventHandler.entitiesToGenerate) {
BuildEntity buildEntity = entityRecords.getSecond();
Structure structure = entityRecords.getFirst();
Optional<EntityType<?>> entityType = EntityType.byString(buildEntity.getEntityResourceString());
if (entityType.isPresent()) {
Entity entity = entityType.get().create(structure.world);
if (entity != null) {
CompoundTag tagCompound = buildEntity.getEntityDataTag();
BlockPos entityPos = buildEntity.getStartingPosition().getRelativePosition(structure.originalPos, structure.getClearSpace().getShape().getDirection(), structure.configuration.houseFacing);
if (tagCompound != null) {
if (tagCompound.hasUUID("UUID")) {
tagCompound.putUUID("UUID", UUID.randomUUID());
}
ListTag nbttaglist = new ListTag();
nbttaglist.add(DoubleTag.valueOf(entityPos.getX()));
nbttaglist.add(DoubleTag.valueOf(entityPos.getY()));
nbttaglist.add(DoubleTag.valueOf(entityPos.getZ()));
tagCompound.put("Pos", nbttaglist);
entity.load(tagCompound);
}
// Set item frame facing and rotation here.
if (entity instanceof ItemFrame) {
entity = StructureEventHandler.setItemFrameFacingAndRotation((ItemFrame) entity, buildEntity, entityPos, structure);
} else if (entity instanceof Painting) {
entity = StructureEventHandler.setPaintingFacingAndRotation((Painting) entity, buildEntity, entityPos, structure);
} else if (entity instanceof AbstractMinecart) {
// Minecarts need to be slightly higher to account for the rails; otherwise they will fall through the rail and the block below the rail.
buildEntity.entityYAxisOffset = buildEntity.entityYAxisOffset + .2;
entity = StructureEventHandler.setEntityFacingAndRotation(entity, buildEntity, entityPos, structure);
} else {
// Other entities
entity = StructureEventHandler.setEntityFacingAndRotation(entity, buildEntity, entityPos, structure);
}
structure.world.addFreshEntity(entity);
}
}
}
// All entities generated; clear out the list.
StructureEventHandler.entitiesToGenerate.clear();
}
Aggregations