Search in sources :

Example 1 with BuildEntity

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);
    }
}
Also used : EntityType(net.minecraft.world.entity.EntityType) BuildEntity(com.wuest.prefab.structures.base.BuildEntity) Structure(com.wuest.prefab.structures.base.Structure)

Example 2 with BuildEntity

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();
}
Also used : EntityType(net.minecraft.world.entity.EntityType) LivingEntity(net.minecraft.world.entity.LivingEntity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) Entity(net.minecraft.world.entity.Entity) BuildEntity(com.wuest.prefab.structures.base.BuildEntity) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) BuildEntity(com.wuest.prefab.structures.base.BuildEntity) BlockPos(net.minecraft.core.BlockPos) ItemFrame(net.minecraft.world.entity.decoration.ItemFrame) Structure(com.wuest.prefab.structures.base.Structure) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) Painting(net.minecraft.world.entity.decoration.Painting)

Aggregations

BuildEntity (com.wuest.prefab.structures.base.BuildEntity)2 Structure (com.wuest.prefab.structures.base.Structure)2 EntityType (net.minecraft.world.entity.EntityType)2 BlockPos (net.minecraft.core.BlockPos)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 ListTag (net.minecraft.nbt.ListTag)1 Entity (net.minecraft.world.entity.Entity)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 HangingEntity (net.minecraft.world.entity.decoration.HangingEntity)1 ItemFrame (net.minecraft.world.entity.decoration.ItemFrame)1 Painting (net.minecraft.world.entity.decoration.Painting)1 AbstractMinecart (net.minecraft.world.entity.vehicle.AbstractMinecart)1