Structure Actually Work!
EnergonRelics/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-07-21 21:23:33 -04:00
parent 2b9becda18
commit 5bfaa0e20b
27 changed files with 336 additions and 266 deletions

View File

@ -1,7 +1,7 @@
package com.thebrokenrail.energonrelics;
import com.thebrokenrail.energonrelics.block.DefensiveLaserBlock;
import com.thebrokenrail.energonrelics.block.structure.ResearchComplexGeneratorBlock;
import com.thebrokenrail.energonrelics.block.structure.StructureGeneratorBlock;
import com.thebrokenrail.energonrelics.block.ThermalGlassBlock;
import com.thebrokenrail.energonrelics.block.battery.ActiveBatteryControllerBlock;
import com.thebrokenrail.energonrelics.block.reactor.ReactorControllerBlock;
@ -16,9 +16,6 @@ import com.thebrokenrail.energonrelics.block.SwitchBlock;
import com.thebrokenrail.energonrelics.block.util.SimpleBlock;
import com.thebrokenrail.energonrelics.item.MultimeterItem;
import com.thebrokenrail.energonrelics.item.NetworkChipItem;
import com.thebrokenrail.energonrelics.structure.feature.ResearchComplexFeature;
import com.thebrokenrail.energonrelics.structure.feature.ResearchComplexGenerator;
import net.earthcomputer.libstructure.LibStructure;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -28,19 +25,12 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.structure.StructurePieceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.chunk.StructureConfig;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
public class EnergonRelics implements ModInitializer {
public static final String NAMESPACE = "energonrelics";
@ -75,11 +65,6 @@ public class EnergonRelics implements ModInitializer {
public static final Item DEFENSIVE_LASER_CORE_ITEM = new Item(new Item.Settings().group(ITEM_GROUP));
public static final DefensiveLaserBlock DEFENSIVE_LASER_BLOCK = new DefensiveLaserBlock();
public static final ResearchComplexGeneratorBlock RESEARCH_COMPLEX_GENERATOR_BLOCK = new ResearchComplexGeneratorBlock();
public static StructureFeature<DefaultFeatureConfig> RESEARCH_COMPLEX_STRUCTURE_FEATURE = new ResearchComplexFeature(DefaultFeatureConfig.CODEC);
public static StructurePieceType RESEARCH_COMPLEX_STRUCTURE_PIECE = (structureManager, tag) -> new ResearchComplexGenerator.Piece(tag);
@Override
public void onInitialize() {
NETWORK_CHIP_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "network_chip"), new NetworkChipItem());
@ -109,10 +94,6 @@ public class EnergonRelics implements ModInitializer {
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "defensive_laser_core"), DEFENSIVE_LASER_CORE_ITEM);
DEFENSIVE_LASER_BLOCK.register("defensive_laser");
RESEARCH_COMPLEX_GENERATOR_BLOCK.register("research_complex_generator");
Registry.register(Registry.STRUCTURE_PIECE, new Identifier(NAMESPACE, "research_complex_piece"), RESEARCH_COMPLEX_STRUCTURE_PIECE);
Biomes.PLAINS.addStructureFeature(RESEARCH_COMPLEX_STRUCTURE_FEATURE.configure(FeatureConfig.DEFAULT));
LibStructure.registerStructure(new Identifier(NAMESPACE, "research_complex"), RESEARCH_COMPLEX_STRUCTURE_FEATURE, GenerationStep.Feature.UNDERGROUND_STRUCTURES, new StructureConfig(32, 8, 14357618), RESEARCH_COMPLEX_STRUCTURE_FEATURE.configure(FeatureConfig.DEFAULT));
StructureGeneratorBlock.register();
}
}

View File

@ -1,7 +1,7 @@
package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.DefensiveLaserBlockEntity;
import com.thebrokenrail.energonrelics.block.util.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.client.block.entity.render.DefensiveLaserBlockEntityRenderer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

View File

@ -1,7 +1,7 @@
package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.EnergonLightBlockEntity;
import com.thebrokenrail.energonrelics.block.util.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;

View File

@ -1,7 +1,7 @@
package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.SolarPanelBlockEntity;
import com.thebrokenrail.energonrelics.block.util.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;

View File

@ -1,7 +1,7 @@
package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.SwitchBlockEntity;
import com.thebrokenrail.energonrelics.block.util.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;

View File

