Skip to content

Commit 36fb651

Browse files
authored
Fixes (#193)
* fix recipes * add mining hammer * fix client/server side issues
1 parent 4fde739 commit 36fb651

File tree

16 files changed

+360
-140
lines changed

16 files changed

+360
-140
lines changed

common/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static Builder of(float harvestSpeed, float attackDamage, int durability,
150150
SHOVEL,
151151
AXE,
152152
HOE,
153-
153+
MINING_HAMMER,
154154
SAW,
155155
HARD_HAMMER,
156156
// SOFT_MALLET,

common/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/ConfiguratorPanel.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ protected void onChildSizeUpdate(Widget child) {
188188
this.addWidget(view);
189189
}
190190

191+
@Override
192+
public void writeInitialData(FriendlyByteBuf buffer) {
193+
super.writeInitialData(buffer);
194+
configurator.writeInitialData(buffer);
195+
}
196+
197+
@Override
198+
public void readInitialData(FriendlyByteBuf buffer) {
199+
super.readInitialData(buffer);
200+
configurator.readInitialData(buffer);
201+
}
202+
191203
@Override
192204
public void detectAndSendChanges() {
193205
super.detectAndSendChanges();

common/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/IFancyConfigurator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ default void readUpdateInfo(int id, FriendlyByteBuf buf) {
3434

3535
}
3636

37+
default void writeInitialData(FriendlyByteBuf buffer) {
38+
39+
}
40+
41+
default void readInitialData(FriendlyByteBuf buffer) {
42+
43+
}
3744
}

common/src/main/java/com/gregtechceu/gtceu/api/gui/widget/CoverContainerConfigurator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,16 @@ public void apply(boolean isTESR, RenderType layer) {
8787
RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
8888
}
8989
});
90+
91+
var playerRotation = gui.entityPlayer.getRotationVector();
92+
sceneWidget.setCameraYawAndPitch(playerRotation.x, playerRotation.y - 90);
9093
}
9194
addWidget(sceneWidget.setBackground(ColorPattern.BLACK.rectTexture()));
9295
addWidget(slotWidget = new SlotWidget(transfer, 0, 4, 80 - 4 - 18)
9396
.setChangeListener(this::coverRemoved)
9497
.setBackgroundTexture(new GuiTextureGroup(GuiTextures.SLOT, GuiTextures.FILTER_SLOT_OVERLAY)));
9598
slotWidget.setVisible(false);
9699
slotWidget.setActive(false);
97-
98-
99-
var playerRotation = gui.entityPlayer.getRotationVector();
100-
sceneWidget.setCameraYawAndPitch(playerRotation.x, playerRotation.y);
101100
}
102101

