Advertisement
Guest User

HousePieces.Piece

a guest
Sep 12th, 2020
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. public static class Piece extends TemplateStructurePiece {
  2. private ResourceLocation resourceLocation;
  3. private Rotation rotation;
  4.  
  5. public Piece(TemplateManager templateManagerIn, ResourceLocation resourceLocationIn, BlockPos pos,
  6. Rotation rotationIn) {
  7. super(FeatureInit.HOUSE_PIECE, 0);
  8. this.resourceLocation = resourceLocationIn;
  9. BlockPos blockpos = HousePieces.OFFSET.get(resourceLocation);
  10. this.templatePosition = pos.add(blockpos.getX(), blockpos.getY(), blockpos.getZ());
  11. this.rotation = rotationIn;
  12. this.setupPiece(templateManagerIn);
  13. }
  14.  
  15. public Piece(TemplateManager templateManagerIn, CompoundNBT tagCompound) {
  16. super(FeatureInit.HOUSE_PIECE, tagCompound);
  17. this.resourceLocation = new ResourceLocation(tagCompound.getString("Template"));
  18. this.rotation = Rotation.valueOf(tagCompound.getString("Rot"));
  19. this.setupPiece(templateManagerIn);
  20. }
  21.  
  22. private void setupPiece(TemplateManager templateManager) {
  23. Template template = templateManager.getTemplateDefaulted(this.resourceLocation);
  24. PlacementSettings placementsettings = (new PlacementSettings()).setRotation(this.rotation)
  25. .setMirror(Mirror.NONE);
  26. this.setup(template, this.templatePosition, placementsettings);
  27. }
  28.  
  29. @Override
  30. protected void readAdditional(CompoundNBT tagCompound) {
  31. super.readAdditional(tagCompound);
  32. tagCompound.putString("Template", this.resourceLocation.toString());
  33. tagCompound.putString("Rot", this.rotation.name());
  34. }
  35.  
  36. @Override
  37. protected void handleDataMarker(String function, BlockPos pos, IWorld worldIn, Random rand,
  38. MutableBoundingBox sbb) {
  39. if ("chest".equals(function)) {
  40. worldIn.setBlockState(pos, Blocks.CHEST.getDefaultState(), 2);
  41. TileEntity tileentity = worldIn.getTileEntity(pos);
  42. if (tileentity instanceof ChestTileEntity) {
  43. // here you can set any loot tables for the chests
  44. }
  45. }
  46. }
  47.  
  48. // create
  49. @Override
  50. public boolean func_225577_a_(IWorld worldIn, ChunkGenerator<?> generator, Random randomIn,
  51. MutableBoundingBox structureBoundingBoxIn, ChunkPos chunkPos) {
  52. PlacementSettings placementsettings = (new PlacementSettings()).setRotation(this.rotation)
  53. .setMirror(Mirror.NONE);
  54. BlockPos blockpos = HousePieces.OFFSET.get(this.resourceLocation);
  55. this.templatePosition.add(Template.transformedBlockPos(placementsettings,
  56. new BlockPos(0 - blockpos.getX(), 0, 0 - blockpos.getZ())));
  57.  
  58. return super.func_225577_a_(worldIn, generator, randomIn, structureBoundingBoxIn, chunkPos);
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement