Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SecretRoomPiece
- {
- private static final ResourceLocation SECRET_ROOM = new ResourceLocation(Necromod.MODID, "secret_room");
- private static final Map<ResourceLocation, BlockPos> OFFSET = ImmutableMap.of(SECRET_ROOM, new BlockPos(0, 1, 0));
- public static void start(TemplateManager manager, BlockPos pos, Rotation rot, List<StructurePiece> pieces, Random rand) {
- BlockPos rotationOffset = new BlockPos(0, 0, 0).rotate(rot);
- BlockPos blockPos = rotationOffset.offset(pos);
- pieces.add(new SecretRoomPiece.Piece(manager, SECRET_ROOM, blockPos, rot));
- }
- public static class Piece extends TemplateStructurePiece {
- private final ResourceLocation resourceLocation;
- private final Rotation rotation;
- public Piece(TemplateManager templateManagerIn, ResourceLocation resourceLocationIn, BlockPos pos, Rotation rotationIn) {
- super(NecromodStructures.Secret_Room_Piece, 0);
- this.resourceLocation = resourceLocationIn;
- this.templatePosition = pos;
- this.rotation = rotationIn;
- this.loadTemplate(templateManagerIn);
- }
- public Piece(TemplateManager templateManagerIn, CompoundNBT tagCompound) {
- super(NecromodStructures.Secret_Room_Piece, tagCompound);
- this.resourceLocation = new ResourceLocation(tagCompound.getString("Template"));
- this.rotation = Rotation.valueOf(tagCompound.getString("Rot"));
- this.loadTemplate(templateManagerIn);
- }
- private void loadTemplate(TemplateManager templateManager) {
- Template template = templateManager.getOrCreate(this.resourceLocation);
- PlacementSettings placementsettings = (new PlacementSettings()).setRotation(this.rotation).setMirror(Mirror.NONE);
- this.setup(template, this.templatePosition, placementsettings);
- }
- /**
- * (abstract) Helper method to read subclass data from NBT
- */
- @Override
- protected void addAdditionalSaveData(CompoundNBT tagCompound) {
- super.addAdditionalSaveData(tagCompound);
- tagCompound.putString("Template", this.resourceLocation.toString());
- tagCompound.putString("Rot", this.rotation.name());
- }
- @Override
- protected void handleDataMarker(String function, BlockPos pos, IServerWorld worldIn, Random rand, MutableBoundingBox sbb)
- {
- if ("chest".equals(function))
- {
- worldIn.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
- TileEntity tileentity = worldIn.getBlockEntity(pos.below());
- if (tileentity instanceof ChestTileEntity)
- {
- ((ChestTileEntity)tileentity).setLootTable(NecromodLootTable.SECRET_ROOM_CHEST, rand.nextLong());
- }
- }
- }
- @Override
- public boolean postProcess(ISeedReader p_230383_1_, StructureManager p_230383_2_, ChunkGenerator p_230383_3_, Random p_230383_4_, MutableBoundingBox p_230383_5_, ChunkPos p_230383_6_, BlockPos p_230383_7_)
- {
- this.placeSettings.setRotation(this.rotation).setMirror(Mirror.NONE).setIgnoreEntities(true);
- BlockPos blockpos = SecretRoomPiece.OFFSET.get(this.resourceLocation);
- this.templatePosition.offset(Template.calculateRelativePosition(placeSettings, new BlockPos(0 - blockpos.getX(), blockpos.getY(), 0 - blockpos.getZ())));
- return super.postProcess(p_230383_1_, p_230383_2_, p_230383_3_, p_230383_4_, p_230383_5_, p_230383_6_, p_230383_7_);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement