Jump to content

[1.14.4] Structures


Lea9ue

Recommended Posts

Having issues figuring out Structures. I tried multiple ways but obviously its not going well since I'm here.  Here are my classes incase anyone could help.

 

Structure Class:

public class TestStructure extends ScatteredStructure<NoFeatureConfig> {

    public TestStructure(Function<Dynamic<?>, ? extends NoFeatureConfig> config) {
        super(config);
    }
  
    @Override
    protected int getSeedModifier() {
        return 11111111;
    }
   
  	@Override
    public IStartFactory getStartFactory() {
        return Start::new;
    }

    @Override
    public String getStructureName() {
        return MobWar.MODID + ":test_structure";
    }

    @Override
    public int getSize() {
        return 1;
    }

    public static class Start extends StructureStart {

        public Start(Structure<?> structure, int chunkX, int chunkZ, Biome biome, MutableBoundingBox boundingBox, int references, long seed) {
            super(structure, chunkX, chunkZ, biome, boundingBox, references, seed);
        }

        @Override
        public void init(ChunkGenerator<?> generator, TemplateManager templateManager, int chunkX, int chunkZ, Biome biome) {

            ResourceLocation templateResource;

            if(this.rand.nextBoolean()) {
                templateResource = new ResourceLocation(MobWar.MODID, "diamond_temple");
            }
            else {
                templateResource = new ResourceLocation(MobWar.MODID, "diamond_temple_2");
            }

            Rotation rotation = Rotation.values()[this.rand.nextInt(Rotation.values().length)];

            TestPiece testPiece = new TestPiece(templateManager, templateResource, new BlockPos(chunkX * 16, 0, chunkZ * 16), rotation);

            this.components.add(testPiece);

            this.recalculateStructureSize();
        }
    }
}

 

Structure Piece:

public class TestPiece extends TemplateStructurePiece {

    private final ResourceLocation templateResource;

    private final Rotation rotation;

    public TestPiece(TemplateManager templateManager, ResourceLocation templateResource, BlockPos pos, Rotation rotation) {
        super(TestStructureRegisty.TEST_STRUCTURE_PIECE, 0);
        this.templateResource = templateResource;
        this.templatePosition = pos;
        this.rotation = rotation;
        setupTemplate(templateManager);
    }

    public TestPiece(TemplateManager templateManager, CompoundNBT nbt) {
        super(TestStructureRegisty.TEST_STRUCTURE_PIECE, nbt);
        this.rotation = Rotation.valueOf(nbt.getString("rot"));
        this.templateResource = new ResourceLocation(nbt.getString("temp"));
        setupTemplate(templateManager);
    }

    private void setupTemplate(TemplateManager templateManager) {
        Template template = templateManager.getTemplateDefaulted(this.templateResource);
        PlacementSettings placementsettings = (new PlacementSettings()).setRotation(this.rotation).setCenterOffset(new BlockPos(3, 0, 4)).addProcessor(BlockIgnoreStructureProcessor.STRUCTURE_BLOCK);
        this.setup(template, this.templatePosition, placementsettings);
    }

    @Override
    protected void readAdditional(CompoundNBT nbt) {
        super.readAdditional(nbt);
        nbt.putString("rot", this.rotation.name());
        nbt.putString("temp", this.templateResource.toString());
    }

    @Override
    protected void handleDataMarker(String function, BlockPos pos, IWorld world, Random rand, MutableBoundingBox boundingBox) {
        if("chest".equals(function)) {
            LockableLootTileEntity.setLootTable(world, rand, pos.down(), LootTables.CHESTS_SIMPLE_DUNGEON);
        }
    }

    @Override
    public boolean addComponentParts(IWorld world, Random rand, MutableBoundingBox boundingBox, ChunkPos chunkPos) {
        float height = 0;
        BlockPos structureSize = this.templatePosition.add(this.template.getSize().getX() - 1, 0, this.template.getSize().getZ() - 1);

        for(BlockPos pos : BlockPos.getAllInBoxMutable(this.templatePosition, structureSize)) {
            int k = world.getHeight(Heightmap.Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
            height += k;
        }
        height = height / (this.template.getSize().getX() * this.template.getSize().getZ()) - 1;
        this.templatePosition = new BlockPos(this.templatePosition.getX() + 8, height, this.templatePosition.getZ() + 8);
        return super.addComponentParts(world, rand, boundingBox, chunkPos);
    }
}

 

Registry:

@Mod.EventBusSubscriber(modid = MobWar.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
@ObjectHolder(MobWar.MODID)
public class TestStructureRegisty {

        public static final Structure<NoFeatureConfig> TEST_STRUCTURE = new TestStructure(NoFeatureConfig::deserialize);

        public static IStructurePieceType TEST_STRUCTURE_PIECE;


        @SubscribeEvent
        public static void registerFeatures(RegistryEvent.Register<Feature<?>> event) {

            TEST_STRUCTURE_PIECE = Registry.register(Registry.STRUCTURE_PIECE, MobWar.MODID + ":test_structure", TestPiece::new);

            TestStructure testStructure = new TestStructure(NoFeatureConfig::deserialize);
            testStructure.setRegistryName(MobWar.MODID, "test_structure");
            event.getRegistry().register(testStructure);
        }

        private static void addOverworldStructures(Biome biome) {
            biome.addFeature(GenerationStage.Decoration.SURFACE_STRUCTURES, Biome.createDecoratedFeature(TEST_STRUCTURE, IFeatureConfig.NO_FEATURE_CONFIG, Placement.NOPE, IPlacementConfig.NO_PLACEMENT_CONFIG));
        }
}

 

When I use command /locate it shows mobwar:dimond_temple, so I believe that is registering correctly but I can not located structure in my custom dimension.

 

Also here is my biome class:

public class DiamondBiome extends Biome {

    public DiamondBiome(){
        super((new Biome.Builder())
        .surfaceBuilder(new ConfiguredSurfaceBuilder<SurfaceBuilderConfig>(SurfaceBuilder.DEFAULT, new SurfaceBuilderConfig(Blocks.GRASS_BLOCK.getDefaultState(), Blocks.STONE.getDefaultState(), Blocks.CLAY.getDefaultState())))
        .precipitation(RainType.NONE)
        .downfall(0.0f)
        .category(Category.NONE)
        .temperature(1.0f)
        .scale(.2f)
        .depth(.3f)
        .waterColor(0x2bf0e6)
        .waterFogColor(0x2bf0e6)
        .parent(null)
        );

        this.addFeature(GenerationStage.Decoration.SURFACE_STRUCTURES, Biome.createDecoratedFeature(TestStructureRegisty.TEST_STRUCTURE, IFeatureConfig.NO_FEATURE_CONFIG, Placement.NOPE, IPlacementConfig.NO_PLACEMENT_CONFIG));
        this.addStructure(TestStructureRegisty.TEST_STRUCTURE, IFeatureConfig.NO_FEATURE_CONFIG);

        this.setRegistryName(MobWar.location(MobWar.MODID + "diamond_biome"));

    }

}

 

If anyone could give me some guidance, as always, I would appreciate.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.