@ -1,7 +1,7 @@
package com.thebrokenrail.energonrelics.block.battery;
import com.thebrokenrail.energonrelics.block.entity.battery.PassiveBatteryControllerBlockEntity;
import com.thebrokenrail.energonrelics.block.util.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;

View File

@ -35,7 +35,7 @@ import java.util.function.Predicate;
public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
private static final float ROTATION_INCREMENT = 4;
public final Rotation rotation = new Rotation(0, 0, "Rotation");
public final Rotation rotation = new Rotation();
private static Vec3d getPosVec(BlockPos pos) {
return new Vec3d(pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d);
@ -57,15 +57,14 @@ public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
public class Rotation {
private float yaw = 0;
private float pitch = 0;
private final String key;
private static final String KEY = "Rotation";
private Rotation(float yaw, float pitch, String key) {
setRaw(yaw, pitch);
this.key = key;
private Rotation() {
setRaw(0f, 0f);
}
private void fromTag(CompoundTag tag) {
CompoundTag rotation = tag.getCompound(key);
CompoundTag rotation = tag.getCompound(KEY);
setRaw(rotation.getInt("Yaw"), rotation.getInt("Pitch"));
}
@ -73,7 +72,7 @@ public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
CompoundTag rotation = new CompoundTag();
rotation.putFloat("Yaw", yaw);
rotation.putFloat("Pitch", pitch);
tag.put(key, rotation);
tag.put(KEY, rotation);
}
private void setRaw(float yaw, float pitch) {

View File

@ -1,52 +0,0 @@
package com.thebrokenrail.energonrelics.block.entity.structure;
import com.thebrokenrail.energonrelics.block.structure.ResearchComplexGeneratorBlock;
import com.thebrokenrail.energonrelics.structure.StructurePart;
import com.thebrokenrail.energonrelics.structure.StructurePlacer;
import com.thebrokenrail.energonrelics.structure.researchcomplex.ResearchComplexStartPart;
import com.thebrokenrail.energonrelics.structure.researchcomplex.ResearchComplexState;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Tickable;
import net.minecraft.util.math.Direction;
import java.util.Collections;
import java.util.Objects;
import java.util.Random;
public class ResearchComplexGeneratorBlockEntity extends BlockEntity implements Tickable {
private long seed = 0;
public ResearchComplexGeneratorBlockEntity(BlockEntityType<?> type) {
super(type);
}
public void setSeed(long seed) {
this.seed = seed;
}
@Override
public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag);
tag.putLong("Seed", seed);
return tag;
}
@Override
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
seed = tag.getLong("Seed");
}
@Override
public void tick() {
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient()) {
Direction facing = getCachedState().get(ResearchComplexGeneratorBlock.HORIZONTAL_FACING);
getWorld().setBlockState(getPos(), Blocks.STONE.getDefaultState());
new StructurePlacer(new ResearchComplexStartPart(new ResearchComplexState(getWorld(), new Random(seed)), Collections.singletonList(StructurePart.getTransformationFromDirection(facing)))).place(getWorld(), getPos());
}
}
}

View File

@ -0,0 +1,59 @@
package com.thebrokenrail.energonrelics.block.entity.structure;
import com.thebrokenrail.energonrelics.block.structure.StructureGeneratorBlock;
import com.thebrokenrail.energonrelics.structure.StructurePart;
import com.thebrokenrail.energonrelics.structure.StructurePlacer;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Random;
public class StructureGeneratorBlockEntity extends BlockEntity {
public interface StructurePartFactory {
StructurePart<?> create(World world, Random random, List<StructurePart.Transformation> transformations);
}
private long seed = 0;
private boolean generated = false;
private final StructurePartFactory factory;
public StructureGeneratorBlockEntity(BlockEntityType<?> type, StructurePartFactory factory) {
super(type);
this.factory = factory;
}
public void setSeed(long seed) {
this.seed = seed;
}
@Override
public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag);
tag.putLong("Seed", seed);
tag.putBoolean("Generated", generated);
return tag;
}
@Override
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
seed = tag.getLong("Seed");
generated = tag.getBoolean("Generated");
}
public void generate() {
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient() && !generated) {
Direction facing = getCachedState().get(StructureGeneratorBlock.HORIZONTAL_FACING);
generated = true;
new StructurePlacer(factory.create(getWorld(), new Random(seed), Collections.singletonList(StructurePart.directionToTransformation(facing)))).place(getWorld(), getPos());
}
}
}

View File

