Guest User

ComponentCornField.java

a guest
Jun 30th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.32 KB | None | 0 0
  1. package panda.corn;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.init.Blocks;
  10. import net.minecraft.nbt.NBTTagCompound;
  11. import net.minecraft.util.BlockPos;
  12. import net.minecraft.util.EnumFacing;
  13. import net.minecraft.util.MathHelper;
  14. import net.minecraft.world.World;
  15. import net.minecraft.world.gen.structure.StructureBoundingBox;
  16. import net.minecraft.world.gen.structure.StructureComponent;
  17. import net.minecraft.world.gen.structure.StructureVillagePieces;
  18. import net.minecraftforge.fml.common.registry.GameRegistry;
  19. import panda.corn.BlockCorn;;
  20.  
  21. public class ComponentCornField extends StructureVillagePieces.Village{
  22.  
  23.         private Block cropTypeA;
  24.        
  25.         public ComponentCornField() {}
  26.  
  27.         public ComponentCornField(StructureVillagePieces.Start p_i45569_1_, int p_i45569_2_, Random p_i45569_3_, StructureBoundingBox p_i45569_4_, EnumFacing p_i45569_5_)
  28.         {
  29.             super(p_i45569_1_, p_i45569_2_);
  30.             this.coordBaseMode = p_i45569_5_;
  31.             this.boundingBox = p_i45569_4_;
  32.             this.cropTypeA = new BlockCorn();
  33.         }
  34.  
  35.         /**
  36.          * (abstract) Helper method to write subclass data to NBT
  37.          */
  38.         protected void writeStructureToNBT(NBTTagCompound tag)
  39.         {
  40.             super.writeStructureToNBT(tag);
  41.             //tag.setInteger("CA", Block.blockRegistry.getIDForObject(this.cropTypeA));
  42.             tag.setInteger("CA",12343217);
  43.             //tag.setInteger("CB", Block.blockRegistry.getIDForObject(this.cropTypeB));
  44.             //GameRegistry.findBlock(Corn.MODID, "corn")
  45.         }
  46.  
  47.         /**
  48.          * (abstract) Helper method to read subclass data from NBT
  49.          */
  50.         protected void readStructureFromNBT(NBTTagCompound tag)
  51.         {
  52.             super.readStructureFromNBT(tag);
  53.             this.cropTypeA = new BlockCorn(); //Block.getBlockById(tag.getInteger("CA"));
  54.             //this.cropTypeB = Block.getBlockById(tag.getInteger("CB"));
  55.         }
  56.        
  57.         @Override
  58.         public boolean addComponentParts(World worldIn, Random rand, StructureBoundingBox box)
  59.         {
  60.             if (this.field_143015_k < 0)
  61.             {
  62.                 this.field_143015_k = this.getAverageGroundLevel(worldIn, box);
  63.  
  64.                 if (this.field_143015_k < 0)
  65.                 {
  66.                     return true;
  67.                 }
  68.  
  69.                 this.boundingBox.offset(0, this.field_143015_k - this.boundingBox.maxY + 4 - 1, 0);
  70.             }
  71.             Block corn = new BlockCorn();
  72.             this.func_175804_a(worldIn, box, 0, 1, 0, 6, 4, 8, Blocks.air.getDefaultState(), Blocks.air.getDefaultState(), false);
  73.             this.func_175804_a(worldIn, box, 1, 0, 1, 2, 0, 7, Blocks.farmland.getDefaultState(), Blocks.farmland.getDefaultState(), false);
  74.             this.func_175804_a(worldIn, box, 4, 0, 1, 5, 0, 7, Blocks.farmland.getDefaultState(), Blocks.farmland.getDefaultState(), false);
  75.             this.func_175804_a(worldIn, box, 0, 0, 0, 0, 0, 8, Blocks.gold_block.getDefaultState(), Blocks.gold_block.getDefaultState(), false);
  76.             this.func_175804_a(worldIn, box, 6, 0, 0, 6, 0, 8, Blocks.gold_block.getDefaultState(), Blocks.gold_block.getDefaultState(), false);
  77.             this.func_175804_a(worldIn, box, 1, 0, 0, 5, 0, 0, Blocks.gold_block.getDefaultState(), Blocks.gold_block.getDefaultState(), false);
  78.             this.func_175804_a(worldIn, box, 1, 0, 8, 5, 0, 8, Blocks.gold_block.getDefaultState(), Blocks.gold_block.getDefaultState(), false);
  79.             this.func_175804_a(worldIn, box, 3, 0, 1, 3, 0, 7, Blocks.water.getDefaultState(), Blocks.water.getDefaultState(), false);
  80.             int i;
  81.            
  82.             for (i = 1; i <= 7; ++i)
  83.             {
  84.                 this.func_175811_a(worldIn, corn.getStateFromMeta(MathHelper.getRandomIntegerInRange(rand, 2, 11)), 1, 1, i, box);
  85.                 this.func_175811_a(worldIn, corn.getStateFromMeta(MathHelper.getRandomIntegerInRange(rand, 2, 11)), 2, 1, i, box);
  86.                 this.func_175811_a(worldIn, corn.getStateFromMeta(MathHelper.getRandomIntegerInRange(rand, 2, 11)), 4, 1, i, box);
  87.                 this.func_175811_a(worldIn, corn.getStateFromMeta(MathHelper.getRandomIntegerInRange(rand, 2, 11)), 5, 1, i, box);
  88.             }
  89.  
  90.             for (i = 0; i < 9; ++i)
  91.             {
  92.                 for (int j = 0; j < 7; ++j)
  93.                 {
  94.                     this.clearCurrentPositionBlocksUpwards(worldIn, j, 4, i, box);
  95.                     this.func_175808_b(worldIn, Blocks.dirt.getDefaultState(), j, -1, i, box);
  96.                 }
  97.             }
  98.  
  99.             return true;
  100.         }
  101.        
  102.         public static ComponentCornField buildComponent(StructureVillagePieces.Start p_175852_0_, List p_175852_1_, Random p_175852_2_, int x, int y, int z, EnumFacing facing, int p_175852_7_)
  103.         {
  104.             StructureBoundingBox structureboundingbox = StructureBoundingBox.func_175897_a(x, y, z, 0, 0, 0, 7, 4, 9, facing);
  105.             return canVillageGoDeeper(structureboundingbox) && StructureComponent.findIntersecting(p_175852_1_, structureboundingbox) == null ? new ComponentCornField(p_175852_0_, p_175852_7_, p_175852_2_, structureboundingbox, facing) : null;
  106.         }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment