use of com.wuest.prefab.structures.base.BuildEntity 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.BuildEntity 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