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...

136 lines
4.8 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;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.entity.BarrelBlockEntity;
import net.minecraft.block.entity.BlockEntity;
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();
static AbstractResearchComplexRoomPart get(ResearchComplexState state, List<Transformation> transformations) {
if (state.random.nextFloat() <= Barrel.CHANCE) {
return new Barrel(state, transformations);
} else {
return new Simple(state, transformations);
}
}
private static class Simple extends AbstractResearchComplexRoomPart {
private Simple(ResearchComplexState state, List<Transformation> list) {
super(state, list);
}
@Override
int getWidth() {
return 1;
}
@Override
protected void buildInterior() {
}
}
private static class Barrel extends AbstractResearchComplexRoomPart {
private static final float CHANCE = 0.05f;
private Barrel(ResearchComplexState state, List<Transformation> list) {
super(state, list);
}
@Override
int getWidth() {
return 2;
}
@Override
protected void buildInterior() {
BlockState barrel = Blocks.BARREL.getDefaultState();
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);
}
@Override
protected void handleBlockPlace(World world, BlockPos pos, BlockState state) {
super.handleBlockPlace(world, pos, state);
BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof BarrelBlockEntity) {
((BarrelBlockEntity) entity).setLootTable(new Identifier(EnergonRelics.NAMESPACE, "chests/research_complex_barrel"), getState().random.nextLong());
}
}
}
}