diff --git a/common/src/main/java/dev/latvian/kubejs/BuiltinKubeJSPlugin.java b/common/src/main/java/dev/latvian/kubejs/BuiltinKubeJSPlugin.java index 861391fca..f84d408c1 100644 --- a/common/src/main/java/dev/latvian/kubejs/BuiltinKubeJSPlugin.java +++ b/common/src/main/java/dev/latvian/kubejs/BuiltinKubeJSPlugin.java @@ -67,6 +67,7 @@ import dev.latvian.mods.rhino.mod.wrapper.DirectionWrapper; import dev.latvian.mods.rhino.mod.wrapper.UUIDWrapper; import dev.latvian.mods.rhino.util.wrap.TypeWrappers; +import lombok.val; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.registry.ToolType; import net.fabricmc.api.EnvType; @@ -182,7 +183,7 @@ public void initStartup() { new ItemToolTierEventJS().post(KubeJSEvents.ITEM_REGISTRY_TOOL_TIERS); new ItemArmorTierEventJS().post(KubeJSEvents.ITEM_REGISTRY_ARMOR_TIERS); - for (var registryInfo : RegistryInfos.WITH_TYPE.values()) { + for (val registryInfo : RegistryInfos.WITH_TYPE.values()) { registryInfo.fireRegistryEvent(); } // new BlockRegistryEventJS().post(KubeJSEvents.BLOCK_REGISTRY); @@ -387,8 +388,12 @@ public void addTypeWrappers(ScriptType type, TypeWrappers typeWrappers) { return (BlockPos) o; } else if (o instanceof BlockContainerJS) { return ((BlockContainerJS) o).getPos(); - } else if (o instanceof List && ((List) o).size() >= 3) { - return new BlockPos(((Number) ((List) o).get(0)).intValue(), ((Number) ((List) o).get(1)).intValue(), ((Number) ((List) o).get(2)).intValue()); + } else if (o instanceof List l && l.size() >= 3) { + return new BlockPos( + ((Number) l.get(0)).intValue(), + ((Number) l.get(1)).intValue(), + ((Number) l.get(2)).intValue() + ); } return BlockPos.ZERO; @@ -399,7 +404,7 @@ public void addTypeWrappers(ScriptType type, TypeWrappers typeWrappers) { return v; } else if (o instanceof EntityJS ent) { return ent.minecraftEntity.position(); - } else if (o instanceof List l && l.size() >= 3) { + } else if (o instanceof List l && l.size() >= 3) { return new Vec3( ((Number) l.get(0)).doubleValue(), ((Number) l.get(1)).doubleValue(), @@ -408,7 +413,7 @@ public void addTypeWrappers(ScriptType type, TypeWrappers typeWrappers) { } else if (o instanceof BlockPos bp) { return new Vec3(bp.getX() + 0.5D, bp.getY() + 0.5D, bp.getZ() + 0.5D); } else if (o instanceof BlockContainerJS container) { - BlockPos bp = container.getPos(); + val bp = container.getPos(); return new Vec3(bp.getX() + 0.5D, bp.getY() + 0.5D, bp.getZ() + 0.5D); } @@ -543,14 +548,14 @@ public void addRecipes(RegisterRecipeHandlersEvent event) { @Override public void generateDataJsons(DataJsonGenerator generator) { - for (var builder : RegistryInfos.ALL_BUILDERS) { + for (val builder : RegistryInfos.ALL_BUILDERS) { builder.generateDataJsons(generator); } } @Override public void generateAssetJsons(AssetJsonGenerator generator) { - for (var builder : RegistryInfos.ALL_BUILDERS) { + for (val builder : RegistryInfos.ALL_BUILDERS) { builder.generateAssetJsons(generator); } } @@ -559,7 +564,7 @@ public void generateAssetJsons(AssetJsonGenerator generator) { public void generateLang(Map lang) { lang.put("itemGroup.kubejs.kubejs", "KubeJS"); - for (var builder : RegistryInfos.ALL_BUILDERS) { + for (val builder : RegistryInfos.ALL_BUILDERS) { if (builder.overrideLangJson && builder.display != null) { lang.put(builder.getTranslationKey(), builder.display.getString()); } diff --git a/common/src/main/java/dev/latvian/kubejs/KubeJS.java b/common/src/main/java/dev/latvian/kubejs/KubeJS.java index a9790144e..edc4f7052 100644 --- a/common/src/main/java/dev/latvian/kubejs/KubeJS.java +++ b/common/src/main/java/dev/latvian/kubejs/KubeJS.java @@ -109,7 +109,7 @@ public KubeJS() throws Throwable { KubeJSPlugins.forEachPlugin(KubeJSPlugin::init); if (!CommonProperties.get().serverOnly) { - var tabEvent = new CreativeTabRegistryEventJS(); + val tabEvent = new CreativeTabRegistryEventJS(); tab = tabEvent.create(KubeJS.MOD_ID, () -> ItemStackJS.of(new ItemStack(Items.PURPLE_DYE))); tabEvent.post(ScriptType.STARTUP, KubeJSEvents.TAB_REGISTRY); } diff --git a/common/src/main/java/dev/latvian/kubejs/bindings/BlockWrapper.java b/common/src/main/java/dev/latvian/kubejs/bindings/BlockWrapper.java index 6be65e91c..1316b2231 100644 --- a/common/src/main/java/dev/latvian/kubejs/bindings/BlockWrapper.java +++ b/common/src/main/java/dev/latvian/kubejs/bindings/BlockWrapper.java @@ -1,6 +1,5 @@ package dev.latvian.kubejs.bindings; -import dev.latvian.kubejs.KubeJSRegistries; import dev.latvian.kubejs.block.MaterialJS; import dev.latvian.kubejs.block.MaterialListJS; import dev.latvian.kubejs.block.predicate.BlockEntityPredicate; @@ -11,7 +10,6 @@ import dev.latvian.mods.rhino.annotations.typing.JSInfo; import lombok.val; import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; import net.minecraft.world.level.block.Block; diff --git a/common/src/main/java/dev/latvian/kubejs/bindings/TextWrapper.java b/common/src/main/java/dev/latvian/kubejs/bindings/TextWrapper.java index 2dbd53e64..b1e1a12a5 100644 --- a/common/src/main/java/dev/latvian/kubejs/bindings/TextWrapper.java +++ b/common/src/main/java/dev/latvian/kubejs/bindings/TextWrapper.java @@ -116,6 +116,8 @@ public static Text fromComponent(Component c) { var style = c.getStyle(); t.bold(style.isBold()) + .color(ColorWrapper.of(style.getColor())) + .font(style.getFont()) .italic(style.isItalic()) .underlined(style.isUnderlined()) .strikethrough(style.isStrikethrough()) diff --git a/common/src/main/java/dev/latvian/kubejs/command/KubeJSCommands.java b/common/src/main/java/dev/latvian/kubejs/command/KubeJSCommands.java index 35bf2bb2d..bf49af4b7 100644 --- a/common/src/main/java/dev/latvian/kubejs/command/KubeJSCommands.java +++ b/common/src/main/java/dev/latvian/kubejs/command/KubeJSCommands.java @@ -359,8 +359,9 @@ private static int reloadStartup(CommandSourceStack source) { } private static int reloadServer(CommandSourceStack source) { - ServerScriptManager.instance.reloadScriptManager(((MinecraftServerKJS) source.getServer()).getServerResourcesKJS() - .getResourceManager()); + ServerScriptManager.instance.reloadScriptManager( + ((MinecraftServerKJS) source.getServer()).getServerResourcesKJS().getResourceManager() + ); UtilsJS.postModificationEvents(); source.sendSuccess(new TextComponent( "Done! To reload recipes, tags, loot tables and other datapack things, run /reload"), false); diff --git a/common/src/main/java/dev/latvian/kubejs/core/AsKJS.java b/common/src/main/java/dev/latvian/kubejs/core/AsKJS.java index 7d1aebad9..e072014dd 100644 --- a/common/src/main/java/dev/latvian/kubejs/core/AsKJS.java +++ b/common/src/main/java/dev/latvian/kubejs/core/AsKJS.java @@ -1,5 +1,5 @@ package dev.latvian.kubejs.core; -public interface AsKJS { - Object asKJS(); +public interface AsKJS { + T asKJS(); } diff --git a/common/src/main/java/dev/latvian/kubejs/core/EntityKJS.java b/common/src/main/java/dev/latvian/kubejs/core/EntityKJS.java index fd921e9c8..88aba5825 100644 --- a/common/src/main/java/dev/latvian/kubejs/core/EntityKJS.java +++ b/common/src/main/java/dev/latvian/kubejs/core/EntityKJS.java @@ -1,14 +1,14 @@ package dev.latvian.kubejs.core; import dev.latvian.kubejs.KubeJS; +import dev.latvian.kubejs.entity.EntityJS; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.Entity; -public interface EntityKJS extends AsKJS { +public interface EntityKJS extends AsKJS { @Override - default Object asKJS() { - Entity entity = (Entity) this; - return KubeJS.PROXY.getWorld(entity.level).getEntity(entity); + default EntityJS asKJS() { + return KubeJS.PROXY.getWorld(((Entity) this).level).getEntity((Entity) this); } CompoundTag getPersistentDataKJS(); diff --git a/common/src/main/java/dev/latvian/kubejs/core/IngredientKJS.java b/common/src/main/java/dev/latvian/kubejs/core/IngredientKJS.java index bd7a557c0..ae2cf584b 100644 --- a/common/src/main/java/dev/latvian/kubejs/core/IngredientKJS.java +++ b/common/src/main/java/dev/latvian/kubejs/core/IngredientKJS.java @@ -3,9 +3,9 @@ import dev.latvian.kubejs.item.ingredient.IngredientJS; import net.minecraft.world.item.ItemStack; -public interface IngredientKJS extends AsKJS { +public interface IngredientKJS extends AsKJS { @Override - default Object asKJS() { + default IngredientJS asKJS() { return IngredientJS.of(this); } diff --git a/common/src/main/java/dev/latvian/kubejs/core/ItemStackKJS.java b/common/src/main/java/dev/latvian/kubejs/core/ItemStackKJS.java index cd7ce07aa..a461ea72d 100644 --- a/common/src/main/java/dev/latvian/kubejs/core/ItemStackKJS.java +++ b/common/src/main/java/dev/latvian/kubejs/core/ItemStackKJS.java @@ -2,9 +2,9 @@ import dev.latvian.kubejs.item.ItemStackJS; -public interface ItemStackKJS extends AsKJS { +public interface ItemStackKJS extends AsKJS { @Override - default Object asKJS() { + default ItemStackJS asKJS() { return ItemStackJS.of(this); } diff --git a/common/src/main/java/dev/latvian/kubejs/core/LevelKJS.java b/common/src/main/java/dev/latvian/kubejs/core/LevelKJS.java index b11e2a687..a860f6a03 100644 --- a/common/src/main/java/dev/latvian/kubejs/core/LevelKJS.java +++ b/common/src/main/java/dev/latvian/kubejs/core/LevelKJS.java @@ -1,11 +1,12 @@ package dev.latvian.kubejs.core; import dev.latvian.kubejs.KubeJS; +import dev.latvian.kubejs.world.WorldJS; import net.minecraft.world.level.Level; -public interface LevelKJS extends AsKJS { +public interface LevelKJS extends AsKJS { @Override - default Object asKJS() { + default WorldJS asKJS() { return KubeJS.PROXY.getWorld((Level) this); } } diff --git a/common/src/main/java/dev/latvian/kubejs/core/MinecraftServerKJS.java b/common/src/main/java/dev/latvian/kubejs/core/MinecraftServerKJS.java index f06c4916c..d09012dac 100644 --- a/common/src/main/java/dev/latvian/kubejs/core/MinecraftServerKJS.java +++ b/common/src/main/java/dev/latvian/kubejs/core/MinecraftServerKJS.java @@ -3,9 +3,9 @@ import dev.latvian.kubejs.server.ServerJS; import net.minecraft.server.ServerResources; -public interface MinecraftServerKJS extends AsKJS { +public interface MinecraftServerKJS extends AsKJS { @Override - default Object asKJS() { + default ServerJS asKJS() { return ServerJS.instance; } diff --git a/common/src/main/java/dev/latvian/kubejs/event/EventJS.java b/common/src/main/java/dev/latvian/kubejs/event/EventJS.java index 5ba10ae8b..274bccd13 100644 --- a/common/src/main/java/dev/latvian/kubejs/event/EventJS.java +++ b/common/src/main/java/dev/latvian/kubejs/event/EventJS.java @@ -40,10 +40,10 @@ public final boolean post(@NotNull ScriptType type, @NotNull List ids) { val e = type.manager.get().events; boolean cancelled = false; for (val id : ids) { + cancelled = e.postToHandlers(id, e.handlers(id), this); if (cancelled) { break; //prevent posting events after being cancelled } - cancelled = e.postToHandlers(id, e.handlers(id), this); } afterPosted(cancelled); return cancelled; diff --git a/common/src/main/java/dev/latvian/kubejs/item/ingredient/MatchAllIngredientJS.java b/common/src/main/java/dev/latvian/kubejs/item/ingredient/MatchAllIngredientJS.java index 27b2deb21..8218922c3 100644 --- a/common/src/main/java/dev/latvian/kubejs/item/ingredient/MatchAllIngredientJS.java +++ b/common/src/main/java/dev/latvian/kubejs/item/ingredient/MatchAllIngredientJS.java @@ -1,6 +1,8 @@ package dev.latvian.kubejs.item.ingredient; import dev.latvian.kubejs.item.ItemStackJS; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -12,11 +14,9 @@ /** * @author LatvianModder */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class MatchAllIngredientJS implements IngredientJS { - public static MatchAllIngredientJS INSTANCE = new MatchAllIngredientJS(); - - private MatchAllIngredientJS() { - } + public static final MatchAllIngredientJS INSTANCE = new MatchAllIngredientJS(); @Override public boolean test(ItemStackJS stack) { diff --git a/common/src/main/java/dev/latvian/kubejs/mixin/common/EntityMixin.java b/common/src/main/java/dev/latvian/kubejs/mixin/common/EntityMixin.java index f464e284e..bd8556fff 100644 --- a/common/src/main/java/dev/latvian/kubejs/mixin/common/EntityMixin.java +++ b/common/src/main/java/dev/latvian/kubejs/mixin/common/EntityMixin.java @@ -14,21 +14,21 @@ @Mixin(Entity.class) public abstract class EntityMixin implements EntityKJS { @Unique - private final CompoundTag persistentDataKJS = new CompoundTag(); + private final CompoundTag kjs$persistentData = new CompoundTag(); @Override public CompoundTag getPersistentDataKJS() { - return persistentDataKJS; + return kjs$persistentData; } @Inject(method = "saveWithoutId", at = @At("RETURN")) private void saveKJS(CompoundTag tag, CallbackInfoReturnable ci) { - tag.put("KubeJSPersistentData", persistentDataKJS); + tag.put("KubeJSPersistentData", kjs$persistentData); } @Inject(method = "load", at = @At("RETURN")) private void loadKJS(CompoundTag tag, CallbackInfo ci) { - ((MapLike) persistentDataKJS).clearML(); - persistentDataKJS.merge(tag.getCompound("KubeJSPersistentData")); + ((MapLike) kjs$persistentData).clearML(); + kjs$persistentData.merge(tag.getCompound("KubeJSPersistentData")); } } diff --git a/common/src/main/java/dev/latvian/kubejs/mixin/common/ItemMixin.java b/common/src/main/java/dev/latvian/kubejs/mixin/common/ItemMixin.java index 41c2b3b06..012d4626e 100644 --- a/common/src/main/java/dev/latvian/kubejs/mixin/common/ItemMixin.java +++ b/common/src/main/java/dev/latvian/kubejs/mixin/common/ItemMixin.java @@ -91,13 +91,6 @@ private void isFoilKJS(ItemStack itemStack, CallbackInfoReturnable ci) } } - @Inject(method = "appendHoverText", at = @At("RETURN")) - private void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag flagIn, CallbackInfo ci) { - if (itemBuilderKJS != null && !itemBuilderKJS.tooltip.isEmpty()) { - tooltip.addAll(itemBuilderKJS.tooltip); - } - } - @Inject(method = "getUseDuration", at = @At("HEAD"), cancellable = true) private void getUseDuration(ItemStack itemStack, CallbackInfoReturnable ci) { if (itemBuilderKJS != null && itemBuilderKJS.useDuration != null) { diff --git a/common/src/main/java/dev/latvian/kubejs/recipe/RegisterRecipeHandlersEvent.java b/common/src/main/java/dev/latvian/kubejs/recipe/RegisterRecipeHandlersEvent.java index a58b15226..c369bb6b3 100644 --- a/common/src/main/java/dev/latvian/kubejs/recipe/RegisterRecipeHandlersEvent.java +++ b/common/src/main/java/dev/latvian/kubejs/recipe/RegisterRecipeHandlersEvent.java @@ -36,7 +36,7 @@ public RegisterRecipeHandlersEvent(Map m) { public void register(RecipeTypeJS type) { map.put(Registries.getId(type.serializer, Registry.RECIPE_SERIALIZER_REGISTRY), type); - KubeJS.LOGGER.info("Registered custom recipe handler for type " + type); + KubeJS.LOGGER.info("Registered custom recipe handler for type {}", type); } public void register(ResourceLocation id, Supplier f) { diff --git a/common/src/main/java/dev/latvian/kubejs/text/Text.java b/common/src/main/java/dev/latvian/kubejs/text/Text.java index b7da205a3..17413d013 100644 --- a/common/src/main/java/dev/latvian/kubejs/text/Text.java +++ b/common/src/main/java/dev/latvian/kubejs/text/Text.java @@ -316,9 +316,14 @@ public final Text insertion(@Nullable String value) { return this; } + public final Text font(ResourceLocation rl) { + font = rl; + return this; + } + + @HideFromJS public final Text font(@Nullable String value) { - font = value == null || value.isEmpty() ? null : new ResourceLocation(value); - return this; + return font(value == null || value.isEmpty() ? null : new ResourceLocation(value)); } public final Text click(@Nullable Object o) { diff --git a/common/src/main/java/dev/latvian/kubejs/util/AttachedData.java b/common/src/main/java/dev/latvian/kubejs/util/AttachedData.java index 94eb84b38..72da297e4 100644 --- a/common/src/main/java/dev/latvian/kubejs/util/AttachedData.java +++ b/common/src/main/java/dev/latvian/kubejs/util/AttachedData.java @@ -1,18 +1,17 @@ package dev.latvian.kubejs.util; +import lombok.Getter; + import java.util.HashMap; /** * @author LatvianModder */ +@Getter public class AttachedData extends HashMap { private final Object parent; public AttachedData(Object p) { parent = p; } - - public Object getParent() { - return parent; - } } \ No newline at end of file diff --git a/common/src/main/java/dev/latvian/kubejs/world/BlockContainerJS.java b/common/src/main/java/dev/latvian/kubejs/world/BlockContainerJS.java index 4b1f544a7..97b5964a7 100644 --- a/common/src/main/java/dev/latvian/kubejs/world/BlockContainerJS.java +++ b/common/src/main/java/dev/latvian/kubejs/world/BlockContainerJS.java @@ -13,6 +13,7 @@ import dev.latvian.kubejs.util.UtilsJS; import dev.latvian.mods.rhino.util.SpecialEquality; import dev.architectury.injectables.annotations.ExpectPlatform; +import lombok.val; import me.shedaniel.architectury.hooks.PlayerHooks; import me.shedaniel.architectury.registry.Registries; import net.minecraft.core.BlockPos; @@ -23,11 +24,9 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LightningBolt; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; @@ -152,17 +151,17 @@ public boolean hasTag(ResourceLocation tag) { } public void set(ResourceLocation id, Map properties, int flags) { - Block block = KubeJSRegistries.blocks().get(id); - BlockState state = block.defaultBlockState(); + val block = KubeJSRegistries.blocks().get(id); + BlockState state = block.defaultBlockState(); if (!properties.isEmpty() && state.getBlock() != Blocks.AIR) { - Map pmap = new HashMap<>(); + val pmap = new HashMap(); - for (Property property : state.getProperties()) { + for (val property : state.getProperties()) { pmap.put(property.getName(), property); } - for (Map.Entry entry : properties.entrySet()) { + for (val entry : properties.entrySet()) { Property property = pmap.get(String.valueOf(entry.getKey())); if (property != null) { @@ -203,24 +202,22 @@ public BlockEntity getEntity() { } public String getEntityId() { - BlockEntity entity = getEntity(); + val entity = getEntity(); return entity == null ? "minecraft:air" : Registries.getId(entity.getType(), Registry.BLOCK_ENTITY_TYPE_REGISTRY).toString(); } @Nullable public CompoundTag getEntityData() { - BlockEntity entity = getEntity(); + val entity = getEntity(); - if (entity != null) { - return entity.save(new CompoundTag()); - } - - return null; - } + return entity == null + ? null + : entity.save(new CompoundTag()); + } public void setEntityData(@Nullable CompoundTag tag) { if (tag != null) { - BlockEntity entity = getEntity(); + val entity = getEntity(); if (entity != null) { entity.load(entity.getBlockState(), tag); @@ -229,7 +226,7 @@ public void setEntityData(@Nullable CompoundTag tag) { } public void mergeEntityData(@Nullable CompoundTag tag) { - CompoundTag t = getEntityData(); + val t = getEntityData(); if (t == null) { setEntityData(tag); @@ -297,7 +294,8 @@ public EntityJS createEntity(ResourceLocation id) { public void spawnLightning(boolean effectOnly, @Nullable EntityJS player) { if (minecraftLevel instanceof ServerLevel) { - LightningBolt e = EntityType.LIGHTNING_BOLT.create(minecraftLevel); + val e = EntityType.LIGHTNING_BOLT.create(minecraftLevel); + e.setVisualOnly(effectOnly); e.moveTo(getX() + 0.5D, getY() + 0.5D, getZ() + 0.5D); e.setCause(player instanceof ServerPlayerJS ? ((ServerPlayerJS) player).minecraftPlayer : null); minecraftLevel.addFreshEntity(e); diff --git a/fabric/src/main/java/dev/latvian/kubejs/event/fabric/PlatformEventHandlerImpl.java b/fabric/src/main/java/dev/latvian/kubejs/event/fabric/PlatformEventHandlerImpl.java new file mode 100644 index 000000000..177488a7a --- /dev/null +++ b/fabric/src/main/java/dev/latvian/kubejs/event/fabric/PlatformEventHandlerImpl.java @@ -0,0 +1,14 @@ +package dev.latvian.kubejs.event.fabric; + +import dev.latvian.kubejs.event.PlatformEventHandler; +import dev.latvian.kubejs.script.ScriptManager; + +/** + * @author ZZZank + */ +public class PlatformEventHandlerImpl extends PlatformEventHandler { + + public static void onUnload(ScriptManager manager) { + } +} + diff --git a/fabric/src/main/java/dev/latvian/kubejs/fabric/KubeJSFabric.java b/fabric/src/main/java/dev/latvian/kubejs/fabric/KubeJSFabric.java index ed5326bf9..f853691fa 100644 --- a/fabric/src/main/java/dev/latvian/kubejs/fabric/KubeJSFabric.java +++ b/fabric/src/main/java/dev/latvian/kubejs/fabric/KubeJSFabric.java @@ -6,6 +6,7 @@ import dev.latvian.kubejs.script.ScriptType; import dev.latvian.kubejs.world.gen.fabric.WorldgenAddEventJSFabric; import dev.latvian.kubejs.world.gen.fabric.WorldgenRemoveEventJSFabric; +import lombok.val; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.api.ModInitializer; @@ -13,34 +14,45 @@ import net.fabricmc.fabric.api.biome.v1.BiomeSelectors; import net.fabricmc.fabric.api.biome.v1.ModificationPhase; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.resources.ResourceLocation; -import org.apache.logging.log4j.Level; public class KubeJSFabric implements ModInitializer, ClientModInitializer, DedicatedServerModInitializer { - @Override - public void onInitialize() { - try { - KubeJS.instance = new KubeJS(); - FabricLoader.getInstance().getEntrypoints("kubejs-init", KubeJSInitializer.class).forEach((it) -> { - it.onKubeJSInitialization(); - KubeJS.LOGGER.log(Level.DEBUG, "[KubeJS] Initialized entrypoint " + it.getClass().getSimpleName() + "."); - }); - KubeJS.instance.setup(); + @Override + public void onInitialize() { + try { + KubeJS.instance = new KubeJS(); + for (val initializer : FabricLoader.getInstance().getEntrypoints("kubejs-init", KubeJSInitializer.class)) { + initializer.onKubeJSInitialization(); + KubeJS.LOGGER.debug("[KubeJS] Initialized entrypoint {}.", initializer.getClass().getSimpleName()); + } + KubeJS.instance.setup(); - BiomeModifications.create(new ResourceLocation("kubejs", "worldgen_removals")).add(ModificationPhase.REMOVALS, BiomeSelectors.all(), (s, m) -> new WorldgenRemoveEventJSFabric(s, m).post(ScriptType.STARTUP, KubeJSEvents.WORLDGEN_REMOVE)); - BiomeModifications.create(new ResourceLocation("kubejs", "worldgen_additions")).add(ModificationPhase.REPLACEMENTS, BiomeSelectors.all(), (s, m) -> new WorldgenAddEventJSFabric(s, m).post(ScriptType.STARTUP, KubeJSEvents.WORLDGEN_ADD)); - } catch (Throwable throwable) { - throw new RuntimeException(throwable); - } - } + BiomeModifications.create(KubeJS.id("worldgen_removals")) + .add( + ModificationPhase.REMOVALS, + BiomeSelectors.all(), + (s, m) -> new WorldgenRemoveEventJSFabric(s, m).post( + ScriptType.STARTUP, + KubeJSEvents.WORLDGEN_REMOVE + ) + ); + BiomeModifications.create(KubeJS.id("worldgen_additions")) + .add( + ModificationPhase.REPLACEMENTS, + BiomeSelectors.all(), + (s, m) -> new WorldgenAddEventJSFabric(s, m).post(ScriptType.STARTUP, KubeJSEvents.WORLDGEN_ADD) + ); + } catch (Throwable throwable) { + throw new RuntimeException(throwable); + } + } - @Override - public void onInitializeClient() { - KubeJS.instance.loadComplete(); - } + @Override + public void onInitializeClient() { + KubeJS.instance.loadComplete(); + } - @Override - public void onInitializeServer() { - KubeJS.instance.loadComplete(); - } + @Override + public void onInitializeServer() { + KubeJS.instance.loadComplete(); + } } diff --git a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/AddREIEventJS.java b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/AddREIEventJS.java index 4bc6d62ab..196f34735 100644 --- a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/AddREIEventJS.java +++ b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/AddREIEventJS.java @@ -15,6 +15,9 @@ */ public class AddREIEventJS extends EventJS { private final EntryRegistry registry; + /** + * itemSerializer + */ private final Function> function; private final List added = Lists.newArrayList(); @@ -26,7 +29,6 @@ public AddREIEventJS(EntryRegistry registry, Function stacks = function.apply(o1); - if (stacks != null && !stacks.isEmpty()) { for (EntryStack stack : stacks) { if (stack != null && !stack.isEmpty()) { diff --git a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/HideREIEventJS.java b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/HideREIEventJS.java index 59cd2f72e..167303410 100644 --- a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/HideREIEventJS.java +++ b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/HideREIEventJS.java @@ -27,7 +27,10 @@ public HideREIEventJS(EntryRegistry registry, EntryStack.Type type, Function getAllIngredients() { - return (Collection) registry.getEntryStacks().filter(this::filterType).map(EntryStack::getObject).collect(Collectors.toList()); + return (Collection) registry.getEntryStacks() + .filter(this::filterType) + .map(EntryStack::getObject) + .collect(Collectors.toList()); } private boolean filterType(EntryStack stack) { diff --git a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/InformationREIEventJS.java b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/InformationREIEventJS.java index fdfcb13d7..855c3f4c4 100644 --- a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/InformationREIEventJS.java +++ b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/InformationREIEventJS.java @@ -14,23 +14,26 @@ * @author shedaniel */ public class InformationREIEventJS extends EventJS { - /** - * Registers an information display. - * - * @param stacks The target stacks - * @param title The title of the information display - * @param description The information to be provided - */ - public void add(Object stacks, Component title, Object description) { - BuiltinPlugin.getInstance().registerInformation( - EntryStack.ofItemStacks(CollectionUtils.map(IngredientJS.of(stacks).getStacks(), ItemStackJS::getItemStack)), - title, - components -> { - for (Object o : ListJS.orSelf(description)) { - components.add(Text.componentOf(o)); - } - return components; - } - ); - } + /** + * Registers an information display. + * + * @param stacks The target stacks + * @param title The title of the information display + * @param description The information to be provided + */ + public void add(Object stacks, Component title, Object description) { + BuiltinPlugin.getInstance().registerInformation( + EntryStack.ofItemStacks(CollectionUtils.map( + IngredientJS.of(stacks).getStacks(), + ItemStackJS::getItemStack + )), + title, + components -> { + for (Object o : ListJS.orSelf(description)) { + components.add(Text.componentOf(o)); + } + return components; + } + ); + } } \ No newline at end of file diff --git a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/REIPlugin.java b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/REIPlugin.java index a9cf0d88b..79a0f534e 100644 --- a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/REIPlugin.java +++ b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/REIPlugin.java @@ -30,7 +30,12 @@ public ResourceLocation getPluginIdentifier() { @Override public void registerEntries(EntryRegistry entryRegistry) { - Function> itemSerializer = o -> EntryStack.ofItemStacks(CollectionUtils.map(IngredientJS.of(o).getStacks(), ItemStackJS::getItemStack)); + Function> itemSerializer = o -> EntryStack.ofItemStacks( + CollectionUtils.map( + IngredientJS.of(o).getStacks(), + ItemStackJS::getItemStack + ) + ); new HideREIEventJS<>(entryRegistry, EntryStack.Type.ITEM, itemSerializer).post(ScriptType.CLIENT, REIIntegration.REI_HIDE_ITEMS); new AddREIEventJS(entryRegistry, itemSerializer).post(ScriptType.CLIENT, REIIntegration.REI_ADD_ITEMS); diff --git a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/RemoveREICategoryEventJS.java b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/RemoveREICategoryEventJS.java index 7aab3ebc7..33abedd0c 100644 --- a/fabric/src/main/java/dev/latvian/kubejs/integration/rei/RemoveREICategoryEventJS.java +++ b/fabric/src/main/java/dev/latvian/kubejs/integration/rei/RemoveREICategoryEventJS.java @@ -10,21 +10,24 @@ import java.util.Set; public class RemoveREICategoryEventJS extends EventJS { - private final Set categoriesRemoved; + private final Set categoriesRemoved; - public RemoveREICategoryEventJS(Set categoriesRemoved) { - this.categoriesRemoved = categoriesRemoved; - } + public RemoveREICategoryEventJS(Set categoriesRemoved) { + this.categoriesRemoved = categoriesRemoved; + } - public Collection getCategories() { - return CollectionUtils.map(RecipeHelper.getInstance().getAllCategories(), category -> category.getIdentifier().toString()); - } + public Collection getCategories() { + return CollectionUtils.map( + RecipeHelper.getInstance().getAllCategories(), + category -> category.getIdentifier().toString() + ); + } - public void remove(ResourceLocation[] categoriesToYeet) { - categoriesRemoved.addAll(Arrays.asList(categoriesToYeet)); - } + public void remove(ResourceLocation[] categoriesToYeet) { + categoriesRemoved.addAll(Arrays.asList(categoriesToYeet)); + } - public void yeet(ResourceLocation[] categoriesToYeet) { - remove(categoriesToYeet); - } + public void yeet(ResourceLocation[] categoriesToYeet) { + remove(categoriesToYeet); + } } diff --git a/fabric/src/main/java/dev/latvian/kubejs/integration/techreborn/TechRebornIntegration.java b/fabric/src/main/java/dev/latvian/kubejs/integration/techreborn/TechRebornIntegration.java index 92e5b389f..8b8845a5a 100644 --- a/fabric/src/main/java/dev/latvian/kubejs/integration/techreborn/TechRebornIntegration.java +++ b/fabric/src/main/java/dev/latvian/kubejs/integration/techreborn/TechRebornIntegration.java @@ -2,49 +2,54 @@ import dev.latvian.kubejs.KubeJSInitializer; import dev.latvian.kubejs.recipe.RegisterRecipeHandlersEvent; +import lombok.val; import me.shedaniel.architectury.platform.Platform; import net.minecraft.resources.ResourceLocation; public class TechRebornIntegration implements KubeJSInitializer { - @Override - public void onKubeJSInitialization() { - if (Platform.isModLoaded("techreborn")) { - RegisterRecipeHandlersEvent.EVENT.register(event -> { - for (String s : new String[]{ - // Default recipes - "techreborn:alloy_smelter", - "techreborn:assembling_machine", - "techreborn:centrifuge", - "techreborn:chemical_reactor", - "techreborn:compressor", - "techreborn:distillation_tower", - "techreborn:extractor", - "techreborn:grinder", - "techreborn:implosion_compressor", - "techreborn:industrial_electrolyzer", - "techreborn:recycler", - "techreborn:scrapbox", - "techreborn:vacuum_freezer", - "techreborn:solid_canning_machine", - "techreborn:wire_mill", - // Similar enough that the same serializer works - "techreborn:blast_furnace", - }) { - event.register(new ResourceLocation(s), TRRecipeJS::new); - } - for (String s : new String[]{ - "techreborn:industrial_grinder", - "techreborn:industrial_grinder", - "techreborn:fluid_replicator", - }) { - event.register(new ResourceLocation(s), TRRecipeWithTankJS::new); - } + @Override + public void onKubeJSInitialization() { + if (!Platform.isModLoaded("techreborn")) { + return; + } + RegisterRecipeHandlersEvent.EVENT.register(TechRebornIntegration::registerRecipeHandlers); + } - // To be implemented later - // "techreborn:fusion_reactor", // See FusionReactorRecipe - // "techreborn:rolling_machine", // See RollingMachineRecipe - }); - } - } + private static void registerRecipeHandlers(RegisterRecipeHandlersEvent event) { + for (val s : new String[]{ + // Default recipes + "alloy_smelter", + "assembling_machine", + "centrifuge", + "chemical_reactor", + "compressor", + "distillation_tower", + "extractor", + "grinder", + "implosion_compressor", + "industrial_electrolyzer", + "recycler", + "scrapbox", + "vacuum_freezer", + "solid_canning_machine", + "wire_mill", + // Similar enough that the same serializer works + "blast_furnace", + }) { + event.register(new ResourceLocation("techreborn", s), TRRecipeJS::new); + } + + for (val s : new String[]{ + "industrial_grinder", + "industrial_grinder", + "fluid_replicator", + }) { + event.register(new ResourceLocation("techreborn", s), TRRecipeWithTankJS::new); + } + + // To be implemented later + // "techreborn:fusion_reactor", // See FusionReactorRecipe + // "techreborn:rolling_machine", // See RollingMachineRecipe + } }