Skip to content

Commit

Permalink
Add workaround to make DimensionType#getId work for 1.16.2 to 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Aug 17, 2024
1 parent 86cf0d5 commit 06cc25b
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.github.retrooper.packetevents.util.mappings.IRegistry;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame;
import org.jetbrains.annotations.Nullable;

public interface DimensionTypeRef {

Expand Down Expand Up @@ -172,18 +173,37 @@ public DataRef(NBT data) {

@Override
public DimensionType resolve(IRegistry<DimensionType> registry, ClientVersion version) {
// workaround to make DimensionType#getId work
//
// some 1.16 versions don't send any info about the registry id or name
// of the dimension type, so technically we have to assume it is never defined in a registry
//
// as some projects depend on getId working, this is a workaround
// which will hopefully work for nearly everything
ResourceLocation name = this.getNullableName();
if (name != null) {
DimensionType dimensionType = registry.getByName(name);
if (dimensionType != null) {
return dimensionType;
}
}
return DimensionType.decode(this.data, version, null);
}

@Override
public ResourceLocation getName() {
public @Nullable ResourceLocation getNullableName() {
if (this.data instanceof NBTCompound) {
String effectsName = ((NBTCompound) this.data).getStringTagValueOrNull("effects");
if (effectsName != null) {
return new ResourceLocation(effectsName);
}
}
return DimensionTypeRef.super.getName();
return null;
}

@Override
public ResourceLocation getName() {
ResourceLocation name = this.getNullableName();
return name != null ? name : DimensionTypeRef.super.getName();
}

@Override
Expand Down

0 comments on commit 06cc25b

Please sign in to comment.