Skip to content

Commit

Permalink
Fixes (#193)
Browse files Browse the repository at this point in the history
* fix recipes

* add mining hammer

* fix client/server side issues
  • Loading branch information
Yefancy authored Jul 24, 2023
1 parent 4fde739 commit 36fb651
Show file tree
Hide file tree
Showing 16 changed files with 360 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static Builder of(float harvestSpeed, float attackDamage, int durability,
SHOVEL,
AXE,
HOE,

MINING_HAMMER,
SAW,
HARD_HAMMER,
// SOFT_MALLET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ protected void onChildSizeUpdate(Widget child) {
this.addWidget(view);
}

@Override
public void writeInitialData(FriendlyByteBuf buffer) {
super.writeInitialData(buffer);
configurator.writeInitialData(buffer);
}

@Override
public void readInitialData(FriendlyByteBuf buffer) {
super.readInitialData(buffer);
configurator.readInitialData(buffer);
}

@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ default void readUpdateInfo(int id, FriendlyByteBuf buf) {

}

default void writeInitialData(FriendlyByteBuf buffer) {

}

default void readInitialData(FriendlyByteBuf buffer) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,16 @@ public void apply(boolean isTESR, RenderType layer) {
RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
}
});

var playerRotation = gui.entityPlayer.getRotationVector();
sceneWidget.setCameraYawAndPitch(playerRotation.x, playerRotation.y - 90);
}
addWidget(sceneWidget.setBackground(ColorPattern.BLACK.rectTexture()));
addWidget(slotWidget = new SlotWidget(transfer, 0, 4, 80 - 4 - 18)
.setChangeListener(this::coverRemoved)
.setBackgroundTexture(new GuiTextureGroup(GuiTextures.SLOT, GuiTextures.FILTER_SLOT_OVERLAY)));
slotWidget.setVisible(false);
slotWidget.setActive(false);


var playerRotation = gui.entityPlayer.getRotationVector();
sceneWidget.setCameraYawAndPitch(playerRotation.x, playerRotation.y);
}

private void coverRemoved() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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;
Expand All @@ -32,107 +31,148 @@ public class OverclockFancyConfigurator implements IFancyConfigurator {
protected IOverclockMachine overclockMachine;
// runtime
protected int currentTier;
@Nullable
protected WidgetGroup group;
protected Map<Integer, WidgetGroup> lightGroups;

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

@Override
public String getTitle() {
return "gtceu.gui.overclock.title";
}

@Override
public IGuiTexture getIcon() {
return new TextTexture(GTValues.VNF[this.currentTier]).setDropShadow(false);
}

@Override
public void writeInitialData(FriendlyByteBuf buffer) {
this.currentTier = overclockMachine.getOverclockTier();
buffer.writeVarInt(currentTier);
}

@Override
public void readInitialData(FriendlyByteBuf buffer) {
this.currentTier = buffer.readVarInt();
}

@Override
public void detectAndSendChange(BiConsumer<Integer, Consumer<FriendlyByteBuf>> sender) {
var newTier = overclockMachine.getOverclockTier();
if (newTier != this.currentTier) {
if (newTier != currentTier) {
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;
}
sender.accept(0, buf -> buf.writeVarInt(newTier));
}
}

@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);
}
}

@Override
public String getTitle() {
return "gtceu.gui.overclock.title";
}
public Widget createConfigurator() {
return new WidgetGroup(0, 0, 120, 40) {
final Map<Integer, WidgetGroup> lightGroups = new HashMap<>();

@Override
public IGuiTexture getIcon() {
return new TextTexture(GTValues.VNF[this.currentTier]).setDropShadow(false);
}
@Override
public void initWidget() {
super.initWidget();
setBackground(GuiTextures.BACKGROUND_INVERSE);
addWidget(new PredicatedButtonWidget(5, 5, 10, 20, new GuiTextureGroup(GuiTextures.BUTTON, Icons.LEFT.copy().scale(0.7f)), cd -> {
if (!cd.isRemote) {
overclockMachine.setOverclockTier(currentTier - 1);
}
}).setPredicate(() -> currentTier > overclockMachine.getMinOverclockTier()));
addWidget(new ImageWidget(20, 5, 120 - 5 - 10 - 5 - 20, 20, () -> new GuiTextureGroup(GuiTextures.DISPLAY_FRAME, new TextTexture(GTValues.VNF[currentTier]))));
addWidget(new PredicatedButtonWidget(120 -5 - 10, 5, 10, 20, new GuiTextureGroup(GuiTextures.BUTTON, Icons.RIGHT.copy().scale(0.7f)), cd -> {
if (!cd.isRemote) {
overclockMachine.setOverclockTier(currentTier + 1);
}
}).setPredicate(() -> currentTier < overclockMachine.getMaxOverclockTier()));
}

@Override
public Widget createConfigurator() {
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) {
overclockMachine.setOverclockTier(currentTier - 1);
@Override
public void writeInitialData(FriendlyByteBuf buffer) {
int min = overclockMachine.getMinOverclockTier();
int max = overclockMachine.getMaxOverclockTier();
buffer.writeVarInt(min);
buffer.writeVarInt(max);
buffer.writeVarInt(currentTier);
updateLightButton(min, max);
super.writeInitialData(buffer);
}
}).setPredicate(() -> currentTier > overclockMachine.getMinOverclockTier()));
group.addWidget(new ImageWidget(20, 5, 120 - 5 - 10 - 5 - 20, 20, () -> new GuiTextureGroup(GuiTextures.DISPLAY_FRAME, new TextTexture(GTValues.VNF[this.currentTier]))));
group.addWidget(new PredicatedButtonWidget(120 -5 - 10, 5, 10, 20, new GuiTextureGroup(GuiTextures.BUTTON, Icons.RIGHT.copy().scale(0.7f)), cd -> {
if (!cd.isRemote) {
overclockMachine.setOverclockTier(currentTier + 1);

@Override
public void readInitialData(FriendlyByteBuf buffer) {
int min = buffer.readVarInt();
int max = buffer.readVarInt();
currentTier = buffer.readVarInt();
updateLightButton(min, max);
super.readInitialData(buffer);
}
}).setPredicate(() -> currentTier < overclockMachine.getMaxOverclockTier()));
return group;
}

private void updateLightButton(int min, int max) {
for (WidgetGroup light : lightGroups.values()) {
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);
addWidget(lightGroup);
x += 10;
}
}

@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
int min = overclockMachine.getMinOverclockTier();
int max = overclockMachine.getMaxOverclockTier();
if (lightGroups.size() != max - min + 1) {
updateLightButton(min, max);
writeUpdateInfo(0, buf -> {
buf.writeVarInt(min);
buf.writeVarInt(max);
});
} else {
for (int i = min; i <= max; i++) {
if (!lightGroups.containsKey(i)) {
updateLightButton(min, max);
writeUpdateInfo(0, buf -> {
buf.writeVarInt(min);
buf.writeVarInt(max);
});
return;
}
}
}
}

@Override
public void readUpdateInfo(int id, FriendlyByteBuf buffer) {
if (id == 0) {
int min = buffer.readVarInt();
int max = buffer.readVarInt();
updateLightButton(min, max);
} else {
super.readUpdateInfo(id, buffer);
}
}
};
}

@Override
public List<Component> getTooltips() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public enum Status {
@Getter
protected long totalContinuousRunningTime;
protected TickableSubscription subscription;
@Environment(EnvType.CLIENT)
protected AutoReleasedSound workingSound;
protected Object workingSound;

public RecipeLogic(IRecipeLogicMachine machine) {
super(machine.self());
Expand Down Expand Up @@ -474,11 +473,11 @@ public ManagedFieldHolder getFieldHolder() {
public void updateSound() {
if (isWorking() && machine.shouldWorkingPlaySound()) {
var sound = machine.getRecipeType().getSound();
if (workingSound != null) {
if (workingSound.soundEntry == sound && !workingSound.isStopped()) {
if (workingSound instanceof AutoReleasedSound soundEntry) {
if (soundEntry.soundEntry == sound && !soundEntry.isStopped()) {
return;
}
workingSound.release();
soundEntry.release();
workingSound = null;
}
if (sound != null) {
Expand All @@ -489,8 +488,8 @@ && isWorking()
&& getMachine().getLevel().isLoaded(getMachine().getPos())
&& MetaMachine.getMachine(getMachine().getLevel(), getMachine().getPos()) == getMachine(), getMachine().getPos(), true, 0, 1, 1);
}
} else if (workingSound != null) {
workingSound.release();
} else if (workingSound instanceof AutoReleasedSound soundEntry) {
soundEntry.release();
workingSound = null;
}
}
Expand Down
Loading

0 comments on commit 36fb651

Please sign in to comment.