2016-11-20 23:52:40 +01:00
|
|
|
/*
|
|
|
|
* This file ("VillageComponentEngineerHouse.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
|
|
|
* © 2015-2016 Ellpeck
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.gen;
|
|
|
|
|
2016-11-21 14:56:45 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
|
|
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.*;
|
2016-11-20 23:52:40 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.init.Blocks;
|
2016-11-21 14:56:45 +01:00
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-11-20 23:52:40 +01:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
2016-11-21 14:56:45 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-11-20 23:52:40 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.Mirror;
|
|
|
|
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.structure.StructureBoundingBox;
|
|
|
|
import net.minecraft.world.gen.structure.StructureComponent;
|
|
|
|
import net.minecraft.world.gen.structure.StructureVillagePieces;
|
|
|
|
import net.minecraft.world.gen.structure.template.PlacementSettings;
|
|
|
|
import net.minecraft.world.gen.structure.template.Template;
|
|
|
|
import net.minecraft.world.gen.structure.template.TemplateManager;
|
2016-11-21 14:56:45 +01:00
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2016-11-20 23:52:40 +01:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class VillageComponentEngineerHouse extends StructureVillagePieces.House1{
|
|
|
|
|
2016-11-20 23:55:58 +01:00
|
|
|
private static final ResourceLocation STRUCTURE_RES_LOC = new ResourceLocation(ModUtil.MOD_ID, "andrew_period_house");
|
2016-11-20 23:52:40 +01:00
|
|
|
|
|
|
|
private static final int X_SIZE = 13;
|
|
|
|
private static final int Y_SIZE = 11;
|
|
|
|
private static final int Z_SIZE = 10;
|
|
|
|
|
|
|
|
private int averageGroundLevel = -1;
|
|
|
|
|
|
|
|
public VillageComponentEngineerHouse(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public VillageComponentEngineerHouse(StructureBoundingBox boundingBox, EnumFacing par5){
|
|
|
|
this.setCoordBaseMode(par5);
|
|
|
|
this.boundingBox = boundingBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static VillageComponentEngineerHouse buildComponent(List pieces, int p1, int p2, int p3, EnumFacing p4){
|
|
|
|
StructureBoundingBox boundingBox = StructureBoundingBox.getComponentToAddBoundingBox(p1, p2, p3, 0, 0, 0, X_SIZE, Y_SIZE, Z_SIZE, p4);
|
|
|
|
return canVillageGoDeeper(boundingBox) && StructureComponent.findIntersecting(pieces, boundingBox) == null ? new VillageComponentEngineerHouse(boundingBox, p4) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addComponentParts(World world, Random rand, StructureBoundingBox sbb){
|
|
|
|
if(this.averageGroundLevel < 0){
|
|
|
|
this.averageGroundLevel = this.getAverageGroundLevel(world, sbb);
|
|
|
|
if(this.averageGroundLevel < 0){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
this.boundingBox.offset(0, this.averageGroundLevel-this.boundingBox.maxY+Y_SIZE-2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.fillWithBlocks(world, sbb, 0, 0, 0, X_SIZE-1, Y_SIZE-1, Z_SIZE-1, Blocks.AIR);
|
2016-11-21 14:56:45 +01:00
|
|
|
this.spawnActualHouse(world, sbb);
|
|
|
|
this.fillHouse(world);
|
2016-11-20 23:52:40 +01:00
|
|
|
|
|
|
|
for(int i = 0; i < X_SIZE; i++){
|
|
|
|
for(int j = 0; j < Z_SIZE; j++){
|
|
|
|
this.clearCurrentPositionBlocksUpwards(world, i, Y_SIZE, j, sbb);
|
|
|
|
this.replaceAirAndLiquidDownwards(world, Blocks.DIRT.getDefaultState(), i, -1, j, sbb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.spawnVillagers(world, sbb, 3, 1, 3, 1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-21 14:56:45 +01:00
|
|
|
private void fillWithBlocks(World world, StructureBoundingBox sbb, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, Block block){
|
2016-11-20 23:52:40 +01:00
|
|
|
this.fillWithBlocks(world, sbb, minX, minY, minZ, maxX, maxY, maxZ, block.getDefaultState(), block.getDefaultState(), false);
|
|
|
|
}
|
|
|
|
|
2016-11-21 14:56:45 +01:00
|
|
|
private void fillHouse(World world){
|
|
|
|
if(world.rand.nextBoolean()){
|
|
|
|
TileEntity compost = this.getTileAtPos(world, 6, 1, 2);
|
|
|
|
if(compost instanceof TileEntityCompost){
|
|
|
|
((TileEntityCompost)compost).setInventorySlotContents(0, new ItemStack(InitItems.itemFertilizer, 10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity ferment = this.getTileAtPos(world, 11, 1, 0);
|
|
|
|
if(ferment instanceof TileEntityFermentingBarrel){
|
|
|
|
TileEntityFermentingBarrel tile = (TileEntityFermentingBarrel)ferment;
|
|
|
|
tile.canolaTank.setFluid(new FluidStack(InitFluids.fluidCanolaOil, world.rand.nextInt(1500)+200));
|
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity coffee = this.getTileAtPos(world, 4, 2, 6);
|
|
|
|
if(coffee instanceof TileEntityCoffeeMachine){
|
|
|
|
TileEntityCoffeeMachine tile = (TileEntityCoffeeMachine)coffee;
|
|
|
|
tile.tank.setFluid(new FluidStack(FluidRegistry.WATER, world.rand.nextInt(3000)+500));
|
|
|
|
tile.coffeeCacheAmount = world.rand.nextInt(150);
|
|
|
|
tile.storage.setEnergyStored(world.rand.nextInt(tile.storage.getMaxEnergyStored()/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity press = this.getTileAtPos(world, 2, 1, 5);
|
|
|
|
if(press instanceof TileEntityCanolaPress){
|
|
|
|
TileEntityCanolaPress tile = (TileEntityCanolaPress)press;
|
|
|
|
tile.storage.setEnergyStored(world.rand.nextInt(tile.storage.getMaxEnergyStored()/3));
|
|
|
|
tile.setInventorySlotContents(0, new ItemStack(InitItems.itemMisc, world.rand.nextInt(60)+1, TheMiscItems.CANOLA.ordinal()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity crusher = this.getTileAtPos(world, 2, 1, 6);
|
|
|
|
if(crusher instanceof TileEntityGrinder){
|
|
|
|
TileEntityGrinder tile = (TileEntityGrinder)crusher;
|
|
|
|
tile.storage.setEnergyStored(world.rand.nextInt(tile.storage.getMaxEnergyStored()/2));
|
|
|
|
if(world.rand.nextBoolean()){
|
|
|
|
tile.setInventorySlotContents(TileEntityGrinder.SLOT_INPUT_1, new ItemStack(InitBlocks.blockMisc, world.rand.nextInt(10)+1, TheMiscBlocks.ORE_QUARTZ.ordinal()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity coal = this.getTileAtPos(world, 5, 5, 6);
|
|
|
|
if(coal instanceof TileEntityCoalGenerator){
|
|
|
|
((TileEntityCoalGenerator)coal).setInventorySlotContents(0, new ItemStack(Items.COAL, world.rand.nextInt(25)+3, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity firstRelay = this.getTileAtPos(world, 6, 5, 6);
|
|
|
|
TileEntity secondRelay = this.getTileAtPos(world, 8, 5, 3);
|
|
|
|
if(firstRelay instanceof TileEntityLaserRelayEnergy && secondRelay instanceof TileEntityLaserRelayEnergy){
|
|
|
|
ActuallyAdditionsAPI.connectionHandler.addConnection(firstRelay.getPos(), secondRelay.getPos(), LaserType.ENERGY, world);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockPos lamp = new BlockPos(this.getXWithOffset(8, 6), this.getYWithOffset(1), this.getZWithOffset(8, 6));
|
|
|
|
int meta = world.rand.nextInt(TheColoredLampColors.values().length);
|
|
|
|
world.setBlockState(lamp, InitBlocks.blockColoredLamp.getStateFromMeta(meta));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void spawnActualHouse(World world, StructureBoundingBox sbb){
|
2016-11-20 23:52:40 +01:00
|
|
|
TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
|
|
|
|
MinecraftServer server = world.getMinecraftServer();
|
|
|
|
|
|
|
|
if(manager != null && server != null){
|
|
|
|
EnumFacing facing = this.getCoordBaseMode();
|
|
|
|
|
|
|
|
Mirror mirror;
|
|
|
|
Rotation rotation;
|
|
|
|
if(facing == EnumFacing.SOUTH){
|
|
|
|
mirror = Mirror.NONE;
|
|
|
|
rotation = Rotation.NONE;
|
|
|
|
}
|
|
|
|
else if(facing == EnumFacing.WEST){
|
|
|
|
mirror = Mirror.NONE;
|
|
|
|
rotation = Rotation.CLOCKWISE_90;
|
|
|
|
}
|
|
|
|
else if(facing == EnumFacing.EAST){
|
|
|
|
mirror = Mirror.LEFT_RIGHT;
|
|
|
|
rotation = Rotation.CLOCKWISE_90;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
mirror = Mirror.LEFT_RIGHT;
|
|
|
|
rotation = Rotation.NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlacementSettings placement = new PlacementSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(sbb);
|
|
|
|
Template template = manager.getTemplate(server, STRUCTURE_RES_LOC);
|
|
|
|
|
|
|
|
if(template != null){
|
|
|
|
template.addBlocksToWorld(world, new BlockPos(this.getXWithOffset(0, 0), this.getYWithOffset(0), this.getZWithOffset(0, 0)), placement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 14:56:45 +01:00
|
|
|
private TileEntity getTileAtPos(World world, int x, int y, int z){
|
|
|
|
BlockPos pos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
|
|
|
|
return world.getTileEntity(pos);
|
|
|
|
}
|
|
|
|
|
2016-11-20 23:52:40 +01:00
|
|
|
/*@Override
|
|
|
|
protected VillagerProfession chooseForgeProfession(int count, VillagerProfession prof){
|
|
|
|
return InitVillager.jamProfession;
|
|
|
|
}*/
|
|
|
|
}
|