Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import aztech.modern_industrialization.machines.models.MachineCasings;
import aztech.modern_industrialization.machines.multiblocks.HatchFlags;
import aztech.modern_industrialization.machines.multiblocks.HatchType;
import aztech.modern_industrialization.machines.multiblocks.HatchTypes;
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
import aztech.modern_industrialization.machines.multiblocks.SimpleMember;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -50,15 +50,7 @@ default HatchFlags noHatch() {
default HatchFlags hatchOf(String... hatches) {
var builder = new HatchFlags.Builder();
for (String hatch : hatches) {
switch (hatch) {
case "item_input" -> builder.with(HatchType.ITEM_INPUT);
case "item_output" -> builder.with(HatchType.ITEM_OUTPUT);
case "fluid_input" -> builder.with(HatchType.FLUID_INPUT);
case "fluid_output" -> builder.with(HatchType.FLUID_OUTPUT);
case "energy_input" -> builder.with(HatchType.ENERGY_INPUT);
case "energy_output" -> builder.with(HatchType.ENERGY_OUTPUT);
default -> throw new IllegalArgumentException("Unsupported hatch type: " + hatch);
}
builder.with(HatchTypes.get(hatch));
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import aztech.modern_industrialization.MIText;
import aztech.modern_industrialization.machines.MachineBlock;
import aztech.modern_industrialization.machines.multiblocks.HatchType;
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
import guideme.color.SymbolicColor;
import guideme.compiler.PageCompiler;
Expand Down Expand Up @@ -83,10 +82,8 @@ public void compile(GuidebookScene scene, PageCompiler compiler, LytErrorSink er

tooltipLines.add(MIText.AcceptsHatches.text());
var flags = entry.getValue();
for (var type : HatchType.values()) {
if (flags.allows(type)) {
tooltipLines.add(Component.literal("- ").append(type.description()));
}
for (var type : flags.values()) {
tooltipLines.add(Component.literal("- ").append(type.description()));
}
annotation.setTooltip(new TextTooltip(tooltipLines));
scene.addAnnotation(annotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import aztech.modern_industrialization.machines.helper.EnergyHelper;
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.HatchType;
import aztech.modern_industrialization.machines.multiblocks.HatchTypes;
import java.util.List;
import net.minecraft.world.level.block.entity.BlockEntityType;

Expand Down Expand Up @@ -67,7 +68,7 @@ public EnergyHatch(BEP bep, String name, boolean input, CableTier tier) {

@Override
public HatchType getHatchType() {
return input ? HatchType.ENERGY_INPUT : HatchType.ENERGY_OUTPUT;
return input ? HatchTypes.ENERGY_INPUT : HatchTypes.ENERGY_OUTPUT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import aztech.modern_industrialization.machines.guicomponents.AutoExtract;
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.HatchType;
import aztech.modern_industrialization.machines.multiblocks.HatchTypes;
import java.util.List;

public class FluidHatch extends HatchBlockEntity {
Expand All @@ -51,7 +52,7 @@ public FluidHatch(BEP bep, MachineGuiParameters guiParams, boolean input, boolea

@Override
public HatchType getHatchType() {
return input ? HatchType.FLUID_INPUT : HatchType.FLUID_OUTPUT;
return input ? HatchTypes.FLUID_INPUT : HatchTypes.FLUID_OUTPUT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import aztech.modern_industrialization.machines.guicomponents.AutoExtract;
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.HatchType;
import aztech.modern_industrialization.machines.multiblocks.HatchTypes;
import java.util.List;

public class ItemHatch extends HatchBlockEntity {
Expand All @@ -51,7 +52,7 @@ public ItemHatch(BEP bep, MachineGuiParameters guiParams, boolean input, boolean

@Override
public HatchType getHatchType() {
return input ? HatchType.ITEM_INPUT : HatchType.ITEM_OUTPUT;
return input ? HatchTypes.ITEM_INPUT : HatchTypes.ITEM_OUTPUT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import aztech.modern_industrialization.machines.gui.MachineGuiParameters;
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.HatchType;
import aztech.modern_industrialization.machines.multiblocks.HatchTypes;
import java.util.List;
import net.minecraft.ChatFormatting;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void openMenu(ServerPlayer player) {

@Override
public HatchType getHatchType() {
return HatchType.LARGE_TANK;
return HatchTypes.LARGE_TANK;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import aztech.modern_industrialization.machines.guicomponents.TemperatureBar;
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.HatchType;
import aztech.modern_industrialization.machines.multiblocks.HatchTypes;
import aztech.modern_industrialization.nuclear.*;
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.fluid.FluidVariant;
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.item.ItemVariant;
Expand Down Expand Up @@ -98,7 +99,7 @@ public NuclearHatch(BEP bep, boolean isFluid) {

@Override
public HatchType getHatchType() {
return isFluid ? HatchType.NUCLEAR_FLUID : HatchType.NUCLEAR_ITEM;
return isFluid ? HatchTypes.NUCLEAR_FLUID : HatchTypes.NUCLEAR_ITEM;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public static void registerReiShapes() {

SimpleMember casing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("clean_stainless_steel_machine_casing")));
SimpleMember pipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("stainless_steel_machine_casing_pipe")));
HatchFlags bottom = new HatchFlags.Builder().with(HatchType.ENERGY_INPUT, HatchType.FLUID_INPUT).build();
HatchFlags layer = new HatchFlags.Builder().with(HatchType.FLUID_OUTPUT).build();
HatchFlags bottom = new HatchFlags.Builder().with(HatchTypes.ENERGY_INPUT, HatchTypes.FLUID_INPUT).build();
HatchFlags layer = new HatchFlags.Builder().with(HatchTypes.FLUID_OUTPUT).build();
for (int i = 0; i < MAX_HEIGHT; ++i) {
ShapeTemplate.Builder builder = new ShapeTemplate.Builder(MachineCasings.CLEAN_STAINLESS_STEEL);
for (int y = 0; y <= i + 1; ++y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package aztech.modern_industrialization.machines.blockentities.multiblocks;

import static aztech.modern_industrialization.machines.multiblocks.HatchType.*;
import static aztech.modern_industrialization.machines.multiblocks.HatchTypes.*;

import aztech.modern_industrialization.MI;
import aztech.modern_industrialization.MIBlock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static ShapeTemplate buildShape(int index) {
ShapeTemplate.Builder templateBuilder = new ShapeTemplate.Builder(MachineCasings.STEEL);
SimpleMember steelCasing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing")));
SimpleMember glass = SimpleMember.forBlock(() -> Blocks.GLASS);
HatchFlags hatchFlags = new HatchFlags.Builder().with(HatchType.LARGE_TANK).build();
HatchFlags hatchFlags = new HatchFlags.Builder().with(HatchTypes.LARGE_TANK).build();

for (int x = -sizeX / 2; x <= sizeX / 2; x++) {
for (int y = -1; y < sizeY - 1; y++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static void registerReiShapes() {

SimpleMember casing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("nuclear_casing")));
SimpleMember pipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("nuclear_alloy_machine_casing_pipe")));
HatchFlags top = new HatchFlags.Builder().with(HatchType.NUCLEAR_FLUID, HatchType.NUCLEAR_ITEM).build();
HatchFlags top = new HatchFlags.Builder().with(HatchTypes.NUCLEAR_FLUID, HatchTypes.NUCLEAR_ITEM).build();
for (int i = 0; i < 4; i++) {
ShapeTemplate.Builder builder = new ShapeTemplate.Builder(MachineCasings.NUCLEAR);
gridLayout[i] = new boolean[5 + 2 * i][5 + 2 * i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package aztech.modern_industrialization.machines.init;

import static aztech.modern_industrialization.machines.models.MachineCasings.CLEAN_STAINLESS_STEEL;
import static aztech.modern_industrialization.machines.multiblocks.HatchType.*;
import static aztech.modern_industrialization.machines.multiblocks.HatchTypes.*;

import aztech.modern_industrialization.MI;
import aztech.modern_industrialization.MIBlock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,31 @@
*/
package aztech.modern_industrialization.machines.multiblocks;

import java.util.HashSet;
import java.util.Set;

public class HatchFlags {
public static final HatchFlags NO_HATCH = new Builder().build();

private final int flags;
private final Set<HatchType> allowed;

public HatchFlags(int flags) {
this.flags = flags;
public HatchFlags(Set<HatchType> allowed) {
this.allowed = Set.copyOf(allowed);
}

public boolean allows(HatchType type) {
return (flags & (1 << type.getId())) > 0;
return allowed.contains(type);
}

public Set<HatchType> values() {
return allowed;
}

public static class Builder {
private int flags = 0;
private final Set<HatchType> allowed = new HashSet<>();

public Builder with(HatchType type) {
flags |= 1 << type.getId();
allowed.add(type);
return this;
}

Expand All @@ -53,7 +60,7 @@ public Builder with(HatchType... types) {
}

public HatchFlags build() {
return new HatchFlags(flags);
return new HatchFlags(allowed);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,41 @@
*/
package aztech.modern_industrialization.machines.multiblocks;

import aztech.modern_industrialization.MI;
import aztech.modern_industrialization.MIText;
import com.mojang.datafixers.util.Either;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;

public enum HatchType {
ITEM_INPUT(0, MIText.ItemInputHatch),
ITEM_OUTPUT(1, MIText.ItemOutputHatch),
FLUID_INPUT(2, MIText.FluidInputHatch),
FLUID_OUTPUT(3, MIText.FluidOutputHatch),
ENERGY_INPUT(4, MIText.EnergyInputHatch),
ENERGY_OUTPUT(5, MIText.EnergyOutputHatch),
NUCLEAR_ITEM(6, "nuclear_item_hatch"),
NUCLEAR_FLUID(7, "nuclear_fluid_hatch"),
LARGE_TANK(8, "large_tank_hatch");
public final class HatchType {
private final ResourceLocation id;
private final Either<Component, ResourceLocation> descriptionOrBlockId;

private final int id;
private final Either<MIText, ResourceLocation> descriptionOrBlockId;

HatchType(int id, MIText description) {
HatchType(ResourceLocation id, Component description) {
this.id = id;
this.descriptionOrBlockId = Either.left(description);
}

HatchType(int id, String blockId) {
HatchType(ResourceLocation id, ResourceLocation blockId) {
this.id = id;
this.descriptionOrBlockId = Either.right(MI.id(blockId));
this.descriptionOrBlockId = Either.right(blockId);
}

public int getId() {
public ResourceLocation id() {
return id;
}

public MutableComponent description() {
return descriptionOrBlockId.map(MIText::text, id -> BuiltInRegistries.BLOCK.get(id).getName());
return descriptionOrBlockId.map(Component::copy, id -> BuiltInRegistries.BLOCK.get(id).getName());
}

@Override
public int hashCode() {
return id.hashCode();
}

@Override
public boolean equals(Object o) {
return o instanceof HatchType other && id.equals(other.id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* MIT License
*
* Copyright (c) 2020 Azercoco & Technici4n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package aztech.modern_industrialization.machines.multiblocks;

import aztech.modern_industrialization.MI;
import aztech.modern_industrialization.MIText;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;

public class HatchTypes {
private static final Map<ResourceLocation, HatchType> registeredHatches = new HashMap<>();

public static final HatchType ITEM_INPUT = register(MI.id("item_input"), MIText.ItemInputHatch);
public static final HatchType ITEM_OUTPUT = register(MI.id("item_output"), MIText.ItemOutputHatch);
public static final HatchType FLUID_INPUT = register(MI.id("fluid_input"), MIText.FluidInputHatch);
public static final HatchType FLUID_OUTPUT = register(MI.id("fluid_output"), MIText.FluidOutputHatch);
public static final HatchType ENERGY_INPUT = register(MI.id("energy_input"), MIText.EnergyInputHatch);
public static final HatchType ENERGY_OUTPUT = register(MI.id("energy_output"), MIText.EnergyOutputHatch);
public static final HatchType NUCLEAR_ITEM = register(MI.id("nuclear_item"), MI.id("nuclear_item_hatch"));
public static final HatchType NUCLEAR_FLUID = register(MI.id("nuclear_fluid"), MI.id("nuclear_fluid_hatch"));
public static final HatchType LARGE_TANK = register(MI.id("large_tank"), MI.id("large_tank_hatch"));

public static HatchType register(ResourceLocation id, MutableComponent description) {
if (registeredHatches.containsKey(id)) {
throw new IllegalArgumentException("Duplicate hatch type definition: " + id);
}
var type = new HatchType(id, description);
registeredHatches.put(id, type);
return type;
}

public static HatchType register(ResourceLocation id, MIText description) {
return register(id, description.text());
}

/**
* The block id corresponds to the user-facing description of the hatch type.
*/
public static HatchType register(ResourceLocation id, ResourceLocation blockId) {
if (registeredHatches.containsKey(id)) {
throw new IllegalArgumentException("Duplicate hatch type definition: " + id);
}
var type = new HatchType(id, blockId);
registeredHatches.put(id, type);
return type;
}

public static HatchType get(ResourceLocation id) {
var type = registeredHatches.get(id);
if (type != null) {
return type;
} else {
throw new IllegalArgumentException("Hatch type \"" + id + "\" does not exist.");
}
}

public static HatchType get(String name) {
return get(ResourceLocation.isValidPath(name) ? MI.id(name) : ResourceLocation.parse(name));
}

public static Collection<HatchType> values() {
return registeredHatches.values();
}
}
Loading