try to fix npe

This commit is contained in:
creeper123123321 2021-03-19 16:23:08 -03:00
parent 02c96d412e
commit d7276da2ea
2 changed files with 8 additions and 13 deletions

View File

@ -1,7 +1,7 @@
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id("java")
`java-library`
id("net.minecrell.licenser") version "0.4.1"
id("fabric-loom") version "0.5-SNAPSHOT"
id("com.palantir.git-version") version "0.12.0-rc2"
@ -136,20 +136,12 @@ tasks.withType<JavaCompile> {
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
options.encoding = "UTF-8"
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
val targetVersion = 8
if (JavaVersion.current().isJava9Compatible) {
options.release.set(targetVersion)
} else {
sourceCompatibility = JavaVersion.toVersion(targetVersion).toString()
targetCompatibility = JavaVersion.toVersion(targetVersion).toString()
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
withSourcesJar()
}

View File

@ -36,6 +36,7 @@ import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.item.ItemStack;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
@ -110,7 +111,9 @@ public class VRHandItemProvider extends HandItemProvider {
}
private Item fromNative(ItemStack original) {
int id = swordId(Registry.ITEM.getId(original.getItem()).toString());
Identifier iid = Registry.ITEM.getId(original.getItem());
if (iid == null) return new Item(0, (byte) 0, (short) 0, null);
int id = swordId(iid.toString());
return new Item(id, (byte) original.getCount(), (short) original.getDamage(), null);
}