This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/structure/researchcomplex/AbstractResearchComplexRoom...

195 lines
7.5 KiB
Java
Raw Normal View History

2020-07-20 21:03:17 +00:00
package com.thebrokenrail.energonrelics.structure.researchcomplex;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import com.thebrokenrail.energonrelics.structure.StructureContext;
2020-07-20 22:40:56 +00:00
import com.thebrokenrail.energonrelics.util.WeightedList;
2020-07-22 01:51:14 +00:00
import net.minecraft.block.AnvilBlock;
2020-07-22 01:23:33 +00:00
import net.minecraft.block.BarrelBlock;
2020-07-20 22:40:56 +00:00
import net.minecraft.block.BedBlock;
2020-07-22 01:51:14 +00:00
import net.minecraft.block.Block;
2020-07-20 21:03:17 +00:00
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
2020-07-20 22:40:56 +00:00
import net.minecraft.block.ChestBlock;
2020-07-20 21:03:17 +00:00
import net.minecraft.block.DoorBlock;
import net.minecraft.block.entity.BlockEntity;
2020-07-20 22:40:56 +00:00
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.block.enums.BedPart;
import net.minecraft.block.enums.ChestType;
2020-07-20 21:03:17 +00:00
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);
2020-08-20 23:03:47 +00:00
BlockState light = EnergonRelics.Blocks.ENERGON_LIGHT.getDefaultState();
2020-07-20 21:03:17 +00:00
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();
2020-07-20 22:40:56 +00:00
@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());
2020-07-20 21:03:17 +00:00
}
}
2020-07-20 22:40:56 +00:00
private static class BedRoom extends AbstractResearchComplexRoomPart {
private BedRoom(ResearchComplexState state, List<Transformation> list) {
2020-07-20 21:03:17 +00:00
super(state, list);
}
@Override
int getWidth() {
return 1;
}
@Override
protected void buildInterior() {
2020-07-20 22:40:56 +00:00
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);
2020-07-20 21:03:17 +00:00
2020-07-20 22:40:56 +00:00
set(new BlockPos(1, 0, 2), bedHead);
set(new BlockPos(1, 0, 3), bedFoot);
set(new BlockPos(1, 0, 4), chest);
2020-07-20 21:03:17 +00:00
}
}
2020-07-20 22:40:56 +00:00
private static class CraftingRoom extends AbstractResearchComplexRoomPart {
private CraftingRoom(ResearchComplexState state, List<Transformation> list) {
super(state, list);
}
2020-07-20 21:03:17 +00:00
2020-07-20 22:40:56 +00:00
@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));
2020-07-22 01:51:14 +00:00
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);
2020-07-20 22:40:56 +00:00
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) {
2020-07-20 21:03:17 +00:00
super(state, list);
}
@Override
int getWidth() {
return 2;
}
@Override
protected void buildInterior() {
2020-07-22 01:23:33 +00:00
BlockState barrel = Blocks.BARREL.getDefaultState().with(BarrelBlock.FACING, Direction.WEST);
2020-07-20 21:03:17 +00:00
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);
}
2020-07-20 22:40:56 +00:00
}
2020-07-20 21:03:17 +00:00
2020-07-20 22:40:56 +00:00
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);
2020-07-22 01:23:33 +00:00
weightedList.add(2, CraftingRoom::new);
weightedList.add(2, BedRoom::new);
2020-07-20 22:40:56 +00:00
return weightedList;
}
static AbstractResearchComplexRoomPart get(ResearchComplexState state, List<Transformation> transformations) {
return createWeightedList().pick(state.random).create(state, transformations);
2020-07-20 21:03:17 +00:00
}
}