Skip to content

Commit

Permalink
Message/Handler: Rely on PacketContext-provided World instance
Browse files Browse the repository at this point in the history
1.16 completely overhauled how Dimension and DimensionType work.
Just remove the DimensionType serialization for now and provide the
associated World instance directly from Fabric's PacketContext.
  • Loading branch information
Sturmlilie committed Jun 17, 2020
1 parent d4b4d60 commit f7cbd18
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,6 @@ public void onMessage(final T message, final PacketContext context) {

@Nullable
protected World getWorld(final DimensionType dimension, final PacketContext context) {
switch (context.getPacketEnvironment()) {
case CLIENT:
//noinspection MethodCallSideOnly Guarded by CLIENT switch case.
return getWorldClient(dimension, context);
case SERVER:
return getWorldServer(dimension, context);
default:
return null;
}
}

@Environment(EnvType.CLIENT)
@Nullable
private static World getWorldClient(final DimensionType dimension, final PacketContext context) {
final PlayerEntity player = context.getPlayer();
if (player == null) {
return null;
}

final World world = player.world;
if (world == null) {
return null;
}

//~ if (world.getDimension().getType() != dimension) {
//~ return null;
//~ }

return world;
}

@Nullable
private static World getWorldServer(final DimensionType dimension, final PacketContext context) {
final MinecraftServer server = context.getPlayer().getServer();
if (server == null) {
return null;
}

//~ return server.getWorld(dimension);
return null; // XXX
return context.getPlayer().world;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
public abstract class AbstractMessageHandlerWithDimension<T extends AbstractMessageWithDimension> extends AbstractMessageHandler<T> {
@Nullable
protected World getWorld(final T message, final PacketContext context) {
return getWorld(message.getDimension(), context);
return context.getPlayer().world;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,21 @@
import net.minecraft.world.dimension.DimensionType;

public abstract class AbstractMessageWithDimension extends AbstractMessage {
private DimensionType dimension;

AbstractMessageWithDimension(final World world) {
//~ this.dimension = world.dimension.getType();
}

AbstractMessageWithDimension() {
}

// --------------------------------------------------------------------- //

public DimensionType getDimension() {
return dimension;
}

// --------------------------------------------------------------------- //
// AbstractMessage

@Override
public void fromBytes(final ByteBuf buf) {
final PacketByteBuf buffer = new PacketByteBuf(buf);
//~ dimension = DimensionType.byRawId(buffer.readVarInt());
}

@Override
public void toBytes(final ByteBuf buf) {
final PacketByteBuf buffer = new PacketByteBuf(buf);
//~ buffer.writeVarInt(dimension.getRawId());
}
}

0 comments on commit f7cbd18

Please sign in to comment.