Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.madcrazydrumma.skyrimcraft.world;
- import net.madcrazydrumma.skyrimcraft.block.BlockHandler;
- import net.madcrazydrumma.skyrimcraft.util.ModInfo;
- import net.minecraft.block.*;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.init.Blocks;
- import net.minecraft.tileentity.TileEntityChest;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.Rotation;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import net.minecraft.world.gen.feature.WorldGenerator;
- import net.minecraftforge.fml.common.registry.GameRegistry;
- import java.util.Random;
- public class AnvilHutGenerator extends WorldGenerator
- {
- public static final ResourceLocation chestLoot = new ResourceLocation(ModInfo.MODID, "loot_tables/anvilHutLoot.json");
- private final int[][] andesitePos = new int[][]{
- //Floor
- {0, -1, 0}, {1, -1, 0}, {2, -1, 0}, {3, -1, 0}, {4, -1, 0}, {5, -1, 0}, {6, -1, 0}, {7, -1, 0}, {8, -1, 0},
- {0, -1, 1}, {1, -1, 1}, {2, -1, 1}, {3, -1, 1}, {4, -1, 1}, {5, -1, 1}, {6, -1, 1}, {7, -1, 1}, {8, -1, 1},
- {0, -1, 2}, {1, -1, 2}, {2, -1, 2}, {3, -1, 2}, {4, -1, 2}, {5, -1, 2}, {6, -1, 2}, {7, -1, 2}, {8, -1, 2},
- {0, -1, 3}, {1, -1, 3}, {2, -1, 3}, {3, -1, 3}, {4, -1, 3}, {5, -1, 3}, {6, -1, 3}, {7, -1, 3}, {8, -1, 3},
- {0, -1, 4}, {1, -1, 4}, {2, -1, 4}, {3, -1, 4}, {4, -1, 4}, {5, -1, 4}, {6, -1, 4}, {7, -1, 4}, {8, -1, 4},
- {0, -1, 5}, {1, -1, 5}, {2, -1, 5}, {3, -1, 5}, {4, -1, 5}, {5, -1, 5}, {6, -1, 5}, {7, -1, 5}, {8, -1, 5},
- {0, -1, 6}, {1, -1, 6}, {2, -1, 6}, {3, -1, 6}, {4, -1, 6}, {5, -1, 6}, {6, -1, 6}, {7, -1, 6}, {8, -1, 6},
- {0, -1, 7}, {1, -1, 7}, {2, -1, 7}, {3, -1, 7}, {4, -1, 7}, {5, -1, 7}, {6, -1, 7}, {7, -1, 7}, {8, -1, 7},
- {0, -1, 8}, {1, -1, 8}, {2, -1, 8}, {3, -1, 8}, {4, -1, 8}, {5, -1, 8}, {6, -1, 8}, {7, -1, 8}, {8, -1, 8},
- {0, -1, 9}, {1, -1, 9}, {2, -1, 9}, {3, -1, 9}, {4, -1, 9}, {5, -1, 9}, {6, -1, 9}, {7, -1, 9}, {8, -1, 9},
- {0, -1, 10}, {1, -1, 10}, {2, -1, 10}, {3, -1, 10}, {4, -1, 10}, {5, -1, 10}, {6, -1, 10}, {7, -1, 10}, {8, -1, 10},
- {0, -1, 11}, {1, -1, 11}, {2, -1, 11}, {3, -1, 11}, {4, -1, 11}, {5, -1, 11}, {6, -1, 11}, {7, -1, 11}, {8, -1, 11},
- {0, -1, 12}, {1, -1, 12}, {2, -1, 12}, {3, -1, 12}, {4, -1, 12}, {5, -1, 12}, {6, -1, 12}, {7, -1, 12}, {8, -1, 12}
- };
- private final int[][] oakLogsPos = new int[][] {
- //Corners
- {1, 0, 1}, {7, 0, 1}, {1, 0, 11}, {7, 0, 11},
- {1, 1, 1}, {7, 1, 1}, {1, 1, 11}, {7, 1, 11},
- {1, 2, 1}, {7, 2, 1}, {1, 2, 11}, {7, 2, 11},
- //Middle
- {1, 0, 6}, {7, 0, 6},
- {1, 1, 6}, {7, 1, 6},
- {1, 2, 6}, {7, 2, 6}
- };
- private final int[][] planksPos = new int[][] {
- {1, 3, 1}, {2, 3, 1}, {3, 3, 1}, {4, 3, 1}, {5, 3, 1}, {6, 3, 1}, {7, 3, 1},
- {1, 3, 2}, {2, 3, 2}, {3, 3, 2}, {4, 3, 2}, {5, 3, 2}, {6, 3, 2}, {7, 3, 2},
- {1, 3, 3}, {2, 3, 3}, {3, 3, 3}, {4, 3, 3}, {5, 3, 3}, {6, 3, 3}, {7, 3, 3},
- {1, 3, 4}, {2, 3, 4}, {3, 3, 4}, {4, 3, 4}, {5, 3, 4}, {6, 3, 4}, {7, 3, 4},
- {1, 3, 5}, {2, 3, 5}, {3, 3, 5}, {4, 3, 5}, {5, 3, 5}, {6, 3, 5}, {7, 3, 5},
- {1, 3, 6}, {2, 3, 6}, {3, 3, 6}, {4, 3, 6}, {5, 3, 6}, {6, 3, 6}, {7, 3, 6},
- {1, 3, 7}, {2, 3, 7}, {3, 3, 7}, {4, 3, 7}, {5, 3, 7}, {6, 3, 7}, {7, 3, 7},
- {1, 3, 8}, {2, 3, 8}, {3, 3, 8}, {4, 3, 8}, {5, 3, 8}, {6, 3, 8}, {7, 3, 8},
- {1, 3, 9}, {2, 3, 9}, {3, 3, 9}, {4, 3, 9}, {5, 3, 9}, {6, 3, 9}, {7, 3, 9},
- {1, 3, 10}, {2, 3, 10}, {3, 3, 10}, {4, 3, 10}, {5, 3, 10}, {6, 3, 10}, {7, 3, 10},
- {1, 3, 11}, {2, 3, 11}, {3, 3, 11}, {4, 3, 11}, {5, 3, 11}, {6, 3, 11}, {7, 3, 11}
- };
- private final int[][] fencePos = new int[][] {
- /* ENTRANCES */
- {2, 0, 1}, {2, 0, 11},
- {3, 0, 1}, {3, 0, 11},
- // 4 is entrance?
- {5, 0, 1}, {5, 0, 11},
- {6, 0, 1}, {6, 0, 11},
- /* END ENTRANCES */
- // EDGES
- {1, 0, 2}, {1, 0, 3}, {1, 0, 4}, {1, 0, 5}, /*6 is middle so dont place fence*/ {1, 0, 7}, {1, 0, 8}, {1, 0, 9}, {1, 0, 10},
- {7, 0, 2}, {7, 0, 3}, {7, 0, 4}, {7, 0, 5}, /*6 is middle so dont place fence*/ {7, 0, 7}, {7, 0, 8}, {7, 0, 9}, {7, 0, 10},
- //Random
- {2, 0, 5}, {3, 0, 5}, {5, 0, 7}, {6, 0, 7}
- };
- private final int[][] fenceGatePos = new int[][] {
- {4, 0, 1}, {4, 0, 11}
- };
- private final int[] chestPos = new int[] {2, 0, 4};
- private final int[][] anvilPos = new int[][] {
- {5, 0, 6}, {6, 0, 6}
- };
- private final int[][] torchPos = new int[][] {
- };
- public AnvilHutGenerator() {
- }
- @Override
- public boolean generate(World worldIn, Random rand, BlockPos corner) {
- if(canSpawnHere(worldIn, corner)) {
- IBlockState andesite = Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE);
- IBlockState oakLogs = Blocks.LOG.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.OAK);
- IBlockState planks = Blocks.PLANKS.getDefaultState().withProperty(BlockPlanks.VARIANT, BlockPlanks.EnumType.OAK);
- IBlockState fence = Blocks.OAK_FENCE.getDefaultState();
- IBlockState fenceGate = Blocks.OAK_FENCE_GATE.getDefaultState();
- IBlockState chest = Blocks.CHEST.getDefaultState().withRotation(Rotation.CLOCKWISE_90);
- IBlockState anvil = BlockHandler.anvil.getDefaultState().withRotation(Rotation.CLOCKWISE_90);
- //Build layers from arrays
- buildLayer(worldIn, corner, andesitePos, andesite);
- buildLayer(worldIn, corner, oakLogsPos, oakLogs);
- buildLayer(worldIn, corner, fencePos, fence);
- buildLayer(worldIn, corner, fenceGatePos, fenceGate);
- buildLayer(worldIn, corner, anvilPos, anvil);
- buildLayer(worldIn, corner, planksPos, planks);
- //Place other features LAST (chests, torches, etc.)
- placeBlock(worldIn, corner, chestPos, chest);
- BlockPos actualPos = corner.add(chestPos[0], chestPos[1], chestPos[2]);
- TileEntityChest chestTE = (TileEntityChest)worldIn.getTileEntity(actualPos);
- if(chestTE != null)
- chestTE.setLootTable(chestLoot, actualPos.toLong());
- return true;
- }
- return false;
- }
- // use an int[][] to place a lot of one block at once
- private void buildLayer(World world, BlockPos frontLeftCorner, int[][] blockPositions, IBlockState toPlace) {
- // iterate through the entire int[][]
- for(int[] coord : blockPositions) {
- placeBlock(world, frontLeftCorner, coord[0], coord[1], coord[2], toPlace);
- }
- }
- /** Helper Method **/
- private void placeBlock(World world, BlockPos frontLeftCorner, int[] offsets, IBlockState toPlace) {
- placeBlock(world, frontLeftCorner, offsets[0], offsets[1], offsets[2], toPlace);
- }
- /** Places a block using corner position and offsets **/
- private void placeBlock(World world, BlockPos frontLeftCorner, int offsetX, int offsetY, int offsetZ, IBlockState toPlace) {
- // figure out where that block is relative to the corner
- BlockPos placePos = frontLeftCorner.add(offsetX, offsetY, offsetZ);
- world.setBlockState(placePos, toPlace, 2);
- }
- private boolean canSpawnHere(World world, BlockPos posAboveGround) {
- // check all the corners to see which ones are replaceable
- boolean corner1Air = canReplace(world, posAboveGround);
- boolean corner2Air = canReplace(world, posAboveGround.add(12, 0, 0)); //Blocks away from origin
- boolean corner4Air = canReplace(world, posAboveGround.add(0, 0, 8));
- boolean corner3Air = canReplace(world, posAboveGround.add(12, 0, 8));
- // if Y > 20 and all corners pass the test, it's okay to spawn the structure
- return posAboveGround.getY() > 20 && corner1Air && corner2Air && corner3Air && corner4Air;
- }
- private boolean canReplace(World world, BlockPos pos) {
- Block at = world.getBlockState(pos).getBlock();
- Material material = at.getDefaultState().getMaterial();
- // we think it's replaceable if it's air / liquid / snow, plants, or leaves
- return material.isReplaceable() || material == Material.PLANTS || material == Material.LEAVES;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement