Skip to content
This repository was archived by the owner on Jul 18, 2023. It is now read-only.

Commit 5a1babe

Browse files
committed
fix: some oxygen sync related crashes, cleanup accesswidener
1 parent 3a4e938 commit 5a1babe

16 files changed

+170
-47
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ val fabric = "0.37.1+1.17"
1515
val lba = "0.9.0"
1616

1717
group = "dev.galacticraft"
18-
version ="0.4.0-prealpha.17+$mc"
18+
version ="0.4.0-prealpha.18+$mc"
1919

2020
base.archivesName.set("GalacticraftAPI")
2121

src/main/java/dev/galacticraft/impl/internal/accessor/ChunkOxygenSyncer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import java.util.List;
3030

3131
public interface ChunkOxygenSyncer {
32-
@NotNull List<@NotNull CustomPayloadS2CPacket> syncToClient();
32+
@NotNull List<@NotNull CustomPayloadS2CPacket> syncToClient_gc();
3333

3434
void readOxygenUpdate(byte b, @NotNull PacketByteBuf buf);
3535
}

src/main/java/dev/galacticraft/impl/internal/mixin/ChunkHolderMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public abstract class ChunkHolderMixin {
4444

4545
@Inject(method = "flushUpdates", at = @At("HEAD"))
4646
private void flushOxygen_gc(WorldChunk chunk, CallbackInfo ci) {
47-
List<CustomPayloadS2CPacket> packets = ((ChunkOxygenSyncer) chunk).syncToClient();
47+
List<CustomPayloadS2CPacket> packets = ((ChunkOxygenSyncer) chunk).syncToClient_gc();
4848
for (CustomPayloadS2CPacket packet : packets) {
4949
this.sendPacketToPlayersWatching(packet, false);
5050
}

src/main/java/dev/galacticraft/impl/internal/mixin/ChunkSectionMixin.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,33 +126,43 @@ public boolean getDefaultBreathable_gc() {
126126
@Override
127127
public void writeData_gc(PacketByteBuf buf) {
128128
boolean[] inverted = this.getChangedArray_gc();
129-
for (int p = 0; p < (16 * 16 * 16) / 8; p++) {
130-
byte b = -128;
131-
b += inverted[(p * 8)] ? 1 : 0;
132-
b += inverted[(p * 8) + 1] ? 2 : 0;
133-
b += inverted[(p * 8) + 2] ? 4 : 0;
134-
b += inverted[(p * 8) + 3] ? 8 : 0;
135-
b += inverted[(p * 8) + 4] ? 16 : 0;
136-
b += inverted[(p * 8) + 5] ? 32 : 0;
137-
b += inverted[(p * 8) + 6] ? 64 : 0;
138-
b += inverted[(p * 8) + 7] ? 128 : 0;
139-
buf.writeByte(b);
129+
if (this.inverted == null) {
130+
buf.writeBoolean(false);
131+
} else {
132+
buf.writeBoolean(true);
133+
for (int p = 0; p < (16 * 16 * 16) / 8; p++) {
134+
byte b = -128;
135+
b += inverted[(p * 8)] ? 1 : 0;
136+
b += inverted[(p * 8) + 1] ? 2 : 0;
137+
b += inverted[(p * 8) + 2] ? 4 : 0;
138+
b += inverted[(p * 8) + 3] ? 8 : 0;
139+
b += inverted[(p * 8) + 4] ? 16 : 0;
140+
b += inverted[(p * 8) + 5] ? 32 : 0;
141+
b += inverted[(p * 8) + 6] ? 64 : 0;
142+
b += inverted[(p * 8) + 7] ? 128 : 0;
143+
buf.writeByte(b);
144+
}
140145
}
141146
}
142147

143148
@Override
144149
public void readData_gc(PacketByteBuf buf) {
145150
boolean[] inverted = this.getChangedArray_gc();
146-
for (int i = 0; i < 512; i++) {
147-
short b = (short) (buf.readByte() + 128);
148-
inverted[(i * 8)] = (b & 1) != 0;
149-
inverted[(i * 8) + 1] = (b & 2) != 0;
150-
inverted[(i * 8) + 2] = (b & 4) != 0;
151-
inverted[(i * 8) + 3] = (b & 8) != 0;
152-
inverted[(i * 8) + 4] = (b & 16) != 0;
153-
inverted[(i * 8) + 5] = (b & 32) != 0;
154-
inverted[(i * 8) + 6] = (b & 64) != 0;
155-
inverted[(i * 8) + 7] = (b & 128) != 0;
151+
boolean notEmpty = buf.readBoolean();
152+
if (notEmpty) {
153+
for (int i = 0; i < 512; i++) {
154+
short b = (short) (buf.readByte() + 128);
155+
inverted[(i * 8)] = (b & 1) != 0;
156+
inverted[(i * 8) + 1] = (b & 2) != 0;
157+
inverted[(i * 8) + 2] = (b & 4) != 0;
158+
inverted[(i * 8) + 3] = (b & 8) != 0;
159+
inverted[(i * 8) + 4] = (b & 16) != 0;
160+
inverted[(i * 8) + 5] = (b & 32) != 0;
161+
inverted[(i * 8) + 6] = (b & 64) != 0;
162+
inverted[(i * 8) + 7] = (b & 128) != 0;
163+
}
164+
} else {
165+
this.setChangedArray_gc(null);
156166
}
157167
}
158168
}

src/main/java/dev/galacticraft/impl/internal/mixin/EmptyChunkMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void setBreathable(int x, int y, int z, boolean value) {
4949
}
5050

5151
@Override
52-
public @NotNull List<CustomPayloadS2CPacket> syncToClient() {
52+
public @NotNull List<CustomPayloadS2CPacket> syncToClient_gc() {
5353
return Collections.emptyList();
5454
}
5555

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2019-2021 Team Galacticraft
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package dev.galacticraft.impl.internal.mixin;
24+
25+
import net.minecraft.server.MinecraftServer;
26+
import net.minecraft.server.world.ServerWorld;
27+
import net.minecraft.util.registry.RegistryKey;
28+
import net.minecraft.world.World;
29+
import net.minecraft.world.level.storage.LevelStorage;
30+
import org.spongepowered.asm.mixin.Mixin;
31+
import org.spongepowered.asm.mixin.gen.Accessor;
32+
33+
import java.util.Map;
34+
import java.util.concurrent.Executor;
35+
36+
@Mixin(MinecraftServer.class)
37+
public interface MinecraftServerAccessor {
38+
@Accessor("workerExecutor")
39+
Executor getWorkerExecutor();
40+
41+
@Accessor("session")
42+
LevelStorage.Session getSession();
43+
44+
@Accessor("worlds")
45+
Map<RegistryKey<World>, ServerWorld> getWorlds();
46+
}

src/main/java/dev/galacticraft/impl/internal/mixin/ProtoChunkMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void setBreathable(int x, int y, int z, boolean value) {
6666
}
6767

6868
@Override
69-
public @NotNull List<CustomPayloadS2CPacket> syncToClient() {
69+
public @NotNull List<CustomPayloadS2CPacket> syncToClient_gc() {
7070
throw new UnsupportedOperationException("ProtoChunks shouldn't be synced");
7171
}
7272

src/main/java/dev/galacticraft/impl/internal/mixin/WorldChunkMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ public void setBreathable(int x, int y, int z, boolean value) {
105105
}
106106

107107
@Override
108-
public @NotNull List<CustomPayloadS2CPacket> syncToClient() {
108+
public @NotNull List<CustomPayloadS2CPacket> syncToClient_gc() {
109109
if (update && !world.isClient) {
110110
update = false;
111111
List<CustomPayloadS2CPacket> list = new LinkedList<>();
112112
for (int i = 0; i < 16; i++) {
113113
if (updatable[i]) {
114114
updatable[i] = false;
115-
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer(1 + ((16 * 16 * 16) / 8) + (4 * 2), 50 + 1 + ((16 * 16 * 16) / 8) + (4 * 2)).writeByte(i).writeInt(this.pos.x).writeInt(this.pos.z));
115+
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer(1 + 1 + ((16 * 16 * 16) / 8) + (4 * 2), 50 + 1 + ((16 * 16 * 16) / 8) + (4 * 2)).writeByte(i).writeInt(this.pos.x).writeInt(this.pos.z));
116116
((ChunkSectionOxygenAccessorInternal) sections[i]).writeData_gc(buf);
117117
list.add(new CustomPayloadS2CPacket(new Identifier(Constant.MOD_ID, "oxygen_update"), buf));
118118
}

src/main/java/dev/galacticraft/impl/internal/mixin/client/AbstractClientPlayerEntityMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ private FullFixedItemInv createInv() {
5757
FullFixedItemInv inv = new FullFixedItemInv(12);
5858
inv.setOwnerListener((invView, slot, prev, current) -> {
5959
if (current.getItem() instanceof Accessory accessory && accessory.enablesHearing()) {
60-
((SoundSystemAccessor) MinecraftClient.getInstance().getSoundManager().soundSystem).gc_updateAtmosphericMultiplier(1.0f);
60+
((SoundSystemAccessor) ((SoundManagerAccessor)MinecraftClient.getInstance().getSoundManager()).getSoundSystem()).gc_updateAtmosphericMultiplier(1.0f);
6161
} else if (prev.getItem() instanceof Accessory accessory && accessory.enablesHearing()) {
6262
boolean hasFreqModule = false;
6363
for (int i = 0; i < invView.getSlotCount(); i++) {
6464
if (i == slot) continue;
6565
if (invView.getInvStack(i).getItem() instanceof Accessory accessory2 && accessory2.enablesHearing()) {
66-
((SoundSystemAccessor) MinecraftClient.getInstance().getSoundManager().soundSystem).gc_updateAtmosphericMultiplier(1.0f);
66+
((SoundSystemAccessor) ((SoundManagerAccessor)MinecraftClient.getInstance().getSoundManager()).getSoundSystem()).gc_updateAtmosphericMultiplier(1.0f);
6767
hasFreqModule = true;
6868
break;
6969
}
7070
}
7171
if (!hasFreqModule) {
72-
((SoundSystemAccessor) MinecraftClient.getInstance().getSoundManager().soundSystem)
72+
((SoundSystemAccessor) ((SoundManagerAccessor)MinecraftClient.getInstance().getSoundManager()).getSoundSystem())
7373
.gc_updateAtmosphericMultiplier(CelestialBody.getByDimension(this.clientWorld)
7474
.map(body -> body.atmosphere().pressure()).orElse(1.0f));
7575
}

src/main/java/dev/galacticraft/impl/internal/mixin/client/MinecraftClientMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public abstract class MinecraftClientMixin {
4646
@Inject(method = "setWorld", at = @At("RETURN"))
4747
private void gc_updateSoundMultiplier(ClientWorld world, CallbackInfo ci) {
4848
if (world != null) {
49-
((SoundSystemAccessor) this.getSoundManager().soundSystem).gc_updateAtmosphericMultiplier(CelestialBody.getByDimension(world).map(body -> body.atmosphere().pressure()).orElse(1.0f));
49+
((SoundSystemAccessor) ((SoundManagerAccessor)this.getSoundManager()).getSoundSystem()).gc_updateAtmosphericMultiplier(CelestialBody.getByDimension(world).map(body -> body.atmosphere().pressure()).orElse(1.0f));
5050
} else {
51-
((SoundSystemAccessor) this.getSoundManager().soundSystem).gc_updateAtmosphericMultiplier(1.0f);
51+
((SoundSystemAccessor) ((SoundManagerAccessor)this.getSoundManager()).getSoundSystem()).gc_updateAtmosphericMultiplier(1.0f);
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)