Skip to content

Commit

Permalink
Creative Computation Provider (#1621)
Browse files Browse the repository at this point in the history
Co-authored-by: screret <[email protected]>
  • Loading branch information
gateguardian523 and screret authored Aug 3, 2024
1 parent 79f8280 commit e435f38
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"page": "gtceu:machines/crate",
"position": [
-200,
-150,
350
],
"section": "gtceu:machines"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"page": "gtceu:machines/creative_chest",
"position": [
-350,
-300,
350
],
"section": "gtceu:machines"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"button_texture": {
"type": "item",
"res": "gtceu:creative_computation_provider"
},
"items": [
"gtceu:creative_computation_provider"
],
"page": "gtceu:machines/creative_computation_provider",
"position": [
-400,
350
],
"section": "gtceu:machines"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"page": "gtceu:machines/creative_tank",
"position": [
-400,
-350,
350
],
"section": "gtceu:machines"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"page": "gtceu:machines/drum",
"position": [
-150,
-100,
350
],
"section": "gtceu:machines"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"page": "gtceu:machines/super_chest",
"position": [
-300,
-250,
350
],
"section": "gtceu:machines"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"page": "gtceu:machines/super_tank",
"position": [
-250,
-200,
350
],
"section": "gtceu:machines"
Expand Down
3 changes: 3 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"block.gtceu.cracked_red_granite_bricks": "sʞɔıɹᗺ ǝʇıuɐɹ⅁ pǝᴚ pǝʞɔɐɹƆ",
"block.gtceu.cracker": "ɹǝʞɔɐɹƆ",
"block.gtceu.creative_chest": "ʇsǝɥƆ ǝʌıʇɐǝɹƆ",
"block.gtceu.creative_computation_provider": "ɹǝpıʌoɹԀ uoıʇɐʇndɯoƆ ǝʌıʇɐǝɹƆ",
"block.gtceu.creative_data_access_hatch": "ɥɔʇɐH ssǝɔɔⱯ ɐʇɐᗡ ǝʌıʇɐǝɹƆ",
"block.gtceu.creative_energy": "ʎbɹǝuƎ ǝʌıʇɐǝɹƆ",
"block.gtceu.creative_tank": "ʞuɐ⟘ ǝʌıʇɐǝɹƆ",
Expand Down Expand Up @@ -1869,6 +1870,7 @@
"compass.node.gtceu.machines/converter": "ɹǝʇɹǝʌuoƆ",
"compass.node.gtceu.machines/crate": "ǝʇɐɹƆ",
"compass.node.gtceu.machines/creative_chest": "ʇsǝɥƆ ǝʌıʇɐǝɹƆ",
"compass.node.gtceu.machines/creative_computation_provider": "ɹǝpıʌoɹԀ uoıʇɐʇndɯoƆ ǝʌıʇɐǝɹƆ",
"compass.node.gtceu.machines/creative_energy": "ʎbɹǝuƎ ǝʌıʇɐǝɹƆ",
"compass.node.gtceu.machines/creative_tank": "ʞuɐ⟘ ǝʌıʇɐǝɹƆ",
"compass.node.gtceu.machines/cutter": "ɹǝʇʇnƆ",
Expand Down Expand Up @@ -2605,6 +2607,7 @@
"gtceu.creative.chest.ipc": "ǝןɔʎƆ ɹǝd sɯǝʇI",
"gtceu.creative.chest.item": "ɯǝʇI",
"gtceu.creative.chest.tpc": "ǝןɔʎƆ ɹǝd sʞɔı⟘",
"gtceu.creative.computation.average": "ʇ∩MƆ pǝʇsǝnbǝᴚ ǝbɐɹǝʌⱯ",
"gtceu.creative.energy.amperage": "ǝbɐɹǝdɯⱯ",
"gtceu.creative.energy.sink": "ʞuıS",
"gtceu.creative.energy.source": "ǝɔɹnoS",
Expand Down
3 changes: 3 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"block.gtceu.cracked_red_granite_bricks": "Cracked Red Granite Bricks",
"block.gtceu.cracker": "Cracker",
"block.gtceu.creative_chest": "Creative Chest",
"block.gtceu.creative_computation_provider": "Creative Computation Provider",
"block.gtceu.creative_data_access_hatch": "Creative Data Access Hatch",
"block.gtceu.creative_energy": "Creative Energy",
"block.gtceu.creative_tank": "Creative Tank",
Expand Down Expand Up @@ -1869,6 +1870,7 @@
"compass.node.gtceu.machines/converter": "Converter",
"compass.node.gtceu.machines/crate": "Crate",
"compass.node.gtceu.machines/creative_chest": "Creative Chest",
"compass.node.gtceu.machines/creative_computation_provider": "Creative Computation Provider",
"compass.node.gtceu.machines/creative_energy": "Creative Energy",
"compass.node.gtceu.machines/creative_tank": "Creative Tank",
"compass.node.gtceu.machines/cutter": "Cutter",
Expand Down Expand Up @@ -2605,6 +2607,7 @@
"gtceu.creative.chest.ipc": "Items per Cycle",
"gtceu.creative.chest.item": "Item",
"gtceu.creative.chest.tpc": "Ticks per Cycle",
"gtceu.creative.computation.average": "Average Requested CWUt",
"gtceu.creative.energy.amperage": "Amperage",
"gtceu.creative.energy.sink": "Sink",
"gtceu.creative.energy.source": "Source",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,14 @@ public static BiConsumer<ItemStack, List<Component>> createCreativeTooltips(bool
.tooltipBuilder(CREATIVE_TOOLTIPS)
.compassNodeSelf()
.register();

public static final MachineDefinition CREATIVE_COMPUTATION_PROVIDER = REGISTRATE
.machine("creative_computation_provider", CreativeComputationProviderMachine::new)
.rotationState(RotationState.NONE)
.tooltipBuilder(CREATIVE_TOOLTIPS)
.compassNodeSelf()
.register();

public static final MachineDefinition CREATIVE_FLUID = REGISTRATE.machine("creative_tank", CreativeTankMachine::new)
.rotationState(RotationState.ALL)
.tooltipBuilder(CREATIVE_TOOLTIPS)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.gregtechceu.gtceu.common.machine.storage;

import com.gregtechceu.gtceu.api.capability.IOpticalComputationProvider;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.machine.TickableSubscription;
import com.gregtechceu.gtceu.api.machine.feature.IUIMachine;

import com.lowdragmc.lowdraglib.gui.modular.ModularUI;
import com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup;
import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture;
import com.lowdragmc.lowdraglib.gui.texture.TextTexture;
import com.lowdragmc.lowdraglib.gui.widget.LabelWidget;
import com.lowdragmc.lowdraglib.gui.widget.SwitchWidget;
import com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.world.entity.player.Player;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class CreativeComputationProviderMachine extends MetaMachine
implements IUIMachine, IOpticalComputationProvider {

public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(
CreativeComputationProviderMachine.class, MetaMachine.MANAGED_FIELD_HOLDER);

@Persisted
private int maxCWUt;
private int lastRequestedCWUt;
private int requestedCWUPerSec;
@Persisted
@Getter
private boolean active;
@Nullable
private TickableSubscription computationSubs;

public CreativeComputationProviderMachine(IMachineBlockEntity holder) {
super(holder);
}

@Override
public void onLoad() {
super.onLoad();
updateComputationSubscription();
}

protected void updateComputationSubscription() {
if (active) {
this.computationSubs = subscribeServerTick(this::updateComputationTick);
} else if (computationSubs != null) {
computationSubs.unsubscribe();
this.computationSubs = null;
this.lastRequestedCWUt = 0;
this.requestedCWUPerSec = 0;
}
}

protected void updateComputationTick() {
if (getOffsetTimer() % 20 == 0) {
this.lastRequestedCWUt = requestedCWUPerSec / 20;
this.requestedCWUPerSec = 0;
}
}

@Override
public int requestCWUt(
int cwut, boolean simulate, @NotNull Collection<IOpticalComputationProvider> seen) {
seen.add(this);
int requestedCWUt = active ? Math.min(cwut, maxCWUt) : 0;
if (!simulate) {
this.requestedCWUPerSec += requestedCWUt;
}
return requestedCWUt;
}

@Override
public int getMaxCWUt(@NotNull Collection<IOpticalComputationProvider> seen) {
seen.add(this);
return active ? maxCWUt : 0;
}

@Override
public boolean canBridge(@NotNull Collection<IOpticalComputationProvider> seen) {
seen.add(this);
return true;
}

public void setActive(boolean active) {
this.active = active;
updateComputationSubscription();
}

@Override
public ModularUI createUI(Player entityPlayer) {
return new ModularUI(140, 95, this, entityPlayer)
.background(GuiTextures.BACKGROUND)
.widget(new LabelWidget(7, 7, "CWUt"))
.widget(new TextFieldWidget(9, 20, 122, 16, () -> String.valueOf(maxCWUt),
value -> maxCWUt = Integer.parseInt(value)).setNumbersOnly(0, Integer.MAX_VALUE))
.widget(new LabelWidget(7, 42, "gtceu.creative.computation.average"))
.widget(new LabelWidget(7, 54, () -> String.valueOf(lastRequestedCWUt)))
.widget(new SwitchWidget(9, 66, 122, 20, (clickData, value) -> setActive(value))
.setSupplier(this::isActive)
.setTexture(new GuiTextureGroup(ResourceBorderTexture.BUTTON_COMMON,
new TextTexture("gtceu.creative.activity.off")),
new GuiTextureGroup(ResourceBorderTexture.BUTTON_COMMON,
new TextTexture("gtceu.creative.activity.on"))));
}

@Override
public ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ protected static void init(RegistrateLangProvider provider) {
provider.add("gtceu.creative.energy.voltage", "Voltage");
provider.add("gtceu.creative.energy.sink", "Sink");
provider.add("gtceu.creative.energy.source", "Source");
provider.add("gtceu.creative.computation.average", "Average Requested CWUt");
provider.add("gtceu.creative.activity.on", "Active");
provider.add("gtceu.creative.activity.off", "Not active");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"parent": "block/block",
"textures": {
"particle": "gtceu:block/casings/voltage/max/side",
"bot_bottom": "gtceu:block/casings/voltage/max/bottom",
"bot_top": "gtceu:block/casings/voltage/max/top",
"bot_side": "gtceu:block/casings/voltage/max/side",
"top_all": "gtceu:block/overlay/machine/overlay_data_hatch_optical",
"emissive_all": "gtceu:block/overlay/machine/overlay_data_hatch_optical_emissive"
},
"elements": [
{
"from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"faces": {
"down": { "texture": "#bot_bottom", "cullface": "down", "tintindex": 1 },
"up": { "texture": "#bot_top", "cullface": "up", "tintindex": 1 },
"north": { "texture": "#bot_side", "cullface": "north", "tintindex": 1 },
"south": { "texture": "#bot_side", "cullface": "south", "tintindex": 1 },
"west": { "texture": "#bot_side", "cullface": "west", "tintindex": 1 },
"east": { "texture": "#bot_side", "cullface": "east", "tintindex": 1 }
}
},
{
"from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"shade": false,
"faces": {
"down": { "texture": "#top_all", "cullface": "down" },
"up": { "texture": "#top_all", "cullface": "up" },
"north": { "texture": "#top_all", "cullface": "north" },
"south": { "texture": "#top_all", "cullface": "south" },
"west": { "texture": "#top_all", "cullface": "west" },
"east": { "texture": "#top_all", "cullface": "east" }
}
},
{
"from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"shade": false,
"faces": {
"down": { "texture": "#emissive_all", "cullface": "down", "tintindex": -101, "emissivity": 15 },
"up": { "texture": "#emissive_all", "cullface": "up", "tintindex": -101, "emissivity": 15 },
"north": { "texture": "#emissive_all", "cullface": "north", "tintindex": -101, "emissivity": 15 },
"south": { "texture": "#emissive_all", "cullface": "south", "tintindex": -101, "emissivity": 15 },
"west": { "texture": "#emissive_all", "cullface": "west", "tintindex": -101, "emissivity": 15 },
"east": { "texture": "#emissive_all", "cullface": "east", "tintindex": -101, "emissivity": 15 }
}
}
]
}

0 comments on commit e435f38

Please sign in to comment.