Skip to content

Commit

Permalink
processing array (#185)
Browse files Browse the repository at this point in the history
* processing array

* fix rendering + overclock

* done
  • Loading branch information
Yefancy authored Jul 24, 2023
1 parent e9e5cce commit 46b7b35
Show file tree
Hide file tree
Showing 15 changed files with 430 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

Expand All @@ -26,12 +29,16 @@
* @implNote OverclockFancyConfigurator
*/
public class OverclockFancyConfigurator implements IFancyConfigurator {
IOverclockMachine overclockMachine;
protected IOverclockMachine overclockMachine;
// runtime
int currentTier;
protected int currentTier;
@Nullable
protected WidgetGroup group;
protected Map<Integer, WidgetGroup> lightGroups;

public OverclockFancyConfigurator(IOverclockMachine overclockMachine) {
this.overclockMachine = overclockMachine;
this.lightGroups = new HashMap<>();
}

@Override
Expand All @@ -41,12 +48,59 @@ public void detectAndSendChange(BiConsumer<Integer, Consumer<FriendlyByteBuf>> s
this.currentTier = newTier;
sender.accept(0, buf -> buf.writeVarInt(this.currentTier));
}
int min = overclockMachine.getMinOverclockTier();
int max = overclockMachine.getMaxOverclockTier();
if (lightGroups.size() != max - min + 1) {
updateLightButton(min, max);
sender.accept(1, buf -> {
buf.writeVarInt(min);
buf.writeVarInt(max);
});
} else {
for (int i = min; i <= max; i++) {
if (!lightGroups.containsKey(i)) {
updateLightButton(min, max);
sender.accept(1, buf -> {
buf.writeVarInt(min);
buf.writeVarInt(max);
});
return;
}
}
}
}

private void updateLightButton(int min, int max) {
if (group != null) {
for (WidgetGroup light : lightGroups.values()) {
group.removeWidget(light);
}
lightGroups.clear();
int x = 5;
for (int tier = min; tier <= max ; tier++) {
int finalTier = tier;
var lightGroup = new WidgetGroup(x, 27, 8, 8);
lightGroup.addWidget(new ButtonWidget(0, 0, 8, 8, null, cd -> {
if (!cd.isRemote) {
overclockMachine.setOverclockTier(finalTier);
}
}));
lightGroup.addWidget(new ImageWidget(0, 0, 8, 8, () -> currentTier >= finalTier ? GuiTextures.LIGHT_ON : GuiTextures.LIGHT_OFF));
lightGroups.put(tier, lightGroup);
group.addWidget(lightGroup);
x += 10;
}
}
}

@Override
public void readUpdateInfo(int id, FriendlyByteBuf buf) {
if (id == 0) {
this.currentTier = buf.readVarInt();
} else if (id == 1) {
int min = buf.readVarInt();
int max = buf.readVarInt();
updateLightButton(min, max);
}
}

Expand All @@ -62,7 +116,7 @@ public IGuiTexture getIcon() {

@Override
public Widget createConfigurator() {
var group = new WidgetGroup(0, 0, 120, 40);
group = new WidgetGroup(0, 0, 120, 40);
group.setBackground(GuiTextures.BACKGROUND_INVERSE);
group.addWidget(new PredicatedButtonWidget(5, 5, 10, 20, new GuiTextureGroup(GuiTextures.BUTTON, Icons.LEFT.copy().scale(0.7f)), cd -> {
if (!cd.isRemote) {
Expand All @@ -75,20 +129,11 @@ public Widget createConfigurator() {
overclockMachine.setOverclockTier(currentTier + 1);
}
}).setPredicate(() -> currentTier < overclockMachine.getMaxOverclockTier()));
int x = 5;
for (int tier = overclockMachine.getMinOverclockTier(); tier <= overclockMachine.getMaxOverclockTier() ; tier++) {
int finalTier = tier;
group.addWidget(new ButtonWidget(x, 27, 8, 8, null, cd -> {
if (!cd.isRemote) {
overclockMachine.setOverclockTier(finalTier);
}
}));
group.addWidget(new ImageWidget(x, 27, 8, 8, () -> currentTier >= finalTier ? GuiTextures.LIGHT_ON : GuiTextures.LIGHT_OFF));
x += 10;
}
return group;
}



@Override
public List<Component> getTooltips() {
return List.of(Component.translatable(getTitle()), Component.translatable("gtceu.gui.overclock.range", GTValues.VNF[overclockMachine.getMinOverclockTier()], GTValues.VNF[overclockMachine.getMaxOverclockTier()]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.feature.IOverclockMachine;
import com.gregtechceu.gtceu.api.machine.feature.ITieredMachine;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;
Expand All @@ -17,16 +18,16 @@
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class TieredWorkableElectricMultiblockMachine extends WorkableElectricMultiblockMachine implements ITieredMachine {
public class TieredWorkableElectricMultiblockMachine extends WorkableElectricMultiblockMachine implements ITieredMachine, IOverclockMachine {
protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(TieredWorkableElectricMultiblockMachine.class, WorkableElectricMultiblockMachine.MANAGED_FIELD_HOLDER);

private final int tier;
@Persisted
@Getter
protected int overclockTier;

public TieredWorkableElectricMultiblockMachine(IMachineBlockEntity holder, int tier) {
super(holder);
public TieredWorkableElectricMultiblockMachine(IMachineBlockEntity holder, int tier, Object... args) {
super(holder, args);
this.tier = tier;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.gregtechceu.gtceu.api.machine.multiblock;

import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.capability.IEnergyContainer;
import com.gregtechceu.gtceu.api.capability.recipe.EURecipeCapability;
import com.gregtechceu.gtceu.api.capability.recipe.IO;
import com.gregtechceu.gtceu.api.capability.recipe.IRecipeHandler;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.fancy.IFancyUIProvider;
import com.gregtechceu.gtceu.api.gui.fancy.TooltipsPanel;
Expand All @@ -10,10 +14,6 @@
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IDisplayUIMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart;
import com.gregtechceu.gtceu.utils.GTUtil;
import com.gregtechceu.gtceu.api.capability.IEnergyContainer;
import com.gregtechceu.gtceu.api.capability.recipe.EURecipeCapability;
import com.gregtechceu.gtceu.api.capability.recipe.IO;
import com.gregtechceu.gtceu.api.capability.recipe.IRecipeHandler;
import com.gregtechceu.gtceu.api.machine.feature.ITieredMachine;
import com.lowdragmc.lowdraglib.gui.modular.ModularUI;
import com.lowdragmc.lowdraglib.gui.widget.*;
Expand All @@ -38,6 +38,29 @@ public class WorkableElectricMultiblockMachine extends WorkableMultiblockMachine
public WorkableElectricMultiblockMachine(IMachineBlockEntity holder, Object... args) {
super(holder, args);
}
//runtime
private long maxHatchVoltage = -1;

//////////////////////////////////////
//*** Multiblock LifeCycle ***//
//////////////////////////////////////
@Override
public void onStructureInvalid() {
super.onStructureInvalid();
maxHatchVoltage = -1;
}

@Override
public void onStructureFormed() {
maxHatchVoltage = -1;
super.onStructureFormed();
}

@Override
public void onPartUnload() {
super.onPartUnload();
maxHatchVoltage = -1;
}

//////////////////////////////////////
//********** GUI ***********//
Expand Down Expand Up @@ -68,7 +91,7 @@ public void addDisplayText(List<Component> textList) {
// .setStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
// Component.translatable("gtceu.multiblock.multiple_recipemaps.tooltip")))));

textList.add(Component.translatable(recipeType.registryName.toLanguageKey())
textList.add(Component.translatable(getRecipeType().registryName.toLanguageKey())
.setStyle(Style.EMPTY.withColor(ChatFormatting.AQUA)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
Component.translatable("gtceu.multiblock.multiple_recipemaps.tooltip")))));
Expand Down Expand Up @@ -166,25 +189,31 @@ public int getTier() {
return GTUtil.getFloorTierByVoltage(getMaxVoltage());
}

public long getMaxVoltage() {
long maxVoltage = 0L;
var capabilities = capabilitiesProxy.get(IO.IN, EURecipeCapability.CAP);
if (capabilities != null) {
for (IRecipeHandler<?> handler : capabilities) {
if (handler instanceof IEnergyContainer container) {
maxVoltage += container.getInputVoltage() * container.getInputAmperage();
}
}
} else {
capabilities = capabilitiesProxy.get(IO.OUT, EURecipeCapability.CAP);
public long getMaxHatchVoltage() {
if (maxHatchVoltage < 0) {
maxHatchVoltage = 0L;
var capabilities = capabilitiesProxy.get(IO.IN, EURecipeCapability.CAP);
if (capabilities != null) {
for (IRecipeHandler<?> handler : capabilities) {
if (handler instanceof IEnergyContainer container) {
maxVoltage += container.getOutputVoltage() * container.getOutputAmperage();
maxHatchVoltage += container.getInputVoltage() * container.getInputAmperage();
}
}
} else {
capabilities = capabilitiesProxy.get(IO.OUT, EURecipeCapability.CAP);
if (capabilities != null) {
for (IRecipeHandler<?> handler : capabilities) {
if (handler instanceof IEnergyContainer container) {
maxHatchVoltage += container.getOutputVoltage() * container.getOutputAmperage();
}
}
}
}
}
return maxVoltage;
return maxHatchVoltage;
}

public long getMaxVoltage() {
return getMaxHatchVoltage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public abstract class WorkableMultiblockMachine extends MultiblockControllerMach
@DescSynced
public final RecipeLogic recipeLogic;
@Getter
public final GTRecipeType recipeType;
private final GTRecipeType recipeType;
@Getter
protected final Table<IO, RecipeCapability<?>, List<IRecipeHandler<?>>> capabilitiesProxy;
protected final List<ISubscription> traitSubscriptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.lowdragmc.lowdraglib.misc.ItemStackTransfer;
import com.lowdragmc.lowdraglib.side.item.IItemTransfer;
import com.lowdragmc.lowdraglib.side.item.ItemTransferHelper;
import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;
import lombok.Getter;
Expand All @@ -22,6 +23,7 @@
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

/**
* @author KilaBash
Expand All @@ -37,19 +39,23 @@ public class NotifiableItemStackHandler extends NotifiableRecipeHandlerTrait<Ing
public final IO capabilityIO;
@Getter @Setter
private long timeStamp;
@Persisted
@Persisted @DescSynced
public final ItemStackTransfer storage;
private Boolean isEmpty;

public NotifiableItemStackHandler(MetaMachine machine, int slots, IO handlerIO, IO capabilityIO) {
public NotifiableItemStackHandler(MetaMachine machine, int slots, IO handlerIO, IO capabilityIO, Function<Integer, ItemStackTransfer> transferFactory) {
super(machine);
this.timeStamp = Long.MIN_VALUE;
this.handlerIO = handlerIO;
this.storage = new ItemStackTransfer(slots);
this.storage = transferFactory.apply(slots);
this.capabilityIO = capabilityIO;
this.storage.setOnContentsChanged(this::onContentChanged);
}

public NotifiableItemStackHandler(MetaMachine machine, int slots, IO handlerIO, IO capabilityIO) {
this(machine, slots, handlerIO, capabilityIO, ItemStackTransfer::new);
}

public NotifiableItemStackHandler(MetaMachine machine, int slots, IO handlerIO) {
this(machine, slots, handlerIO, handlerIO);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.gregtechceu.gtceu.client.renderer.machine;

import com.gregtechceu.gtceu.api.machine.MachineDefinition;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.common.machine.multiblock.electric.ProcessingArrayMachine;
import com.lowdragmc.lowdraglib.client.bakedpipeline.Quad;
import com.mojang.math.Vector3f;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
* @author KilaBash
* @date 2023/7/24
* @implNote ProcessingArrayMachineRenderer
*/
public class ProcessingArrayMachineRenderer extends WorkableCasingMachineRenderer{
public ProcessingArrayMachineRenderer(ResourceLocation baseCasing, ResourceLocation workableModel) {
super(baseCasing, workableModel, false);
}

@Override
@Environment(EnvType.CLIENT)
public void renderMachine(List<BakedQuad> quads, MachineDefinition definition, @Nullable MetaMachine machine, Direction frontFacing, @Nullable Direction side, RandomSource rand, Direction modelFacing, ModelState modelState) {
super.renderMachine(quads, definition, machine, frontFacing, side, rand, modelFacing, modelState);
// render held machine in the center
if (machine instanceof ProcessingArrayMachine processingArray && processingArray.isFormed()) {
var heldDefinition = processingArray.getMachineDefinition();
if (heldDefinition != null && heldDefinition.getRenderer() instanceof MachineRenderer machineRenderer) {
List<BakedQuad> machineQuad = new ArrayList<>();
machineRenderer.renderMachine(machineQuad, definition, machine, frontFacing, side, rand, modelFacing, modelState);
for (var quad : machineQuad) {
var bakedQuad = Quad.from(quad);
for (int i = 0; i < 4; i++) {
var pos = bakedQuad.getVert(i);
bakedQuad = bakedQuad.withVert(i, new Vector3f(pos.x() - frontFacing.getStepX(), pos.y() + 1, pos.z() - frontFacing.getStepZ()));
}
quads.add(bakedQuad.rebake());
}
}
}
}
}
Loading

0 comments on commit 46b7b35

Please sign in to comment.