Port to 1.18.2

This commit is contained in:
DBotThePony 2022-03-28 17:49:33 +07:00
parent 3ed3f43c59
commit 21e847676f
Signed by: DBot
GPG Key ID: DCC23B5715498507
37 changed files with 188 additions and 124 deletions

View File

@ -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")
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<Any> {
(this as ExternalModuleDependency).isTransitive = false
} as Closure<Any>)))
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<Any> {
// avoid adding kotlin libraries as dependency twice

View File

@ -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

View File

@ -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)

View File

@ -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<Item> {
override fun contains(p_13287_: Item) = false
override fun getValues() = emptyList<Item>()
override fun getName() = name
}

View File

@ -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<Item>): InventoryChangeTrigger.TriggerInstance {
fun has(p_125976_: TagKey<Item>): InventoryChangeTrigger.TriggerInstance {
return inventoryTrigger(ItemPredicate.Builder.item().of(p_125976_).build())
}

View File

@ -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;

View File

@ -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));

View File

@ -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<Item>) RegistryManager.ACTIVE.getRegistry(Item.class)).getID(item));
buffer.writeInt(((ForgeRegistry<Item>) 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<Item>) RegistryManager.ACTIVE.getRegistry(Item.class)).getValue(buffer.readInt());
var item = ((ForgeRegistry<Item>) ForgeRegistries.ITEMS).getValue(buffer.readInt());
if (item == null)
return null;

View File

@ -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<Item>) RegistryManager.ACTIVE.getRegistry(Item.class)).getID(item));
buffer.writeInt(((ForgeRegistry<Item>) 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<Item>) RegistryManager.ACTIVE.getRegistry(Item.class)).getValue(item);
Item get_item = ((ForgeRegistry<Item>) ForgeRegistries.ITEMS).getValue(item);
if (get_item == null)
return null;

View File

@ -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;

View File

@ -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;

View File

@ -109,8 +109,9 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
return menu.patterns.get(slot1).stack();
}
@Nonnull
@Override
protected List<Component> getItemStackTooltip(ItemStack stack) {
protected List<Component> 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<MatterPanelMenu> {
return task.stack(Math.max(task.required(), 1));
}
@Nonnull
@Override
protected List<Component> getItemStackTooltip(ItemStack stack) {
protected List<Component> 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<MatterPanelMenu> {
return ItemStack.EMPTY;
}
@Nonnull
@Override
protected List<Component> getItemStackTooltip(ItemStack stack) {
protected List<Component> getItemStackTooltip(@Nonnull ItemStack stack) {
var task1_index = menu.tasks.indexOf(task);
List<Component> get_list = super.getItemStackTooltip(stack);
@ -299,15 +302,16 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
return new ItemStack(state.item(), 1);
}
@Nonnull
@Override
protected List<Component> getItemStackTooltip(ItemStack stack) {
protected List<Component> 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);

View File

@ -58,7 +58,7 @@ public class SlotPanel<T extends MatterySlot> 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<T extends MatterySlot> 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;
}

View File

@ -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;

View File

@ -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) {

View File

@ -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<Item> INGOT_TRITANIUM = ItemTags.createOptional(new ResourceLocation("forge", "ingots/tritanium"), Set.of(MItems.INSTANCE::getTRITANIUM_INGOT));
public static final Tags.IOptionalNamedTag<Item> PLATE_TRITANIUM = ItemTags.createOptional(new ResourceLocation("forge", "plates/tritanium"), Set.of(MItems.INSTANCE::getTRITANIUM_PLATE));
}
}

View File

@ -164,7 +164,7 @@ inline fun <T> LazyOptional<T>.ifPresentK(lambda: (T) -> Unit) {
}
}
val ItemStack.tagNotNull get() = orCreateTag
val ItemStack.tagNotNull: CompoundTag get() = orCreateTag
inline var Entity.position: Vec3
get() = position()

View File

@ -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<Level, ArrayList<IConditionalTickable>>(
private val preWorldTickOnce = WeakHashMap<Level, ArrayList<ITickable>>()
private val postWorldTickOnce = WeakHashMap<Level, ArrayList<ITickable>>()
// 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
}
}

View File