@ -1,41 +0,0 @@
package com.thebrokenrail.energonrelics.block.structure;
import com.thebrokenrail.energonrelics.block.entity.structure.ResearchComplexGeneratorBlockEntity;
import com.thebrokenrail.energonrelics.block.util.SimpleBlockWithEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Direction;
import java.util.function.Function;
public class ResearchComplexGeneratorBlock extends SimpleBlockWithEntity {
public static DirectionProperty HORIZONTAL_FACING = Properties.HORIZONTAL_FACING;
public ResearchComplexGeneratorBlock() {
super(FabricBlockSettings.of(Material.STONE).strength(-1.0F, 3600000.0F).dropsNothing());
setDefaultState(getDefaultState().with(HORIZONTAL_FACING, Direction.NORTH));
}
@Override
protected boolean registerItem() {
return false;
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(HORIZONTAL_FACING);
}
@Override
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return ResearchComplexGeneratorBlockEntity::new;
}
}

View File

@ -0,0 +1,119 @@
package com.thebrokenrail.energonrelics.block.structure;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.entity.structure.StructureGeneratorBlockEntity;
import com.thebrokenrail.energonrelics.block.util.SimpleBlockWithEntity;
import com.thebrokenrail.energonrelics.structure.researchcomplex.ResearchComplexStartPart;
import com.thebrokenrail.energonrelics.structure.researchcomplex.ResearchComplexState;
import net.earthcomputer.libstructure.LibStructure;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.structure.StructurePieceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.chunk.StructureConfig;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.function.Function;
public class StructureGeneratorBlock extends SimpleBlockWithEntity {
public static final DirectionProperty HORIZONTAL_FACING = Properties.HORIZONTAL_FACING;
private static final Map<String, StructureGeneratorBlock> blocks = new HashMap<>();
private final StructureGeneratorBlockEntity.StructurePartFactory structureFactory;
private final StructureConfig structureConfig;
private final StructureFeature<DefaultFeatureConfig> feature = new StructureGeneratorFeature(this);
final StructurePieceType piece = (structureManager, tag) -> new StructureGeneratorPiece(this, tag);
private StructureGeneratorBlock(StructureGeneratorBlockEntity.StructurePartFactory structureFactory, StructureConfig structureConfig) {
super(FabricBlockSettings.of(Material.STONE).strength(-1f, 3600000f).dropsNothing());
setDefaultState(getDefaultState().with(HORIZONTAL_FACING, Direction.NORTH));
this.structureFactory = structureFactory;
this.structureConfig = structureConfig;
}
@Override
protected boolean registerItem() {
return false;
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(HORIZONTAL_FACING);
}
@Override
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return type -> new StructureGeneratorBlockEntity(type, structureFactory);
}
@SuppressWarnings("deprecation")
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
super.scheduledTick(state, world, pos, random);
BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof StructureGeneratorBlockEntity) {
((StructureGeneratorBlockEntity) entity).generate();
}
}
@SuppressWarnings("deprecation")
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
super.onBlockAdded(state, world, pos, oldState, notify);
schedule(world, pos);
}
public void schedule(World world, BlockPos pos) {
world.getBlockTickScheduler().schedule(pos, this, 0);
}
@Override
public void register(String name) {
super.register(name + "_generator");
Registry.register(Registry.STRUCTURE_PIECE, new Identifier(EnergonRelics.NAMESPACE, name + "_piece"), piece);
LibStructure.registerStructure(new Identifier(EnergonRelics.NAMESPACE, name), feature, GenerationStep.Feature.UNDERGROUND_STRUCTURES, structureConfig, feature.configure(FeatureConfig.DEFAULT));
}
@SuppressWarnings("SameParameterValue")
private static void create(String name, StructureGeneratorBlockEntity.StructurePartFactory factory, StructureConfig config) {
blocks.put(name, new StructureGeneratorBlock(factory, config));
}
public static void register() {
for (Map.Entry<String, StructureGeneratorBlock> entry : blocks.entrySet()) {
entry.getValue().register(entry.getKey());
}
}
public static void addToBiome(Biome biome) {
for (Map.Entry<String, StructureGeneratorBlock> entry : blocks.entrySet()) {
biome.addStructureFeature(entry.getValue().feature.configure(DefaultFeatureConfig.INSTANCE));
}
}
static {
create("research_complex", (world, random, transformations) -> new ResearchComplexStartPart(new ResearchComplexState(world, random), transformations), new StructureConfig(32, 8, 14357618));
}
}

