Skip to content

Instantly share code, notes, and snippets.

@ByteLaw5
Created June 19, 2020 10:42
Show Gist options
  • Save ByteLaw5/8e268eba72d83c4b77ff5c31b797e844 to your computer and use it in GitHub Desktop.
Save ByteLaw5/8e268eba72d83c4b77ff5c31b797e844 to your computer and use it in GitHub Desktop.
Yes, this is all registered
Yes, this is all added to the biomes
No, the create method does not work
package com.bytelaw.bytesstructures.feature.structure;
import com.google.common.collect.Lists;
import com.mojang.datafixers.Dynamic;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeManager;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.feature.ProbabilityConfig;
import net.minecraft.world.gen.feature.structure.Structure;
import net.minecraft.world.gen.feature.structure.StructureStart;
import net.minecraft.world.gen.feature.template.TemplateManager;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Random;
import java.util.function.Function;
public class TestStructure extends AbstractStructure<ProbabilityConfig> {
private static final Logger LOGGER = LogManager.getLogger();
public TestStructure(Function<Dynamic<?>, ? extends ProbabilityConfig> configFactoryIn) {
super(configFactoryIn);
}
@Override
public List<Biome> getBiomesToSpawnAt() {
return Lists.newArrayList(ForgeRegistries.BIOMES.getValues());
}
@Override
protected int getSeedModifier() {
return 165745293;
}
@Override
public IStartFactory getStartFactory() {
return Start::new;
}
@Override
public String getStructureName() {
return "bytesstructures:test_structure";
}
@Override
public int getSize() {
return 2;
}
@Override
public boolean canBeGenerated(BiomeManager biomeManagerIn, ChunkGenerator<?> generatorIn, Random randIn, int chunkX, int chunkZ, Biome biomeIn) {
ChunkPos chunkpos = this.getStartPositionForPosition(generatorIn, randIn, chunkX, chunkZ, 0, 0);
if (chunkX == chunkpos.x && chunkZ == chunkpos.z) {
int i = chunkX >> 4;
int j = chunkZ >> 4;
randIn.setSeed((long)(i ^ j << 4) ^ generatorIn.getSeed());
randIn.nextInt();
if (randIn.nextInt(5) != 0) {
return false;
}
return generatorIn.hasStructure(biomeIn, this);
}
return false;
}
public static class Start extends StructureStart {
public Start(Structure<?> structure, int cx, int cz, MutableBoundingBox boundingBox, int references, long seed) {
super(structure, cx, cz, boundingBox, references, seed);
}
@Override
public void init(ChunkGenerator<?> generator, TemplateManager templateManagerIn, int chunkX, int chunkZ, Biome biomeIn) {
int i = chunkX * 16;
int j = chunkZ * 16;
int k = generator.func_222531_c(i, j, Heightmap.Type.WORLD_SURFACE_WG);
BlockPos pos = new BlockPos(i, k, j);
TestStructurePieces.addStructurePieces(templateManagerIn, pos, this.components);
this.recalculateStructureSize();
}
}
}
package com.bytelaw.bytesstructures.feature.structure;
import com.bytelaw.bytesstructures.BytesStructures;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ChestTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Mirror;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.world.IWorld;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.feature.structure.StructurePiece;
import net.minecraft.world.gen.feature.structure.TemplateStructurePiece;
import net.minecraft.world.gen.feature.template.BlockIgnoreStructureProcessor;
import net.minecraft.world.gen.feature.template.PlacementSettings;
import net.minecraft.world.gen.feature.template.Template;
import net.minecraft.world.gen.feature.template.TemplateManager;
import net.minecraft.world.storage.loot.LootTables;
import java.util.List;
import java.util.Random;
public class TestStructurePieces {
private static final ResourceLocation
LOCATION = BytesStructures.resource("teststructureroom"),
LOCATION_2 = BytesStructures.resource("teststructureroom2");
public static void addStructurePieces(TemplateManager manager, BlockPos pos, List<StructurePiece> pieces) {
pieces.add(new Piece(pos, manager));
pieces.add(new AncientPiece(pos, manager));
}
public static class Piece extends TemplateStructurePiece {
public Piece(BlockPos pos, TemplateManager manager) {
super(BytesFeatures.TEST_STRUCTURE_ROOM, 0);
this.templatePosition = new BlockPos(pos.getX(), pos.getY(), pos.getZ());
setup(manager);
}
public Piece(TemplateManager manager, CompoundNBT nbt) {
super(BytesFeatures.TEST_STRUCTURE_ROOM, nbt);
setup(manager);
}
protected void setup(TemplateManager manager) {
Template template = manager.getTemplateDefaulted(LOCATION);
PlacementSettings settings = new PlacementSettings().setRotation(Rotation.NONE).setMirror(Mirror.NONE).setCenterOffset(BlockPos.ZERO).addProcessor(BlockIgnoreStructureProcessor.STRUCTURE_BLOCK);
setup(template, this.templatePosition, settings);
}
@Override
public boolean create(IWorld worldIn, ChunkGenerator<?> chunkGeneratorIn, Random randomIn, MutableBoundingBox mutableBoundingBoxIn, ChunkPos chunkPosIn) {
PlacementSettings placementsettings = (new PlacementSettings()).setRotation(Rotation.NONE).setMirror(Mirror.NONE).setCenterOffset(BlockPos.ZERO).addProcessor(BlockIgnoreStructureProcessor.STRUCTURE_BLOCK);
BlockPos blockpos1 = this.templatePosition.add(Template.transformedBlockPos(placementsettings, new BlockPos(3, 0, 0)));
int strucHeight = worldIn.getHeight(Heightmap.Type.WORLD_SURFACE_WG, blockpos1.getX(), blockpos1.getZ());
this.templatePosition = this.templatePosition.add(0, strucHeight, 0);
return super.create(worldIn, chunkGeneratorIn, randomIn, boundingBox, chunkPosIn);
}
@Override
protected void handleDataMarker(String function, BlockPos pos, IWorld worldIn, Random rand, MutableBoundingBox sbb) {
if("chest".equals(function)) {
TileEntity te = worldIn.getTileEntity(pos);
if(te instanceof ChestTileEntity) {
((ChestTileEntity)te).setLootTable(LootTables.CHESTS_BURIED_TREASURE, rand.nextLong());
}
}
}
}
public static class AncientPiece extends TemplateStructurePiece {
public AncientPiece(BlockPos pos, TemplateManager manager) {
super(BytesFeatures.TEST_STRUCTURE_ANCIENT_ROOM, 1);
this.templatePosition = new BlockPos(pos.getX(), pos.getY(), pos.getZ());
setup(manager);
}
public AncientPiece(TemplateManager manager, CompoundNBT nbt) {
super(BytesFeatures.TEST_STRUCTURE_ANCIENT_ROOM, nbt);
setup(manager);
}
protected void setup(TemplateManager manager) {
Template template = manager.getTemplateDefaulted(LOCATION);
PlacementSettings settings = new PlacementSettings().setRotation(Rotation.NONE).setMirror(Mirror.NONE).setCenterOffset(BlockPos.ZERO).addProcessor(BlockIgnoreStructureProcessor.STRUCTURE_BLOCK);
setup(template, this.templatePosition, settings);
}
@Override
public boolean create(IWorld worldIn, ChunkGenerator<?> chunkGeneratorIn, Random randomIn, MutableBoundingBox mutableBoundingBoxIn, ChunkPos chunkPosIn) {
PlacementSettings placementsettings = (new PlacementSettings()).setRotation(Rotation.NONE).setMirror(Mirror.NONE).setCenterOffset(BlockPos.ZERO).addProcessor(BlockIgnoreStructureProcessor.STRUCTURE_BLOCK);
BlockPos blockpos1 = this.templatePosition.add(Template.transformedBlockPos(placementsettings, new BlockPos(3, 0, 0)));
int strucHeight = worldIn.getHeight(Heightmap.Type.WORLD_SURFACE_WG, blockpos1.getX(), blockpos1.getZ());
this.templatePosition = this.templatePosition.add(0, strucHeight, 0);
return super.create(worldIn, chunkGeneratorIn, randomIn, boundingBox, chunkPosIn);
}
@Override
protected void handleDataMarker(String function, BlockPos pos, IWorld worldIn, Random rand, MutableBoundingBox sbb) {
if("chest".equals(function)) {
TileEntity te = worldIn.getTileEntity(pos);
if(te instanceof ChestTileEntity) {
((ChestTileEntity)te).setLootTable(LootTables.CHESTS_BURIED_TREASURE, rand.nextLong());
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment