Merge pull request #1411 from AoElite/resourcekey-refactor
ResourceLocation refactor
This commit is contained in:
3 files changed
+21
-30
No files matched your search
@@ -2,6 +2,7 @@ import com.github.retrooper.compression.strategy.dir.JsonBase64DataDirStrategy
|
||||
import com.github.retrooper.compression.strategy.dir.JsonRegistryCompressionDirStrategy
|
||||
import com.github.retrooper.compression.strategy.dir.JsonToNbtDirStrategy
|
||||
import com.github.retrooper.excludeAdventure
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
|
||||
plugins {
|
||||
packetevents.`shadow-conventions`
|
||||
@@ -86,6 +87,9 @@ tasks {
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
|
||||
+2
-3
@@ -1497,7 +1497,7 @@ public final class StateTypes {
|
||||
MaterialType materialType;
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = new ResourceLocation(name);
|
||||
this.name = new ResourceLocation(name.toLowerCase(Locale.ROOT));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1542,8 +1542,7 @@ public final class StateTypes {
|
||||
}
|
||||
|
||||
public StateType build() {
|
||||
String definedName = this.name.getKey().toLowerCase(Locale.ROOT);
|
||||
return REGISTRY.define(definedName, data -> new StateType(
|
||||
return REGISTRY.define(name.getKey(), data -> new StateType(
|
||||
data, this.blastResistance, this.hardness, this.isSolid, this.isBlocking, this.isAir,
|
||||
this.requiresCorrectTool, this.isShapeExceedsCube, this.materialType
|
||||
).getMapped()).getStateType();
|
||||
|
||||
+15
-27
@@ -24,44 +24,32 @@ import com.github.retrooper.packetevents.protocol.util.NbtCodec;
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtCodecs;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.key.KeyPattern;
|
||||
import net.kyori.adventure.key.Keyed;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@NullMarked
|
||||
public class ResourceLocation implements Keyed {
|
||||
|
||||
public static final NbtCodec<ResourceLocation> CODEC = NbtCodecs.STRING
|
||||
.apply(ResourceLocation::new, ResourceLocation::toString);
|
||||
|
||||
public static final String VANILLA_NAMESPACE = "minecraft";
|
||||
public static final String VANILLA_NAMESPACE = Key.MINECRAFT_NAMESPACE;
|
||||
|
||||
protected final String namespace;
|
||||
protected final String key;
|
||||
private final Key key;
|
||||
|
||||
public ResourceLocation(Key key) {
|
||||
this(key.namespace(), key.value());
|
||||
}
|
||||
|
||||
public ResourceLocation(String namespace, String key) {
|
||||
this.namespace = namespace;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public ResourceLocation(@KeyPattern.Namespace String namespace, @KeyPattern.Value String key) {
|
||||
this.key = Key.key(namespace, key);
|
||||
}
|
||||
|
||||
public ResourceLocation(String location) {
|
||||
String[] array = new String[]{VANILLA_NAMESPACE, location};
|
||||
int index = location.indexOf(":");
|
||||
if (index != -1) {
|
||||
array[1] = location.substring(index + 1);
|
||||
if (index >= 1) {
|
||||
array[0] = location.substring(0, index);
|
||||
}
|
||||
}
|
||||
this.namespace = array[0];
|
||||
this.key = array[1];
|
||||
this.key = Key.key(location);
|
||||
}
|
||||
|
||||
public static ResourceLocation read(PacketWrapper<?> wrapper) {
|
||||
@@ -115,37 +103,37 @@ public class ResourceLocation implements Keyed {
|
||||
|
||||
@Override
|
||||
public Key key() {
|
||||
return Key.key(this.namespace, this.key);
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
return key.namespace();
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
return key.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.namespace, this.key);
|
||||
return key.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ResourceLocation) {
|
||||
ResourceLocation other = (ResourceLocation) obj;
|
||||
return other.namespace.equals(namespace) && other.key.equals(key);
|
||||
return other.key.equals(this.key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return namespace + ":" + key;
|
||||
return key.asString();
|
||||
}
|
||||
|
||||
public static ResourceLocation minecraft(String key) {
|
||||
public static ResourceLocation minecraft(@KeyPattern.Value String key) {
|
||||
return new ResourceLocation(VANILLA_NAMESPACE, key);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user