View File

@ -1,6 +1,5 @@
package com.thebrokenrail.energonrelics.structure.feature;
package com.thebrokenrail.energonrelics.block.structure;
import com.mojang.serialization.Codec;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.BlockRotation;
@ -13,26 +12,32 @@ import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
public class ResearchComplexFeature extends StructureFeature<DefaultFeatureConfig> {
public ResearchComplexFeature(Codec<DefaultFeatureConfig> codec) {
super(codec);
class StructureGeneratorFeature extends StructureFeature<DefaultFeatureConfig> {
private final StructureGeneratorBlock block;
StructureGeneratorFeature(StructureGeneratorBlock block) {
super(DefaultFeatureConfig.CODEC);
this.block = block;
}
@Override
public StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
return Start::new;
return (structureFeature, i, j, blockBox, k, l) -> new Start(block, structureFeature, i, j, blockBox, k, l);
}
public static class Start extends StructureStart<DefaultFeatureConfig> {
public Start(StructureFeature<DefaultFeatureConfig> structureFeature, int i, int j, BlockBox blockBox, int k, long l) {
private static class Start extends StructureStart<DefaultFeatureConfig> {
private final StructureGeneratorBlock block;
private Start(StructureGeneratorBlock block, StructureFeature<DefaultFeatureConfig> structureFeature, int i, int j, BlockBox blockBox, int k, long l) {
super(structureFeature, i, j, blockBox, k, l);
this.block = block;
}
@Override
public void init(DynamicRegistryManager dynamicRegistryManager, ChunkGenerator chunkGenerator, StructureManager structureManager, int x, int z, Biome biome, DefaultFeatureConfig defaultFeatureConfig) {
BlockPos blockPos = new BlockPos(x * 16, chunkGenerator.getHeight(x, z, Heightmap.Type.WORLD_SURFACE) / 2, z * 16);
BlockRotation blockRotation = BlockRotation.random(random);
ResearchComplexGenerator.addPieces(blockPos, blockRotation, children);
children.add(new StructureGeneratorPiece(block, blockRotation, blockPos));
setBoundingBoxFromChildren();
}
}

View File

@ -0,0 +1,57 @@
package com.thebrokenrail.energonrelics.block.structure;
import com.thebrokenrail.energonrelics.block.entity.structure.StructureGeneratorBlockEntity;
import com.thebrokenrail.energonrelics.structure.StructurePart;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.structure.StructurePiece;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import java.util.Random;
class StructureGeneratorPiece extends StructurePiece {
private final StructureGeneratorBlock block;
private final BlockRotation rotation;
private final BlockPos pos;
StructureGeneratorPiece(StructureGeneratorBlock block, BlockRotation rotation, BlockPos pos) {
super(block.piece, 0);
this.block = block;
this.rotation = rotation;
this.pos = pos;
boundingBox = BlockBox.create(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1);
}
StructureGeneratorPiece(StructureGeneratorBlock block, CompoundTag tag) {
this(block, BlockRotation.valueOf(tag.getString("Rot")), new BlockPos(tag.getInt("X"), tag.getInt("Y"), tag.getInt("Z")));
}
@Override
protected void toNbt(CompoundTag tag) {
tag.putString("Rot", rotation.name());
tag.putInt("X", pos.getX());
tag.putInt("Y", pos.getY());
tag.putInt("Z", pos.getZ());
}
@Override
public boolean generate(ServerWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockBox boundingBox, ChunkPos chunkPos, BlockPos blockPos) {
BlockState state = block.getDefaultState().with(StructureGeneratorBlock.HORIZONTAL_FACING, StructurePart.blockRotationToDirection(rotation));
world.setBlockState(pos, state, 3);
BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof StructureGeneratorBlockEntity) {
((StructureGeneratorBlockEntity) entity).setSeed(random.nextLong());
}
block.schedule(world.getWorld(), pos);
return true;
}
}

View File

@ -1,6 +1,7 @@
package com.thebrokenrail.energonrelics.block.util;
package com.thebrokenrail.energonrelics.block.util.energy;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.util.SimpleBlockWithEntity;
import com.thebrokenrail.energonrelics.client.block.entity.render.HighlightBlockEntityRenderer;
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
import net.fabricmc.api.EnvType;

View File

@ -1,7 +1,7 @@
package com.thebrokenrail.energonrelics.client;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.util.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.client.config.UserConfig;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.ConfigData;

View File

@ -11,6 +11,7 @@ import java.util.Locale;
@Environment(EnvType.CLIENT)
@Config(name = EnergonRelics.NAMESPACE)
public class UserConfig implements ConfigData {
@SuppressWarnings("unused")
public enum TextureSet {
TheBrokenRail,
PoeticRainbow;
@ -20,5 +21,6 @@ public class UserConfig implements ConfigData {
}
}
@SuppressWarnings("CanBeFinal")
public TextureSet textureSet = TextureSet.TheBrokenRail;
}

View File

@ -4,9 +4,7 @@ import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity;
import com.thebrokenrail.energonrelics.energy.helper.EnergyGenerator;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
@ -14,7 +12,6 @@ import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.world.RayTraceContext;
import net.minecraft.world.World;
import java.util.Objects;

View File

@ -1,6 +1,7 @@
package com.thebrokenrail.energonrelics.mixin;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.structure.StructureGeneratorBlock;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.feature.DefaultBiomeFeatures;
@ -15,4 +16,9 @@ public class MixinDefaultBiomeFeatures {
private static void addDefaultOres(Biome biome, CallbackInfo info) {
biome.addFeature(GenerationStep.Feature.UNDERGROUND_ORES, EnergonRelics.VERIDIUM_ORE_FEATURE);
}
@Inject(at = @At("RETURN"), method = "addDefaultUndergroundStructures")
private static void addDefaultUndergroundStructures(Biome biome, CallbackInfo info) {
StructureGeneratorBlock.addToBiome(biome);
}
}

View File

@ -11,11 +11,6 @@ public interface RenderPhaseAccessor {
throw new UnsupportedOperationException();
}
@Accessor
static RenderPhase.Target getTRANSLUCENT_TARGET() {
throw new UnsupportedOperationException();
}
@Accessor
static RenderPhase.Layering getVIEW_OFFSET_Z_LAYERING() {
throw new UnsupportedOperationException();

View File

@ -2,7 +2,6 @@ package com.thebrokenrail.energonrelics.structure;
import com.thebrokenrail.energonrelics.util.MissingCaseException;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
@ -16,7 +15,7 @@ import java.util.List;
import java.util.Map;
public abstract class StructurePart<T> {
protected interface Transformation {
public interface Transformation {
BlockPos transform(BlockPos pos);
BlockState transform(BlockState state);
}
@ -80,7 +79,7 @@ public abstract class StructurePart<T> {
return state.rotate(BlockRotation.COUNTERCLOCKWISE_90);
}
};
protected static final Transformation MIRROR = new Transformation() {
protected static final Transformation MIRROR_DEPTH = new Transformation() {
@Override
public BlockPos transform(BlockPos pos) {
return new BlockPos(pos.getX(), pos.getY(), -pos.getZ());
@ -142,18 +141,18 @@ public abstract class StructurePart<T> {
public void place(World world, BlockPos pos) {
for (Map.Entry<Long, BlockState> entry : blocks.entrySet()) {
BlockState state = entry.getValue();
if (state.getBlock() != Blocks.VOID_AIR) {
BlockPos newPos = pos.add(BlockPos.fromLong(entry.getKey()));
world.removeBlockEntity(newPos);
world.setBlockState(newPos, state);
handleBlockPlace(world, newPos, state);
}
BlockPos newPos = pos.add(BlockPos.fromLong(entry.getKey()));
world.removeBlockEntity(newPos);
world.setBlockState(newPos, state);
handleBlockPlace(world, newPos, state);
}
}
protected abstract void handleBlockPlace(World world, BlockPos pos, BlockState state);
public static Transformation getTransformationFromDirection(Direction direction) {
public static Transformation directionToTransformation(Direction direction) {
switch (direction) {
case NORTH: {
return NONE;
@ -173,6 +172,26 @@ public abstract class StructurePart<T> {
}
}
public static Direction blockRotationToDirection(BlockRotation rotation) {
switch (rotation) {
case NONE: {
return Direction.NORTH;
}
case CLOCKWISE_90: {
return Direction.EAST;
}
case CLOCKWISE_180: {
return Direction.SOUTH;
}
case COUNTERCLOCKWISE_90: {
return Direction.WEST;
}
default: {
throw new MissingCaseException(rotation);
}
}
}
protected void part(StructureContext context, BlockPos originalPos, StructurePart<?> part) {
BlockPos pos = transform(originalPos);
context.addPart(pos.getX(), pos.getY(), pos.getZ(), part);

View File

@ -1,82 +0,0 @@
package com.thebrokenrail.energonrelics.structure.feature;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.entity.structure.ResearchComplexGeneratorBlockEntity;
import com.thebrokenrail.energonrelics.block.structure.ResearchComplexGeneratorBlock;
import com.thebrokenrail.energonrelics.util.MissingCaseException;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.structure.StructurePiece;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import java.util.List;
import java.util.Random;
public class ResearchComplexGenerator {
static void addPieces(BlockPos pos, BlockRotation rotation, List<StructurePiece> pieces) {
pieces.add(new Piece(rotation, pos));
}
public static class Piece extends StructurePiece {
private final BlockRotation rotation;
private final BlockPos pos;
private Piece(BlockRotation rotation, BlockPos pos) {
super(EnergonRelics.RESEARCH_COMPLEX_STRUCTURE_PIECE, 0);
this.rotation = rotation;
this.pos = pos;
boundingBox = BlockBox.create(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1);
}
public Piece(CompoundTag tag) {
super(EnergonRelics.RESEARCH_COMPLEX_STRUCTURE_PIECE, tag);
rotation = BlockRotation.valueOf(tag.getString("Rot"));
pos = new BlockPos(tag.getInt("X"), tag.getInt("Y"), tag.getInt("Z"));
}
@Override
protected void toNbt(CompoundTag tag) {
tag.putString("Rot", rotation.name());
tag.putInt("X", pos.getX());
tag.putInt("Y", pos.getY());
tag.putInt("Z", pos.getZ());
}
@Override
public boolean generate(ServerWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockBox boundingBox, ChunkPos chunkPos, BlockPos blockPos) {
world.setBlockState(pos, EnergonRelics.RESEARCH_COMPLEX_GENERATOR_BLOCK.getDefaultState().with(ResearchComplexGeneratorBlock.HORIZONTAL_FACING, blockRotationToDirection(rotation)), 4);
BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof ResearchComplexGeneratorBlockEntity) {
((ResearchComplexGeneratorBlockEntity) entity).setSeed(random.nextLong());
}
return true;
}
private static Direction blockRotationToDirection(BlockRotation rotation) {
switch (rotation) {
case NONE: {
return Direction.NORTH;
}
case CLOCKWISE_90: {
return Direction.EAST;
}
case CLOCKWISE_180: {
return Direction.SOUTH;
}
case COUNTERCLOCKWISE_90: {
return Direction.WEST;
}
default: {
throw new MissingCaseException(rotation);
}
}
}
}
}

View File

@ -4,6 +4,7 @@ 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.BarrelBlock;
import net.minecraft.block.BedBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -157,7 +158,7 @@ public abstract class AbstractResearchComplexRoomPart extends BaseResearchComple
@Override
protected void buildInterior() {
BlockState barrel = Blocks.BARREL.getDefaultState();
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);
@ -172,8 +173,8 @@ public abstract class AbstractResearchComplexRoomPart extends BaseResearchComple
private static WeightedList<RoomFactory> createWeightedList() {
WeightedList<RoomFactory> weightedList = new WeightedList<>();
weightedList.add(1, StorageRoom::new);
weightedList.add(4, CraftingRoom::new);
weightedList.add(4, BedRoom::new);
weightedList.add(2, CraftingRoom::new);
weightedList.add(2, BedRoom::new);
return weightedList;
}

View File

@ -19,7 +19,7 @@ public class ResearchComplexHallwayPart extends BaseResearchComplexPart {
private int rightRoomPadding;
private int leftRoomPadding;
private static final float ROOM_CHANCE = 0.4f;
private static final float ROOM_CHANCE = 0.45f;
public ResearchComplexHallwayPart(ResearchComplexState state, List<Transformation> list, boolean hasLight, int rightRoomPadding, int leftRoomPadding) {
super(state, list);
@ -28,13 +28,9 @@ public class ResearchComplexHallwayPart extends BaseResearchComplexPart {
this.leftRoomPadding = leftRoomPadding;
}
private int getHeight() {
return 6;
}
private static final int HEIGHT = 6;
private int getDepth() {
return 3;
}
private static final int DEPTH = 3;
@Override
protected void build(StructureContext context) {
@ -46,22 +42,22 @@ public class ResearchComplexHallwayPart extends BaseResearchComplexPart {
BlockState westStairs = stairs.with(StairsBlock.FACING, Direction.WEST);
BlockState eastStairs = stairs.with(StairsBlock.FACING, Direction.EAST);
for (int y = 0; y < getHeight(); y++) {
BlockState state = y == 0 || y == getHeight() - 1 ? bricks : air;
if (y > 1 && y < getHeight() - 2) {
rect(new BlockPos(1, y, 0), 5, 1, getDepth(), air);
rect(new BlockPos(0, y, 0), 1, 1, getDepth(), bricks);
rect(new BlockPos(6, y, 0), 1, 1, getDepth(), bricks);
for (int y = 0; y < HEIGHT; y++) {
BlockState state = y == 0 || y == HEIGHT - 1 ? bricks : air;
if (y > 1 && y < HEIGHT - 2) {
rect(new BlockPos(1, y, 0), 5, 1, DEPTH, air);
rect(new BlockPos(0, y, 0), 1, 1, DEPTH, bricks);
rect(new BlockPos(6, y, 0), 1, 1, DEPTH, bricks);
} else {
rect(new BlockPos(2, y, 0), 3, 1, getDepth(), state);
rect(new BlockPos(2, y, 0), 3, 1, DEPTH, state);
}
if (y == 1 || y == getHeight() - 2) {
if (y == getHeight() - 2) {
if (y == 1 || y == HEIGHT - 2) {
if (y == HEIGHT - 2) {
eastStairs = eastStairs.with(StairsBlock.HALF, BlockHalf.TOP);
westStairs = westStairs.with(StairsBlock.HALF, BlockHalf.TOP);
}
rect(new BlockPos(1, y, 0), 1, 1, getDepth(), westStairs);
rect(new BlockPos(5, y, 0), 1, 1, getDepth(), eastStairs);
rect(new BlockPos(1, y, 0), 1, 1, DEPTH, westStairs);
rect(new BlockPos(5, y, 0), 1, 1, DEPTH, eastStairs);
}
}
@ -88,7 +84,7 @@ public class ResearchComplexHallwayPart extends BaseResearchComplexPart {
rightRoomPadding = rightRoomPadding - 1;
}
part(context, new BlockPos(0, 0, getDepth()), new ResearchComplexHallwayPart(getState(), getTransformations(), !hasLight, rightRoomPadding, leftRoomPadding));
part(context, new BlockPos(0, 0, DEPTH), new ResearchComplexHallwayPart(getState(), getTransformations(), !hasLight, rightRoomPadding, leftRoomPadding));
} else {
rect(new BlockPos(1, 1, 0), 5, 4, 1, bricks);
}
@ -97,7 +93,7 @@ public class ResearchComplexHallwayPart extends BaseResearchComplexPart {
private List<Transformation> getRoomTransformation(boolean mirror) {
List<Transformation> list = new ArrayList<>();
if (mirror) {
list.add(MIRROR);
list.add(MIRROR_DEPTH);
}
list.addAll(getTransformations());
list.add(com.thebrokenrail.energonrelics.structure.StructurePart.CLOCKWISE_90);

View File

@ -21,12 +21,12 @@ public class ResearchComplexState {
this.random = random;
}
private int getID(int id) {
return baseID + id;
private int getID() {
return baseID;
}
int getMainNetwork() {
return getID(0);
return getID();
}
boolean hasEnergy(long amount, BlockPos pos) {

View File

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "minecraft:block/structure_block_load"
}
}
}

View File

@ -25,5 +25,6 @@
"text.autoconfig.energonrelics.title": "EnergonRelics",
"text.autoconfig.energonrelics.option.textureSet": "Texture Set",
"death.attack.energonrelics.defensive_laser": "%s was evaporated by a laser",
"death.attack.energonrelics.defensive_laser.player": "%s was evaporated by a laser whilst fighting %s"
"death.attack.energonrelics.defensive_laser.player": "%s was evaporated by a laser whilst fighting %s",
"block.energonrelics.research_complex_generator": "Research Complex Generator"
}

View File

@ -37,7 +37,7 @@
{
"type": "minecraft:item",
"name": "minecraft:iron_ingot",
"weight": 5,
"weight": 4,
"functions": [
{
"function": "minecraft:set_count",
@ -79,7 +79,7 @@
"count": {
"type": "minecraft:uniform",
"min": 1,
"max": 6
"max": 7
}
}
]