TheBrokenRail
b3d5f35072
All checks were successful
EnergonRelics/pipeline/head This commit looks good
195 lines
7.5 KiB
Java
195 lines
7.5 KiB
Java
package com.thebrokenrail.energonrelics.structure.researchcomplex;
|
|
|
|
import com.thebrokenrail.energonrelics.EnergonRelics;
|
|
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
|
import com.thebrokenrail.energonrelics.structure.StructureContext;
|
|
import com.thebrokenrail.energonrelics.util.WeightedList;
|
|
import net.minecraft.block.AnvilBlock;
|
|
import net.minecraft.block.BarrelBlock;
|
|
import net.minecraft.block.BedBlock;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.block.ChestBlock;
|
|
import net.minecraft.block.DoorBlock;
|
|
import net.minecraft.block.entity.BlockEntity;
|
|
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
|
import net.minecraft.block.enums.BedPart;
|
|
import net.minecraft.block.enums.ChestType;
|
|
import net.minecraft.block.enums.DoubleBlockHalf;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.Direction;
|
|
import net.minecraft.world.World;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public abstract class AbstractResearchComplexRoomPart extends BaseResearchComplexPart {
|
|
public AbstractResearchComplexRoomPart(ResearchComplexState state, List<Transformation> list) {
|
|
super(state, list);
|
|
}
|
|
|
|
@Override
|
|
protected void build(StructureContext context) {
|
|
if (hasEnergy()) {
|
|
BlockState air = Blocks.AIR.getDefaultState();
|
|
BlockState bricks = Blocks.QUARTZ_BRICKS.getDefaultState();
|
|
|
|
rect(new BlockPos(-1, 0, 2), getWidth() * 3, 3, 3, air);
|
|
rect(new BlockPos(-1, -1, 2), getWidth() * 3, 1, 3, bricks);
|
|
rect(new BlockPos(-1, 3, 2), getWidth() * 3, 1, 3, bricks);
|
|
rect(new BlockPos(-1, 0, 5), getWidth() * 3, 3, 1, bricks);
|
|
rect(new BlockPos(-1, 0, 1), getWidth() * 3, 3, 1, bricks);
|
|
rect(new BlockPos(-2, 0, 2), 1, 3, 3, bricks);
|
|
rect(new BlockPos(-1 + getWidth() * 3, 0, 2), 1, 3, 3, bricks);
|
|
|
|
BlockState plate = Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE.getDefaultState();
|
|
|
|
set(new BlockPos(0, -1, 0), bricks);
|
|
set(new BlockPos(0, 0, 0), plate);
|
|
|
|
BlockState door = Blocks.IRON_DOOR.getDefaultState().with(DoorBlock.FACING, Direction.SOUTH);
|
|
BlockState bottomDoor = door.with(DoorBlock.HALF, DoubleBlockHalf.LOWER);
|
|
BlockState topDoor = door.with(DoorBlock.HALF, DoubleBlockHalf.UPPER);
|
|
|
|
set(new BlockPos(0, 0, 1), bottomDoor);
|
|
set(new BlockPos(0, 1, 1), topDoor);
|
|
set(new BlockPos(0, -1, 1), bricks);
|
|
|
|
set(new BlockPos(0, 0, 2), plate);
|
|
|
|
BlockState light = EnergonRelics.ENERGON_LIGHT_BLOCK.getDefaultState();
|
|
List<BlockPos> list = getLights();
|
|
for (BlockPos pos : list) {
|
|
set(pos, light);
|
|
}
|
|
|
|
buildInterior();
|
|
}
|
|
}
|
|
|
|
protected abstract void buildInterior();
|
|
|
|
private List<BlockPos> getLights() {
|
|
List<BlockPos> lights = new ArrayList<>();
|
|
for (int i = 0; i < getWidth(); i++) {
|
|
lights.add(new BlockPos(i * 3, 3, 3));
|
|
}
|
|
return lights;
|
|
}
|
|
|
|
protected boolean hasEnergy() {
|
|
List<BlockPos> list = getLights();
|
|
return getState().hasEnergy(list.size() * HardcodedConfig.ENERGON_LIGHT_ENERGY_REQUIRED, getPosFromOrigin(list.get(list.size() - 1)));
|
|
}
|
|
|
|
abstract int getWidth();
|
|
|
|
@Override
|
|
protected void handleBlockPlace(World world, BlockPos pos, BlockState state) {
|
|
super.handleBlockPlace(world, pos, state);
|
|
BlockEntity entity = world.getBlockEntity(pos);
|
|
if (entity instanceof LootableContainerBlockEntity) {
|
|
((LootableContainerBlockEntity) entity).setLootTable(new Identifier(EnergonRelics.NAMESPACE, "chests/research_complex"), getState().random.nextLong());
|
|
}
|
|
}
|
|
|
|
private static class BedRoom extends AbstractResearchComplexRoomPart {
|
|
private BedRoom(ResearchComplexState state, List<Transformation> list) {
|
|
super(state, list);
|
|
}
|
|
|
|
@Override
|
|
int getWidth() {
|
|
return 1;
|
|
}
|
|
|
|
@Override
|
|
protected void buildInterior() {
|
|
BlockState chest = Blocks.CHEST.getDefaultState();
|
|
|
|
BlockState bed = Blocks.RED_BED.getDefaultState();
|
|
BlockState bedFoot = bed.with(BedBlock.PART, BedPart.FOOT);
|
|
BlockState bedHead = bed.with(BedBlock.PART, BedPart.HEAD);
|
|
|
|
set(new BlockPos(-1, 0, 2), bedHead);
|
|
set(new BlockPos(-1, 0, 3), bedFoot);
|
|
set(new BlockPos(-1, 0, 4), chest);
|
|
|
|
set(new BlockPos(1, 0, 2), bedHead);
|
|
set(new BlockPos(1, 0, 3), bedFoot);
|
|
set(new BlockPos(1, 0, 4), chest);
|
|
}
|
|
}
|
|
|
|
private static class CraftingRoom extends AbstractResearchComplexRoomPart {
|
|
private CraftingRoom(ResearchComplexState state, List<Transformation> list) {
|
|
super(state, list);
|
|
}
|
|
|
|
@Override
|
|
int getWidth() {
|
|
return 2;
|
|
}
|
|
|
|
@Override
|
|
protected void buildInterior() {
|
|
BlockState chest = Blocks.CHEST.getDefaultState().with(ChestBlock.FACING, Direction.SOUTH);
|
|
set(new BlockPos(2, 0, 2), chest.with(ChestBlock.CHEST_TYPE, ChestType.RIGHT));
|
|
set(new BlockPos(3, 0, 2), chest.with(ChestBlock.CHEST_TYPE, ChestType.LEFT));
|
|
|
|
WeightedList<Block> anvilList = new WeightedList<>();
|
|
anvilList.add(1, Blocks.ANVIL);
|
|
anvilList.add(1, Blocks.CHIPPED_ANVIL);
|
|
anvilList.add(1, Blocks.DAMAGED_ANVIL);
|
|
BlockState anvil = anvilList.pick(getState().random).getDefaultState();
|
|
|
|
anvil = anvil.with(AnvilBlock.FACING, Direction.EAST);
|
|
|
|
set(new BlockPos(4, 0, 4), anvil);
|
|
set(new BlockPos(3, 0, 4), Blocks.BLAST_FURNACE.getDefaultState());
|
|
set(new BlockPos(2, 0, 4), Blocks.SMOKER.getDefaultState());
|
|
set(new BlockPos(1, 0, 4), Blocks.FURNACE.getDefaultState());
|
|
set(new BlockPos(0, 0, 4), Blocks.STONECUTTER.getDefaultState());
|
|
set(new BlockPos(-1, 0, 4), Blocks.CRAFTING_TABLE.getDefaultState());
|
|
}
|
|
}
|
|
|
|
private static class StorageRoom extends AbstractResearchComplexRoomPart {
|
|
private StorageRoom(ResearchComplexState state, List<Transformation> list) {
|
|
super(state, list);
|
|
}
|
|
|
|
@Override
|
|
int getWidth() {
|
|
return 2;
|
|
}
|
|
|
|
@Override
|
|
protected void buildInterior() {
|
|
BlockState barrel = Blocks.BARREL.getDefaultState().with(BarrelBlock.FACING, Direction.WEST);
|
|
rect(new BlockPos(3, 0, 2), 2, 2, 3, barrel);
|
|
rect(new BlockPos(2, 0, 3), 1, 1, 2, barrel);
|
|
rect(new BlockPos(4, 2, 3), 1, 1, 2, barrel);
|
|
set(new BlockPos(1, 0, 4), barrel);
|
|
}
|
|
}
|
|
|
|
private interface RoomFactory {
|
|
AbstractResearchComplexRoomPart create(ResearchComplexState state, List<Transformation> transformations);
|
|
}
|
|
|
|
private static WeightedList<RoomFactory> createWeightedList() {
|
|
WeightedList<RoomFactory> weightedList = new WeightedList<>();
|
|
weightedList.add(1, StorageRoom::new);
|
|
weightedList.add(2, CraftingRoom::new);
|
|
weightedList.add(2, BedRoom::new);
|
|
return weightedList;
|
|
}
|
|
|
|
static AbstractResearchComplexRoomPart get(ResearchComplexState state, List<Transformation> transformations) {
|
|
return createWeightedList().pick(state.random).create(state, transformations);
|
|
}
|
|
}
|