Add rubber plantation to villages
This commit is contained in:
parent
790c363c03
commit
07ffd97e92
6 changed files with 234 additions and 2 deletions
|
@ -26,6 +26,7 @@ package techreborn;
|
|||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.gen.structure.MapGenStructureIO;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
|
@ -36,6 +37,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.common.registry.VillagerRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.api.recipe.RecipeHandler;
|
||||
|
@ -61,6 +63,9 @@ import techreborn.proxies.CommonProxy;
|
|||
import techreborn.utils.StackWIPHandler;
|
||||
import techreborn.world.OilLakeGenerator;
|
||||
import techreborn.world.TechRebornWorldGen;
|
||||
import techreborn.world.village.ModLootTables;
|
||||
import techreborn.world.village.VillageComponentRubberPlantaion;
|
||||
import techreborn.world.village.VillagePlantaionHandler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
@ -144,6 +149,10 @@ public class Core {
|
|||
MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new TRTickHandler());
|
||||
MinecraftForge.EVENT_BUS.register(worldGen.retroGen);
|
||||
//Village stuff
|
||||
VillagerRegistry.instance().registerVillageCreationHandler(new VillagePlantaionHandler());
|
||||
MapGenStructureIO.registerStructureComponent(VillageComponentRubberPlantaion.class, new ResourceLocation(ModInfo.MOD_ID, "rubberplantation").toString());
|
||||
ModLootTables.CHESTS_RUBBER_PLANTATION.toString(); //Done to make it load, then it will be read from disk
|
||||
// Scrapbox
|
||||
if (BehaviorDispenseScrapbox.dispenseScrapboxes) {
|
||||
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(ModItems.SCRAP_BOX, new BehaviorDispenseScrapbox());
|
||||
|
|
|
@ -130,7 +130,7 @@ public class RubberTreeGenerator extends WorldGenerator {
|
|||
|| block.canBeReplacedByLeaves(state1, world,
|
||||
new BlockPos(xOffset, yOffset, zOffset)))) {
|
||||
this.setBlockAndNotifyAdequately(world, new BlockPos(xOffset, yOffset, zOffset),
|
||||
ModBlocks.RUBBER_LEAVES.getDefaultState());
|
||||
ModBlocks.RUBBER_LEAVES.getDefaultState().withProperty(BlockRubberLeaves.DECAYABLE, true).withProperty(BlockRubberLeaves.CHECK_DECAY, false));
|
||||
hasPlacedBlock = true;
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public class RubberTreeGenerator extends WorldGenerator {
|
|||
for (int i = 0; i < Core.worldGen.config.rubberTreeConfig.spireHeight; i++) {
|
||||
BlockPos spikePos = topLogPos.up(i);
|
||||
this.setBlockAndNotifyAdequately(world, spikePos, ModBlocks.RUBBER_LEAVES.getDefaultState()
|
||||
.withProperty(BlockRubberLeaves.DECAYABLE, true));
|
||||
.withProperty(BlockRubberLeaves.DECAYABLE, true).withProperty(BlockRubberLeaves.CHECK_DECAY, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
11
src/main/java/techreborn/world/village/ModLootTables.java
Normal file
11
src/main/java/techreborn/world/village/ModLootTables.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package techreborn.world.village;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.LootTableList;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
public class ModLootTables {
|
||||
|
||||
public static final ResourceLocation CHESTS_RUBBER_PLANTATION = LootTableList.register(new ResourceLocation(ModInfo.MOD_ID, "chests/rubber_plantation"));
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package techreborn.world.village;
|
||||
|
||||
import net.minecraft.block.BlockCrops;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||
import net.minecraft.world.gen.structure.StructureComponent;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.world.RubberTreeGenerator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class VillageComponentRubberPlantaion extends StructureVillagePieces.Field1 {
|
||||
|
||||
public static StructureVillagePieces.Village buildComponent(StructureVillagePieces.PieceWeight villagePiece, StructureVillagePieces.Start startPiece, List<StructureComponent> pieces, Random random, int p1, int p2, int p3, EnumFacing facing, int p5) {
|
||||
StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(p1, p2, p3, 0, 0, 0, 13, 4, 9, facing);
|
||||
return canVillageGoDeeper(structureboundingbox) && StructureComponent.findIntersecting(pieces, structureboundingbox) == null ? new VillageComponentRubberPlantaion(startPiece, p5, random, structureboundingbox, facing) : null;
|
||||
}
|
||||
|
||||
public VillageComponentRubberPlantaion() {
|
||||
}
|
||||
|
||||
public VillageComponentRubberPlantaion(StructureVillagePieces.Start start, int type, Random rand, StructureBoundingBox structureBoundingBox, EnumFacing facing) {
|
||||
super(start, type, rand, structureBoundingBox, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillWithBlocks(World worldIn, StructureBoundingBox boundingboxIn, int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, IBlockState boundaryBlockState, IBlockState insideBlockState, boolean existingOnly) {
|
||||
//Replaces farmland with dirt, its not great but it works.
|
||||
if (boundaryBlockState.getBlock() == Blocks.FARMLAND) {
|
||||
boundaryBlockState = Blocks.GRASS.getDefaultState();
|
||||
insideBlockState = Blocks.GRASS.getDefaultState();
|
||||
}
|
||||
//Replaces the water and logs with stone bricks
|
||||
if (boundaryBlockState.getBlock() == Blocks.WATER || boundaryBlockState.getBlock() == Blocks.LOG) {
|
||||
boundaryBlockState = Blocks.STONEBRICK.getDefaultState();
|
||||
insideBlockState = Blocks.STONEBRICK.getDefaultState();
|
||||
}
|
||||
super.fillWithBlocks(worldIn, boundingboxIn, xMin, yMin, zMin, xMax, yMax, zMax, boundaryBlockState, insideBlockState, existingOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setBlockState(World worldIn, IBlockState blockstateIn, int x, int y, int z, StructureBoundingBox boundingboxIn) {
|
||||
if (isCrop(blockstateIn)) {
|
||||
blockstateIn = ModBlocks.RUBBER_SAPLING.getDefaultState();
|
||||
}
|
||||
super.setBlockState(worldIn, blockstateIn, x, y, z, boundingboxIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) {
|
||||
super.addComponentParts(worldIn, randomIn, structureBoundingBoxIn);
|
||||
for (int i = 1; i < 7; i++) {
|
||||
growRandom(i, 1, structureBoundingBoxIn, randomIn, worldIn);
|
||||
growRandom(i, 2, structureBoundingBoxIn, randomIn, worldIn);
|
||||
growRandom(i, 4, structureBoundingBoxIn, randomIn, worldIn);
|
||||
growRandom(i, 5, structureBoundingBoxIn, randomIn, worldIn);
|
||||
growRandom(i, 7, structureBoundingBoxIn, randomIn, worldIn);
|
||||
growRandom(i, 8, structureBoundingBoxIn, randomIn, worldIn);
|
||||
growRandom(i, 10, structureBoundingBoxIn, randomIn, worldIn);
|
||||
growRandom(i, 11, structureBoundingBoxIn, randomIn, worldIn);
|
||||
}
|
||||
generateChest(worldIn, structureBoundingBoxIn, randomIn, 0, 1, 0, ModLootTables.CHESTS_RUBBER_PLANTATION);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void growRandom(int coloum, int row, StructureBoundingBox structureBoundingBox, Random random, World world) {
|
||||
if (random.nextInt(10) == 0) {
|
||||
setBlockState(world, Blocks.AIR.getDefaultState(), row, 1, coloum, structureBoundingBox);
|
||||
BlockPos pos = new BlockPos(this.getXWithOffset(row, coloum), this.getYWithOffset(1), this.getZWithOffset(row, coloum));
|
||||
if (!new RubberTreeGenerator(true).growTree(world, random, pos.getX(), pos.getY(), pos.getZ())) {
|
||||
//Puts the sapling back if the tree did not grow
|
||||
setBlockState(world, ModBlocks.RUBBER_SAPLING.getDefaultState(), row, 1, coloum, structureBoundingBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCrop(IBlockState state) {
|
||||
if (state.getBlock() instanceof BlockCrops) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package techreborn.world.village;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.gen.structure.StructureComponent;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces;
|
||||
import net.minecraftforge.fml.common.registry.VillagerRegistry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class VillagePlantaionHandler implements VillagerRegistry.IVillageCreationHandler {
|
||||
|
||||
@Override
|
||||
public StructureVillagePieces.PieceWeight getVillagePieceWeight(Random random, int i) {
|
||||
return new StructureVillagePieces.PieceWeight(VillageComponentRubberPlantaion.class, 5, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getComponentClass() {
|
||||
return VillageComponentRubberPlantaion.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureVillagePieces.Village buildComponent(StructureVillagePieces.PieceWeight villagePiece, StructureVillagePieces.Start startPiece, List<StructureComponent> pieces, Random random, int p1, int p2, int p3, EnumFacing facing, int p5) {
|
||||
return VillageComponentRubberPlantaion.buildComponent(villagePiece, startPiece, pieces, random, p1, p2, p3, facing, p5);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
{
|
||||
"pools": [
|
||||
{
|
||||
"name": "techreborn:rubber_plantation",
|
||||
"rolls": {
|
||||
"min": 1,
|
||||
"max": 5
|
||||
},
|
||||
"bonus_rolls": {
|
||||
"min": 1,
|
||||
"max": 3
|
||||
},
|
||||
"entries": [
|
||||
{
|
||||
"type": "item",
|
||||
"name": "techreborn:treetap",
|
||||
"weight": 6,
|
||||
"functions": [
|
||||
{
|
||||
"function": "set_data",
|
||||
"data": 0
|
||||
},
|
||||
{
|
||||
"function": "set_count",
|
||||
"count": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "item",
|
||||
"name": "minecraft:dye",
|
||||
"weight": 4,
|
||||
"functions": [
|
||||
{
|
||||
"function": "set_data",
|
||||
"data": 15
|
||||
},
|
||||
{
|
||||
"function": "set_count",
|
||||
"count" : {
|
||||
"min": 8,
|
||||
"max": 16
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "item",
|
||||
"name": "techreborn:part",
|
||||
"weight": 3,
|
||||
"functions": [
|
||||
{
|
||||
"function": "set_data",
|
||||
"data": 31
|
||||
},
|
||||
{
|
||||
"function": "set_count",
|
||||
"count" : {
|
||||
"min": 1,
|
||||
"max": 64
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "item",
|
||||
"name": "techreborn:rubber_sapling",
|
||||
"weight": 4,
|
||||
"functions": [
|
||||
{
|
||||
"function": "set_count",
|
||||
"count" : {
|
||||
"min": 1,
|
||||
"max": 16
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "item",
|
||||
"name": "techreborn:rubber_log",
|
||||
"weight": 4,
|
||||
"functions": [
|
||||
{
|
||||
"function": "set_count",
|
||||
"count": {
|
||||
"min": 1,
|
||||
"max": 16
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue