Advertisement
Guest User

SecretRoomPiece

a guest
Feb 5th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.64 KB | None | 0 0
  1. public class SecretRoomPiece
  2. {
  3.  
  4.     private static final ResourceLocation SECRET_ROOM = new ResourceLocation(Necromod.MODID, "secret_room");
  5.  
  6.     private static final Map<ResourceLocation, BlockPos> OFFSET = ImmutableMap.of(SECRET_ROOM, new BlockPos(0, 1, 0));
  7.  
  8.     public static void start(TemplateManager manager, BlockPos pos, Rotation rot, List<StructurePiece> pieces, Random rand) {
  9.         BlockPos rotationOffset = new BlockPos(0, 0, 0).rotate(rot);
  10.         BlockPos blockPos = rotationOffset.offset(pos);
  11.         pieces.add(new SecretRoomPiece.Piece(manager, SECRET_ROOM, blockPos, rot));
  12.     }
  13.  
  14.     public static class Piece extends TemplateStructurePiece {
  15.         private final ResourceLocation resourceLocation;
  16.         private final Rotation rotation;
  17.  
  18.  
  19.         public Piece(TemplateManager templateManagerIn, ResourceLocation resourceLocationIn, BlockPos pos, Rotation rotationIn) {
  20.             super(NecromodStructures.Secret_Room_Piece, 0);
  21.             this.resourceLocation = resourceLocationIn;
  22.             this.templatePosition = pos;
  23.             this.rotation = rotationIn;
  24.             this.loadTemplate(templateManagerIn);
  25.         }
  26.  
  27.  
  28.         public Piece(TemplateManager templateManagerIn, CompoundNBT tagCompound) {
  29.             super(NecromodStructures.Secret_Room_Piece, tagCompound);
  30.             this.resourceLocation = new ResourceLocation(tagCompound.getString("Template"));
  31.             this.rotation = Rotation.valueOf(tagCompound.getString("Rot"));
  32.             this.loadTemplate(templateManagerIn);
  33.         }
  34.  
  35.  
  36.         private void loadTemplate(TemplateManager templateManager) {
  37.             Template template = templateManager.getOrCreate(this.resourceLocation);
  38.             PlacementSettings placementsettings = (new PlacementSettings()).setRotation(this.rotation).setMirror(Mirror.NONE);
  39.             this.setup(template, this.templatePosition, placementsettings);
  40.         }
  41.  
  42.  
  43.         /**
  44.          * (abstract) Helper method to read subclass data from NBT
  45.          */
  46.         @Override
  47.         protected void addAdditionalSaveData(CompoundNBT tagCompound) {
  48.             super.addAdditionalSaveData(tagCompound);
  49.             tagCompound.putString("Template", this.resourceLocation.toString());
  50.             tagCompound.putString("Rot", this.rotation.name());
  51.         }
  52.  
  53.         @Override
  54.         protected void handleDataMarker(String function, BlockPos pos, IServerWorld worldIn, Random rand, MutableBoundingBox sbb)
  55.         {
  56.             if ("chest".equals(function))
  57.             {
  58.                 worldIn.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
  59.                 TileEntity tileentity = worldIn.getBlockEntity(pos.below());
  60.                 if (tileentity instanceof ChestTileEntity)
  61.                 {
  62.                    ((ChestTileEntity)tileentity).setLootTable(NecromodLootTable.SECRET_ROOM_CHEST, rand.nextLong());
  63.                 }
  64.  
  65.              }
  66.  
  67.         }
  68.  
  69.         @Override
  70.         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_)
  71.         {
  72.             this.placeSettings.setRotation(this.rotation).setMirror(Mirror.NONE).setIgnoreEntities(true);
  73.             BlockPos blockpos = SecretRoomPiece.OFFSET.get(this.resourceLocation);
  74.             this.templatePosition.offset(Template.calculateRelativePosition(placeSettings, new BlockPos(0 - blockpos.getX(), blockpos.getY(), 0 - blockpos.getZ())));
  75.  
  76.             return super.postProcess(p_230383_1_, p_230383_2_, p_230383_3_, p_230383_4_, p_230383_5_, p_230383_6_, p_230383_7_);
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement