-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creative Computation Provider (#1621)
Co-authored-by: screret <[email protected]>
- Loading branch information
1 parent
79f8280
commit e435f38
Showing
13 changed files
with
213 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
], | ||
"page": "gtceu:machines/crate", | ||
"position": [ | ||
-200, | ||
-150, | ||
350 | ||
], | ||
"section": "gtceu:machines" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...enerated/resources/assets/gtceu/compass/nodes/machines/creative_computation_provider.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
], | ||
"page": "gtceu:machines/drum", | ||
"position": [ | ||
-150, | ||
-100, | ||
350 | ||
], | ||
"section": "gtceu:machines" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...java/com/gregtechceu/gtceu/common/machine/storage/CreativeComputationProviderMachine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/resources/assets/gtceu/models/block/machine/creative_computation_provider.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} | ||
] | ||
} |