fix nullpointerexception
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
package com.kasetoatz.superenchants.mixin;
|
||||
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.screen.*;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
@@ -22,19 +19,6 @@ public class AnvilScreenHandlerMixin
|
||||
@Unique private Field properties;
|
||||
@Unique private Field syncHandler;
|
||||
|
||||
@Inject(method="<init>(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/screen/ScreenHandlerContext;)V", at=@At("TAIL"))
|
||||
public void init(int syncId, PlayerInventory inventory, ScreenHandlerContext context, CallbackInfo ci)
|
||||
{
|
||||
try
|
||||
{
|
||||
properties = ScreenHandler.class.getDeclaredField("properties");
|
||||
properties.setAccessible(true);
|
||||
syncHandler = ScreenHandler.class.getDeclaredField("syncHandler");
|
||||
syncHandler.setAccessible(true);
|
||||
}
|
||||
catch (NoSuchFieldException ignored) {}
|
||||
}
|
||||
|
||||
@Redirect(method="updateResult", at=@At(value="INVOKE", target="Lnet/minecraft/screen/Property;get()I"))
|
||||
public int getLevel(Property levelCost)
|
||||
{
|
||||
@@ -43,13 +27,23 @@ public class AnvilScreenHandlerMixin
|
||||
levelCost.set(MAX_ANVIL_COST);
|
||||
try
|
||||
{
|
||||
if (properties == null)
|
||||
{
|
||||
properties = ScreenHandler.class.getDeclaredField("properties");
|
||||
properties.setAccessible(true);
|
||||
}
|
||||
if (syncHandler == null)
|
||||
{
|
||||
syncHandler = ScreenHandler.class.getDeclaredField("syncHandler");
|
||||
syncHandler.setAccessible(true);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
int index = ((List<Property>)properties.get(this)).indexOf(levelCost);
|
||||
@SuppressWarnings("DataFlowIssue")
|
||||
AnvilScreenHandler handler = (AnvilScreenHandler)(Object)this;
|
||||
((ScreenHandlerSyncHandler)syncHandler.get(this)).updateProperty(handler, index, levelCost.get());
|
||||
}
|
||||
catch (IllegalAccessException ignored) {}
|
||||
catch (NoSuchFieldException | IllegalAccessException ignored) {}
|
||||
}
|
||||
return levelCost.get();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import static com.kasetoatz.superenchants.util.Util.getCustomLevel;
|
||||
@Mixin(EnchantCommand.class)
|
||||
public class EnchantCommandMixin
|
||||
{
|
||||
@Redirect(method="execute", at= @At(value = "INVOKE", target = "Lnet/minecraft/enchantment/Enchantment;getMaxLevel()I"))
|
||||
@Redirect(method="execute", at=@At(value="INVOKE", target="Lnet/minecraft/enchantment/Enchantment;getMaxLevel()I"))
|
||||
private static int execute(Enchantment enchant)
|
||||
{
|
||||
int custom = getCustomLevel(enchant);
|
||||
|
||||
Reference in New Issue
Block a user