调整subtype注册方式
This commit is contained in:
parent
02b1230f39
commit
ab886e10cd
1 changed files with 19 additions and 18 deletions
|
@ -18,8 +18,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.alchemy.PotionContents;
|
import net.minecraft.world.item.alchemy.PotionContents;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
|
||||||
|
|
||||||
@JeiPlugin
|
@JeiPlugin
|
||||||
public class SbwJEIPlugin implements IModPlugin {
|
public class SbwJEIPlugin implements IModPlugin {
|
||||||
|
@ -43,8 +42,7 @@ public class SbwJEIPlugin implements IModPlugin {
|
||||||
public void registerItemSubtypes(ISubtypeRegistration registration) {
|
public void registerItemSubtypes(ISubtypeRegistration registration) {
|
||||||
registration.registerSubtypeInterpreter(ModItems.CONTAINER.get(), new ISubtypeInterpreter<>() {
|
registration.registerSubtypeInterpreter(ModItems.CONTAINER.get(), new ISubtypeInterpreter<>() {
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
public @Nullable Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
||||||
public @NotNull Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
|
||||||
var data = ingredient.get(DataComponents.BLOCK_ENTITY_DATA);
|
var data = ingredient.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||||
var tag = data != null ? data.copyTag() : new CompoundTag();
|
var tag = data != null ? data.copyTag() : new CompoundTag();
|
||||||
if (tag.contains("EntityType")) {
|
if (tag.contains("EntityType")) {
|
||||||
|
@ -54,38 +52,41 @@ public class SbwJEIPlugin implements IModPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
public String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
||||||
public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
|
||||||
return (String) getSubtypeData(ingredient, context);
|
return (String) getSubtypeData(ingredient, context);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
registration.registerSubtypeInterpreter(ModItems.POTION_MORTAR_SHELL.get(), new ISubtypeInterpreter<>() {
|
registration.registerSubtypeInterpreter(ModItems.POTION_MORTAR_SHELL.get(), new ISubtypeInterpreter<>() {
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
public @Nullable Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
||||||
public @NotNull Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
PotionContents contents = ingredient.get(DataComponents.POTION_CONTENTS);
|
||||||
var potion = ingredient.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
|
if (contents == null) {
|
||||||
return potion.potion().map(Holder::getRegisteredName);
|
return null;
|
||||||
|
}
|
||||||
|
return contents.potion().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
public String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
||||||
public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
if (ingredient.getComponentsPatch().isEmpty()) {
|
||||||
return (String) getSubtypeData(ingredient, context);
|
return "";
|
||||||
|
}
|
||||||
|
PotionContents contents = ingredient.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
|
||||||
|
String itemDescriptionId = ingredient.getItem().getDescriptionId();
|
||||||
|
String potionEffectId = contents.potion().map(Holder::getRegisteredName).orElse("none");
|
||||||
|
return itemDescriptionId + ".effect_id." + potionEffectId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
registration.registerSubtypeInterpreter(ModItems.C4_BOMB.get(), new ISubtypeInterpreter<>() {
|
registration.registerSubtypeInterpreter(ModItems.C4_BOMB.get(), new ISubtypeInterpreter<>() {
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
public @Nullable Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
||||||
public @NotNull Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
|
||||||
return NBTTool.getTag(ingredient).getBoolean("Control");
|
return NBTTool.getTag(ingredient).getBoolean("Control");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
public String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
||||||
public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
|
||||||
return (String) getSubtypeData(ingredient, context);
|
return (String) getSubtypeData(ingredient, context);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue