diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt index 3025bef58..fcdb05480 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt @@ -1,12 +1,19 @@ package ru.dbotthepony.mc.otm.datagen import net.minecraft.core.Direction +import net.minecraft.data.recipes.ShapedRecipeBuilder +import net.minecraft.data.recipes.ShapelessRecipeBuilder import net.minecraft.resources.ResourceLocation +import net.minecraft.tags.ItemTags +import net.minecraft.tags.Tag +import net.minecraft.world.item.Item import net.minecraft.world.level.block.Block +import net.minecraftforge.common.Tags import net.minecraftforge.eventbus.api.SubscribeEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.forge.event.lifecycle.GatherDataEvent import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.Registry import ru.dbotthepony.mc.otm.Registry.Blocks import ru.dbotthepony.mc.otm.Registry.Items import ru.dbotthepony.mc.otm.block.BlockDriveViewer @@ -22,6 +29,7 @@ import ru.dbotthepony.mc.otm.datagen.loot.MatteryLootTableProvider import ru.dbotthepony.mc.otm.datagen.loot.TileNbtCopy import ru.dbotthepony.mc.otm.datagen.models.BlockMatteryModelProvider import ru.dbotthepony.mc.otm.datagen.recipes.MatteryRecipeProvider +import ru.dbotthepony.mc.otm.datagen.recipes.has @Mod.EventBusSubscriber(modid = DataGen.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) object DataGen { @@ -311,6 +319,60 @@ object DataGen { for (thing in hardMetals) { plate(thing, workTicks = 300) } + + lambda { _, consumer -> + ShapelessRecipeBuilder(Registry.INDUSTRIAL_GLASS.item, 8) + .requires(net.minecraft.world.item.Items.GLASS, 8) + .requires(Registry.Tags.Items.PLATE_TRITANIUM) + .unlockedBy("has_plate", has(Registry.Tags.Items.PLATE_TRITANIUM)) + .unlockedBy("has_glass", has(net.minecraft.world.item.Items.GLASS)) + .save(consumer) + + ShapedRecipeBuilder(Registry.INDUSTRIAL_GLASS.paneItem, 16) + .define('#', Registry.INDUSTRIAL_GLASS.item) + .pattern("###").pattern("###") + .unlockedBy("has_tritanium_glass", has(Registry.INDUSTRIAL_GLASS.item)) + .save(consumer) + + val mapping = mapOf>( + Registry.INDUSTRIAL_GLASS_BLACK to Tags.Items.DYES_BLACK, + Registry.INDUSTRIAL_GLASS_RED to Tags.Items.DYES_RED, + Registry.INDUSTRIAL_GLASS_GREEN to Tags.Items.DYES_GREEN, + Registry.INDUSTRIAL_GLASS_BROWN to Tags.Items.DYES_BROWN, + Registry.INDUSTRIAL_GLASS_BLUE to Tags.Items.DYES_BLUE, + Registry.INDUSTRIAL_GLASS_PURPLE to Tags.Items.DYES_PURPLE, + Registry.INDUSTRIAL_GLASS_CYAN to Tags.Items.DYES_CYAN, + Registry.INDUSTRIAL_GLASS_LIGHT_GRAY to Tags.Items.DYES_LIGHT_GRAY, + Registry.INDUSTRIAL_GLASS_GRAY to Tags.Items.DYES_GRAY, + Registry.INDUSTRIAL_GLASS_PINK to Tags.Items.DYES_PINK, + Registry.INDUSTRIAL_GLASS_LIME to Tags.Items.DYES_LIME, + Registry.INDUSTRIAL_GLASS_YELLOW to Tags.Items.DYES_YELLOW, + Registry.INDUSTRIAL_GLASS_LIGHT_BLUE to Tags.Items.DYES_LIGHT_BLUE, + Registry.INDUSTRIAL_GLASS_MAGENTA to Tags.Items.DYES_MAGENTA, + Registry.INDUSTRIAL_GLASS_ORANGE to Tags.Items.DYES_ORANGE, + Registry.INDUSTRIAL_GLASS_WHITE to Tags.Items.DYES_WHITE, + ) + + for ((item, tag) in mapping) { + ShapelessRecipeBuilder(item.item, 8) + .requires(Registry.INDUSTRIAL_GLASS.item, 8) + .requires(tag) + .unlockedBy("has_tritanium_glass", has(Registry.INDUSTRIAL_GLASS.item)) + .save(consumer) + + ShapelessRecipeBuilder(item.paneItem, 8) + .requires(Registry.INDUSTRIAL_GLASS.paneItem, 8) + .requires(tag) + .unlockedBy("has_tritanium_glass_pane", has(Registry.INDUSTRIAL_GLASS.paneItem)) + .save(consumer) + + ShapedRecipeBuilder(item.paneItem, 16) + .define('#', item.item) + .pattern("###").pattern("###") + .unlockedBy("has_colored_tritanium_glass", has(item.paneItem)) + .save(consumer, ResourceLocation(MOD_ID, "${item.namePane.path}_alt")) + } + } } } } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/MatteryRecipeProvider.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/MatteryRecipeProvider.kt index a76ca2326..a6afa14b8 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/MatteryRecipeProvider.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/MatteryRecipeProvider.kt @@ -1,16 +1,45 @@ package ru.dbotthepony.mc.otm.datagen.recipes +import net.minecraft.advancements.critereon.EntityPredicate +import net.minecraft.advancements.critereon.InventoryChangeTrigger +import net.minecraft.advancements.critereon.ItemPredicate +import net.minecraft.advancements.critereon.MinMaxBounds import net.minecraft.data.DataGenerator import net.minecraft.data.recipes.FinishedRecipe import net.minecraft.data.recipes.RecipeProvider import net.minecraft.resources.ResourceLocation +import net.minecraft.tags.Tag +import net.minecraft.world.item.Item import net.minecraft.world.item.crafting.Ingredient +import net.minecraft.world.level.ItemLike import ru.dbotthepony.mc.otm.datagen.DataGen import ru.dbotthepony.mc.otm.recipe.PlatePressRecipe import java.util.function.Consumer private typealias RecipeLambda = (MatteryRecipeProvider, Consumer) -> Unit +private fun has(p_176521_: MinMaxBounds.Ints, p_176522_: ItemLike): InventoryChangeTrigger.TriggerInstance { + return inventoryTrigger(ItemPredicate.Builder.item().of(p_176522_).withCount(p_176521_).build()) +} + +fun has(p_125978_: ItemLike): InventoryChangeTrigger.TriggerInstance { + return inventoryTrigger(ItemPredicate.Builder.item().of(p_125978_).build()) +} + +fun has(p_125976_: Tag): InventoryChangeTrigger.TriggerInstance { + return inventoryTrigger(ItemPredicate.Builder.item().of(p_125976_).build()) +} + +fun inventoryTrigger(vararg p_126012_: ItemPredicate): InventoryChangeTrigger.TriggerInstance { + return InventoryChangeTrigger.TriggerInstance( + EntityPredicate.Composite.ANY, + MinMaxBounds.Ints.ANY, + MinMaxBounds.Ints.ANY, + MinMaxBounds.Ints.ANY, + p_126012_ + ) +} + class MatteryRecipeProvider(generatorIn: DataGenerator) : RecipeProvider(generatorIn) { private val lambdas = ArrayList() diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 606359f3c..4e7a782e6 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -80,7 +80,8 @@ public class OverdriveThatMatters { if (event.phase != TickEvent.Phase.START || event.side != LogicalSide.SERVER) return; - final var until = tick_until.get(event.world); + // удаляем список сразу что бы если кто-либо добавит туда элементы у нас была "копия" + final var until = tick_until.remove(event.world); if (until != null) { for (int i = until.size() - 1; i >= 0; i--) { @@ -89,12 +90,16 @@ public class OverdriveThatMatters { } } - if (until.size() == 0) { - tick_until.remove(event.world); + if (until.size() != 0) { + final var replaced = tick_until.put(event.world, until); + + if (replaced != null) { + until.addAll(replaced); + } } } - final var once = tick_once.get(event.world); + final var once = tick_once.remove(event.world); if (once != null) { ArrayList> invalid = new ArrayList<>(); @@ -102,8 +107,6 @@ public class OverdriveThatMatters { for (var ticker : once) { ticker.accept(event.world); } - - tick_once.remove(event.world); } } @@ -120,6 +123,13 @@ public class OverdriveThatMatters { } public OverdriveThatMatters() { + CREATIVE_TAB = new CreativeModeTab("otm") { + @Override + public ItemStack makeIcon() { + return new ItemStack(Registry.Items.BATTERY_CREATIVE, 1); + } + }; + // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient); @@ -151,13 +161,6 @@ public class OverdriveThatMatters { // force Registry static initializer to be called Registry.dummy(); - - CREATIVE_TAB = new CreativeModeTab("otm") { - @Override - public ItemStack makeIcon() { - return new ItemStack(Registry.Items.BATTERY_CREATIVE, 1); - } - }; } public static StorageObjectTuple ITEM_STORAGE; diff --git a/src/main/java/ru/dbotthepony/mc/otm/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/Registry.java index a807fc480..ab23a066e 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/Registry.java @@ -21,9 +21,7 @@ import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.OreBlock; -import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.Material; @@ -62,10 +60,17 @@ import ru.dbotthepony.mc.otm.recipe.PlatePressRecipeFactory; import net.minecraftforge.common.Tags.IOptionalNamedTag; import javax.annotation.Nonnull; +import java.util.ConcurrentModificationException; import java.util.List; import java.util.Set; public class Registry { + static { + if (OverdriveThatMatters.CREATIVE_TAB == 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."); + } + } + public static final DamageSource DAMAGE_BECOME_ANDROID = new DamageSource("otm_become_android"); public static final DamageSource DAMAGE_BECOME_HUMANE = new DamageSource("otm_become_humane"); public static final DamageSource DAMAGE_EVENT_HORIZON = new DamageSource("otm_event_horizon"); @@ -118,6 +123,109 @@ public class Registry { new CrateProps(MaterialColor.COLOR_PURPLE, "purple"), }; + public record IndustrialGlassProps(@Nullable DyeColor color, ResourceLocation name, ResourceLocation namePane, Block block, Block pane, BlockItem item, BlockItem paneItem) { + public IndustrialGlassProps(@Nullable DyeColor color, ResourceLocation name, ResourceLocation namePane, Block block, Block pane, BlockItem item, BlockItem paneItem) { + this.color = color; + this.name = name; + this.namePane = namePane; + this.block = block; + this.pane = pane; + this.item = item; + this.paneItem = paneItem; + + this.block.setRegistryName(this.name); + this.pane.setRegistryName(this.namePane); + this.item.setRegistryName(this.name); + this.paneItem.setRegistryName(this.namePane); + } + + 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))); + } + + IndustrialGlassProps(@Nullable DyeColor color, ResourceLocation name, ResourceLocation namePane) { + this(color, name, namePane, + glass(color, BlockBehaviour.Properties.of(Material.GLASS, color != null ? color.getMaterialColor() : MaterialColor.NONE) + .strength(1.5F, 5.0F) + .requiresCorrectToolForDrops() + .sound(SoundType.GLASS) + .noOcclusion() + .isValidSpawn((_a, _b, _c, _d) -> false) + .isRedstoneConductor((_a, _b, _c) -> false) + .isSuffocating((_a, _b, _c) -> false) + .isViewBlocking((_a, _b, _c) -> false)), + pane(color, BlockBehaviour.Properties.of(Material.GLASS, color != null ? color.getMaterialColor() : MaterialColor.NONE) + .strength(1.25F, 5.0F) + .requiresCorrectToolForDrops() + .sound(SoundType.GLASS) + .noOcclusion()) + ); + } + + private static Block glass(@Nullable DyeColor color, BlockBehaviour.Properties props) { + if (color == null) { + return new GlassBlock(props); + } + + return new StainedGlassBlock(color, props); + } + + private static Block pane(@Nullable DyeColor color, BlockBehaviour.Properties props) { + if (color == null) { + return new IronBarsBlock(props); + } + + return new StainedGlassPaneBlock(color, props); + } + + IndustrialGlassProps(@Nullable DyeColor color) { + this(color, + new ResourceLocation(OverdriveThatMatters.MOD_ID, color != null ? "industrial_glass_" + color.getName() : "industrial_glass"), + new ResourceLocation(OverdriveThatMatters.MOD_ID, color != null ? "industrial_glass_pane_" + color.getName() : "industrial_glass_pane") + ); + } + } + + public static final IndustrialGlassProps INDUSTRIAL_GLASS = new IndustrialGlassProps(null); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_WHITE = new IndustrialGlassProps(DyeColor.WHITE); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_ORANGE = new IndustrialGlassProps(DyeColor.ORANGE); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_MAGENTA = new IndustrialGlassProps(DyeColor.MAGENTA); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_LIGHT_BLUE = new IndustrialGlassProps(DyeColor.LIGHT_BLUE); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_YELLOW = new IndustrialGlassProps(DyeColor.YELLOW); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_LIME = new IndustrialGlassProps(DyeColor.LIME); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_PINK = new IndustrialGlassProps(DyeColor.PINK); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_GRAY = new IndustrialGlassProps(DyeColor.GRAY); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_LIGHT_GRAY = new IndustrialGlassProps(DyeColor.LIGHT_GRAY); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_CYAN = new IndustrialGlassProps(DyeColor.CYAN); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_PURPLE = new IndustrialGlassProps(DyeColor.PURPLE); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_BLUE = new IndustrialGlassProps(DyeColor.BLUE); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_BROWN = new IndustrialGlassProps(DyeColor.BROWN); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_GREEN = new IndustrialGlassProps(DyeColor.GREEN); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_RED = new IndustrialGlassProps(DyeColor.RED); + public static final IndustrialGlassProps INDUSTRIAL_GLASS_BLACK = new IndustrialGlassProps(DyeColor.BLACK); + + public static final IndustrialGlassProps[] INDUSTRIAL_GLASS_LIST = new IndustrialGlassProps[] { + INDUSTRIAL_GLASS, + INDUSTRIAL_GLASS_WHITE, + INDUSTRIAL_GLASS_ORANGE, + INDUSTRIAL_GLASS_MAGENTA, + INDUSTRIAL_GLASS_LIGHT_BLUE, + INDUSTRIAL_GLASS_YELLOW, + INDUSTRIAL_GLASS_LIME, + INDUSTRIAL_GLASS_PINK, + INDUSTRIAL_GLASS_GRAY, + INDUSTRIAL_GLASS_LIGHT_GRAY, + INDUSTRIAL_GLASS_CYAN, + INDUSTRIAL_GLASS_PURPLE, + INDUSTRIAL_GLASS_BLUE, + INDUSTRIAL_GLASS_BROWN, + INDUSTRIAL_GLASS_GREEN, + INDUSTRIAL_GLASS_RED, + INDUSTRIAL_GLASS_BLACK, + }; + public static class Names { private static ResourceLocation loc(String path) { return new ResourceLocation(OverdriveThatMatters.MOD_ID, path); @@ -141,7 +249,6 @@ public class Registry { public static final ResourceLocation CHEMICAL_GENERATOR = loc("chemical_generator"); // есть рецепт public static final ResourceLocation PLATE_PRESS = loc("plate_press"); // есть рецепт - public static final ResourceLocation DEBUG_EXPLOSION_SMALL = loc("debug_explosion_small"); public static final ResourceLocation DEBUG_SPHERE_POINTS = loc("debug_sphere_points"); @@ -438,6 +545,11 @@ public class Registry { event.getRegistry().register(crate); } + for (var glass : INDUSTRIAL_GLASS_LIST) { + event.getRegistry().register(glass.block); + event.getRegistry().register(glass.pane); + } + // OverdriveThatMatters.LOGGER.info("Registered blocks"); } } @@ -791,6 +903,11 @@ public class Registry { event.getRegistry().register(crate); } + for (var glass : INDUSTRIAL_GLASS_LIST) { + event.getRegistry().register(glass.item); + event.getRegistry().register(glass.paneItem); + } + event.getRegistry().register(TRITANIUM_SWORD); event.getRegistry().register(TRITANIUM_SHOVEL); event.getRegistry().register(TRITANIUM_AXE); @@ -1269,6 +1386,7 @@ public class Registry { public static class Tags { public static class Items { public static final IOptionalNamedTag INGOT_TRITANIUM = ItemTags.createOptional(new ResourceLocation("forge", "ingots/tritanium"), Set.of(() -> Registry.Items.TRITANIUM_INGOT)); + public static final IOptionalNamedTag PLATE_TRITANIUM = ItemTags.createOptional(new ResourceLocation("forge", "plates/tritanium"), Set.of(() -> Registry.Items.TRITANIUM_PLATE)); } } }