@ -57,6 +57,6 @@ class CargoCrateBlock : RotatableMatteryBlock(), EntityBlock {
companion object {
@JvmField
val IS_OPEN = BooleanProperty.create("open")
val IS_OPEN: BooleanProperty = BooleanProperty.create("open")
}
}

View File

@ -42,6 +42,6 @@ class DriveViewerBlock : RotatableMatteryBlock(), EntityBlock {
}
companion object {
val DRIVE_PRESENT = BooleanProperty.create("drive")
val DRIVE_PRESENT: BooleanProperty = BooleanProperty.create("drive")
}
}

View File

@ -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()
}
}

View File

@ -98,6 +98,6 @@ class MatterPanelBlock : MatteryBlock(), EntityBlock {
}
companion object {
val FACING = EnumProperty.create("facing", Direction::class.java)
val FACING: EnumProperty<Direction> = EnumProperty.create("facing", Direction::class.java)
}
}

View File

@ -120,7 +120,7 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope
companion object {
@JvmField
val FACING = EnumProperty.create(
val FACING: EnumProperty<Direction> = 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<Direction> = EnumProperty.create("facing", Direction::class.java)
}
}

View File

@ -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)
}
}

View File

@ -125,6 +125,7 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl
val ref = WeakReference(this)
resolver.addListener {
if (!SERVER_IS_DYING)
ref.get()?.checkSurroundings()
}
}

View File

@ -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(

View File

@ -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,9 +374,10 @@ 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)
component = ItemHandlerComponent(storage.orThrow())

View File

@ -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) {

View File

@ -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())

View File

@ -10,7 +10,7 @@ class GraphFlooder<T>(val startNode: Graph6Node<T>, @JvmField val seen: Int = ne
private val _nodes = ArrayList<Graph6Node<T>>()
@JvmField
val nodes = Collections.unmodifiableCollection(_nodes)
val nodes = Collections.unmodifiableCollection(_nodes)!!
fun size() = _nodes.size

View File

@ -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)) {

View File

@ -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"

View File

@ -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<Item>, value: ImpreciseFraction, complexity: Double = defaultComplexity(value)) {
for (item in tag.stream().iterator()) {
make(item, value, complexity)
}
}
private fun make(tag: Tag<Item>, value: ImpreciseFraction, complexity: Double = defaultComplexity(value)) {
for (item in tag.values) {
make(item, value, complexity)
}
}
private fun make(tag: TagKey<Item>, 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(" -> "))

View File

@ -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

View File

@ -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<T, V> : ReadOnlyProperty<T, V> {
private var value: V? = null
private class RegistryDelegate<V>(private val name: String) {
private var value: Supplier<V>? = 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<V>) {
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<T, V> : ReadOnlyProperty<T, V> {
}
object MRegistry {
private val features = WriteOnceReadMany<MRegistry, ForgeRegistry<AndroidFeatureType<*>>>()
private val research = WriteOnceReadMany<MRegistry, ForgeRegistry<AndroidResearchType<*>>>()
private val features = RegistryDelegate<IForgeRegistry<AndroidFeatureType<*>>>("ANDROID_FEATURES")
private val research = RegistryDelegate<IForgeRegistry<AndroidResearchType<*>>>("ANDROID_RESEARCH")
val ANDROID_FEATURES by features
val ANDROID_RESEARCH by research
val ANDROID_FEATURES get() = features.get() as ForgeRegistry<AndroidFeatureType<*>>
val ANDROID_RESEARCH get() = research.get() as ForgeRegistry<AndroidResearchType<*>>
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<AndroidFeatureType<*>>().let {
it.setName(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_features"))
it.type = AndroidFeatureType::class.java
it.create() as ForgeRegistry<AndroidFeatureType<*>>
event.create(it)
})
research.write(RegistryBuilder<AndroidResearchType<*>>().let {
it.setName(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research"))
it.type = AndroidResearchType::class.java
it.create() as ForgeRegistry<AndroidResearchType<*>>
event.create(it)
})
}

View File

@ -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<Item> = ItemTags.create(ResourceLocation("forge", "ingots/tritanium"))
val PLATE_TRITANIUM: TagKey<Item> = ItemTags.create(ResourceLocation("forge", "plates/tritanium"))
}

View File

@ -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"