diff --git a/build.gradle.kts b/build.gradle.kts index f35e92a16..7dbc96232 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,6 +10,8 @@ val mod_version: String by project val mc_version: String by project val forge_version: String by project val mod_id: String by project +val handle_deps: String by project +val handleDeps = handle_deps == "true" plugins { java @@ -98,13 +100,16 @@ dependencies { val jei_version: String by project val mc_version_weak: String by project val the_one_probe_version: String by project + val mekanism_version: String by project - implementation("mezz.jei:jei-${mc_version}:${jei_version}:deobf") - implementation(fg.deobf(create("mcjty.theoneprobe:theoneprobe:${mc_version_weak}-${the_one_probe_version}", closureOf { - (this as ExternalModuleDependency).isTransitive = false - } as Closure))) + if (handleDeps) { + implementation(fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}")) + implementation(fg.deobf(create("mcjty.theoneprobe:theoneprobe:${mc_version_weak}-${the_one_probe_version}", closureOf { + (this as ExternalModuleDependency).isTransitive = false + } as Closure))) - implementation(fg.deobf("mekanism:Mekanism:1.18.1-10.1.2.homebaked:all")) + implementation(fg.deobf("mekanism:Mekanism:${mc_version}-${mekanism_version}:all")) + } library(create("ru.dbotthepony:kvector:1.2.0", closureOf { // avoid adding kotlin libraries as dependency twice diff --git a/gradle.properties b/gradle.properties index d6d49db4e..2a43f94c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,17 +7,19 @@ kotlin.stdlib.default.dependency=false mod_id=overdrive_that_matters mod_version=1.0-SNAPSHOT -mc_version=1.18.1 +mc_version=1.18.2 mc_version_weak=1.18 forge_gradle_version=5.1.27 -forge_version=39.0.85 +forge_version=40.0.32 -jei_version=9.4.1.106 +jei_version=9.5.4.171 jupiter_version=5.8.2 -the_one_probe_version=5.0.1-5 +the_one_probe_version=5.1.0 +mekanism_version=10.1.2.homebaked kotlin_for_forge_version=3.1.0 kotlin_version=1.6.10 kotlin_coroutines_version=1.6.0 kotlin_serialization_version=1.3.2 +handle_deps=true diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt index aabfca251..fdbee4c49 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt @@ -32,7 +32,7 @@ import ru.dbotthepony.mc.otm.datagen.loot.TileNbtCopy import ru.dbotthepony.mc.otm.datagen.models.BlockMatteryModelProvider import ru.dbotthepony.mc.otm.datagen.recipes.MatteryRecipeProvider import ru.dbotthepony.mc.otm.datagen.recipes.has -import ru.dbotthepony.mc.otm.registry.MTags +import ru.dbotthepony.mc.otm.registry.MItemTags @Mod.EventBusSubscriber(modid = DataGen.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) object DataGen { @@ -392,8 +392,8 @@ object DataGen { lambda { _, consumer -> ShapelessRecipeBuilder(MItems.INDUSTRIAL_GLASS, 8) .requires(net.minecraft.world.item.Items.GLASS, 8) - .requires(MTags.Items.PLATE_TRITANIUM) - .unlockedBy("has_plate", has(MTags.Items.PLATE_TRITANIUM)) + .requires(MItemTags.PLATE_TRITANIUM) + .unlockedBy("has_plate", has(MItemTags.PLATE_TRITANIUM)) .unlockedBy("has_glass", has(net.minecraft.world.item.Items.GLASS)) .save(consumer) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/items/DummyItemTag.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/items/DummyItemTag.kt deleted file mode 100644 index 6577b60b9..000000000 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/items/DummyItemTag.kt +++ /dev/null @@ -1,11 +0,0 @@ -package ru.dbotthepony.mc.otm.datagen.items - -import net.minecraft.resources.ResourceLocation -import net.minecraft.tags.Tag -import net.minecraft.world.item.Item - -class DummyItemTag(private val name: ResourceLocation) : Tag.Named { - override fun contains(p_13287_: Item) = false - override fun getValues() = emptyList() - override fun getName() = name -} diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/MatteryRecipeProvider.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/MatteryRecipeProvider.kt index a6afa14b8..ab015b850 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/MatteryRecipeProvider.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/MatteryRecipeProvider.kt @@ -9,6 +9,7 @@ import net.minecraft.data.recipes.FinishedRecipe import net.minecraft.data.recipes.RecipeProvider import net.minecraft.resources.ResourceLocation import net.minecraft.tags.Tag +import net.minecraft.tags.TagKey import net.minecraft.world.item.Item import net.minecraft.world.item.crafting.Ingredient import net.minecraft.world.level.ItemLike @@ -26,7 +27,7 @@ fun has(p_125978_: ItemLike): InventoryChangeTrigger.TriggerInstance { return inventoryTrigger(ItemPredicate.Builder.item().of(p_125978_).build()) } -fun has(p_125976_: Tag): InventoryChangeTrigger.TriggerInstance { +fun has(p_125976_: TagKey): InventoryChangeTrigger.TriggerInstance { return inventoryTrigger(ItemPredicate.Builder.item().of(p_125976_).build()) } diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 1d3924337..180451f99 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -6,7 +6,6 @@ import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.ModLoader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; diff --git a/src/main/java/ru/dbotthepony/mc/otm/android/AndroidResearchBuilder.java b/src/main/java/ru/dbotthepony/mc/otm/android/AndroidResearchBuilder.java index 9306a0458..e0b7ae42b 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/android/AndroidResearchBuilder.java +++ b/src/main/java/ru/dbotthepony/mc/otm/android/AndroidResearchBuilder.java @@ -4,10 +4,9 @@ import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraftforge.registries.RegistryManager; +import net.minecraftforge.registries.ForgeRegistries; import ru.dbotthepony.mc.otm.client.render.SkinElement; import ru.dbotthepony.mc.otm.registry.MRegistry; @@ -17,6 +16,7 @@ import java.util.List; import java.util.Objects; import java.util.function.Consumer; +@SuppressWarnings("unused") public class AndroidResearchBuilder { record DeferredItemStack(ResourceLocation id, int amount) { } @@ -171,7 +171,7 @@ public class AndroidResearchBuilder { resolved = true; for (var item : items) { - var get_item = RegistryManager.ACTIVE.getRegistry(Item.class).getValue(item.id); + var get_item = ForgeRegistries.ITEMS.getValue(item.id); if (get_item != null && get_item != Items.AIR) { resolved_stacks.add(new ItemStack(get_item, item.amount)); diff --git a/src/main/java/ru/dbotthepony/mc/otm/capability/matter/MatterTask.java b/src/main/java/ru/dbotthepony/mc/otm/capability/matter/MatterTask.java index c0044d24c..03823a922 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/matter/MatterTask.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/matter/MatterTask.java @@ -8,10 +8,10 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistry; import net.minecraftforge.registries.RegistryManager; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import java.util.Objects; @@ -87,7 +87,7 @@ public record MatterTask(UUID id, @Nullable UUID pattern, Item item, int in_prog return null; if (nbt instanceof CompoundTag tag) { - Item get_item = RegistryManager.ACTIVE.getRegistry(Item.class).getValue(new ResourceLocation(tag.getString("item"))); + Item get_item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("item"))); if (get_item != null && get_item != Items.AIR) { long a = tag.getLong("pattern_u"); @@ -122,7 +122,7 @@ public record MatterTask(UUID id, @Nullable UUID pattern, Item item, int in_prog buffer.writeBoolean(false); } - buffer.writeInt(((ForgeRegistry) RegistryManager.ACTIVE.getRegistry(Item.class)).getID(item)); + buffer.writeInt(((ForgeRegistry) ForgeRegistries.ITEMS).getID(item)); buffer.writeInt(in_progress); buffer.writeInt(finished); buffer.writeInt(required); @@ -132,7 +132,7 @@ public record MatterTask(UUID id, @Nullable UUID pattern, Item item, int in_prog public static MatterTask read(FriendlyByteBuf buffer) { var id = new UUID(buffer.readLong(), buffer.readLong()); var pattern = buffer.readBoolean() ? new UUID(buffer.readLong(), buffer.readLong()) : null; - var item = ((ForgeRegistry) RegistryManager.ACTIVE.getRegistry(Item.class)).getValue(buffer.readInt()); + var item = ((ForgeRegistry) ForgeRegistries.ITEMS).getValue(buffer.readInt()); if (item == null) return null; diff --git a/src/main/java/ru/dbotthepony/mc/otm/capability/matter/PatternState.java b/src/main/java/ru/dbotthepony/mc/otm/capability/matter/PatternState.java index f219293c2..5c07494f0 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/matter/PatternState.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/matter/PatternState.java @@ -6,6 +6,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistry; import net.minecraftforge.registries.RegistryManager; @@ -52,7 +53,7 @@ public record PatternState(@Nonnull UUID id, @Nonnull Item item, double research @Nullable public static PatternState deserializeNBT(Tag nbt) { if (nbt instanceof CompoundTag tag) { - var item = RegistryManager.ACTIVE.getRegistry(Item.class).getValue(new ResourceLocation(tag.getString("item"))); + var item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("item"))); if (item == null) return null; @@ -70,7 +71,7 @@ public record PatternState(@Nonnull UUID id, @Nonnull Item item, double research buffer.writeLong(id.getMostSignificantBits()); buffer.writeLong(id.getLeastSignificantBits()); - buffer.writeInt(((ForgeRegistry) RegistryManager.ACTIVE.getRegistry(Item.class)).getID(item)); + buffer.writeInt(((ForgeRegistry) ForgeRegistries.ITEMS).getID(item)); buffer.writeDouble(research); } @@ -83,7 +84,7 @@ public record PatternState(@Nonnull UUID id, @Nonnull Item item, double research int item = buffer.readInt(); double percent = buffer.readDouble(); - Item get_item = ((ForgeRegistry) RegistryManager.ACTIVE.getRegistry(Item.class)).getValue(item); + Item get_item = ((ForgeRegistry) ForgeRegistries.ITEMS).getValue(item); if (get_item == null) return null; diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java b/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java index 846c8a47f..868ac9e59 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java +++ b/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java @@ -23,8 +23,6 @@ import ru.dbotthepony.mc.otm.OverdriveThatMatters; import ru.dbotthepony.mc.otm.capability.android.AndroidCapabilityPlayer; import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability; import ru.dbotthepony.mc.otm.capability.MatteryCapability; -import ru.dbotthepony.mc.otm.core.Fraction; -import ru.dbotthepony.mc.otm.core.ImpreciseFraction; import java.util.Optional; import java.util.Random; diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/model/TritaniumArmorModel.java b/src/main/java/ru/dbotthepony/mc/otm/client/model/TritaniumArmorModel.java index 0aaba9b7b..cbcdbd1f4 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/client/model/TritaniumArmorModel.java +++ b/src/main/java/ru/dbotthepony/mc/otm/client/model/TritaniumArmorModel.java @@ -7,15 +7,11 @@ package ru.dbotthepony.mc.otm.client.model; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.client.model.HumanoidModel; -import net.minecraft.client.model.geom.LayerDefinitions; import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.model.geom.PartPose; import net.minecraft.client.model.geom.builders.*; -import net.minecraft.client.player.AbstractClientPlayer; -import net.minecraft.resources.ResourceLocation; import net.minecraftforge.client.ForgeHooksClient; -import ru.dbotthepony.mc.otm.OverdriveThatMatters; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/screen/MatterPanelScreen.java b/src/main/java/ru/dbotthepony/mc/otm/client/screen/MatterPanelScreen.java index 7c9b18e46..d15284693 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/client/screen/MatterPanelScreen.java +++ b/src/main/java/ru/dbotthepony/mc/otm/client/screen/MatterPanelScreen.java @@ -109,8 +109,9 @@ public class MatterPanelScreen extends MatteryScreen { return menu.patterns.get(slot1).stack(); } + @Nonnull @Override - protected List getItemStackTooltip(ItemStack stack) { + protected List getItemStackTooltip(@Nonnull ItemStack stack) { var slot1 = slot + scroll_panel.getScroll(menu.patterns.size() / GRID_WIDTH) * GRID_WIDTH; if (slot1 >= menu.patterns.size()) { @@ -151,8 +152,9 @@ public class MatterPanelScreen extends MatteryScreen { return task.stack(Math.max(task.required(), 1)); } + @Nonnull @Override - protected List getItemStackTooltip(ItemStack stack) { + protected List getItemStackTooltip(@Nonnull ItemStack stack) { var slot1 = slot + scroll_panel.getScroll(menu.tasks.size() / GRID_WIDTH) * GRID_WIDTH; if (slot1 >= menu.tasks.size()) { @@ -228,8 +230,9 @@ public class MatterPanelScreen extends MatteryScreen { return ItemStack.EMPTY; } + @Nonnull @Override - protected List getItemStackTooltip(ItemStack stack) { + protected List getItemStackTooltip(@Nonnull ItemStack stack) { var task1_index = menu.tasks.indexOf(task); List get_list = super.getItemStackTooltip(stack); @@ -299,15 +302,16 @@ public class MatterPanelScreen extends MatteryScreen { return new ItemStack(state.item(), 1); } + @Nonnull @Override - protected List getItemStackTooltip(ItemStack stack) { + protected List getItemStackTooltip(@Nonnull ItemStack stack) { return getPatternTooltip(super.getItemStackTooltip(stack), state); } }; var input_amount = new EditBoxPanel(this, row_2, 0, 0, 10, 20, new TextComponent("Input amount")) { @Override - protected void configureNew(EditBox widget, boolean recreation) { + protected void configureNew(@Nonnull EditBox widget, boolean recreation) { super.configureNew(widget, recreation); widget.setMaxLength(6); diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/screen/panels/SlotPanel.java b/src/main/java/ru/dbotthepony/mc/otm/client/screen/panels/SlotPanel.java index 50d4367a1..b67698d2f 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/client/screen/panels/SlotPanel.java +++ b/src/main/java/ru/dbotthepony/mc/otm/client/screen/panels/SlotPanel.java @@ -58,7 +58,7 @@ public class SlotPanel extends AbstractSlotPanel { } @Override - protected void innerRender(PoseStack stack, float mouse_x, float mouse_y, float flag) { + protected void innerRender(@Nonnull PoseStack stack, float mouse_x, float mouse_y, float flag) { renderSlotBackground(stack, mouse_x, mouse_y, flag); var itemstack = slot.getItem(); @@ -103,7 +103,7 @@ public class SlotPanel extends AbstractSlotPanel { } @Override - protected boolean innerRenderTooltips(PoseStack stack, float mouse_x, float mouse_y, float flag) { + protected boolean innerRenderTooltips(@Nonnull PoseStack stack, float mouse_x, float mouse_y, float flag) { // no op, screen does it for us (completely) return false; } diff --git a/src/main/java/ru/dbotthepony/mc/otm/menu/FormattingHelper.java b/src/main/java/ru/dbotthepony/mc/otm/menu/FormattingHelper.java index 1a1c51d4b..2ead8529d 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/menu/FormattingHelper.java +++ b/src/main/java/ru/dbotthepony/mc/otm/menu/FormattingHelper.java @@ -2,16 +2,13 @@ package ru.dbotthepony.mc.otm.menu; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; -import ru.dbotthepony.mc.otm.OverdriveThatMatters; import ru.dbotthepony.mc.otm.core.Fraction; import ru.dbotthepony.mc.otm.core.ImpreciseFraction; import javax.annotation.ParametersAreNonnullByDefault; import java.math.BigDecimal; -import java.math.BigInteger; import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/ru/dbotthepony/mc/otm/network/android/AndroidEnergyPacket.java b/src/main/java/ru/dbotthepony/mc/otm/network/android/AndroidEnergyPacket.java index 96c185fc0..aa952c297 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/network/android/AndroidEnergyPacket.java +++ b/src/main/java/ru/dbotthepony/mc/otm/network/android/AndroidEnergyPacket.java @@ -6,11 +6,8 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; import ru.dbotthepony.mc.otm.capability.MatteryCapability; -import ru.dbotthepony.mc.otm.core.Fraction; import ru.dbotthepony.mc.otm.core.ImpreciseFraction; -import ru.dbotthepony.mc.otm.network.NetworkHelper; -import java.math.BigDecimal; import java.util.function.Supplier; public record AndroidEnergyPacket(boolean is_maximal, ImpreciseFraction energy) { diff --git a/src/main/java/ru/dbotthepony/mc/otm/registry/MTags.java b/src/main/java/ru/dbotthepony/mc/otm/registry/MTags.java deleted file mode 100644 index 443ac0d10..000000000 --- a/src/main/java/ru/dbotthepony/mc/otm/registry/MTags.java +++ /dev/null @@ -1,15 +0,0 @@ -package ru.dbotthepony.mc.otm.registry; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.ItemTags; -import net.minecraft.world.item.Item; -import net.minecraftforge.common.Tags; - -import java.util.Set; - -public class MTags { - public static class Items { - public static final Tags.IOptionalNamedTag INGOT_TRITANIUM = ItemTags.createOptional(new ResourceLocation("forge", "ingots/tritanium"), Set.of(MItems.INSTANCE::getTRITANIUM_INGOT)); - public static final Tags.IOptionalNamedTag PLATE_TRITANIUM = ItemTags.createOptional(new ResourceLocation("forge", "plates/tritanium"), Set.of(MItems.INSTANCE::getTRITANIUM_PLATE)); - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/Ext.kt index 1706f3cf3..dcac7f4b2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/Ext.kt @@ -164,7 +164,7 @@ inline fun LazyOptional.ifPresentK(lambda: (T) -> Unit) { } } -val ItemStack.tagNotNull get() = orCreateTag +val ItemStack.tagNotNull: CompoundTag get() = orCreateTag inline var Entity.position: Vec3 get() = position() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt index 41efcab87..deb8c09c9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt @@ -8,9 +8,11 @@ import net.minecraftforge.event.TickEvent import net.minecraftforge.event.TickEvent.ServerTickEvent import net.minecraftforge.event.TickEvent.WorldTickEvent import net.minecraftforge.event.server.ServerAboutToStartEvent +import net.minecraftforge.event.server.ServerStoppedEvent import net.minecraftforge.event.server.ServerStoppingEvent import net.minecraftforge.eventbus.api.EventPriority import net.minecraftforge.eventbus.api.SubscribeEvent +import org.apache.logging.log4j.LogManager import java.util.* import kotlin.collections.ArrayList @@ -24,6 +26,13 @@ private val postWorldTick = WeakHashMap>( private val preWorldTickOnce = WeakHashMap>() private val postWorldTickOnce = WeakHashMap>() +// Flag whenever is server alive +// To avoid baby deadlocks caused by minecraft engine design issues +var SERVER_IS_DYING = true + private set + +private val LOGGER = LogManager.getLogger() + fun interface ITickable { fun tick() } @@ -73,18 +82,38 @@ fun onServerTick(event: ServerTickEvent) { } fun addPreServerTicker(ticker: IConditionalTickable) { + if (SERVER_IS_DYING) { + LOGGER.error("Refusing to add ticker $ticker while server is dying", IllegalStateException("Server is stopping")) + return + } + preServerTick.add(ticker) } fun addPostServerTicker(ticker: IConditionalTickable) { + if (SERVER_IS_DYING) { + LOGGER.error("Refusing to add ticker $ticker while server is dying", IllegalStateException("Server is stopping")) + return + } + postServerTick.add(ticker) } fun addPreServerTickerOnce(ticker: ITickable) { + if (SERVER_IS_DYING) { + LOGGER.error("Refusing to add ticker $ticker while server is dying", IllegalStateException("Server is stopping")) + return + } + preServerTickOnce.add(ticker) } fun addPostServerTickerOnce(ticker: ITickable) { + if (SERVER_IS_DYING) { + LOGGER.error("Refusing to add ticker $ticker while server is dying", IllegalStateException("Server is stopping")) + return + } + postServerTickOnce.add(ticker) } @@ -140,18 +169,38 @@ fun onWorldTick(event: WorldTickEvent) { } fun addPreWorldTicker(level: Level, ticker: IConditionalTickable) { + if (SERVER_IS_DYING) { + LOGGER.error("Refusing to add ticker $ticker while server is dying", IllegalStateException("Server is stopping")) + return + } + preWorldTick.computeIfAbsent(level) { ArrayList() }.add(ticker) } fun addPostWorldTicker(level: Level, ticker: IConditionalTickable) { + if (SERVER_IS_DYING) { + LOGGER.error("Refusing to add ticker $ticker while server is dying", IllegalStateException("Server is stopping")) + return + } + postWorldTick.computeIfAbsent(level) { ArrayList() }.add(ticker) } fun addPreWorldTickerOnce(level: Level, ticker: ITickable) { + if (SERVER_IS_DYING) { + LOGGER.error("Refusing to add ticker $ticker while server is dying", IllegalStateException("Server is stopping")) + return + } + preWorldTickOnce.computeIfAbsent(level) { ArrayList() }.add(ticker) } fun addPostWorldTickerOnce(level: Level, ticker: ITickable) { + if (SERVER_IS_DYING) { + LOGGER.error("Refusing to add ticker $ticker while server is dying", IllegalStateException("Server is stopping")) + return + } + postWorldTickOnce.computeIfAbsent(level) { ArrayList() }.add(ticker) } @@ -169,9 +218,21 @@ private fun clear() { @SubscribeEvent(priority = EventPriority.HIGHEST) fun onServerStarting(event: ServerAboutToStartEvent?) { clear() + SERVER_IS_DYING = false } @SubscribeEvent(priority = EventPriority.HIGHEST) fun onServerStopping(event: ServerStoppingEvent?) { clear() + SERVER_IS_DYING = true +} + +@SubscribeEvent(priority = EventPriority.HIGHEST) +fun onServerStopped(event: ServerStoppedEvent?) { + if (!SERVER_IS_DYING) { + LOGGER.fatal("ServerStoppingEvent did not fire. If server has crashed this is normal. However, if server finished it's work 'gracefully' this is a bug.") + + clear() + SERVER_IS_DYING = true + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/CargoCrateBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/CargoCrateBlock.kt index bb3b0593e..7d267b726 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/CargoCrateBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/CargoCrateBlock.kt @@ -57,6 +57,6 @@ class CargoCrateBlock : RotatableMatteryBlock(), EntityBlock { companion object { @JvmField - val IS_OPEN = BooleanProperty.create("open") + val IS_OPEN: BooleanProperty = BooleanProperty.create("open") } } \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/DriveViewerBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/DriveViewerBlock.kt index d579bad01..87146e2a9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/DriveViewerBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/DriveViewerBlock.kt @@ -42,6 +42,6 @@ class DriveViewerBlock : RotatableMatteryBlock(), EntityBlock { } companion object { - val DRIVE_PRESENT = BooleanProperty.create("drive") + val DRIVE_PRESENT: BooleanProperty = BooleanProperty.create("drive") } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/EnergyCounterBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/EnergyCounterBlock.kt index 50b2178cd..dbf9db5bf 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/EnergyCounterBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/EnergyCounterBlock.kt @@ -15,6 +15,7 @@ import net.minecraft.world.level.block.state.StateDefinition import net.minecraft.world.level.block.state.properties.EnumProperty import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape +import ru.dbotthepony.mc.otm.SERVER_IS_DYING import ru.dbotthepony.mc.otm.block.entity.EnergyCounterBlockEntity import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -70,8 +71,8 @@ class EnergyCounterBlock : MatteryBlock(), EntityBlock { ) { super.neighborChanged(state, level, pos, sender, sender_pos, flag) - if (!level.isClientSide) { - (level.getBlockEntity(pos) as? EnergyCounterBlockEntity)?.checkSurroundings(level) + if (!level.isClientSide && !SERVER_IS_DYING) { + (level.getBlockEntity(pos) as? EnergyCounterBlockEntity)?.checkSurroundings() } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatterPanelBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatterPanelBlock.kt index f21c23b21..2c3e2a6e0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatterPanelBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatterPanelBlock.kt @@ -98,6 +98,6 @@ class MatterPanelBlock : MatteryBlock(), EntityBlock { } companion object { - val FACING = EnumProperty.create("facing", Direction::class.java) + val FACING: EnumProperty = EnumProperty.create("facing", Direction::class.java) } } \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt index a1dc65a60..3b3405b2a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt @@ -120,7 +120,7 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope companion object { @JvmField - val FACING = EnumProperty.create( + val FACING: EnumProperty = EnumProperty.create( "facing", Direction::class.java, Direction.SOUTH, @@ -130,6 +130,6 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope ) @JvmField - val FACING_FULL = EnumProperty.create("facing", Direction::class.java) + val FACING_FULL: EnumProperty = EnumProperty.create("facing", Direction::class.java) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt index 4140a31af..a0dfe7dde 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt @@ -19,16 +19,14 @@ import net.minecraftforge.common.util.LazyOptional import net.minecraftforge.energy.CapabilityEnergy import net.minecraftforge.energy.IEnergyStorage import net.minecraftforge.items.CapabilityItemHandler +import ru.dbotthepony.mc.otm.* import ru.dbotthepony.mc.otm.block.BatteryBankBlock import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.capability.* import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.core.ImpreciseFraction -import ru.dbotthepony.mc.otm.ifPresentK import ru.dbotthepony.mc.otm.menu.BatteryBankMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities -import ru.dbotthepony.mc.otm.set -import ru.dbotthepony.mc.otm.unaryMinus import javax.annotation.ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @@ -282,7 +280,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte @Suppress("name_shadowing") val level = this.level - if (level is ServerLevel) + if (level is ServerLevel && !SERVER_IS_DYING) checkSurroundings(level) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt index 1790b2847..9ad7edf79 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt @@ -125,7 +125,8 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl val ref = WeakReference(this) resolver.addListener { - ref.get()?.checkSurroundings() + if (!SERVER_IS_DYING) + ref.get()?.checkSurroundings() } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyCounterBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyCounterBlockEntity.kt index 9259f7de8..c0881a49c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyCounterBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyCounterBlockEntity.kt @@ -379,8 +379,7 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat resolverOutputMekanism = LazyOptional.of { MatteryToMekanismEnergyWrapper(energyInput) } } - if (level != null) - checkSurroundings(level) + checkSurroundings() } } @@ -396,11 +395,8 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat val weak = WeakReference(this) resolve.addListener { - val get = weak.get() - - if (get?.level != null) { - get.checkSurroundings(get.level) - } + if (!SERVER_IS_DYING) + weak.get()?.checkSurroundings() } return resolve @@ -409,7 +405,8 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat return old } - fun checkSurroundings(level: Level?) { + fun checkSurroundings() { + val level = level if (isRemoved || level !is ServerLevel) return inputCapability = getAndBind( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/StorageBusBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/StorageBusBlockEntity.kt index aca8f4e01..63bf10e22 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/StorageBusBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/StorageBusBlockEntity.kt @@ -19,16 +19,14 @@ import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.util.LazyOptional import net.minecraftforge.items.CapabilityItemHandler import net.minecraftforge.items.IItemHandler -import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.* import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage import ru.dbotthepony.mc.otm.core.ImpreciseFraction import ru.dbotthepony.mc.otm.core.plus -import ru.dbotthepony.mc.otm.get import ru.dbotthepony.mc.otm.graph.storage.BasicStorageGraphNode import ru.dbotthepony.mc.otm.graph.storage.StorageNetworkGraph -import ru.dbotthepony.mc.otm.orThrow import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MNames import ru.dbotthepony.mc.otm.storage.* @@ -361,6 +359,9 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter } fun checkSurroundings() { + if (isRemoved) + return + val front = blockPos + blockState.getValue(RotatableMatteryBlock.FACING_FULL) val storage = level?.getBlockEntity(front)?.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)?.let { if (it.isPresent) it else null } @@ -373,8 +374,9 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter storage.addListener { val self = ref.get() ?: return@addListener - if (self.neighbour === it) + if (self.neighbour === it && !SERVER_IS_DYING) { self.checkSurroundings() + } } component?.let(cell::removeStorageComponent) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt index dbac180fe..32515fefd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt @@ -206,7 +206,7 @@ class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : BlockEn var affectedBounds = BoundingBox(0, 0, 0, 1, 1, 1) private set - var affectedBoundsAABB = AABB.of(affectedBounds) + var affectedBoundsAABB: AABB = AABB.of(affectedBounds) private set private fun setDeltaMovement(living: Entity, center: Vec3, distance: Double, weaker: Boolean) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt index d6afbc393..2c7786f19 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt @@ -10,9 +10,9 @@ import net.minecraft.network.chat.Component import net.minecraft.util.FormattedCharSequence import ru.dbotthepony.mc.otm.core.* -fun VertexConsumer.normal(vector: Vector) = normal(vector.x.toFloat(), vector.y.toFloat(), vector.z.toFloat()) -fun VertexConsumer.vertex(matrix4f: Matrix4f, vector: Vector) = vertex(matrix4f, vector.x.toFloat(), vector.y.toFloat(), vector.z.toFloat()) -fun VertexConsumer.color(color: RGBAColor) = color(color.red, color.green, color.blue, color.alpha) +fun VertexConsumer.normal(vector: Vector): VertexConsumer = normal(vector.x.toFloat(), vector.y.toFloat(), vector.z.toFloat()) +fun VertexConsumer.vertex(matrix4f: Matrix4f, vector: Vector): VertexConsumer = vertex(matrix4f, vector.x.toFloat(), vector.y.toFloat(), vector.z.toFloat()) +fun VertexConsumer.color(color: RGBAColor): VertexConsumer = color(color.red, color.green, color.blue, color.alpha) fun PoseStack.translate(vector: Vector) = translate(vector.x, vector.y, vector.z) fun PoseStack.translate(vector: Vec3i) = translate(vector.x.toDouble(), vector.y.toDouble(), vector.z.toDouble()) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/GraphFlooder.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/GraphFlooder.kt index 361ef2155..5c0a4d1c3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/GraphFlooder.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/GraphFlooder.kt @@ -10,7 +10,7 @@ class GraphFlooder(val startNode: Graph6Node, @JvmField val seen: Int = ne private val _nodes = ArrayList>() @JvmField - val nodes = Collections.unmodifiableCollection(_nodes) + val nodes = Collections.unmodifiableCollection(_nodes)!! fun size() = _nodes.size diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/PortableCondensationDriveItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/PortableCondensationDriveItem.kt index 05651f15e..83170eaa0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/PortableCondensationDriveItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/PortableCondensationDriveItem.kt @@ -145,8 +145,8 @@ class PortableCondensationDriveItem(capacity: Int) : } if (matchTag) { - val thisTags = item.item.tags - val stackTatgs = stack.item.tags + val thisTags = item.tags + val stackTatgs = stack.tags.toArray() for (tag1 in thisTags) { if (stackTatgs.contains(tag1)) { @@ -166,8 +166,8 @@ class PortableCondensationDriveItem(capacity: Int) : var same = ItemStack.isSame(item, stack) if (!same && matchTag) { - val thisTags = item.item.tags - val stackTatgs = stack.item.tags + val thisTags = item.tags + val stackTatgs = stack.tags.toArray() for (tag1 in thisTags) { if (stackTatgs.contains(tag1)) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/TritaniumArmorItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/TritaniumArmorItem.kt index 48d3c1b8f..d30ce23ce 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/TritaniumArmorItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/TritaniumArmorItem.kt @@ -14,10 +14,9 @@ import net.minecraft.world.item.crafting.Ingredient import net.minecraftforge.client.IItemRenderProperties import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.client.model.TritaniumArmorModel -import ru.dbotthepony.mc.otm.registry.MTags +import ru.dbotthepony.mc.otm.registry.MItemTags import java.util.function.Consumer - private object TritaniumArmorMaterial : ArmorMaterial { override fun getDurabilityForSlot(p_40410_: EquipmentSlot): Int { return when (p_40410_) { @@ -43,7 +42,7 @@ private object TritaniumArmorMaterial : ArmorMaterial { override fun getEnchantmentValue() = 9 override fun getEquipSound(): SoundEvent = SoundEvents.ARMOR_EQUIP_GENERIC - override fun getRepairIngredient(): Ingredient = Ingredient.of(MTags.Items.INGOT_TRITANIUM) + override fun getRepairIngredient(): Ingredient = Ingredient.of(MItemTags.INGOT_TRITANIUM) const val ID = "${OverdriveThatMatters.MOD_ID}:tritanium_armor" diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterData.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterData.kt index 56bdd8d56..1d9e6d295 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterData.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterData.kt @@ -2,12 +2,15 @@ package ru.dbotthepony.mc.otm.matter import net.minecraft.tags.ItemTags import net.minecraft.tags.Tag +import net.minecraft.tags.TagKey import net.minecraft.world.item.Item import net.minecraft.world.item.Items import net.minecraft.world.item.crafting.Recipe import net.minecraft.world.item.crafting.RecipeType import net.minecraftforge.event.server.ServerStartedEvent import net.minecraftforge.eventbus.api.SubscribeEvent +import net.minecraftforge.registries.ForgeRegistries +import net.minecraftforge.registries.tags.ITag import org.apache.logging.log4j.LogManager import ru.dbotthepony.mc.otm.core.ImpreciseFraction import ru.dbotthepony.mc.otm.registry.MItems @@ -113,12 +116,26 @@ private fun deriveIfMissing(from: Item, to: Item, multValue: ImpreciseFraction = private fun deriveIfMissing(from: Item, to: Item, multValue: Double, multComplexity: Double = 1.0) = deriveIfMissing(from, to, ImpreciseFraction(multValue), multComplexity) +private fun make(tag: ITag, value: ImpreciseFraction, complexity: Double = defaultComplexity(value)) { + for (item in tag.stream().iterator()) { + make(item, value, complexity) + } +} + private fun make(tag: Tag, value: ImpreciseFraction, complexity: Double = defaultComplexity(value)) { for (item in tag.values) { make(item, value, complexity) } } +private fun make(tag: TagKey, value: ImpreciseFraction, complexity: Double = defaultComplexity(value)) { + val resolved = ForgeRegistries.ITEMS.tags()?.getTag(tag) + + if (resolved != null) { + make(resolved, value, complexity) + } +} + private fun logResolutionError(text: String) { LOGGER.debug("... Item chain: " + seenItems.joinToString(" -> ")) // LOGGER.error("Recipe chain: " + seenRecipes.joinToString(" -> ")) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/data/MultiByteDataContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/data/MultiByteDataContainer.kt index efcb0cda4..4a7de7cfa 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/data/MultiByteDataContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/data/MultiByteDataContainer.kt @@ -34,7 +34,7 @@ open class MultiByteDataContainer(bytes: Int) { require(bytes >= 1) { "Buffer size of $bytes does not make any sense" } } - protected val buffer = ByteBuffer.allocate(bytes) + protected val buffer: ByteBuffer = ByteBuffer.allocate(bytes) var slotID = 0 var dirty = false diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt index def523102..bfc8326c6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt @@ -11,13 +11,15 @@ import net.minecraft.world.level.block.state.BlockBehaviour import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.material.Material import net.minecraft.world.level.material.MaterialColor -import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext import net.minecraftforge.registries.ForgeRegistry +import net.minecraftforge.registries.IForgeRegistry +import net.minecraftforge.registries.NewRegistryEvent import net.minecraftforge.registries.RegistryBuilder import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.android.AndroidFeatureType import ru.dbotthepony.mc.otm.android.AndroidResearchType +import java.util.function.Supplier import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty @@ -66,16 +68,17 @@ class IndustrialGlassProperties(val color: DyeColor?, val name: String, val name } } -private class WriteOnceReadMany : ReadOnlyProperty { - private var value: V? = null +private class RegistryDelegate(private val name: String) { + private var value: Supplier? = null - override fun getValue(thisRef: T, property: KProperty<*>): V { - return value ?: throw IllegalStateException("Tried to access uninitialized property ${property.name}") + fun get(): V { + val supp = value ?: throw IllegalStateException("Tried to access uninitialized registry $name") + return supp.get() ?: throw IllegalStateException("Accessing registry $name too early") } - fun write(value: V) { + fun write(value: Supplier) { if (this.value != null) { - throw IllegalStateException("Already have value written") + throw IllegalStateException("Already have registry written") } this.value = value @@ -83,11 +86,11 @@ private class WriteOnceReadMany : ReadOnlyProperty { } object MRegistry { - private val features = WriteOnceReadMany>>() - private val research = WriteOnceReadMany>>() + private val features = RegistryDelegate>>("ANDROID_FEATURES") + private val research = RegistryDelegate>>("ANDROID_RESEARCH") - val ANDROID_FEATURES by features - val ANDROID_RESEARCH by research + val ANDROID_FEATURES get() = features.get() as ForgeRegistry> + val ANDROID_RESEARCH get() = research.get() as ForgeRegistry> fun initialize(context: FMLJavaModLoadingContext) { context.modEventBus.addListener(this::register) @@ -103,17 +106,17 @@ object MRegistry { AndroidResearch.register() } - internal fun register(event: RegistryEvent.NewRegistry) { + private fun register(event: NewRegistryEvent) { features.write(RegistryBuilder>().let { it.setName(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_features")) it.type = AndroidFeatureType::class.java - it.create() as ForgeRegistry> + event.create(it) }) research.write(RegistryBuilder>().let { it.setName(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research")) it.type = AndroidResearchType::class.java - it.create() as ForgeRegistry> + event.create(it) }) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/Tags.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/Tags.kt new file mode 100644 index 000000000..27237d276 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/Tags.kt @@ -0,0 +1,11 @@ +package ru.dbotthepony.mc.otm.registry + +import net.minecraft.resources.ResourceLocation +import net.minecraft.tags.ItemTags +import net.minecraft.tags.TagKey +import net.minecraft.world.item.Item + +object MItemTags { + val INGOT_TRITANIUM: TagKey = ItemTags.create(ResourceLocation("forge", "ingots/tritanium")) + val PLATE_TRITANIUM: TagKey = ItemTags.create(ResourceLocation("forge", "plates/tritanium")) +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 5edab4ab4..6b260a645 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -6,7 +6,7 @@ # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml modLoader="javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="[38,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion="[40,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. license="MIT" @@ -43,7 +43,7 @@ Matter. Energy. Combined. # Does this dependency have to exist - if not, ordering below must be specified mandatory=true #mandatory # The version range of the dependency - versionRange="[39,)" #mandatory + versionRange="[40,)" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory ordering="NONE" # Side this dependency is applied on - BOTH, CLIENT or SERVER @@ -53,6 +53,6 @@ Matter. Energy. Combined. modId="minecraft" mandatory=true # This version range declares a minimum of the current minecraft version up to but not including the next major version - versionRange="[1.18.1,1.19)" + versionRange="[1.18.2,1.19)" ordering="NONE" side="BOTH"