103102
private void coverRemoved() {

common/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/OverclockFancyConfigurator.java

Lines changed: 116 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import net.minecraft.network.FriendlyByteBuf;
1717
import net.minecraft.network.chat.Component;
1818

19-
import javax.annotation.Nullable;
2019
import java.util.HashMap;
2120
import java.util.List;
2221
import java.util.Map;
@@ -32,107 +31,148 @@ public class OverclockFancyConfigurator implements IFancyConfigurator {
3231
protected IOverclockMachine overclockMachine;
3332
// runtime
3433
protected int currentTier;
35-
@Nullable
36-
protected WidgetGroup group;
37-
protected Map<Integer, WidgetGroup> lightGroups;
3834

3935
public OverclockFancyConfigurator(IOverclockMachine overclockMachine) {
4036
this.overclockMachine = overclockMachine;
41-
this.lightGroups = new HashMap<>();
37+
}
38+
39+
@Override
40+
public String getTitle() {
41+
return "gtceu.gui.overclock.title";
42+
}
43+
44+
@Override
45+
public IGuiTexture getIcon() {
46+
return new TextTexture(GTValues.VNF[this.currentTier]).setDropShadow(false);
47+
}
48+
49+
@Override
50+
public void writeInitialData(FriendlyByteBuf buffer) {
51+
this.currentTier = overclockMachine.getOverclockTier();
52+
buffer.writeVarInt(currentTier);
53+
}
54+
55+
@Override
56+
public void readInitialData(FriendlyByteBuf buffer) {
57+
this.currentTier = buffer.readVarInt();
4258
}
4359

4460
@Override
4561
public void detectAndSendChange(BiConsumer<Integer, Consumer<FriendlyByteBuf>> sender) {
4662
var newTier = overclockMachine.getOverclockTier();
47-
if (newTier != this.currentTier) {
63+
if (newTier != currentTier) {
4864
this.currentTier = newTier;
49-
sender.accept(0, buf -> buf.writeVarInt(this.currentTier));
50-
}
51-
int min = overclockMachine.getMinOverclockTier();
52-
int max = overclockMachine.getMaxOverclockTier();
53-
if (lightGroups.size() != max - min + 1) {
54-
updateLightButton(min, max);
55-
sender.accept(1, buf -> {
56-
buf.writeVarInt(min);
57-
buf.writeVarInt(max);
58-
});
59-
} else {
60-
for (int i = min; i <= max; i++) {
61-
if (!lightGroups.containsKey(i)) {
62-
updateLightButton(min, max);
63-
sender.accept(1, buf -> {
64-
buf.writeVarInt(min);
65-
buf.writeVarInt(max);
66-
});
67-
return;
68-
}
69-
}
70-
}
71-
}
72-
73-
private void updateLightButton(int min, int max) {
74-
if (group != null) {
75-
for (WidgetGroup light : lightGroups.values()) {
76-
group.removeWidget(light);
77-
}
78-
lightGroups.clear();
79-
int x = 5;
80-
for (int tier = min; tier <= max ; tier++) {
81-
int finalTier = tier;
82-
var lightGroup = new WidgetGroup(x, 27, 8, 8);
83-
lightGroup.addWidget(new ButtonWidget(0, 0, 8, 8, null, cd -> {
84-
if (!cd.isRemote) {
85-
overclockMachine.setOverclockTier(finalTier);
86-
}
87-
}));
88-
lightGroup.addWidget(new ImageWidget(0, 0, 8, 8, () -> currentTier >= finalTier ? GuiTextures.LIGHT_ON : GuiTextures.LIGHT_OFF));
89-
lightGroups.put(tier, lightGroup);
90-
group.addWidget(lightGroup);
91-
x += 10;
92-
}
65+
sender.accept(0, buf -> buf.writeVarInt(newTier));
9366
}
9467
}
9568

9669
@Override
9770
public void readUpdateInfo(int id, FriendlyByteBuf buf) {
9871
if (id == 0) {
9972
this.currentTier = buf.readVarInt();
100-
} else if (id == 1) {
101-
int min = buf.readVarInt();
102-
int max = buf.readVarInt();
103-
updateLightButton(min, max);
10473
}
10574
}
10675

10776
@Override
108-
public String getTitle() {
109-
return "gtceu.gui.overclock.title";
110-
}
77+
public Widget createConfigurator() {
78+
return new WidgetGroup(0, 0, 120, 40) {
79+
final Map<Integer, WidgetGroup> lightGroups = new HashMap<>();
11180

112-
@Override
113-
public IGuiTexture getIcon() {
114-
return new TextTexture(GTValues.VNF[this.currentTier]).setDropShadow(false);
115-
}
81+
@Override
82+
public void initWidget() {
83+
super.initWidget();
84+
setBackground(GuiTextures.BACKGROUND_INVERSE);
85+
addWidget(new PredicatedButtonWidget(5, 5, 10, 20, new GuiTextureGroup(GuiTextures.BUTTON, Icons.LEFT.copy().scale(0.7f)), cd -> {
86+
if (!cd.isRemote) {
87+
overclockMachine.setOverclockTier(currentTier - 1);
88+
}
89+
}).setPredicate(() -> currentTier > overclockMachine.getMinOverclockTier()));
90+
addWidget(new ImageWidget(20, 5, 120 - 5 - 10 - 5 - 20, 20, () -> new GuiTextureGroup(GuiTextures.DISPLAY_FRAME, new TextTexture(GTValues.VNF[currentTier]))));
91+
addWidget(new PredicatedButtonWidget(120 -5 - 10, 5, 10, 20, new GuiTextureGroup(GuiTextures.BUTTON, Icons.RIGHT.copy().scale(0.7f)), cd -> {
92+
if (!cd.isRemote) {
93+
overclockMachine.setOverclockTier(currentTier + 1);
94+
}
95+
}).setPredicate(() -> currentTier < overclockMachine.getMaxOverclockTier()));
96+
}
11697

117-
@Override
118-
public Widget createConfigurator() {
119-
group = new WidgetGroup(0, 0, 120, 40);
120-
group.setBackground(GuiTextures.BACKGROUND_INVERSE);
121-
group.addWidget(new PredicatedButtonWidget(5, 5, 10, 20, new GuiTextureGroup(GuiTextures.BUTTON, Icons.LEFT.copy().scale(0.7f)), cd -> {
122-
if (!cd.isRemote) {
123-
overclockMachine.setOverclockTier(currentTier - 1);
98+
@Override
99+
public void writeInitialData(FriendlyByteBuf buffer) {
100+
int min = overclockMachine.getMinOverclockTier();
101+
int max = overclockMachine.getMaxOverclockTier();
102+
buffer.writeVarInt(min);
103+
buffer.writeVarInt(max);
104+
buffer.writeVarInt(currentTier);
105+
updateLightButton(min, max);
106+
super.writeInitialData(buffer);
124107
}
125-
}).setPredicate(() -> currentTier > overclockMachine.getMinOverclockTier()));
126-
group.addWidget(new ImageWidget(20, 5, 120 - 5 - 10 - 5 - 20, 20, () -> new GuiTextureGroup(GuiTextures.DISPLAY_FRAME, new TextTexture(GTValues.VNF[this.currentTier]))));
127-
group.addWidget(new PredicatedButtonWidget(120 -5 - 10, 5, 10, 20, new GuiTextureGroup(GuiTextures.BUTTON, Icons.RIGHT.copy().scale(0.7f)), cd -> {
128-
if (!cd.isRemote) {
129-
overclockMachine.setOverclockTier(currentTier + 1);
108+
109+
@Override
110+
public void readInitialData(FriendlyByteBuf buffer) {
111+
int min = buffer.readVarInt();
112+
int max = buffer.readVarInt();
113+
currentTier = buffer.readVarInt();
114+
updateLightButton(min, max);
115+
super.readInitialData(buffer);
130116
}
131-
}).setPredicate(() -> currentTier < overclockMachine.getMaxOverclockTier()));
132-
return group;
133-
}
134117

118+
private void updateLightButton(int min, int max) {
119+
for (WidgetGroup light : lightGroups.values()) {
120+
removeWidget(light);
121+
}
122+
lightGroups.clear();
123+
int x = 5;
124+
for (int tier = min; tier <= max ; tier++) {
125+
int finalTier = tier;
126+
var lightGroup = new WidgetGroup(x, 27, 8, 8);
127+
lightGroup.addWidget(new ButtonWidget(0, 0, 8, 8, null, cd -> {
128+
if (!cd.isRemote) {
129+
overclockMachine.setOverclockTier(finalTier);
130+
}
131+
}));
132+
lightGroup.addWidget(new ImageWidget(0, 0, 8, 8, () -> currentTier >= finalTier ? GuiTextures.LIGHT_ON : GuiTextures.LIGHT_OFF));
133+
lightGroups.put(tier, lightGroup);
134+
addWidget(lightGroup);
135+
x += 10;
136+
}
137+
}
135138

139+
@Override
140+
public void detectAndSendChanges() {
141+
super.detectAndSendChanges();
142+
int min = overclockMachine.getMinOverclockTier();
143+
int max = overclockMachine.getMaxOverclockTier();
144+
if (lightGroups.size() != max - min + 1) {
145+
updateLightButton(min, max);
146+
writeUpdateInfo(0, buf -> {
147+
buf.writeVarInt(min);
148+
buf.writeVarInt(max);
149+
});
150+
} else {
151+
for (int i = min; i <= max; i++) {
152+
if (!lightGroups.containsKey(i)) {
153+
updateLightButton(min, max);
154+
writeUpdateInfo(0, buf -> {
155+
buf.writeVarInt(min);
156+
buf.writeVarInt(max);
157+
});
158+
return;
159+
}
160+
}
161+
}
162+
}
163+
164+
@Override
165+
public void readUpdateInfo(int id, FriendlyByteBuf buffer) {
166+
if (id == 0) {
167+
int min = buffer.readVarInt();
168+
int max = buffer.readVarInt();
169+
updateLightButton(min, max);
170+
} else {
171+
super.readUpdateInfo(id, buffer);
172+
}
173+
}
174+
};
175+
}
136176

137177
@Override
138178
public List<Component> getTooltips() {

common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public enum Status {
7171
@Getter
7272
protected long totalContinuousRunningTime;
7373
protected TickableSubscription subscription;
74-
@Environment(EnvType.CLIENT)
75-
protected AutoReleasedSound workingSound;
74+
protected Object workingSound;
7675

7776
public RecipeLogic(IRecipeLogicMachine machine) {
7877
super(machine.self());
@@ -474,11 +473,11 @@ public ManagedFieldHolder getFieldHolder() {
474473
public void updateSound() {
475474
if (isWorking() && machine.shouldWorkingPlaySound()) {
476475
var sound = machine.getRecipeType().getSound();
477-
if (workingSound != null) {
478-
if (workingSound.soundEntry == sound && !workingSound.isStopped()) {
476+
if (workingSound instanceof AutoReleasedSound soundEntry) {
477+
if (soundEntry.soundEntry == sound && !soundEntry.isStopped()) {
479478
return;
480479
}
481-
workingSound.release();
480+
soundEntry.release();
482481
workingSound = null;
483482
}
484483
if (sound != null) {
@@ -489,8 +488,8 @@ && isWorking()
489488
&& getMachine().getLevel().isLoaded(getMachine().getPos())
490489
&& MetaMachine.getMachine(getMachine().getLevel(), getMachine().getPos()) == getMachine(), getMachine().getPos(), true, 0, 1, 1);
491490
}
492-
} else if (workingSound != null) {
493-
workingSound.release();
491+
} else if (workingSound instanceof AutoReleasedSound soundEntry) {
492+
soundEntry.release();
494493
workingSound = null;
495494
}
496495
}

0 commit comments

Comments
 (0)