Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx4G
name=bbor
buildVersion=2.6
# leave a space to reduce merge conflicts on version change
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.2

#Fabric api
fabric_version=0.85.0+1.20.1
fabric_version=0.91.3+1.20.4

modmenu_version=4.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ abstract class AbstractSlider extends AbstractControl {
protected void renderBackground(DrawContext ctx) {
// this.minecraft.getTextureManager().bindTexture(WIDGETS_TEXTURE);
int hoverState = this.isSelected() ? 1 : 0;
ctx.drawTexture(WIDGETS_TEXTURE, this.getX() + (int) getProgressPercentage(), this.getY(), 0, 46 + hoverState * 20, 4, this.height);
ctx.drawTexture(WIDGETS_TEXTURE, this.getX() + (int) getProgressPercentage() + 4, this.getY(), 196, 46 + hoverState * 20, 4, 20);
// ctx.drawTexture(WIDGETS_TEXTURE, this.getX() + (int) getProgressPercentage(), this.getY(), 0, 46 + hoverState * 20, 4, this.height); FIX
// ctx.drawTexture(WIDGETS_TEXTURE, this.getX() + (int) getProgressPercentage() + 4, this.getY(), 196, 46 + hoverState * 20, 4, 20);
}

private double getProgressPercentage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private int getScrollBarHeight() {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) {
public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount, double verticalAmount) {
this.amountScrolled -= scrollAmount * 10;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/irtimaled/bbor/client/gui/IControlSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ default boolean mouseDragged(double mouseX, double mouseY, int button, double de
return focused != null && this.isDragging() && button == 0 && focused.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}

default boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) {
default boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount, double verticalAmount) {
IControl focused = this.getFocused();
return focused != null && focused.mouseScrolled(mouseX, mouseY, scrollAmount);
return focused != null && focused.mouseScrolled(mouseX, mouseY, scrollAmount, verticalAmount);
}

default boolean keyPressed(int key, int scanCode, int modifiers) {
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/irtimaled/bbor/client/gui/ListScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ public void render(DrawContext ctx, int mouseX, int mouseY, float unknown) {
}



protected void render(DrawContext ctx, int mouseX, int mouseY) {
RenderSystem.assertOnRenderThread();
this.renderBackground(ctx);
this.renderBackground(ctx, mouseX, mouseY, 0);
this.controlList.render(ctx, mouseX, mouseY);

ctx.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 8, 16777215);
Expand All @@ -72,7 +71,7 @@ protected void render(DrawContext ctx, int mouseX, int mouseY) {

@Override
public void tick() {
this.searchField.tick();
// this.searchField.tick(); TODO fix
}

@Override
Expand All @@ -86,8 +85,8 @@ public boolean charTyped(char character, int modifiers) {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) {
return this.controlList.mouseScrolled(mouseX, mouseY, scrollAmount);
public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount, double verticalAmount) {
return this.controlList.mouseScrolled(mouseX, mouseY, scrollAmount, verticalAmount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtSizeTracker;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.WorldSavePath;
Expand Down Expand Up @@ -97,7 +98,7 @@ public void done() {
e.printStackTrace();
}
try {
long seed = NbtIo.readCompressed(new FileInputStream(worldInfo.getDirectory(WorldSavePath.LEVEL_DAT).toFile()))
long seed = NbtIo.readCompressed(worldInfo.getDirectory(WorldSavePath.LEVEL_DAT), NbtSizeTracker.ofUnlimitedBytes())
.getCompound("Data")
.getCompound("WorldGenSettings").getLong("seed");
worldInfo.close();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/irtimaled/bbor/common/BBORCustomPayload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.irtimaled.bbor.common;

import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;

public record BBORCustomPayload(PacketByteBuf byteBuf, Identifier id) implements CustomPayload {

public BBORCustomPayload(Identifier identifier, PacketByteBuf buf) {
this(new PacketByteBuf(buf.readBytes(buf.readableBytes())), identifier);
}

@Override
public void write(PacketByteBuf buf) {
buf.writeBytes(byteBuf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.irtimaled.bbor.common.models.AbstractBoundingBox;
import com.irtimaled.bbor.common.models.DimensionId;
import com.irtimaled.bbor.common.models.ServerPlayer;
import com.irtimaled.bbor.mixin.access.IServerPlayNetworkHandler;
import com.irtimaled.bbor.mixin.access.IServerCommonNetworkHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.ClientConnection;
Expand Down Expand Up @@ -103,7 +103,7 @@ public static void playerLoggedIn(ServerPlayerEntity player) {
ServerPlayNetworkHandler connection = player.networkHandler;
if (connection == null) return;

ClientConnection networkManager = ((IServerPlayNetworkHandler) connection).getConnection();
ClientConnection networkManager = ((IServerCommonNetworkHandler) connection).getConnection();
if (networkManager.isLocal()) return;

EventBus.publish(new PlayerLoggedIn(new ServerPlayer(player)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import com.irtimaled.bbor.common.models.Coords;
import com.irtimaled.bbor.common.models.DimensionId;
import com.irtimaled.bbor.common.BBORCustomPayload;
import io.netty.buffer.Unpooled;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket;
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
import net.minecraft.util.Identifier;

import java.util.Map;
Expand All @@ -17,11 +18,11 @@ public class PayloadBuilder {
private static final Map<String, Identifier> packetNames = new ConcurrentHashMap<>();

public static PayloadBuilder clientBound(String name) {
return new PayloadBuilder(packetNames.computeIfAbsent(name, Identifier::new), CustomPayloadS2CPacket::new);
return new PayloadBuilder(packetNames.computeIfAbsent(name, Identifier::new), ((identifier, byteBuf) -> new CustomPayloadS2CPacket(new BBORCustomPayload(identifier, byteBuf))));
}

public static PayloadBuilder serverBound(String name) {
return new PayloadBuilder(packetNames.computeIfAbsent(name, Identifier::new), CustomPayloadC2SPacket::new);
return new PayloadBuilder(packetNames.computeIfAbsent(name, Identifier::new), ((identifier, byteBuf) -> new CustomPayloadC2SPacket(new BBORCustomPayload(identifier, byteBuf))));
}

private final Identifier name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import com.irtimaled.bbor.common.models.Coords;
import com.irtimaled.bbor.common.models.DimensionId;
import com.irtimaled.bbor.common.BBORCustomPayload;
import net.minecraft.network.PacketByteBuf;

public class PayloadReader {
private final PacketByteBuf buffer;

public PayloadReader(BBORCustomPayload payload) {
this.buffer = payload.byteBuf();
}

public PayloadReader(PacketByteBuf buffer) {
this.buffer = buffer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

package com.irtimaled.bbor.common.messages.protocols;

import com.irtimaled.bbor.common.BBORCustomPayload;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket;
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.util.Identifier;
import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -35,20 +37,20 @@ public class PacketSplitter {
private static final Map<Pair<PacketListener, Identifier>, ReadingSession> readingSessions = new ConcurrentHashMap<>();

public static void send(ServerPlayNetworkHandler networkHandler, Identifier channel, PacketByteBuf packet) {
send(packet, MAX_PAYLOAD_PER_PACKET_S2C, buf -> networkHandler.sendPacket(new CustomPayloadS2CPacket(channel, buf)));
send(packet, MAX_PAYLOAD_PER_PACKET_S2C, buf -> networkHandler.sendPacket(new CustomPayloadS2CPacket(new BBORCustomPayload(channel, buf))));
}

@Environment(EnvType.CLIENT)
public static void send(ClientPlayNetworkHandler networkHandler, Identifier channel, PacketByteBuf packet) {
send(packet, MAX_PAYLOAD_PER_PACKET_C2S, buf -> networkHandler.sendPacket(new CustomPayloadC2SPacket(channel, buf)));
send(packet, MAX_PAYLOAD_PER_PACKET_C2S, buf -> networkHandler.sendPacket(new CustomPayloadC2SPacket(new BBORCustomPayload(channel, buf))));
}

public static void send(PacketByteBuf packet, int payloadLimit, Consumer<PacketByteBuf> sender) {
int len = packet.writerIndex();
packet.resetReaderIndex();
for (int offset = 0; offset < len; offset += payloadLimit) {
int thisLen = Math.min(len - offset, payloadLimit);
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer(thisLen + (offset == 0 ? PacketByteBuf.getVarIntLength(len) : 0)));
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer(thisLen));
buf.resetWriterIndex();
if (offset == 0) buf.writeVarInt(len);
buf.writeBytes(packet, thisLen);
Expand All @@ -62,23 +64,30 @@ public static PacketByteBuf receive(ServerPlayNetworkHandler networkHandler, Cus
}

public static PacketByteBuf receive(ServerPlayNetworkHandler networkHandler, CustomPayloadC2SPacket message, int maxLength) {
Pair<PacketListener, Identifier> key = Pair.of(networkHandler, message.getChannel());
return readingSessions.computeIfAbsent(key, ReadingSession::new).receive(message.getData(), maxLength);
if (message.payload() instanceof BBORCustomPayload payload) {
Pair<PacketListener, Identifier> key = Pair.of(networkHandler, payload.id());
return readingSessions.computeIfAbsent(key, ReadingSession::new).receive(payload.byteBuf(), maxLength);
}
return null;
}

public static PacketByteBuf receive(ClientPlayPacketListener networkHandler, CustomPayloadS2CPacket message) {
public static PacketByteBuf receive(ClientPlayPacketListener networkHandler, CustomPayload message) {
return receive(networkHandler, message, DEFAULT_MAX_RECEIVE_SIZE_S2C);
}

public static PacketByteBuf receive(ClientPlayPacketListener networkHandler, CustomPayloadS2CPacket message, int maxLength) {
Pair<PacketListener, Identifier> key = Pair.of(networkHandler, message.getChannel());
return readingSessions.computeIfAbsent(key, ReadingSession::new).receive(message.getData(), maxLength);
public static PacketByteBuf receive(ClientPlayPacketListener networkHandler, CustomPayload message, int maxLength) {
if (message instanceof BBORCustomPayload payload) {
Pair<PacketListener, Identifier> key = Pair.of(networkHandler, payload.id());
return readingSessions.computeIfAbsent(key, ReadingSession::new).receive(payload.byteBuf(), maxLength);
}
return null;
}

private static class ReadingSession {
private final Pair<PacketListener, Identifier> key;
private int expectedSize = -1;
private PacketByteBuf received;

private ReadingSession(Pair<PacketListener, Identifier> key) {
this.key = key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import java.util.concurrent.Executors;

public class RegistryUtil {
static final DynamicRegistryManager.Immutable REGISTRY_MANAGER;
static final DynamicRegistryManager.Immutable REGISTRY_MANAGER = null; // TODO fix

static {
/* TODO fix
final ExecutorService executorService = Executors.newSingleThreadExecutor();

try {
Expand Down Expand Up @@ -53,6 +54,7 @@ public GeneratorOptionsHolder create(LifecycledResourceManager resourceManager,
} finally {
executorService.shutdown();
}
*/
}

record WorldCreationSettings(WorldGenSettings worldGenSettings, DataConfiguration dataConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.irtimaled.bbor.mixin.access;

import net.minecraft.network.ClientConnection;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerCommonNetworkHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(ServerPlayNetworkHandler.class)
public interface IServerPlayNetworkHandler {
@Mixin(ServerCommonNetworkHandler.class)
public interface IServerCommonNetworkHandler {

@Accessor
ClientConnection getConnection();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.irtimaled.bbor.mixin.client.network.common;

import com.irtimaled.bbor.client.interop.ClientInterop;
import com.irtimaled.bbor.common.BBORCustomPayload;
import com.irtimaled.bbor.common.EventBus;
import com.irtimaled.bbor.common.messages.AddBoundingBox;
import com.irtimaled.bbor.common.messages.InitializeClient;
import com.irtimaled.bbor.common.messages.PayloadReader;
import com.irtimaled.bbor.common.messages.StructureListSync;
import com.irtimaled.bbor.common.messages.SubscribeToServer;
import com.irtimaled.bbor.common.messages.protocols.PacketSplitter;
import com.irtimaled.bbor.common.messages.servux.ServuxStructurePackets;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.NetworkThreadUtils;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientCommonNetworkHandler.class)
public class MixinClientCommonNetworkHandler {

@Inject(method = "onDisconnect", at = @At("HEAD"))
private void onDisconnect(CallbackInfo ci) {
ClientInterop.disconnectedFromRemoteServer();
}
}
Loading