From 86c170be8a59910dfabad7fe0b3e24450fbc1d70 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 30 Jan 2022 20:47:50 +0700 Subject: [PATCH] Some un-static'ing --- .../mc/otm/OverdriveThatMatters.java | 88 +++--------------- .../dbotthepony/mc/otm/registry/MItems.java | 12 +-- .../dbotthepony/mc/otm/registry/Registry.java | 6 +- .../kotlin/ru/dbotthepony/mc/otm/Ticker.kt | 89 +++++++++++++++++++ .../mc/otm/block/BlockChemicalGenerator.kt | 4 +- .../otm/block/BlockGravitationStabilizer.kt | 25 +++--- .../entity/BlockEntityChemicalGenerator.kt | 10 +-- .../block/entity/BlockEntityDriveViewer.kt | 47 ++++------ .../block/entity/BlockEntityEnergyCounter.kt | 6 +- .../mc/otm/block/entity/BlockEntityMattery.kt | 20 ++--- .../mc/otm/graph/Abstract6Graph.kt | 3 +- .../ru/dbotthepony/mc/otm/item/ItemBattery.kt | 4 +- .../mc/otm/item/ItemGravitationalDisruptor.kt | 2 +- .../mc/otm/item/ItemMatterCapacitor.kt | 4 +- .../dbotthepony/mc/otm/item/ItemMatterDust.kt | 2 +- .../mc/otm/item/ItemPatternStorage.kt | 4 +- .../ru/dbotthepony/mc/otm/item/ItemPill.kt | 4 +- .../otm/item/ItemPortableCondensationDrive.kt | 2 +- .../item/ItemPortableGravitationStabilizer.kt | 2 +- .../mc/otm/item/ItemTritaniumArmor.kt | 2 +- 20 files changed, 171 insertions(+), 165 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index d7c61fd9f..cc0cf4e2b 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -46,87 +46,24 @@ import java.util.function.Supplier; @Mod(OverdriveThatMatters.MOD_ID) @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -public class OverdriveThatMatters { +public final class OverdriveThatMatters { // Directly reference a log4j logger. public static final String MOD_ID = "overdrive_that_matters"; public static final Logger LOGGER = LogManager.getLogger(); - public static AndroidGui ANDROID_GUI; + public static OverdriveThatMatters INSTANCE; + public AndroidGui ANDROID_GUI; + public StorageObjectTuple ITEM_STORAGE; - public static CreativeModeTab CREATIVE_TAB; - - // why no LinkedList? - // because you can't get nodes directly, which is vital in getting this thing working faster. - private static final WeakHashMap>> tick_until = new WeakHashMap<>(); - private static final WeakHashMap>> tick_once = new WeakHashMap<>(); - - @SubscribeEvent(priority = EventPriority.HIGHEST) - @SuppressWarnings("unused") - public void onServerStarting(ServerAboutToStartEvent event) { - tick_until.clear(); - } - - @SubscribeEvent(priority = EventPriority.HIGHEST) - @SuppressWarnings("unused") - public void onServerStopping(ServerStoppingEvent event) { - tick_until.clear(); - } - - @SubscribeEvent(priority = EventPriority.LOWEST) - @SuppressWarnings("unused") - public void onPreTick(TickEvent.WorldTickEvent event) { - if (event.phase != TickEvent.Phase.START || event.side != LogicalSide.SERVER) - return; - - // удаляем список сразу что бы если кто-либо добавит туда элементы у нас была "копия" - final var until = tick_until.remove(event.world); - - if (until != null) { - for (int i = until.size() - 1; i >= 0; i--) { - if (until.get(i).get()) { - until.remove(i); - } - } - - if (until.size() != 0) { - final var replaced = tick_until.put(event.world, until); - - if (replaced != null) { - until.addAll(replaced); - } - } + public final CreativeModeTab CREATIVE_TAB = new CreativeModeTab("otm") { + @Override + public ItemStack makeIcon() { + return new ItemStack(MItems.BATTERY_CREATIVE, 1); } - - final var once = tick_once.remove(event.world); - - if (once != null) { - ArrayList> invalid = new ArrayList<>(); - - for (var ticker : once) { - ticker.accept(event.world); - } - } - } - - public static void tickUntil(Level level, Supplier ticker) { - tick_until.computeIfAbsent(level, (k) -> new ArrayList<>()).add(ticker); - } - - public static void tickOnceSelf(Level level, Consumer ticker) { - tick_once.computeIfAbsent(level, (k) -> new ArrayList<>()).add(ticker); - } - - public static void tickOnce(Level level, Runnable ticker) { - tick_once.computeIfAbsent(level, (k) -> new ArrayList<>()).add((l) -> ticker.run()); - } + }; public OverdriveThatMatters() { - CREATIVE_TAB = new CreativeModeTab("otm") { - @Override - public ItemStack makeIcon() { - return new ItemStack(MItems.BATTERY_CREATIVE, 1); - } - }; + INSTANCE = this; // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); @@ -134,6 +71,7 @@ public class OverdriveThatMatters { // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(TickerKt.class); MinecraftForge.EVENT_BUS.register(AndroidCapabilityPlayer.Companion); MinecraftForge.EVENT_BUS.register(AndroidCapability.Companion); MinecraftForge.EVENT_BUS.register(MatterRegistryKt.class); @@ -156,14 +94,10 @@ public class OverdriveThatMatters { FMLJavaModLoadingContext.get().getModEventBus().addListener(AndroidCapability::registerEffects); - // LOGGER.info("Registered event handlers"); - // force Registry static initializer to be called Registry.dummy(); } - public static StorageObjectTuple ITEM_STORAGE; - private void setup(final FMLCommonSetupEvent event) { MatteryNetworking.register(); // LOGGER.info("Registered network"); diff --git a/src/main/java/ru/dbotthepony/mc/otm/registry/MItems.java b/src/main/java/ru/dbotthepony/mc/otm/registry/MItems.java index 0a4393fa3..1991fceed 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/registry/MItems.java +++ b/src/main/java/ru/dbotthepony/mc/otm/registry/MItems.java @@ -23,12 +23,12 @@ import java.util.List; public class MItems { static { - if (OverdriveThatMatters.CREATIVE_TAB == null) { + if (OverdriveThatMatters.INSTANCE == null) { throw new ConcurrentModificationException("Accessing Registry before OverdriveThatMatters class is initialized. This is not supported! If no other mods are installed this is a bug."); } } - private static final Item.Properties DEFAULT_PROPERTIES = new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB); + private static final Item.Properties DEFAULT_PROPERTIES = new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB); public static final BlockItem ANDROID_STATION = new BlockItem(MBlocks.ANDROID_STATION, DEFAULT_PROPERTIES); public static final BlockItem BATTERY_BANK = new BlockItem(MBlocks.BATTERY_BANK, DEFAULT_PROPERTIES); @@ -87,7 +87,7 @@ public class MItems { ); } - private static final Item.Properties TOOLS_PROPRTIES = new Item.Properties().tab(OverdriveThatMatters.CREATIVE_TAB); + private static final Item.Properties TOOLS_PROPRTIES = new Item.Properties().tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB); public static final SwordItem TRITANIUM_SWORD = new SwordItem(TRITANIUM_COMPONENT, 4, -2.7f, TOOLS_PROPRTIES); public static final ShovelItem TRITANIUM_SHOVEL = new ShovelItem(TRITANIUM_COMPONENT, 1.5f, -2.4f, TOOLS_PROPRTIES); public static final AxeItem TRITANIUM_AXE = new AxeItem(TRITANIUM_COMPONENT, 8.5f, -3.4f, TOOLS_PROPRTIES); @@ -166,7 +166,7 @@ public class MItems { BATTERY_CAPACITOR, }; - public static final Item MATTER_CAPACITOR_PARTS = new Item(new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); + public static final Item MATTER_CAPACITOR_PARTS = new Item(new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)); public static final Item[] DATAGEN_COMPONENTS = { ENERGY_BUS, @@ -194,7 +194,7 @@ public class MItems { public static final ItemPortableCondensationDrive PORTABLE_CONDENSATION_DRIVE = new ItemPortableCondensationDrive(4000); public static final ItemPortableCondensationDrive PORTABLE_DENSE_CONDENSATION_DRIVE = new ItemPortableCondensationDrive(25000); - public static final Item NUTRIENT_PASTE = new Item(new Item.Properties().stacksTo(64).food(new FoodProperties.Builder().meat().nutrition(8).saturationMod(0.9F).build()).tab(OverdriveThatMatters.CREATIVE_TAB)); + public static final Item NUTRIENT_PASTE = new Item(new Item.Properties().stacksTo(64).food(new FoodProperties.Builder().meat().nutrition(8).saturationMod(0.9F).build()).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)); public static final Item[] CRATES = new Item[Registry.CRATES.length]; @@ -204,7 +204,7 @@ public class MItems { static { for (int i = 0; i < Registry.CRATES.length; i++) { - CRATES[i] = new BlockItem(MBlocks.CRATES[i], new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); + CRATES[i] = new BlockItem(MBlocks.CRATES[i], new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)); CRATES[i].setRegistryName(Registry.CRATES[i].name()); } diff --git a/src/main/java/ru/dbotthepony/mc/otm/registry/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/registry/Registry.java index 5978ac23b..192427916 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/registry/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/registry/Registry.java @@ -44,7 +44,7 @@ import java.util.Set; public class Registry { static { - if (OverdriveThatMatters.CREATIVE_TAB == null) { + if (OverdriveThatMatters.INSTANCE == null) { throw new ConcurrentModificationException("Accessing Registry before OverdriveThatMatters class is initialized. This is not supported! If no other mods are installed this is a bug."); } } @@ -119,8 +119,8 @@ public class Registry { IndustrialGlassProps(@Nullable DyeColor color, ResourceLocation name, ResourceLocation namePane, Block block, Block pane) { this(color, name, namePane, block, pane, - new BlockItem(block, new Item.Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(64)), - new BlockItem(pane, new Item.Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(64))); + new BlockItem(block, new Item.Properties().tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB).stacksTo(64)), + new BlockItem(pane, new Item.Properties().tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB).stacksTo(64))); } IndustrialGlassProps(@Nullable DyeColor color, ResourceLocation name, ResourceLocation namePane) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt new file mode 100644 index 000000000..c996c767a --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt @@ -0,0 +1,89 @@ +package ru.dbotthepony.mc.otm + +import net.minecraft.client.multiplayer.ClientLevel +import net.minecraft.server.level.ServerLevel +import net.minecraft.world.level.Level +import net.minecraftforge.event.TickEvent +import net.minecraftforge.event.TickEvent.WorldTickEvent +import net.minecraftforge.event.server.ServerAboutToStartEvent +import net.minecraftforge.event.server.ServerStoppingEvent +import net.minecraftforge.eventbus.api.EventPriority +import net.minecraftforge.eventbus.api.SubscribeEvent +import net.minecraftforge.fml.LogicalSide +import java.util.* +import java.util.function.Consumer +import java.util.function.Supplier + +private val tick_until = WeakHashMap>>() +private val tick_once = WeakHashMap>() + +@SubscribeEvent(priority = EventPriority.HIGHEST) +@Suppress("unused") +fun onServerStarting(event: ServerAboutToStartEvent?) { + tick_until.clear() +} + +@SubscribeEvent(priority = EventPriority.HIGHEST) +@Suppress("unused") +fun onServerStopping(event: ServerStoppingEvent?) { + tick_until.clear() +} + +@SubscribeEvent(priority = EventPriority.LOWEST) +@Suppress("unused") +fun onPreTick(event: WorldTickEvent) { + if (event.phase != TickEvent.Phase.START || event.side != LogicalSide.SERVER) return + + // удаляем список сразу что бы если кто-либо добавит туда элементы у нас была "копия" + val until = tick_until.remove(event.world) + + if (until != null) { + for (i in until.indices.reversed()) { + if (until[i].get()) { + until.removeAt(i) + } + } + + if (until.size != 0) { + val replaced = tick_until.put(event.world, until) + + if (replaced != null) { + until.addAll(replaced) + } + } + } + + val once = tick_once.remove(event.world) + + if (once != null) + for (ticker in once) + ticker.run() +} + +fun tickUntil(level: Level, ticker: Supplier) { + tick_until.computeIfAbsent(level) { ArrayList() }.add(ticker) +} + +fun tickUntilServer(level: Level, ticker: Supplier) { + if (level is ServerLevel) + tick_until.computeIfAbsent(level) { ArrayList() }.add(ticker) +} + +fun tickUntilClient(level: Level, ticker: Supplier) { + if (level is ClientLevel) + tick_until.computeIfAbsent(level) { ArrayList() }.add(ticker) +} + +fun tickOnce(level: Level, ticker: Runnable) { + tick_once.computeIfAbsent(level) { ArrayList() }.add(ticker) +} + +fun tickOnceServer(level: Level, ticker: Runnable) { + if (level is ServerLevel) + tick_once.computeIfAbsent(level) { ArrayList() }.add(ticker) +} + +fun tickOnceClient(level: Level, ticker: Runnable) { + if (level is ClientLevel) + tick_once.computeIfAbsent(level) { ArrayList() }.add(ticker) +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockChemicalGenerator.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockChemicalGenerator.kt index bcf245df1..eae0aa67a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockChemicalGenerator.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockChemicalGenerator.kt @@ -19,6 +19,8 @@ import ru.dbotthepony.mc.otm.block.entity.BlockEntityChemicalGenerator import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes +import ru.dbotthepony.mc.otm.tickOnce +import ru.dbotthepony.mc.otm.tickOnceServer class BlockChemicalGenerator : BlockMatteryRotatable(), EntityBlock { override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity { @@ -55,7 +57,7 @@ class BlockChemicalGenerator : BlockMatteryRotatable(), EntityBlock { val tile = level.getBlockEntity(pos) if (tile is BlockEntityChemicalGenerator) { - OverdriveThatMatters.tickOnce(level) { + tickOnceServer(level) { tile.checkSurroundings() } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockGravitationStabilizer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockGravitationStabilizer.kt index 7f7c499c3..abad258bf 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockGravitationStabilizer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockGravitationStabilizer.kt @@ -31,6 +31,7 @@ import ru.dbotthepony.mc.otm.core.times import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlocks import ru.dbotthepony.mc.otm.shapes.BlockShapes +import ru.dbotthepony.mc.otm.tickOnceServer import kotlin.math.PI private val props = BlockBehaviour.Properties.of(Material.STONE, MaterialColor.COLOR_BLUE).requiresCorrectToolForDrops().strength(3f, 600.0f) @@ -120,14 +121,12 @@ class BlockGravitationStabilizer : BlockMatteryRotatable(props), EntityBlock { ) { super.neighborChanged(state, level, pos, sender, sender_pos, flag) - if (!level.isClientSide) { - OverdriveThatMatters.tickOnce(level) { - if (level.getBlockState(pos).block !is BlockGravitationStabilizer) return@tickOnce + tickOnceServer(level) { + if (level.getBlockState(pos).block !is BlockGravitationStabilizer) return@tickOnceServer - val bb = getBoundingBlock(level, state, pos) - if (bb.block !is BlockGravitationStabilizerLens) { - level.setBlock(pos, Blocks.AIR.defaultBlockState(), UPDATE_ALL) - } + val bb = getBoundingBlock(level, state, pos) + if (bb.block !is BlockGravitationStabilizerLens) { + level.setBlock(pos, Blocks.AIR.defaultBlockState(), UPDATE_ALL) } } } @@ -183,14 +182,12 @@ class BlockGravitationStabilizerLens : BlockMatteryRotatable(props) { ) { super.neighborChanged(state, level, pos, sender, sender_pos, flag) - if (!level.isClientSide) { - OverdriveThatMatters.tickOnce(level) { - if (level.getBlockState(pos).block !is BlockGravitationStabilizerLens) return@tickOnce + tickOnceServer(level) { + if (level.getBlockState(pos).block !is BlockGravitationStabilizerLens) return@tickOnceServer - val bb = getBoundingBlock(level, state, pos) - if (bb.block !is BlockGravitationStabilizer) { - level.setBlock(pos, Blocks.AIR.defaultBlockState(), UPDATE_ALL) - } + val bb = getBoundingBlock(level, state, pos) + if (bb.block !is BlockGravitationStabilizer) { + level.setBlock(pos, Blocks.AIR.defaultBlockState(), UPDATE_ALL) } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityChemicalGenerator.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityChemicalGenerator.kt index c3e40ec3a..9cdbd35de 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityChemicalGenerator.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityChemicalGenerator.kt @@ -76,10 +76,7 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti override fun setLevel(level: Level) { super.setLevel(level) - - if (level is ServerLevel) { - OverdriveThatMatters.tickOnce(level, this::checkSurroundings) - } + tickOnceServer(this::checkSurroundings) } override fun saveAdditional(nbt: CompoundTag) { @@ -159,9 +156,8 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti override fun setBlockState(p_155251_: BlockState) { super.setBlockState(p_155251_) - if (valid && level is ServerLevel) { - OverdriveThatMatters.tickOnce(level!!, this::checkSurroundings) - } + if (valid) + tickOnceServer(this::checkSurroundings) } var workingTicks = 0 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityDriveViewer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityDriveViewer.kt index b5efaa220..5260e6ab4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityDriveViewer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityDriveViewer.kt @@ -28,23 +28,17 @@ class BlockEntityDriveViewer(p_155229_: BlockPos, p_155230_: BlockState) : Block override fun setChanged() { super.setChanged() - val level = level + tickOnceServer { + var state = blockState - if (level != null) { - OverdriveThatMatters.tickOnceSelf(level) { - if (isRemoved) return@tickOnceSelf + if (container.getItem(0).getCapability(MatteryCapability.DRIVE).isPresent && energy.batteryLevel >= OverdriveThatMatters.INSTANCE.ITEM_STORAGE.energyPerOperation()) { + state = state.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING) + } else { + state = state.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE) + } - var state = blockState - - if (container.getItem(0).getCapability(MatteryCapability.DRIVE).isPresent && energy.batteryLevel >= OverdriveThatMatters.ITEM_STORAGE.energyPerOperation()) { - state = state.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING) - } else { - state = state.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE) - } - - if (state !== blockState) { - it.setBlock(blockPos, state, Block.UPDATE_CLIENTS) - } + if (state !== blockState) { + it.setBlock(blockPos, state, Block.UPDATE_CLIENTS) } } } @@ -56,21 +50,18 @@ class BlockEntityDriveViewer(p_155229_: BlockPos, p_155230_: BlockState) : Block override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { super.setChanged(slot, new, old) - val level = level - if (level != null) { - OverdriveThatMatters.tickOnceSelf(level) { - if (!isRemoved) { - var state = blockState + tickOnceServer { + if (!isRemoved) { + var state = blockState - if (new.getCapability(MatteryCapability.DRIVE).isPresent) { - state = state.setValue(BlockDriveViewer.DRIVE_PRESENT, true) - } else { - state = state.setValue(BlockDriveViewer.DRIVE_PRESENT, false) - } + if (new.getCapability(MatteryCapability.DRIVE).isPresent) { + state = state.setValue(BlockDriveViewer.DRIVE_PRESENT, true) + } else { + state = state.setValue(BlockDriveViewer.DRIVE_PRESENT, false) + } - if (state !== blockState) { - level.setBlock(blockPos, state, Block.UPDATE_CLIENTS) - } + if (state !== blockState) { + it.setBlock(blockPos, state, Block.UPDATE_CLIENTS) } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityEnergyCounter.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityEnergyCounter.kt index 858cfa878..0227c9879 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityEnergyCounter.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityEnergyCounter.kt @@ -167,11 +167,7 @@ class BlockEntityEnergyCounter(p_155229_: BlockPos, p_155230_: BlockState) : Blo override fun setLevel(p_155231_: Level) { super.setLevel(p_155231_) - - val level = level - if (level is ServerLevel) { - OverdriveThatMatters.tickOnce(level) { checkSurroundings(level) } - } + tickOnceServer(this::checkSurroundings) } private inner class EnergyCounterCap(val is_input: Boolean) : IMatteryEnergyStorage { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMattery.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMattery.kt index 3e65726ca..ed14ee063 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMattery.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMattery.kt @@ -73,32 +73,32 @@ abstract class BlockEntityMattery(p_155228_: BlockEntityType<*>, p_155229_: Bloc protected fun tickOnce(func: Runnable) { val level = level - if (level != null) OverdriveThatMatters.tickOnce(level, func) - } + if (level != null) ru.dbotthepony.mc.otm.tickOnce(level) { if (!isRemoved) func.run() } + } protected fun tickOnceServer(func: Runnable) { val level = level - if (level is ServerLevel) OverdriveThatMatters.tickOnce(level, func) + if (level is ServerLevel) ru.dbotthepony.mc.otm.tickOnce(level) { if (!isRemoved) func.run() } } protected fun tickOnceClient(func: Runnable) { val level = level - if (level is ClientLevel) OverdriveThatMatters.tickOnce(level, func) + if (level is ClientLevel) ru.dbotthepony.mc.otm.tickOnce(level) { if (!isRemoved) func.run() } } - protected fun tickOnce(func: Consumer) { + protected fun tickOnce(func: (Level) -> Unit) { val level = level - if (level != null) OverdriveThatMatters.tickOnceSelf(level, func) + if (level != null) ru.dbotthepony.mc.otm.tickOnce(level) { if (!isRemoved) func(level) } } - protected fun tickOnceServer(func: Consumer) { + protected fun tickOnceServer(func: (ServerLevel) -> Unit) { val level = level - if (level is ServerLevel) OverdriveThatMatters.tickOnceSelf(level, func) + if (level is ServerLevel) ru.dbotthepony.mc.otm.tickOnce(level) { if (!isRemoved) func(level) } } - protected fun tickOnceClient(func: Consumer) { + protected fun tickOnceClient(func: (ClientLevel) -> Unit) { val level = level - if (level is ClientLevel) OverdriveThatMatters.tickOnceSelf(level, func) + if (level is ClientLevel) ru.dbotthepony.mc.otm.tickOnce(level) { if (!isRemoved) func(level) } } protected fun getAndBind( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/Abstract6Graph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/Abstract6Graph.kt index 7b3b2f983..93618fa88 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/Abstract6Graph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/Abstract6Graph.kt @@ -7,6 +7,7 @@ import net.minecraft.server.level.ServerLevel import net.minecraft.world.level.block.entity.BlockEntity import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.core.plus +import ru.dbotthepony.mc.otm.tickUntil import java.util.* import kotlin.collections.ArrayList @@ -64,7 +65,7 @@ abstract class Abstract6Graph { nodeGetter: (BlockEntity) -> Graph6Node?, factory: () -> Abstract6Graph ) { - OverdriveThatMatters.tickUntil(level) { + tickUntil(level) { !node.valid || discover(level, blockPos, node, nodeGetter, factory) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemBattery.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemBattery.kt index c52327e38..960212ea7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemBattery.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemBattery.kt @@ -101,7 +101,7 @@ class ItemBattery : Item { private val throughputText: Component constructor(storage: ImpreciseFraction, receive: ImpreciseFraction, extract: ImpreciseFraction) : super( - Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB) + Properties().stacksTo(1).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB) ) { isCreative = false this.storage = storage @@ -114,7 +114,7 @@ class ItemBattery : Item { ).withStyle(ChatFormatting.GRAY) } - constructor() : super(Properties().stacksTo(1).rarity(Rarity.EPIC).tab(OverdriveThatMatters.CREATIVE_TAB)) { + constructor() : super(Properties().stacksTo(1).rarity(Rarity.EPIC).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) { isCreative = true storage = ImpreciseFraction.LONG_MAX_VALUE receive = ImpreciseFraction.LONG_MAX_VALUE diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemGravitationalDisruptor.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemGravitationalDisruptor.kt index b892a60ae..1dffe90f0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemGravitationalDisruptor.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemGravitationalDisruptor.kt @@ -12,7 +12,7 @@ import net.minecraft.world.item.Rarity import net.minecraft.world.level.Level class ItemGravitationalDisruptor : - Item(Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1).rarity(Rarity.EPIC)) { + Item(Properties().tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB).stacksTo(1).rarity(Rarity.EPIC)) { override fun appendHoverText( p_41421_: ItemStack, p_41422_: Level?, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemMatterCapacitor.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemMatterCapacitor.kt index 331586d97..a2c5dd90a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemMatterCapacitor.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemMatterCapacitor.kt @@ -93,12 +93,12 @@ class ItemMatterCapacitor : Item { val storage: ImpreciseFraction private val isCreative: Boolean - constructor(storage: ImpreciseFraction) : super(Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB)) { + constructor(storage: ImpreciseFraction) : super(Properties().stacksTo(1).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) { isCreative = false this.storage = storage } - constructor() : super(Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB).rarity(Rarity.EPIC)) { + constructor() : super(Properties().stacksTo(1).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB).rarity(Rarity.EPIC)) { isCreative = true storage = ImpreciseFraction.LONG_MAX_VALUE } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemMatterDust.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemMatterDust.kt index 278d8a7f1..426616f6e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemMatterDust.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemMatterDust.kt @@ -13,7 +13,7 @@ import ru.dbotthepony.mc.otm.matter.IMatterItem import ru.dbotthepony.mc.otm.matter.MatterTuple import ru.dbotthepony.mc.otm.set -class ItemMatterDust : Item(Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(64)), IMatterItem { +class ItemMatterDust : Item(Properties().tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB).stacksTo(64)), IMatterItem { private fun matter(stack: ItemStack): ImpreciseFraction { return stack.tag?.get("matter")?.let { return@let ImpreciseFraction.deserializeNBT(it) } ?: return ImpreciseFraction.ZERO } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPatternStorage.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPatternStorage.kt index 79ee84595..1189bdef3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPatternStorage.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPatternStorage.kt @@ -23,12 +23,12 @@ class ItemPatternStorage : Item { val capacity: Int var isCreative: Boolean - constructor(capacity: Int) : super(Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1)) { + constructor(capacity: Int) : super(Properties().tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB).stacksTo(1)) { this.capacity = capacity isCreative = false } - constructor() : super(Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1)) { + constructor() : super(Properties().tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB).stacksTo(1)) { isCreative = true capacity = Int.MAX_VALUE } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPill.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPill.kt index 30e5c4d67..c82881f2c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPill.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPill.kt @@ -21,7 +21,7 @@ enum class PillType { BECOME_ANDROID, BECOME_HUMANE, OBLIVION } -class ItemPillHeal : Item(Properties().stacksTo(64).rarity(Rarity.UNCOMMON).tab(OverdriveThatMatters.CREATIVE_TAB)) { +class ItemPillHeal : Item(Properties().stacksTo(64).rarity(Rarity.UNCOMMON).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) { override fun getUseDuration(p_41454_: ItemStack): Int { return 24 } @@ -66,7 +66,7 @@ class ItemPillHeal : Item(Properties().stacksTo(64).rarity(Rarity.UNCOMMON).tab( } class ItemPill(val pillType: PillType) : - Item(Properties().stacksTo(64).rarity(Rarity.UNCOMMON).tab(OverdriveThatMatters.CREATIVE_TAB)) { + Item(Properties().stacksTo(64).rarity(Rarity.UNCOMMON).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) { override fun getUseDuration(p_41454_: ItemStack): Int { return 32 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPortableCondensationDrive.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPortableCondensationDrive.kt index 0c9fd180c..ae3b3a31a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPortableCondensationDrive.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPortableCondensationDrive.kt @@ -30,7 +30,7 @@ import ru.dbotthepony.mc.otm.set import java.util.* class ItemPortableCondensationDrive(capacity: Int) : - Item(Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB)) { + Item(Properties().stacksTo(1).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) { val capacity: ImpreciseFraction init { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPortableGravitationStabilizer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPortableGravitationStabilizer.kt index dec4b3aaa..a0110f0de 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPortableGravitationStabilizer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemPortableGravitationStabilizer.kt @@ -38,7 +38,7 @@ private object GravitationStabilizerArmorRenderProperties : IItemRenderPropertie } } -class ItemPortableGravitationStabilizer : ArmorItem(GravitationStabilizerArmorMaterial, EquipmentSlot.CHEST, Properties().stacksTo(1).rarity(Rarity.RARE).tab(OverdriveThatMatters.CREATIVE_TAB)) { +class ItemPortableGravitationStabilizer : ArmorItem(GravitationStabilizerArmorMaterial, EquipmentSlot.CHEST, Properties().stacksTo(1).rarity(Rarity.RARE).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) { override fun initializeClient(consumer: Consumer) { super.initializeClient(consumer) consumer.accept(GravitationStabilizerArmorRenderProperties) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemTritaniumArmor.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemTritaniumArmor.kt index 5d43a2fd1..ab785c2c8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemTritaniumArmor.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ItemTritaniumArmor.kt @@ -67,7 +67,7 @@ private object TritaniumArmorRenderProperties : IItemRenderProperties { } } -class ItemTritaniumArmor(slot: EquipmentSlot) : ArmorItem(TritaniumArmorMaterial, slot, Properties().stacksTo(1).rarity(Rarity.RARE).tab(OverdriveThatMatters.CREATIVE_TAB)) { +class ItemTritaniumArmor(slot: EquipmentSlot) : ArmorItem(TritaniumArmorMaterial, slot, Properties().stacksTo(1).rarity(Rarity.RARE).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) { override fun initializeClient(consumer: Consumer) { super.initializeClient(consumer) consumer.accept(TritaniumArmorRenderProperties)