Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REGISTERS #324

Merged
merged 2 commits into from
Dec 11, 2021
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
9 changes: 9 additions & 0 deletions src/main/java/gregtech/api/gui/GuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,13 @@ public class GuiTextures {
public final static TextureArea ICON_CALCULATOR = TextureArea.fullImage("textures/gui/terminal/icon/other/calculator_hover.png");
public final static TextureArea UI_FRAME_SIDE_UP = TextureArea.fullImage("textures/gui/terminal/frame_side_up.png");
public final static TextureArea UI_FRAME_SIDE_DOWN = TextureArea.fullImage("textures/gui/terminal/frame_side_down.png");

// Texture Areas
public static final TextureArea BUTTON_FLUID = TextureArea.fullImage("textures/blocks/cover/cover_interface_fluid_button.png");
public static final TextureArea BUTTON_ITEM = TextureArea.fullImage("textures/blocks/cover/cover_interface_item_button.png");
public static final TextureArea BUTTON_ENERGY = TextureArea.fullImage("textures/blocks/cover/cover_interface_energy_button.png");
public static final TextureArea BUTTON_MACHINE = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_button.png");
public static final TextureArea BUTTON_INTERFACE = TextureArea.fullImage("textures/blocks/cover/cover_interface_computer_button.png");
public static final TextureArea COVER_INTERFACE_MACHINE_ON_PROXY = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_on_proxy.png");
public static final TextureArea COVER_INTERFACE_MACHINE_OFF_PROXY = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_off_proxy.png");
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,41 @@
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.items.IItemHandlerModifiable;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;

@SuppressWarnings("InstantiationOfUtilityClass")
public class MultiblockAbility<T> {
public static final Map<String, MultiblockAbility<?>> NAME_REGISTRY = new HashMap<>();
public static final Map<MultiblockAbility<?>, List<MetaTileEntity>> REGISTRY = new Object2ObjectOpenHashMap<>();

public static final MultiblockAbility<IItemHandlerModifiable> EXPORT_ITEMS = new MultiblockAbility<>();
public static final MultiblockAbility<IItemHandlerModifiable> IMPORT_ITEMS = new MultiblockAbility<>();
public static final MultiblockAbility<IItemHandlerModifiable> EXPORT_ITEMS = new MultiblockAbility<>("export_items");
public static final MultiblockAbility<IItemHandlerModifiable> IMPORT_ITEMS = new MultiblockAbility<>("import_items");

public static final MultiblockAbility<IFluidTank> EXPORT_FLUIDS = new MultiblockAbility<>();
public static final MultiblockAbility<IFluidTank> IMPORT_FLUIDS = new MultiblockAbility<>();
public static final MultiblockAbility<IFluidTank> EXPORT_FLUIDS = new MultiblockAbility<>("export_fluids");
public static final MultiblockAbility<IFluidTank> IMPORT_FLUIDS = new MultiblockAbility<>("import_fluids");

public static final MultiblockAbility<IEnergyContainer> INPUT_ENERGY = new MultiblockAbility<>();
public static final MultiblockAbility<IEnergyContainer> OUTPUT_ENERGY = new MultiblockAbility<>();
public static final MultiblockAbility<IEnergyContainer> INPUT_ENERGY = new MultiblockAbility<>("input_energy");
public static final MultiblockAbility<IEnergyContainer> OUTPUT_ENERGY = new MultiblockAbility<>("output_energy");

public static final MultiblockAbility<MetaTileEntityRotorHolder> ABILITY_ROTOR_HOLDER = new MultiblockAbility<>();
public static final MultiblockAbility<MetaTileEntityRotorHolder> ABILITY_ROTOR_HOLDER = new MultiblockAbility<>("ability_rotor_holder");

public static final MultiblockAbility<IFluidTank> PUMP_FLUID_HATCH = new MultiblockAbility<>();
public static final MultiblockAbility<IFluidTank> PUMP_FLUID_HATCH = new MultiblockAbility<>("pump_fluid_hatch");

public static final MultiblockAbility<IFluidTank> STEAM = new MultiblockAbility<>();
public static final MultiblockAbility<IItemHandlerModifiable> STEAM_IMPORT_ITEMS = new MultiblockAbility<>();
public static final MultiblockAbility<IItemHandlerModifiable> STEAM_EXPORT_ITEMS = new MultiblockAbility<>();
public static final MultiblockAbility<IFluidTank> STEAM = new MultiblockAbility<>("steam");
public static final MultiblockAbility<IItemHandlerModifiable> STEAM_IMPORT_ITEMS = new MultiblockAbility<>("steam_import_items");
public static final MultiblockAbility<IItemHandlerModifiable> STEAM_EXPORT_ITEMS = new MultiblockAbility<>("steam_export_items");

public static final MultiblockAbility<IMaintenanceHatch> MAINTENANCE_HATCH = new MultiblockAbility<>();
public static final MultiblockAbility<IMufflerHatch> MUFFLER_HATCH = new MultiblockAbility<>();

public static final Map<MultiblockAbility<?>, List<MetaTileEntity>> REGISTER = new Object2ObjectOpenHashMap<>();
public static final MultiblockAbility<IMaintenanceHatch> MAINTENANCE_HATCH = new MultiblockAbility<>("maintenance_hatch");
public static final MultiblockAbility<IMufflerHatch> MUFFLER_HATCH = new MultiblockAbility<>("muffler_hatch");

public static void registerMultiblockAbility(MultiblockAbility<?> ability, MetaTileEntity part) {
if (!REGISTER.containsKey(ability)) {
REGISTER.put(ability, new ArrayList<>());
if (!REGISTRY.containsKey(ability)) {
REGISTRY.put(ability, new ArrayList<>());
}
REGISTER.get(ability).add(part);
REGISTRY.get(ability).add(part);
}

public MultiblockAbility(String name){
NAME_REGISTRY.put(name.toLowerCase(), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Matrix4;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IMaintenanceHatch;
import gregtech.api.capability.IMultiblockController;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
Expand All @@ -15,13 +14,11 @@
import gregtech.api.pattern.TraceabilityPredicate;
import gregtech.api.render.ICubeRenderer;
import gregtech.api.render.OrientedOverlayRenderer;
import gregtech.api.render.SimpleOverlayRenderer;
import gregtech.api.render.Textures;
import gregtech.api.util.BlockInfo;
import gregtech.api.util.GTUtility;
import gregtech.common.blocks.MetaBlocks;
import gregtech.common.blocks.VariantActiveBlock;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityRotorHolder;
import gregtech.api.pattern.MultiblockShapeInfo;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -163,7 +160,7 @@ private static Supplier<BlockInfo[]> getCandidates(IBlockState... allowedStates)
public static TraceabilityPredicate abilities(MultiblockAbility<?>... allowedAbilities) {
return tilePredicate((state, tile) -> tile instanceof IMultiblockAbilityPart<?> &&
ArrayUtils.contains(allowedAbilities, ((IMultiblockAbilityPart<?>) tile).getAbility()),
getCandidates(Arrays.stream(allowedAbilities).flatMap(ability -> MultiblockAbility.REGISTER.get(ability).stream()).toArray(MetaTileEntity[]::new)));
getCandidates(Arrays.stream(allowedAbilities).flatMap(ability -> MultiblockAbility.REGISTRY.get(ability).stream()).toArray(MetaTileEntity[]::new)));
}

public static TraceabilityPredicate states(IBlockState... allowedStates) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/gregtech/api/render/IOverlayRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gregtech.api.render;

import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public interface IOverlayRenderer {

@SideOnly(Side.CLIENT)
default void renderSided(EnumFacing side, CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
renderSided(side, Cuboid6.full, renderState, pipeline, translation);
}

@SideOnly(Side.CLIENT)
void renderSided(EnumFacing side, Cuboid6 bounds, CCRenderState renderState, IVertexOperation[] pipeline, Matrix4 translation);

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SimpleCubeRenderer implements ICubeRenderer, IIconRegister {

public SimpleCubeRenderer(String basePath) {
this.basePath = basePath;
Textures.CUBE_RENDERER_REGISTRY.put(basePath, this);
Textures.iconRegisters.add(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import javax.annotation.Nullable;

public class SimpleOverlayRenderer implements IIconRegister {
public class SimpleOverlayRenderer implements IOverlayRenderer, IIconRegister {

private final String basePath;

Expand All @@ -31,6 +31,7 @@ public class SimpleOverlayRenderer implements IIconRegister {

public SimpleOverlayRenderer(String basePath) {
this.basePath = basePath;
Textures.CUBE_SIDE_RENDERER_REGISTRY.put(basePath, this);
Textures.iconRegisters.add(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static RenderSide bySide(EnumFacing side) {

public SimpleSidedCubeRenderer(String basePath) {
this.basePath = basePath;
Textures.CUBE_RENDERER_REGISTRY.put(basePath, this);
Textures.iconRegisters.add(this);
}

Expand Down
17 changes: 6 additions & 11 deletions src/main/java/gregtech/api/render/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import codechicken.lib.vec.uv.IconTransformation;
import codechicken.lib.vec.uv.UVTransformationList;
import gregtech.api.GTValues;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.util.GTLog;
import gregtech.core.hooks.BloomRenderLayerHooks;
import gregtech.common.render.CrateRenderer;
import gregtech.common.render.DrumRenderer;
import gregtech.core.hooks.BloomRenderLayerHooks;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.EnumFacing;
Expand All @@ -23,12 +22,17 @@
import org.apache.commons.lang3.ArrayUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static gregtech.api.render.OrientedOverlayRenderer.OverlayFace.*;

public class Textures {

public static final Map<String, ICubeRenderer> CUBE_RENDERER_REGISTRY = new HashMap<>();
public static final Map<String, IOverlayRenderer> CUBE_SIDE_RENDERER_REGISTRY = new HashMap<>();

private static final ThreadLocal<BlockFace> blockFaces = ThreadLocal.withInitial(BlockFace::new);
public static final List<IIconRegister> iconRegisters = new ArrayList<>();

Expand Down Expand Up @@ -226,15 +230,6 @@ public class Textures {
public static final SimpleOverlayRenderer COVER_INTERFACE_PROXY = new SimpleOverlayRenderer("cover/cover_interface_proxy");
public static final SimpleOverlayRenderer COVER_INTERFACE_WIRELESS = new SimpleOverlayRenderer("cover/cover_interface_wireless");

// Texture Areas
public static final TextureArea BUTTON_FLUID = TextureArea.fullImage("textures/blocks/cover/cover_interface_fluid_button.png");
public static final TextureArea BUTTON_ITEM = TextureArea.fullImage("textures/blocks/cover/cover_interface_item_button.png");
public static final TextureArea BUTTON_ENERGY = TextureArea.fullImage("textures/blocks/cover/cover_interface_energy_button.png");
public static final TextureArea BUTTON_MACHINE = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_button.png");
public static final TextureArea BUTTON_INTERFACE = TextureArea.fullImage("textures/blocks/cover/cover_interface_computer_button.png");
public static final TextureArea COVER_INTERFACE_MACHINE_ON_PROXY = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_on_proxy.png");
public static final TextureArea COVER_INTERFACE_MACHINE_OFF_PROXY = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_off_proxy.png");


static {
for (int i = 0; i < VOLTAGE_CASINGS.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,19 +431,19 @@ public ModularUI createUI(EntityPlayer player) {
WidgetGroup primaryGroup = new WidgetGroup(new Position(0, 10));
primaryGroup.addWidget(new LabelWidget(10, 5, "metaitem.cover.digital.name", 0));
ToggleButtonWidget[] buttons = new ToggleButtonWidget[5];
buttons[0] = new ToggleButtonWidget(40, 20, 20, 20, Textures.BUTTON_FLUID, () -> this.mode == MODE.FLUID, (pressed) -> {
buttons[0] = new ToggleButtonWidget(40, 20, 20, 20, GuiTextures.BUTTON_FLUID, () -> this.mode == MODE.FLUID, (pressed) -> {
if (pressed) setMode(MODE.FLUID);
}).setTooltipText("metaitem.cover.digital.mode.fluid");
buttons[1] = new ToggleButtonWidget(60, 20, 20, 20, Textures.BUTTON_ITEM, () -> this.mode == MODE.ITEM, (pressed) -> {
buttons[1] = new ToggleButtonWidget(60, 20, 20, 20, GuiTextures.BUTTON_ITEM, () -> this.mode == MODE.ITEM, (pressed) -> {
if (pressed) setMode(MODE.ITEM);
}).setTooltipText("metaitem.cover.digital.mode.item");
buttons[2] = new ToggleButtonWidget(80, 20, 20, 20, Textures.BUTTON_ENERGY, () -> this.mode == MODE.ENERGY, (pressed) -> {
buttons[2] = new ToggleButtonWidget(80, 20, 20, 20, GuiTextures.BUTTON_ENERGY, () -> this.mode == MODE.ENERGY, (pressed) -> {
if (pressed) setMode(MODE.ENERGY);
}).setTooltipText("metaitem.cover.digital.mode.energy");
buttons[3] = new ToggleButtonWidget(100, 20, 20, 20, Textures.BUTTON_MACHINE, () -> this.mode == MODE.MACHINE, (pressed) -> {
buttons[3] = new ToggleButtonWidget(100, 20, 20, 20, GuiTextures.BUTTON_MACHINE, () -> this.mode == MODE.MACHINE, (pressed) -> {
if (pressed) setMode(MODE.MACHINE);
}).setTooltipText("metaitem.cover.digital.mode.machine");
buttons[4] = new ToggleButtonWidget(140, 20, 20, 20, Textures.BUTTON_INTERFACE, () -> this.mode == MODE.PROXY, (pressed) -> {
buttons[4] = new ToggleButtonWidget(140, 20, 20, 20, GuiTextures.BUTTON_INTERFACE, () -> this.mode == MODE.PROXY, (pressed) -> {
if (pressed) setMode(MODE.PROXY);
}).setTooltipText("metaitem.cover.digital.mode.proxy");
primaryGroup.addWidget(new LabelWidget(10, 25, "metaitem.cover.digital.title.mode", 0));
Expand Down Expand Up @@ -966,9 +966,9 @@ private void renderMachineMode(float partialTicks) {
}
if (this.isProxy()) {
if (isWorkingEnabled) {
RenderUtil.renderTextureArea(Textures.COVER_INTERFACE_MACHINE_ON_PROXY, -7f / 16, 1f / 16, 14f / 16, 3f / 16, 0.002f);
RenderUtil.renderTextureArea(GuiTextures.COVER_INTERFACE_MACHINE_ON_PROXY, -7f / 16, 1f / 16, 14f / 16, 3f / 16, 0.002f);
} else {
RenderUtil.renderTextureArea(Textures.COVER_INTERFACE_MACHINE_OFF_PROXY, -7f / 16, -1f / 16, 14f / 16, 5f / 16, 0.002f);
RenderUtil.renderTextureArea(GuiTextures.COVER_INTERFACE_MACHINE_OFF_PROXY, -7f / 16, -1f / 16, 14f / 16, 5f / 16, 0.002f);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import gregtech.common.blocks.MetaBlocks;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityMultiFluidHatch;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
Expand Down Expand Up @@ -68,7 +67,7 @@ protected BlockPattern createStructurePattern() {
.or(abilities(MultiblockAbility.EXPORT_ITEMS).setMinGlobalLimited(1))
.or(abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1)))
.where('X', states(getCasingState())
.or(metaTileEntities(MultiblockAbility.REGISTER.get(MultiblockAbility.EXPORT_FLUIDS).stream()
.or(metaTileEntities(MultiblockAbility.REGISTRY.get(MultiblockAbility.EXPORT_FLUIDS).stream()
.filter(mte->!(mte instanceof MetaTileEntityMultiFluidHatch))
.toArray(MetaTileEntity[]::new))
.setMinLayerLimited(1).setMaxLayerLimited(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,19 +469,19 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
int width = 330;
int height = 260;
ToggleButtonWidget[] buttons = new ToggleButtonWidget[5];
buttons[0] = new ToggleButtonWidget(width - 135, 25, 20, 20, Textures.BUTTON_FLUID, () -> this.mode == CoverDigitalInterface.MODE.FLUID, (isPressed) -> {
buttons[0] = new ToggleButtonWidget(width - 135, 25, 20, 20, GuiTextures.BUTTON_FLUID, () -> this.mode == CoverDigitalInterface.MODE.FLUID, (isPressed) -> {
if (isPressed) setMode(CoverDigitalInterface.MODE.FLUID);
}).setTooltipText("metaitem.cover.digital.mode.fluid");
buttons[1] = new ToggleButtonWidget(width - 115, 25, 20, 20, Textures.BUTTON_ITEM, () -> this.mode == CoverDigitalInterface.MODE.ITEM, (isPressed) -> {
buttons[1] = new ToggleButtonWidget(width - 115, 25, 20, 20, GuiTextures.BUTTON_ITEM, () -> this.mode == CoverDigitalInterface.MODE.ITEM, (isPressed) -> {
if (isPressed) setMode(CoverDigitalInterface.MODE.ITEM);
}).setTooltipText("metaitem.cover.digital.mode.item");
buttons[2] = new ToggleButtonWidget(width - 95, 25, 20, 20, Textures.BUTTON_ENERGY, () -> this.mode == CoverDigitalInterface.MODE.ENERGY, (isPressed) -> {
buttons[2] = new ToggleButtonWidget(width - 95, 25, 20, 20, GuiTextures.BUTTON_ENERGY, () -> this.mode == CoverDigitalInterface.MODE.ENERGY, (isPressed) -> {
if (isPressed) setMode(CoverDigitalInterface.MODE.ENERGY);
}).setTooltipText("metaitem.cover.digital.mode.energy");
buttons[3] = new ToggleButtonWidget(width - 75, 25, 20, 20, Textures.BUTTON_MACHINE, () -> this.mode == CoverDigitalInterface.MODE.MACHINE, (isPressed) -> {
buttons[3] = new ToggleButtonWidget(width - 75, 25, 20, 20, GuiTextures.BUTTON_MACHINE, () -> this.mode == CoverDigitalInterface.MODE.MACHINE, (isPressed) -> {
if (isPressed) setMode(CoverDigitalInterface.MODE.MACHINE);
}).setTooltipText("metaitem.cover.digital.mode.machine");
buttons[4] = new ToggleButtonWidget(width - 35, 25, 20, 20, Textures.BUTTON_INTERFACE, () -> this.mode == CoverDigitalInterface.MODE.PROXY, (isPressed) -> {
buttons[4] = new ToggleButtonWidget(width - 35, 25, 20, 20, GuiTextures.BUTTON_INTERFACE, () -> this.mode == CoverDigitalInterface.MODE.PROXY, (isPressed) -> {
if (isPressed) setMode(CoverDigitalInterface.MODE.PROXY);
}).setTooltipText("metaitem.cover.digital.mode.proxy");
List<CoverDigitalInterface> covers = new ArrayList<>();
Expand Down