Created
June 19, 2020 20:10
-
-
Save ByteLaw5/8cf142f80fdbb9253804d0e771a85ea9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bytelaw.bytesstructures.world.gen.feature.structure; | |
import com.bytelaw.bytesstructures.BytesStructures; | |
import com.bytelaw.bytesstructures.entity.BytesEntities; | |
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.ScatteredStructure; | |
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.event.world.WorldEvent; | |
import net.minecraftforge.eventbus.api.SubscribeEvent; | |
import net.minecraftforge.fml.common.Mod; | |
import java.util.Random; | |
import java.util.function.Function; | |
@Mod.EventBusSubscriber(modid=BytesStructures.MODID) | |
public class AncientLootStructure extends ScatteredStructure<ProbabilityConfig> { | |
public AncientLootStructure(Function<Dynamic<?>, ? extends ProbabilityConfig> configFactoryIn) { | |
super(configFactoryIn); | |
} | |
@Override | |
protected int getSeedModifier() { | |
return 165745293; | |
} | |
@Override | |
public IStartFactory getStartFactory() { | |
return Start::new; | |
} | |
@Override | |
public String getStructureName() { | |
return "bytesstructures:ancient_loot"; | |
} | |
@Override | |
public int getSize() { | |
return 1; | |
} | |
@SubscribeEvent | |
public static void getPossibleCreatures(WorldEvent.PotentialSpawns event) { | |
event.getList().addAll(Lists.newArrayList(new Biome.SpawnListEntry(BytesEntities.GUARD.get(), 10, 1, 3))); | |
} | |
@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<?> p_i225876_1_, int p_i225876_2_, int p_i225876_3_, MutableBoundingBox p_i225876_4_, int p_i225876_5_, long p_i225876_6_) { | |
super(p_i225876_1_, p_i225876_2_, p_i225876_3_, p_i225876_4_, p_i225876_5_, p_i225876_6_); | |
} | |
@Override | |
public void init(ChunkGenerator<?> generator, TemplateManager templateManagerIn, int chunkX, int chunkZ, Biome biomeIn) { | |
int cx = chunkX * 16; | |
int cz = chunkZ * 16; | |
int y = generator.func_222531_c(cx, cz, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES); | |
BlockPos pos = new BlockPos(cx, y, cz); | |
AncientLootStructurePieces.addStructurePieces(templateManagerIn, pos, this.components); | |
this.recalculateStructureSize(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bytelaw.bytesstructures.world.gen.feature.structure; | |
import com.bytelaw.bytesstructures.BytesStructures; | |
import com.bytelaw.bytesstructures.world.gen.feature.BytesFeatures; | |
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 AncientLootStructurePieces { | |
private static final ResourceLocation LOCATION = BytesStructures.resource("ancient_loot_room"); | |
public static void addStructurePieces(TemplateManager manager, BlockPos pos, List<StructurePiece> pieces) { | |
pieces.add(new Piece(pos, manager)); | |
} | |
public static class Piece extends TemplateStructurePiece { | |
public Piece(BlockPos pos, TemplateManager manager) { | |
super(BytesFeatures.ANCIENT_LOOT_ROOM, 0); | |
this.templatePosition = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); | |
setup(manager); | |
} | |
public Piece(TemplateManager manager, CompoundNBT nbt) { | |
super(BytesFeatures.ANCIENT_LOOT_ROOM, nbt); | |
setup(manager); | |
} | |
private 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.MOTION_BLOCKING_NO_LEAVES, blockpos1.getX(), blockpos1.getZ()); | |
this.templatePosition = this.templatePosition.add(0, strucHeight, 0); | |
return super.create(worldIn, chunkGeneratorIn, randomIn, mutableBoundingBoxIn, 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