Some un-static'ing
This commit is contained in:
parent
bb606f3c8d
commit
86c170be8a
@ -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<ItemStackWrapper> 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<Level, ArrayList<Supplier<Boolean>>> tick_until = new WeakHashMap<>();
|
||||
private static final WeakHashMap<Level, ArrayList<Consumer<Level>>> 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<Supplier<Boolean>> invalid = new ArrayList<>();
|
||||
|
||||
for (var ticker : once) {
|
||||
ticker.accept(event.world);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void tickUntil(Level level, Supplier<Boolean> ticker) {
|
||||
tick_until.computeIfAbsent(level, (k) -> new ArrayList<>()).add(ticker);
|
||||
}
|
||||
|
||||
public static void tickOnceSelf(Level level, Consumer<Level> 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<ItemStackWrapper> ITEM_STORAGE;
|
||||
|
||||
private void setup(final FMLCommonSetupEvent event) {
|
||||
MatteryNetworking.register();
|
||||
// LOGGER.info("Registered network");
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
89
src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt
Normal file
89
src/main/kotlin/ru/dbotthepony/mc/otm/Ticker.kt
Normal file
@ -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<Level, ArrayList<Supplier<Boolean>>>()
|
||||
private val tick_once = WeakHashMap<Level, ArrayList<Runnable>>()
|
||||
|
||||
@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<Boolean>) {
|
||||
tick_until.computeIfAbsent(level) { ArrayList() }.add(ticker)
|
||||
}
|
||||
|
||||
fun tickUntilServer(level: Level, ticker: Supplier<Boolean>) {
|
||||
if (level is ServerLevel)
|
||||
tick_until.computeIfAbsent(level) { ArrayList() }.add(ticker)
|
||||
}
|
||||
|
||||
fun tickUntilClient(level: Level, ticker: Supplier<Boolean>) {
|
||||
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)
|
||||
}
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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<Level>) {
|
||||
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<Level>) {
|
||||
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<Level>) {
|
||||
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 <T> getAndBind(
|
||||
|
@ -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<T> {
|
||||
nodeGetter: (BlockEntity) -> Graph6Node<T>?,
|
||||
factory: () -> Abstract6Graph<T>
|
||||
) {
|
||||
OverdriveThatMatters.tickUntil(level) {
|
||||
tickUntil(level) {
|
||||
!node.valid || discover(level, blockPos, node, nodeGetter, factory)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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?,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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<IItemRenderProperties>) {
|
||||
super.initializeClient(consumer)
|
||||
consumer.accept(GravitationStabilizerArmorRenderProperties)
|
||||
|
@ -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<IItemRenderProperties>) {
|
||||
super.initializeClient(consumer)
|
||||
consumer.accept(TritaniumArmorRenderProperties)
|
||||
|
Loading…
Reference in New Issue
Block a user