Some un-static'ing
This commit is contained in:
parent
bb606f3c8d
commit
86c170be8a
@ -46,94 +46,32 @@ import java.util.function.Supplier;
|
|||||||
@Mod(OverdriveThatMatters.MOD_ID)
|
@Mod(OverdriveThatMatters.MOD_ID)
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
public class OverdriveThatMatters {
|
public final class OverdriveThatMatters {
|
||||||
// Directly reference a log4j logger.
|
// Directly reference a log4j logger.
|
||||||
public static final String MOD_ID = "overdrive_that_matters";
|
public static final String MOD_ID = "overdrive_that_matters";
|
||||||
public static final Logger LOGGER = LogManager.getLogger();
|
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;
|
public final CreativeModeTab CREATIVE_TAB = new CreativeModeTab("otm") {
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public ItemStack makeIcon() {
|
public ItemStack makeIcon() {
|
||||||
return new ItemStack(MItems.BATTERY_CREATIVE, 1);
|
return new ItemStack(MItems.BATTERY_CREATIVE, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public OverdriveThatMatters() {
|
||||||
|
INSTANCE = this;
|
||||||
|
|
||||||
// Register the setup method for modloading
|
// Register the setup method for modloading
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient);
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient);
|
||||||
|
|
||||||
// Register ourselves for server and other game events we are interested in
|
// Register ourselves for server and other game events we are interested in
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
MinecraftForge.EVENT_BUS.register(TickerKt.class);
|
||||||
MinecraftForge.EVENT_BUS.register(AndroidCapabilityPlayer.Companion);
|
MinecraftForge.EVENT_BUS.register(AndroidCapabilityPlayer.Companion);
|
||||||
MinecraftForge.EVENT_BUS.register(AndroidCapability.Companion);
|
MinecraftForge.EVENT_BUS.register(AndroidCapability.Companion);
|
||||||
MinecraftForge.EVENT_BUS.register(MatterRegistryKt.class);
|
MinecraftForge.EVENT_BUS.register(MatterRegistryKt.class);
|
||||||
@ -156,14 +94,10 @@ public class OverdriveThatMatters {
|
|||||||
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(AndroidCapability::registerEffects);
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(AndroidCapability::registerEffects);
|
||||||
|
|
||||||
// LOGGER.info("Registered event handlers");
|
|
||||||
|
|
||||||
// force Registry static initializer to be called
|
// force Registry static initializer to be called
|
||||||
Registry.dummy();
|
Registry.dummy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StorageObjectTuple<ItemStackWrapper> ITEM_STORAGE;
|
|
||||||
|
|
||||||
private void setup(final FMLCommonSetupEvent event) {
|
private void setup(final FMLCommonSetupEvent event) {
|
||||||
MatteryNetworking.register();
|
MatteryNetworking.register();
|
||||||
// LOGGER.info("Registered network");
|
// LOGGER.info("Registered network");
|
||||||
|
@ -23,12 +23,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MItems {
|
public class MItems {
|
||||||
static {
|
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.");
|
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 ANDROID_STATION = new BlockItem(MBlocks.ANDROID_STATION, DEFAULT_PROPERTIES);
|
||||||
public static final BlockItem BATTERY_BANK = new BlockItem(MBlocks.BATTERY_BANK, 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 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 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);
|
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,
|
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 = {
|
public static final Item[] DATAGEN_COMPONENTS = {
|
||||||
ENERGY_BUS,
|
ENERGY_BUS,
|
||||||
@ -194,7 +194,7 @@ public class MItems {
|
|||||||
public static final ItemPortableCondensationDrive PORTABLE_CONDENSATION_DRIVE = new ItemPortableCondensationDrive(4000);
|
public static final ItemPortableCondensationDrive PORTABLE_CONDENSATION_DRIVE = new ItemPortableCondensationDrive(4000);
|
||||||
public static final ItemPortableCondensationDrive PORTABLE_DENSE_CONDENSATION_DRIVE = new ItemPortableCondensationDrive(25000);
|
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];
|
public static final Item[] CRATES = new Item[Registry.CRATES.length];
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ public class MItems {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
for (int i = 0; i < Registry.CRATES.length; i++) {
|
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());
|
CRATES[i].setRegistryName(Registry.CRATES[i].name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class Registry {
|
public class Registry {
|
||||||
static {
|
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.");
|
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) {
|
IndustrialGlassProps(@Nullable DyeColor color, ResourceLocation name, ResourceLocation namePane, Block block, Block pane) {
|
||||||
this(color, name, namePane, block, pane,
|
this(color, name, namePane, block, pane,
|
||||||
new BlockItem(block, 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.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) {
|
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.block.entity.worker.WorkerState
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
||||||
|
import ru.dbotthepony.mc.otm.tickOnce
|
||||||
|
import ru.dbotthepony.mc.otm.tickOnceServer
|
||||||
|
|
||||||
class BlockChemicalGenerator : BlockMatteryRotatable(), EntityBlock {
|
class BlockChemicalGenerator : BlockMatteryRotatable(), EntityBlock {
|
||||||
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
|
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
|
||||||
@ -55,7 +57,7 @@ class BlockChemicalGenerator : BlockMatteryRotatable(), EntityBlock {
|
|||||||
val tile = level.getBlockEntity(pos)
|
val tile = level.getBlockEntity(pos)
|
||||||
|
|
||||||
if (tile is BlockEntityChemicalGenerator) {
|
if (tile is BlockEntityChemicalGenerator) {
|
||||||
OverdriveThatMatters.tickOnce(level) {
|
tickOnceServer(level) {
|
||||||
tile.checkSurroundings()
|
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.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
import ru.dbotthepony.mc.otm.registry.MBlocks
|
||||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
||||||
|
import ru.dbotthepony.mc.otm.tickOnceServer
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
|
|
||||||
private val props = BlockBehaviour.Properties.of(Material.STONE, MaterialColor.COLOR_BLUE).requiresCorrectToolForDrops().strength(3f, 600.0f)
|
private val props = BlockBehaviour.Properties.of(Material.STONE, MaterialColor.COLOR_BLUE).requiresCorrectToolForDrops().strength(3f, 600.0f)
|
||||||
@ -120,9 +121,8 @@ class BlockGravitationStabilizer : BlockMatteryRotatable(props), EntityBlock {
|
|||||||
) {
|
) {
|
||||||
super.neighborChanged(state, level, pos, sender, sender_pos, flag)
|
super.neighborChanged(state, level, pos, sender, sender_pos, flag)
|
||||||
|
|
||||||
if (!level.isClientSide) {
|
tickOnceServer(level) {
|
||||||
OverdriveThatMatters.tickOnce(level) {
|
if (level.getBlockState(pos).block !is BlockGravitationStabilizer) return@tickOnceServer
|
||||||
if (level.getBlockState(pos).block !is BlockGravitationStabilizer) return@tickOnce
|
|
||||||
|
|
||||||
val bb = getBoundingBlock(level, state, pos)
|
val bb = getBoundingBlock(level, state, pos)
|
||||||
if (bb.block !is BlockGravitationStabilizerLens) {
|
if (bb.block !is BlockGravitationStabilizerLens) {
|
||||||
@ -130,7 +130,6 @@ class BlockGravitationStabilizer : BlockMatteryRotatable(props), EntityBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun getShape(
|
override fun getShape(
|
||||||
p_60555_: BlockState,
|
p_60555_: BlockState,
|
||||||
@ -183,9 +182,8 @@ class BlockGravitationStabilizerLens : BlockMatteryRotatable(props) {
|
|||||||
) {
|
) {
|
||||||
super.neighborChanged(state, level, pos, sender, sender_pos, flag)
|
super.neighborChanged(state, level, pos, sender, sender_pos, flag)
|
||||||
|
|
||||||
if (!level.isClientSide) {
|
tickOnceServer(level) {
|
||||||
OverdriveThatMatters.tickOnce(level) {
|
if (level.getBlockState(pos).block !is BlockGravitationStabilizerLens) return@tickOnceServer
|
||||||
if (level.getBlockState(pos).block !is BlockGravitationStabilizerLens) return@tickOnce
|
|
||||||
|
|
||||||
val bb = getBoundingBlock(level, state, pos)
|
val bb = getBoundingBlock(level, state, pos)
|
||||||
if (bb.block !is BlockGravitationStabilizer) {
|
if (bb.block !is BlockGravitationStabilizer) {
|
||||||
@ -193,7 +191,6 @@ class BlockGravitationStabilizerLens : BlockMatteryRotatable(props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun getShape(
|
override fun getShape(
|
||||||
p_60555_: BlockState,
|
p_60555_: BlockState,
|
||||||
|
@ -76,10 +76,7 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
|||||||
|
|
||||||
override fun setLevel(level: Level) {
|
override fun setLevel(level: Level) {
|
||||||
super.setLevel(level)
|
super.setLevel(level)
|
||||||
|
tickOnceServer(this::checkSurroundings)
|
||||||
if (level is ServerLevel) {
|
|
||||||
OverdriveThatMatters.tickOnce(level, this::checkSurroundings)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveAdditional(nbt: CompoundTag) {
|
override fun saveAdditional(nbt: CompoundTag) {
|
||||||
@ -159,9 +156,8 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
|||||||
override fun setBlockState(p_155251_: BlockState) {
|
override fun setBlockState(p_155251_: BlockState) {
|
||||||
super.setBlockState(p_155251_)
|
super.setBlockState(p_155251_)
|
||||||
|
|
||||||
if (valid && level is ServerLevel) {
|
if (valid)
|
||||||
OverdriveThatMatters.tickOnce(level!!, this::checkSurroundings)
|
tickOnceServer(this::checkSurroundings)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var workingTicks = 0
|
var workingTicks = 0
|
||||||
|
@ -28,15 +28,10 @@ class BlockEntityDriveViewer(p_155229_: BlockPos, p_155230_: BlockState) : Block
|
|||||||
override fun setChanged() {
|
override fun setChanged() {
|
||||||
super.setChanged()
|
super.setChanged()
|
||||||
|
|
||||||
val level = level
|
tickOnceServer {
|
||||||
|
|
||||||
if (level != null) {
|
|
||||||
OverdriveThatMatters.tickOnceSelf(level) {
|
|
||||||
if (isRemoved) return@tickOnceSelf
|
|
||||||
|
|
||||||
var state = blockState
|
var state = blockState
|
||||||
|
|
||||||
if (container.getItem(0).getCapability(MatteryCapability.DRIVE).isPresent && energy.batteryLevel >= OverdriveThatMatters.ITEM_STORAGE.energyPerOperation()) {
|
if (container.getItem(0).getCapability(MatteryCapability.DRIVE).isPresent && energy.batteryLevel >= OverdriveThatMatters.INSTANCE.ITEM_STORAGE.energyPerOperation()) {
|
||||||
state = state.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING)
|
state = state.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING)
|
||||||
} else {
|
} else {
|
||||||
state = state.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE)
|
state = state.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE)
|
||||||
@ -47,7 +42,6 @@ class BlockEntityDriveViewer(p_155229_: BlockPos, p_155230_: BlockState) : Block
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override val energy = WorkerEnergyStorage(this)
|
override val energy = WorkerEnergyStorage(this)
|
||||||
|
|
||||||
@ -56,9 +50,7 @@ class BlockEntityDriveViewer(p_155229_: BlockPos, p_155230_: BlockState) : Block
|
|||||||
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||||
super.setChanged(slot, new, old)
|
super.setChanged(slot, new, old)
|
||||||
|
|
||||||
val level = level
|
tickOnceServer {
|
||||||
if (level != null) {
|
|
||||||
OverdriveThatMatters.tickOnceSelf(level) {
|
|
||||||
if (!isRemoved) {
|
if (!isRemoved) {
|
||||||
var state = blockState
|
var state = blockState
|
||||||
|
|
||||||
@ -69,8 +61,7 @@ class BlockEntityDriveViewer(p_155229_: BlockPos, p_155230_: BlockState) : Block
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state !== blockState) {
|
if (state !== blockState) {
|
||||||
level.setBlock(blockPos, state, Block.UPDATE_CLIENTS)
|
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) {
|
override fun setLevel(p_155231_: Level) {
|
||||||
super.setLevel(p_155231_)
|
super.setLevel(p_155231_)
|
||||||
|
tickOnceServer(this::checkSurroundings)
|
||||||
val level = level
|
|
||||||
if (level is ServerLevel) {
|
|
||||||
OverdriveThatMatters.tickOnce(level) { checkSurroundings(level) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class EnergyCounterCap(val is_input: Boolean) : IMatteryEnergyStorage {
|
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) {
|
protected fun tickOnce(func: Runnable) {
|
||||||
val level = level
|
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) {
|
protected fun tickOnceServer(func: Runnable) {
|
||||||
val level = level
|
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) {
|
protected fun tickOnceClient(func: Runnable) {
|
||||||
val level = level
|
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
|
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
|
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
|
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(
|
protected fun <T> getAndBind(
|
||||||
|
@ -7,6 +7,7 @@ import net.minecraft.server.level.ServerLevel
|
|||||||
import net.minecraft.world.level.block.entity.BlockEntity
|
import net.minecraft.world.level.block.entity.BlockEntity
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||||
import ru.dbotthepony.mc.otm.core.plus
|
import ru.dbotthepony.mc.otm.core.plus
|
||||||
|
import ru.dbotthepony.mc.otm.tickUntil
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ abstract class Abstract6Graph<T> {
|
|||||||
nodeGetter: (BlockEntity) -> Graph6Node<T>?,
|
nodeGetter: (BlockEntity) -> Graph6Node<T>?,
|
||||||
factory: () -> Abstract6Graph<T>
|
factory: () -> Abstract6Graph<T>
|
||||||
) {
|
) {
|
||||||
OverdriveThatMatters.tickUntil(level) {
|
tickUntil(level) {
|
||||||
!node.valid || discover(level, blockPos, node, nodeGetter, factory)
|
!node.valid || discover(level, blockPos, node, nodeGetter, factory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ class ItemBattery : Item {
|
|||||||
private val throughputText: Component
|
private val throughputText: Component
|
||||||
|
|
||||||
constructor(storage: ImpreciseFraction, receive: ImpreciseFraction, extract: ImpreciseFraction) : super(
|
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
|
isCreative = false
|
||||||
this.storage = storage
|
this.storage = storage
|
||||||
@ -114,7 +114,7 @@ class ItemBattery : Item {
|
|||||||
).withStyle(ChatFormatting.GRAY)
|
).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
|
isCreative = true
|
||||||
storage = ImpreciseFraction.LONG_MAX_VALUE
|
storage = ImpreciseFraction.LONG_MAX_VALUE
|
||||||
receive = 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
|
import net.minecraft.world.level.Level
|
||||||
|
|
||||||
class ItemGravitationalDisruptor :
|
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(
|
override fun appendHoverText(
|
||||||
p_41421_: ItemStack,
|
p_41421_: ItemStack,
|
||||||
p_41422_: Level?,
|
p_41422_: Level?,
|
||||||
|
@ -93,12 +93,12 @@ class ItemMatterCapacitor : Item {
|
|||||||
val storage: ImpreciseFraction
|
val storage: ImpreciseFraction
|
||||||
private val isCreative: Boolean
|
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
|
isCreative = false
|
||||||
this.storage = storage
|
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
|
isCreative = true
|
||||||
storage = ImpreciseFraction.LONG_MAX_VALUE
|
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.matter.MatterTuple
|
||||||
import ru.dbotthepony.mc.otm.set
|
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 {
|
private fun matter(stack: ItemStack): ImpreciseFraction {
|
||||||
return stack.tag?.get("matter")?.let { return@let ImpreciseFraction.deserializeNBT(it) } ?: return ImpreciseFraction.ZERO
|
return stack.tag?.get("matter")?.let { return@let ImpreciseFraction.deserializeNBT(it) } ?: return ImpreciseFraction.ZERO
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ class ItemPatternStorage : Item {
|
|||||||
val capacity: Int
|
val capacity: Int
|
||||||
var isCreative: Boolean
|
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
|
this.capacity = capacity
|
||||||
isCreative = false
|
isCreative = false
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() : super(Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1)) {
|
constructor() : super(Properties().tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB).stacksTo(1)) {
|
||||||
isCreative = true
|
isCreative = true
|
||||||
capacity = Int.MAX_VALUE
|
capacity = Int.MAX_VALUE
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ enum class PillType {
|
|||||||
BECOME_ANDROID, BECOME_HUMANE, OBLIVION
|
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 {
|
override fun getUseDuration(p_41454_: ItemStack): Int {
|
||||||
return 24
|
return 24
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ class ItemPillHeal : Item(Properties().stacksTo(64).rarity(Rarity.UNCOMMON).tab(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ItemPill(val pillType: PillType) :
|
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 {
|
override fun getUseDuration(p_41454_: ItemStack): Int {
|
||||||
return 32
|
return 32
|
||||||
|
@ -30,7 +30,7 @@ import ru.dbotthepony.mc.otm.set
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ItemPortableCondensationDrive(capacity: Int) :
|
class ItemPortableCondensationDrive(capacity: Int) :
|
||||||
Item(Properties().stacksTo(1).tab(OverdriveThatMatters.CREATIVE_TAB)) {
|
Item(Properties().stacksTo(1).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) {
|
||||||
val capacity: ImpreciseFraction
|
val capacity: ImpreciseFraction
|
||||||
|
|
||||||
init {
|
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>) {
|
override fun initializeClient(consumer: Consumer<IItemRenderProperties>) {
|
||||||
super.initializeClient(consumer)
|
super.initializeClient(consumer)
|
||||||
consumer.accept(GravitationStabilizerArmorRenderProperties)
|
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>) {
|
override fun initializeClient(consumer: Consumer<IItemRenderProperties>) {
|
||||||
super.initializeClient(consumer)
|
super.initializeClient(consumer)
|
||||||
consumer.accept(TritaniumArmorRenderProperties)
|
consumer.accept(TritaniumArmorRenderProperties)
|
||||||
|
Loading…
Reference in New Issue
Block a user