diff --git a/build.gradle.kts b/build.gradle.kts index 2ef01a6fb..60c447dcb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,15 +2,15 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { // "maven-publish" - kotlin("jvm") version "1.9.10" - id("fabric-loom") version "1.3-SNAPSHOT" + kotlin("jvm") version "1.9.22" + id("fabric-loom") version "1.4-SNAPSHOT" } val version = "0.0.1" val group = "one.oktw" -val fabricVersion = "0.88.1+1.20.1" -val galaxyLibVersion = "adc1ed90" +val fabricVersion = "0.92.0+1.20.4" +val galaxyLibVersion = "9a964eaf" repositories { mavenCentral() @@ -40,9 +40,9 @@ loom { dependencies { // Core - minecraft(group = "com.mojang", name = "minecraft", version = "1.20.1") - mappings(group = "net.fabricmc", name = "yarn", version = "1.20.1+build.10", classifier = "v2") - modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.14.22") + minecraft(group = "com.mojang", name = "minecraft", version = "1.20.4") + mappings(group = "net.fabricmc", name = "yarn", version = "1.20.4+build.3", classifier = "v2") + modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.15.3") // fabric api modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = fabricVersion) { diff --git a/docker b/docker index 61e036276..38cb74777 160000 --- a/docker +++ b/docker @@ -1 +1 @@ -Subproject commit 61e036276f1f45bb25830a04b8588fffb2176ca1 +Subproject commit 38cb74777a16eaab089773e024f00065f6ad25e6 diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_NetworkHandler.java index 8880fbfb5..d69d88ae3 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_NetworkHandler.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2023 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,29 +18,31 @@ package one.oktw.galaxy.mixin.event; +import net.minecraft.network.ClientConnection; import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SignedMessage; import net.minecraft.server.MinecraftServer; import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ConnectedClientData; +import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import one.oktw.galaxy.event.EventManager; import one.oktw.galaxy.event.type.PlayerChatEvent; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ServerPlayNetworkHandler.class) -public class MixinPlayerChat_NetworkHandler { +public abstract class MixinPlayerChat_NetworkHandler extends ServerCommonNetworkHandler { @Shadow public ServerPlayerEntity player; - @Shadow - @Final - private MinecraftServer server; + public MixinPlayerChat_NetworkHandler(MinecraftServer server, ClientConnection connection, ConnectedClientData clientData) { + super(server, connection, clientData); + } @Redirect(method = "handleDecoratedMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageType$Parameters;)V")) private void onChat(PlayerManager playerManager, SignedMessage message, ServerPlayerEntity sender, MessageType.Parameters messageType) { diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java index dfd32a92c..16fa020a0 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java @@ -18,8 +18,15 @@ package one.oktw.galaxy.mixin.event; +import net.minecraft.entity.EntityStatuses; +import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket; +import net.minecraft.network.packet.s2c.play.HealthUpdateS2CPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ConnectedClientData; +import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -33,10 +40,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerPlayNetworkHandler.class) -public class MixinPlayerInteractBlock_NetworkHandler { +public abstract class MixinPlayerInteractBlock_NetworkHandler extends ServerCommonNetworkHandler { @Shadow public ServerPlayerEntity player; + public MixinPlayerInteractBlock_NetworkHandler(MinecraftServer server, ClientConnection connection, ConnectedClientData clientData) { + super(server, connection, clientData); + } + @Inject(method = "onPlayerInteractBlock", at = @At( value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;interactBlock(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;" @@ -49,8 +60,10 @@ private void onPlayerInteractBlock(PlayerInteractBlockC2SPacket packet, Callback // Re-sync block & inventory ServerWorld world = player.getServerWorld(); BlockPos blockPos = packet.getBlockHitResult().getBlockPos(); - player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockPos)); - player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockPos.offset(packet.getBlockHitResult().getSide()))); + sendPacket(new EntityStatusS2CPacket(player, EntityStatuses.CONSUME_ITEM)); + sendPacket(new HealthUpdateS2CPacket(player.getHealth(), player.getHungerManager().getFoodLevel(), player.getHungerManager().getSaturationLevel())); + sendPacket(new BlockUpdateS2CPacket(world, blockPos)); + sendPacket(new BlockUpdateS2CPacket(world, blockPos.offset(packet.getBlockHitResult().getSide()))); player.currentScreenHandler.syncState(); } } diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java index 02d44e898..62e96d3a4 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java @@ -18,9 +18,14 @@ package one.oktw.galaxy.mixin.event; -import net.minecraft.network.packet.Packet; +import net.minecraft.entity.EntityStatuses; +import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket; import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket; +import net.minecraft.network.packet.s2c.play.HealthUpdateS2CPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ConnectedClientData; +import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import one.oktw.galaxy.event.EventManager; @@ -32,12 +37,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerPlayNetworkHandler.class) -public abstract class MixinPlayerInteractItem_NetworkHandler { +public abstract class MixinPlayerInteractItem_NetworkHandler extends ServerCommonNetworkHandler { @Shadow public ServerPlayerEntity player; - @Shadow - public abstract void sendPacket(Packet packet); + public MixinPlayerInteractItem_NetworkHandler(MinecraftServer server, ClientConnection connection, ConnectedClientData clientData) { + super(server, connection, clientData); + } @Inject(method = "onPlayerInteractItem", at = @At( value = "INVOKE", @@ -47,7 +53,8 @@ private void onPlayerInteractItem(PlayerInteractItemC2SPacket packet, CallbackIn PlayerInteractItemEvent event = EventManager.safeEmit(new PlayerInteractItemEvent(packet, player)); if (event.getCancel()) { info.cancel(); - sendPacket(new EntityStatusS2CPacket(player, (byte) 9)); + sendPacket(new EntityStatusS2CPacket(player, EntityStatuses.CONSUME_ITEM)); + sendPacket(new HealthUpdateS2CPacket(player.getHealth(), player.getHungerManager().getFoodLevel(), player.getHungerManager().getSaturationLevel())); player.currentScreenHandler.syncState(); } if (event.getSwing()) this.player.swingHand(packet.getHand(), true); diff --git a/src/main/java/one/oktw/galaxy/mixin/interfaces/CustomRecipeManager.java b/src/main/java/one/oktw/galaxy/mixin/interfaces/CustomRecipeManager.java index 3d1e467f1..77963f3c4 100644 --- a/src/main/java/one/oktw/galaxy/mixin/interfaces/CustomRecipeManager.java +++ b/src/main/java/one/oktw/galaxy/mixin/interfaces/CustomRecipeManager.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * Copyright (C) 2018-2023 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -19,15 +19,16 @@ package one.oktw.galaxy.mixin.interfaces; import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeEntry; import net.minecraft.recipe.RecipeType; import net.minecraft.util.Identifier; import java.util.HashMap; public interface CustomRecipeManager { - HashMap, HashMap>> customRecipes = new HashMap<>(); + HashMap, HashMap>> customRecipes = new HashMap<>(); - static void addRecipe(RecipeType type, Recipe recipe) { - customRecipes.computeIfAbsent(type, k -> new HashMap<>()).putIfAbsent(recipe.getId(), recipe); + static void addRecipe(RecipeType type, Identifier id, Recipe recipe) { + customRecipes.computeIfAbsent(type, k -> new HashMap<>()).put(id, new RecipeEntry>(id, recipe)); } } diff --git a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_PlayerManager.java b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_PlayerManager.java deleted file mode 100644 index bf2218b95..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_PlayerManager.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2022 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.mixin.recipe; - -import net.minecraft.recipe.Recipe; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.server.PlayerManager; -import one.oktw.galaxy.mixin.interfaces.CustomRecipeManager; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.Collection; - -@Mixin(PlayerManager.class) -public class MixinCustomRecipe_PlayerManager { - // TODO Client mod - - @Redirect(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/RecipeManager;values()Ljava/util/Collection;")) - private Collection> skipSendRecipe(RecipeManager recipeManager) { - Collection> recipes = recipeManager.values(); - recipes.removeAll(CustomRecipeManager.customRecipes.values().stream().flatMap(i -> i.values().stream()).toList()); - return recipes; - } - - @Redirect(method = "onDataPacksReloaded", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/RecipeManager;values()Ljava/util/Collection;")) - private Collection> skipSyncRecipe(RecipeManager recipeManager) { - Collection> recipes = recipeManager.values(); - recipes.removeAll(CustomRecipeManager.customRecipes.values().stream().flatMap(i -> i.values().stream()).toList()); - return recipes; - } -} diff --git a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_RecipeManager.java b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_RecipeManager.java index 4607d4d54..c482e3898 100644 --- a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_RecipeManager.java +++ b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_RecipeManager.java @@ -20,7 +20,7 @@ import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; -import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeEntry; import net.minecraft.recipe.RecipeManager; import net.minecraft.recipe.RecipeType; import net.minecraft.resource.ResourceManager; @@ -37,8 +37,9 @@ @Mixin(RecipeManager.class) public class MixinCustomRecipe_RecipeManager implements CustomRecipeManager { - @Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;", ordinal = 1), locals = LocalCapture.CAPTURE_FAILSOFT) - private void recipeLoad(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci, Map, ImmutableMap.Builder>> map2) { + @Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;", ordinal = 0), locals = LocalCapture.CAPTURE_FAILSOFT) + private void recipeLoad(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci, Map, ImmutableMap.Builder>> map2, ImmutableMap.Builder> builder) { customRecipes.forEach((i, v) -> map2.computeIfAbsent(i, k -> ImmutableMap.builder()).putAll(v)); + customRecipes.forEach((i, v) -> builder.putAll(v)); } } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinGlobalDataPack_VanillaDataPackProvider.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinGlobalDataPack_VanillaDataPackProvider.java new file mode 100644 index 000000000..4f195a4d3 --- /dev/null +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinGlobalDataPack_VanillaDataPackProvider.java @@ -0,0 +1,34 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2024 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.mixin.tweak; + +import net.minecraft.resource.VanillaDataPackProvider; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +import java.nio.file.Path; + +@Mixin(VanillaDataPackProvider.class) +public class MixinGlobalDataPack_VanillaDataPackProvider { + @ModifyArg(method = "createManager(Lnet/minecraft/world/level/storage/LevelStorage$Session;)Lnet/minecraft/resource/ResourcePackManager;", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/VanillaDataPackProvider;createManager(Ljava/nio/file/Path;Lnet/minecraft/util/path/SymlinkFinder;)Lnet/minecraft/resource/ResourcePackManager;"), index = 0) + private static Path moveDataPackPath(Path dataPacksPath) { + return Path.of("datapacks"); + } +} diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_LootableContainerBlockEntity.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_LootableContainerBlockEntity.java index 3808ab800..50505f784 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_LootableContainerBlockEntity.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_LootableContainerBlockEntity.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2021 + * Copyright (C) 2018-2023 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -30,13 +30,13 @@ @Mixin(LootableContainerBlockEntity.class) public abstract class MixinOptimizeContainer_LootableContainerBlockEntity { @Shadow - protected abstract DefaultedList getInvStackList(); + protected abstract DefaultedList method_11282(); @Inject(method = "isEmpty", - at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/LootableContainerBlockEntity;checkLootInteraction(Lnet/minecraft/entity/player/PlayerEntity;)V", shift = At.Shift.AFTER), + at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/LootableContainerBlockEntity;generateLoot(Lnet/minecraft/entity/player/PlayerEntity;)V", shift = At.Shift.AFTER), cancellable = true) private void replaceStream(CallbackInfoReturnable cir) { - for (ItemStack itemStack : getInvStackList()) { + for (ItemStack itemStack : method_11282()) { if (!itemStack.isEmpty()) { cir.setReturnValue(false); return; diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/server/network/ServerPlayNetworkHandlerMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/server/network/ServerPlayNetworkHandlerMixin_RealTime.java index 454b0f029..dc11f35cf 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/server/network/ServerPlayNetworkHandlerMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/server/network/ServerPlayNetworkHandlerMixin_RealTime.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2019 + * Copyright (C) 2018-2023 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -42,11 +42,13 @@ */ package org.spongepowered.common.mixin.realtime.server.network; +import net.minecraft.network.ClientConnection; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ConnectedClientData; +import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -54,16 +56,17 @@ import org.spongepowered.common.bridge.RealTimeTrackingBridge; @Mixin(ServerPlayNetworkHandler.class) -public abstract class ServerPlayNetworkHandlerMixin_RealTime { +public abstract class ServerPlayNetworkHandlerMixin_RealTime extends ServerCommonNetworkHandler { @Shadow public ServerPlayerEntity player; @Shadow private int messageCooldown; @Shadow private int creativeItemDropThreshold; - @Shadow - @Final - private MinecraftServer server; + + public ServerPlayNetworkHandlerMixin_RealTime(MinecraftServer server, ClientConnection connection, ConnectedClientData clientData) { + super(server, connection, clientData); + } @Redirect( method = "tick", diff --git a/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt b/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt index 0c0c957c6..df9d8c2d3 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt @@ -54,6 +54,7 @@ open class CustomBlock(final override val identifier: Identifier, val baseBlock: val TELEPORTER_CORE_ADVANCE = registry.register(ModelCustomBlock("teleporter_core_advance", CustomBlockItem.TELEPORTER_CORE_ADVANCE.createItemStack())) val TELEPORTER_FRAME = registry.register(ModelCustomBlock("teleporter_frame", CustomBlockItem.TELEPORTER_FRAME.createItemStack())) val TEST_GUI = registry.register(TestGuiBlock()) + val HARVEST = registry.register(HarvestBlock()) } open fun toItem(): CustomBlockItem? = null diff --git a/src/main/kotlin/one/oktw/galaxy/block/CustomBlockHelper.kt b/src/main/kotlin/one/oktw/galaxy/block/CustomBlockHelper.kt index c05bac706..6fcd37631 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/CustomBlockHelper.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/CustomBlockHelper.kt @@ -27,6 +27,7 @@ import net.minecraft.server.world.ServerWorld import net.minecraft.sound.SoundCategory import net.minecraft.sound.SoundEvents import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Direction import one.oktw.galaxy.block.entity.ModelCustomBlockEntity import one.oktw.galaxy.item.CustomBlockItem import one.oktw.galaxy.item.CustomItemHelper @@ -43,7 +44,7 @@ object CustomBlockHelper { fun place(context: ItemPlacementContext): Boolean { val item = CustomItemHelper.getItem(context.stack) as? CustomBlockItem ?: return false if ((Items.BARRIER as BlockItem).place(context).isAccepted) { - postPlace(context.world as ServerWorld, context.blockPos, item.getBlock()) + postPlace(context.world as ServerWorld, context.blockPos, item.getBlock(), context.placementDirections) return true } return false @@ -58,8 +59,13 @@ object CustomBlockHelper { /** * Set BlockEntity and ARMOR_STAND and play sound */ - private fun postPlace(world: ServerWorld, pos: BlockPos, block: CustomBlock) { - world.addBlockEntity(block.createBlockEntity(pos)) + private fun postPlace(world: ServerWorld, pos: BlockPos, block: CustomBlock, direction: Array? = null) { + val entity = block.createBlockEntity(pos) + if (entity is ModelCustomBlockEntity) { + val allowed = entity.allowedFacing + entity.facing = direction?.firstOrNull { it.opposite in allowed }?.opposite + } + world.addBlockEntity(entity) world.playSound(null, pos, SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F) } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/utils/Ingredient.kt b/src/main/kotlin/one/oktw/galaxy/block/HarvestBlock.kt similarity index 51% rename from src/main/kotlin/one/oktw/galaxy/recipe/utils/Ingredient.kt rename to src/main/kotlin/one/oktw/galaxy/block/HarvestBlock.kt index 53a764594..846b23af8 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/utils/Ingredient.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/HarvestBlock.kt @@ -16,26 +16,15 @@ * along with this program. If not, see . */ -package one.oktw.galaxy.recipe.utils +package one.oktw.galaxy.block -import net.minecraft.item.Item -import net.minecraft.item.ItemStack -import net.minecraft.registry.tag.TagKey +import net.minecraft.util.math.BlockPos +import one.oktw.galaxy.block.entity.CustomBlockEntity +import one.oktw.galaxy.block.entity.HarvestBlockEntity +import one.oktw.galaxy.item.CustomBlockItem -class Ingredient( - private val tag: TagKey? = null, - private val items: List? = null -) { - init { - if (tag == null && items == null) throw IllegalArgumentException("No input provided.") - if (tag != null && items != null) throw IllegalArgumentException("Only one input is allowed.") - } - - fun matches(input: ItemStack): Boolean { - return when { - tag != null -> input.isIn(tag) - items != null -> items.contains(input.item) - else -> false - } +class HarvestBlock : ModelCustomBlock("harvest", CustomBlockItem.HARVEST.createItemStack()) { + override fun createBlockEntity(pos: BlockPos): CustomBlockEntity { + return HarvestBlockEntity(blockEntityType, pos, modelItem) } } diff --git a/src/main/kotlin/one/oktw/galaxy/block/entity/HarvestBlockEntity.kt b/src/main/kotlin/one/oktw/galaxy/block/entity/HarvestBlockEntity.kt new file mode 100644 index 000000000..1fb143687 --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/HarvestBlockEntity.kt @@ -0,0 +1,187 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2023 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.block.entity + +import net.minecraft.block.* +import net.minecraft.block.entity.BlockEntityType +import net.minecraft.entity.player.PlayerEntity +import net.minecraft.inventory.Inventories +import net.minecraft.inventory.SidedInventory +import net.minecraft.item.HoeItem +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NbtCompound +import net.minecraft.screen.ScreenHandlerType +import net.minecraft.screen.slot.Slot +import net.minecraft.server.network.ServerPlayerEntity +import net.minecraft.server.world.ServerWorld +import net.minecraft.text.Text +import net.minecraft.util.ActionResult +import net.minecraft.util.Hand +import net.minecraft.util.collection.DefaultedList +import net.minecraft.util.hit.BlockHitResult +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Direction +import one.oktw.galaxy.block.listener.CustomBlockClickListener +import one.oktw.galaxy.block.listener.CustomBlockTickListener +import one.oktw.galaxy.gui.GUI +import one.oktw.galaxy.gui.GUISBackStackManager +import one.oktw.galaxy.item.Gui +import one.oktw.galaxy.util.HarvestUtil + +class HarvestBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: ItemStack) : + ModelCustomBlockEntity(type, pos, modelItem, facing = Direction.NORTH), + CustomBlockClickListener, SidedInventory, CustomBlockTickListener { + companion object { + private val ALL_SLOT = intArrayOf(0, 1, 2, 3) + } + + override val allowedFacing = listOf(Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST) + private val inventory = DefaultedList.ofSize(4, ItemStack.EMPTY) + private val gui = GUI.Builder(ScreenHandlerType.GENERIC_9X3).setTitle(Text.translatable("block.HARVEST")).apply { + var i = 0 + addSlot(4, 0, object : Slot(this@HarvestBlockEntity, i++, 0, 0) { // Tool + override fun canInsert(item: ItemStack) = isHoe(item) + }) + for (x in 3..5) addSlot(x, 2, object : Slot(this@HarvestBlockEntity, i++, 0, 0) { // Output + override fun canInsert(stack: ItemStack) = false + }) + }.build().apply { + editInventory { + // Fill empty + fillAll(Gui.MAIN_FIELD.createItemStack()) + } + } + private var progress = 0 + + override fun tick() { + super.tick() + + // Only work have hoe and empty slot >= 2 + val tool = inventory[0] + if (!isHoe(tool) || inventory.count { it.isEmpty } < 2) return + + val world = world as? ServerWorld ?: return + + val range = 4 // TODO range upgrade + val diameter = range * 2 + 1 + if (progress >= diameter * diameter) progress = 0 + val blockPos = pos.offset(facing, (progress / diameter) + 1).offset(facing!!.rotateYClockwise(), (progress % diameter) - range) + progress++ + val blockState = world.getBlockState(blockPos) + + if (HarvestUtil.isMature(world, blockPos, world.getBlockState(blockPos))) { + val block = blockState.block + val ageProperties = when (block) { + Blocks.WHEAT, Blocks.CARROTS, Blocks.POTATOES -> CropBlock.AGE + Blocks.BEETROOTS -> BeetrootsBlock.AGE + Blocks.COCOA -> CocoaBlock.AGE + Blocks.NETHER_WART -> NetherWartBlock.AGE + Blocks.PUMPKIN, Blocks.MELON -> null + else -> return + } + world.breakBlock(blockPos, false) + val drop = Block.getDroppedStacks(blockState, world, blockPos, world.getBlockEntity(blockPos), null, tool) + for (item in drop) { + for (slot in 1..3) { + val originItem = getStack(slot) + if (originItem.isEmpty) { + setStack(slot, item) + break + } else if (originItem.count < originItem.maxCount && ItemStack.canCombine(originItem, item)) { + val count = item.count.coerceAtMost(originItem.maxCount - originItem.count) + item.decrement(count) + originItem.increment(count) + if (item.isEmpty) break + } + } + } + if (tool.damage(1, world.random, null)) { + tool.decrement(1) + tool.damage = 0 + } + + if (block != Blocks.PUMPKIN && block != Blocks.MELON) { + world.setBlockState(blockPos, blockState.with(ageProperties, 0)) + world.updateNeighbors(blockPos, block) + } + } + } + + override fun readCopyableData(nbt: NbtCompound) { + Inventories.readNbt(nbt, inventory) + } + + override fun writeNbt(nbt: NbtCompound) { + super.writeNbt(nbt) + Inventories.writeNbt(nbt, inventory) + } + + override fun onClick(player: PlayerEntity, hand: Hand, hit: BlockHitResult): ActionResult { + GUISBackStackManager.openGUI(player as ServerPlayerEntity, gui) + return ActionResult.SUCCESS + } + + override fun clear() { + inventory.clear() + } + + override fun size() = inventory.size + + override fun isEmpty() = inventory.isEmpty() + + override fun getStack(slot: Int) = inventory[slot] + + override fun removeStack(slot: Int, amount: Int): ItemStack { + val itemStack = Inventories.splitStack(inventory, slot, amount) + if (!itemStack.isEmpty) { + this.markDirty() + } + return itemStack + } + + override fun removeStack(slot: Int): ItemStack = Inventories.removeStack(inventory, slot) + + override fun setStack(slot: Int, stack: ItemStack) { + inventory[slot] = stack + if (stack.count > this.maxCountPerStack) { + stack.count = this.maxCountPerStack + } + this.markDirty() + } + + override fun canPlayerUse(player: PlayerEntity): Boolean { + return if (world!!.getBlockEntity(pos) !== this) { + false + } else player.squaredDistanceTo(pos.x.toDouble() + 0.5, pos.y.toDouble() + 0.5, pos.z.toDouble() + 0.5) <= 64.0 + } + + override fun getAvailableSlots(side: Direction): IntArray { + return ALL_SLOT + } + + override fun canInsert(slot: Int, item: ItemStack, dir: Direction?): Boolean { + return slot == 0 && isHoe(item) + } + + override fun canExtract(slot: Int, item: ItemStack, dir: Direction): Boolean { + return slot in 1..3 + } + + private fun isHoe(item: ItemStack) = item.item is HoeItem +} diff --git a/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt b/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt index c220ceed1..4c1836bc9 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt @@ -27,10 +27,12 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound import net.minecraft.server.world.ServerWorld import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Direction import one.oktw.galaxy.block.listener.CustomBlockTickListener import java.util.* -open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, private val modelItem: ItemStack) : CustomBlockEntity(type, pos), +open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, private val modelItem: ItemStack, facing: Direction? = null) : + CustomBlockEntity(type, pos), CustomBlockTickListener { companion object { private val armorStandNbt = NbtCompound().apply { @@ -46,6 +48,14 @@ open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, priva } private var entityUUID: UUID? = null + open var facing = facing + set(direction) { + if (facing != null && direction != null && direction in allowedFacing) { + field = direction + (world as? ServerWorld)?.getEntity(entityUUID)?.yaw = direction.asRotation() + } + } + open val allowedFacing: List = emptyList() override fun tick() { if (entityUUID == null || (world as ServerWorld).getEntity(entityUUID) == null) { @@ -58,12 +68,19 @@ open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, priva override fun readNbt(nbt: NbtCompound) { super.readNbt(nbt) - entityUUID = (nbt.get("GalaxyData") as? NbtCompound)?.getUuid("ModelEntity") ?: return + val data = nbt.get("GalaxyData") as? NbtCompound ?: return + data.getUuid("ModelEntity")?.let { entityUUID = it } + data.getString("Facing")?.let { facing = Direction.byName(it) } } override fun writeNbt(nbt: NbtCompound) { super.writeNbt(nbt) - entityUUID?.let { nbt.put("GalaxyData", NbtCompound().apply { putUuid("ModelEntity", it) }) } + val data = NbtCompound() + entityUUID?.let { data.putUuid("ModelEntity", it) } + facing?.let { data.putString("Facing", it.getName()) } + if (!data.isEmpty) { + nbt.put("GalaxyData", data) + } } override fun markRemoved() { @@ -73,7 +90,7 @@ open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, priva private fun spawnEntity() { val entity: ArmorStandEntity = EntityType.getEntityFromNbt(armorStandNbt, world).get() as ArmorStandEntity - entity.refreshPositionAndAngles(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, 0.0F, 0.0F) + entity.refreshPositionAndAngles(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, facing?.asRotation() ?: 0.0F, 0.0F) entity.equipStack(EquipmentSlot.HEAD, modelItem) entity.addCommandTag("BLOCK") entity.addCommandTag(getId().toString()) diff --git a/src/main/kotlin/one/oktw/galaxy/block/entity/TestGuiBlockEntity.kt b/src/main/kotlin/one/oktw/galaxy/block/entity/TestGuiBlockEntity.kt index b397ccb4f..efa702488 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/TestGuiBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/TestGuiBlockEntity.kt @@ -48,8 +48,8 @@ class TestGuiBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite for (y in 4 until 6) for (x in 0 until 9) addSlot(x, y, Slot(this@TestGuiBlockEntity, i++, 0, 0)) }.build().apply { editInventory { - fill(0 until 9, 1 until 4, Gui.EXTEND.createItemStack()) - set(4, 2, Gui.INFO.createItemStack()) + fill(0 until 9, 1 until 4, Gui.MAIN_FIELD.createItemStack()) + set(4, 2, Button.CHECK_MARK.createItemStack()) } addBinding(4, 2) { GUISBackStackManager.openGUI(player, gui2) @@ -60,8 +60,8 @@ class TestGuiBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite for (y in 0 until 3) for (x in 0 until 9) addSlot(x, y, Slot(this@TestGuiBlockEntity, i++, 0, 0)) }.build().apply { editInventory { - fill(0 until 9, 3..3, Gui.EXTEND.createItemStack()) - set(4, 3, Button.NO.createItemStack().setCustomName(Text.of("CLOSE ALL"))) + fill(0 until 9, 3..3, Gui.MAIN_FIELD.createItemStack()) + set(4, 3, Button.CROSS_MARK.createItemStack().setCustomName(Text.of("CLOSE ALL"))) } addBinding(4, 3) { GUISBackStackManager.closeAll(player) diff --git a/src/main/kotlin/one/oktw/galaxy/chat/Exchange.kt b/src/main/kotlin/one/oktw/galaxy/chat/Exchange.kt index 9844abd7f..6545df625 100644 --- a/src/main/kotlin/one/oktw/galaxy/chat/Exchange.kt +++ b/src/main/kotlin/one/oktw/galaxy/chat/Exchange.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2021 + * Copyright (C) 2018-2023 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -19,8 +19,8 @@ package one.oktw.galaxy.chat import io.netty.buffer.Unpooled +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking.createS2CPacket import net.minecraft.network.PacketByteBuf -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket import net.minecraft.text.Text import net.minecraft.util.Identifier import one.oktw.galaxy.Main @@ -42,13 +42,13 @@ class Exchange { event.cancel = true event.player.networkHandler.sendPacket( - CustomPayloadS2CPacket( + createS2CPacket( PROXY_CHAT_IDENTIFIER, PacketByteBuf( Unpooled.wrappedBuffer( encode( MessageSend( sender = event.player.uuid, - message = Text.Serializer.toJson(event.message), + message = Text.Serialization.toJsonString(event.message), targets = listOf(ProxyAPI.globalChatChannel) ) ) diff --git a/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt b/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt index d194dee3e..fb0500608 100644 --- a/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt +++ b/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt @@ -18,13 +18,16 @@ package one.oktw.galaxy.command.commands +import com.mojang.brigadier.Command.SINGLE_SUCCESS import com.mojang.brigadier.CommandDispatcher import kotlinx.coroutines.delay import kotlinx.coroutines.launch import net.minecraft.server.command.CommandManager import net.minecraft.server.command.ServerCommandSource +import net.minecraft.server.world.ServerWorld import net.minecraft.text.Text import net.minecraft.util.Formatting +import net.minecraft.world.World import one.oktw.galaxy.Main.Companion.main import one.oktw.galaxy.command.Command import one.oktw.galaxy.mixin.accessor.ServerPlayerEntityFunctionAccessor @@ -39,27 +42,37 @@ class Spawn : Command { CommandManager.literal("spawn") .executes { context -> execute(context.source) + SINGLE_SUCCESS } ) } - private fun execute(source: ServerCommandSource): Int { - val player = source.player + private fun execute(source: ServerCommandSource) { + val originPlayer = source.player - if (player == null || lock.contains(player.uuid)) return com.mojang.brigadier.Command.SINGLE_SUCCESS + if (originPlayer == null || lock.contains(originPlayer.uuid)) return - lock += player.uuid + lock += originPlayer.uuid main?.launch { - val world = player.serverWorld - for (i in 0..4) { - player.sendMessage(Text.translatable("Respond.commandCountdown", 5 - i).styled { it.withColor(Formatting.GREEN) }, true) + originPlayer.sendMessage(Text.translatable("Respond.commandCountdown", 5 - i).styled { it.withColor(Formatting.GREEN) }, true) delay(TimeUnit.SECONDS.toMillis(1)) } + + val player = originPlayer.server.playerManager.getPlayer(originPlayer.uuid) ?: return@launch player.sendMessage(Text.translatable("Respond.TeleportStart").styled { it.withColor(Formatting.GREEN) }, true) + val world = player.serverWorld + val type = world.registryKey + + if (type == World.NETHER) { + player.sendMessage(Text.translatable("Respond.TeleportNothing").styled { it.withColor(Formatting.RED) }, true) + lock -= player.uuid + return@launch + } + val oldPos = player.pos player.stopRiding() @@ -67,6 +80,14 @@ class Spawn : Command { player.wakeUp(true, true) } + if (type == World.END) { + val pos = ServerWorld.END_SPAWN_POS.toCenterPos() + player.networkHandler.requestTeleport(pos.x, pos.y, pos.z, 0.0f, 0.0f) + player.networkHandler.syncWithPlayerPosition() + lock -= player.uuid + return@launch + } + (player as ServerPlayerEntityFunctionAccessor).moveToWorldSpawn(world) // force teleport when player pos does not change at all if (oldPos.distanceTo(player.pos) == 0.0) { @@ -80,7 +101,5 @@ class Spawn : Command { player.networkHandler.requestTeleport(player.x, player.y, player.z, player.yaw, player.pitch) lock -= player.uuid } - - return com.mojang.brigadier.Command.SINGLE_SUCCESS } } diff --git a/src/main/kotlin/one/oktw/galaxy/gui/GUI.kt b/src/main/kotlin/one/oktw/galaxy/gui/GUI.kt index 0e6ac94a8..c7b6ba0b5 100644 --- a/src/main/kotlin/one/oktw/galaxy/gui/GUI.kt +++ b/src/main/kotlin/one/oktw/galaxy/gui/GUI.kt @@ -265,7 +265,7 @@ class GUI private constructor(private val type: ScreenHandlerType allowedFacing.lastIndex) allowedFacing.first() else allowedFacing[next] + startDirection[player] = blockPos to direction + + blockEntity.facing = if (next == -1 || next > allowedFacing.lastIndex) allowedFacing.first() else allowedFacing[next] + } + // Check destructible if (blockState.getHardness(world, blockPos) < 0.0) return false if (block == PISTON_HEAD || (block == PISTON || block == STICKY_PISTON) && blockState.get(EXTENDED)) return false diff --git a/src/main/kotlin/one/oktw/galaxy/player/Harvest.kt b/src/main/kotlin/one/oktw/galaxy/player/Harvest.kt index 1ee3f67e9..c2e79917b 100644 --- a/src/main/kotlin/one/oktw/galaxy/player/Harvest.kt +++ b/src/main/kotlin/one/oktw/galaxy/player/Harvest.kt @@ -22,15 +22,11 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents import net.minecraft.block.* import net.minecraft.block.Blocks.* import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.server.world.ServerWorld -import net.minecraft.state.property.IntProperty -import net.minecraft.state.property.Properties.HORIZONTAL_FACING import net.minecraft.util.Hand -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Direction import one.oktw.galaxy.event.annotation.EventListener import one.oktw.galaxy.event.type.PlayerInteractBlockEvent import one.oktw.galaxy.event.type.PlayerInteractItemEvent +import one.oktw.galaxy.util.HarvestUtil.isMature class Harvest { private val justHarvested = HashSet() @@ -50,19 +46,21 @@ class Harvest { if (event.packet.hand == Hand.MAIN_HAND && !player.isSneaking && isMature(world, blockPos, blockState)) { event.cancel = true - val ageProperties = when (blockState.block) { + val block = blockState.block + val ageProperties = when (block) { WHEAT, CARROTS, POTATOES -> CropBlock.AGE BEETROOTS -> BeetrootsBlock.AGE COCOA -> CocoaBlock.AGE NETHER_WART -> NetherWartBlock.AGE - else -> IntProperty.of("AGE", 0, 1) + PUMPKIN, MELON -> null + else -> return } player.swingHand(Hand.MAIN_HAND, true) world.breakBlock(blockPos, false) Block.dropStacks(blockState, world, blockPos, world.getBlockEntity(blockPos), player, player.mainHandStack) // Fortune drop - if (blockState.block != PUMPKIN && blockState.block != MELON) { + if (block != PUMPKIN && block != MELON) { world.setBlockState(blockPos, blockState.with(ageProperties, 0)) - world.updateNeighbors(blockPos, blockState.block) + world.updateNeighbors(blockPos, block) } justHarvested.add(player) } @@ -72,34 +70,4 @@ class Harvest { fun onPlayerInteractItem(event: PlayerInteractItemEvent) { if (event.player in justHarvested) event.cancel = true } - - private fun isMature(world: ServerWorld, blockPos: BlockPos, blockState: BlockState): Boolean = when (blockState.block) { - WHEAT, CARROTS, POTATOES, BEETROOTS -> blockState.let((blockState.block as CropBlock)::isMature) - COCOA -> blockState[CocoaBlock.AGE] >= 2 - NETHER_WART -> blockState[NetherWartBlock.AGE] >= 3 - MELON -> isNextTo(world, blockPos, ATTACHED_MELON_STEM) - PUMPKIN -> isNextTo(world, blockPos, ATTACHED_PUMPKIN_STEM) - else -> false - } - - private fun isNextTo(world: ServerWorld, blockPos: BlockPos, block: Block): Boolean = - (world.getBlockState(blockPos.east()).block == block && isPaired(world, blockPos, blockPos.east())) || - (world.getBlockState(blockPos.west()).block == block && isPaired(world, blockPos, blockPos.west())) || - (world.getBlockState(blockPos.north()).block == block && isPaired(world, blockPos, blockPos.north())) || - (world.getBlockState(blockPos.south()).block == block && isPaired(world, blockPos, blockPos.south())) - - private fun isPaired(world: ServerWorld, blockPos: BlockPos, stemPos: BlockPos): Boolean { - val connectedPos = world.getBlockState(stemPos)[HORIZONTAL_FACING] - .let { - when (it) { - Direction.EAST -> stemPos.east() - Direction.WEST -> stemPos.west() - Direction.NORTH -> stemPos.north() - Direction.SOUTH -> stemPos.south() - else -> null - } - } - - return connectedPos == blockPos - } } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/RecipeRegistry.kt b/src/main/kotlin/one/oktw/galaxy/recipe/RecipeRegistry.kt index 255272914..f3d99aeb9 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/RecipeRegistry.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/RecipeRegistry.kt @@ -19,10 +19,12 @@ package one.oktw.galaxy.recipe import net.minecraft.recipe.RecipeType +import net.minecraft.util.Identifier import one.oktw.galaxy.mixin.interfaces.CustomRecipeManager import one.oktw.galaxy.recipe.blocks.Elevator import one.oktw.galaxy.recipe.blocks.HTCraftingTable -import one.oktw.galaxy.recipe.easyRecipe.* +import one.oktw.galaxy.recipe.blocks.Harvest +import one.oktw.galaxy.recipe.blocks.Trashcan import one.oktw.galaxy.recipe.materials.CeramicPlate import one.oktw.galaxy.recipe.tools.Crowbar import one.oktw.galaxy.recipe.tools.Wrench @@ -30,31 +32,12 @@ import one.oktw.galaxy.recipe.tools.Wrench object RecipeRegistry { fun register() { // Recipe - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Wrench()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Crowbar()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Elevator()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, HTCraftingTable()) - CustomRecipeManager.addRecipe(RecipeType.SMELTING, CeramicPlate()) - // Easy Recipe - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Ladder()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Chest()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Hopper()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, RedStoneLamp()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Dispenser()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, DispenserWithBow()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, RedStoneRepeater()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, TrappedChest()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, CarrotOnAStick()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, WarpedFungusOnAStick()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, BookAndQuill()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Minecart()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Stick()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Glass()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, GlassPane()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, GlassPaneRestore()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, StainedGlassRestore()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, StainedGlassPaneRestore()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, WoodenSlab()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, SlabRestore()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "item/wrench"), Wrench()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "item/crowbar"), Crowbar()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "block/elevator"), Elevator()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "block/htct"), HTCraftingTable()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "block/harvest"), Harvest()) + CustomRecipeManager.addRecipe(RecipeType.SMELTING, Identifier("galaxy", "material/ceramic_plate"), CeramicPlate()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "block/trashcan"), Trashcan()) } } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Elevator.kt b/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Elevator.kt index d5eec01f9..4bd05b828 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Elevator.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Elevator.kt @@ -18,41 +18,16 @@ package one.oktw.galaxy.recipe.blocks -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer +import net.minecraft.recipe.Ingredient +import net.minecraft.recipe.ShapelessRecipe import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World +import net.minecraft.util.collection.DefaultedList import one.oktw.galaxy.item.CustomBlockItem -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils -class Elevator : CraftingRecipe { - private val item = CustomBlockItem.ELEVATOR.createItemStack() - private val list = - listOf(Ingredient(items = listOf(Items.ENDER_PEARL)), Ingredient(items = listOf(Items.IRON_BLOCK))) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapelessMatches(inv, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "block/elevator") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} +class Elevator : ShapelessRecipe( + "", + CraftingRecipeCategory.EQUIPMENT, + CustomBlockItem.ELEVATOR.createItemStack(), + DefaultedList.copyOf(Ingredient.EMPTY, Ingredient.ofItems(Items.ENDER_PEARL), Ingredient.ofItems(Items.IRON_BLOCK)) +) diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/blocks/HTCraftingTable.kt b/src/main/kotlin/one/oktw/galaxy/recipe/blocks/HTCraftingTable.kt index 59c825243..cfb645ed6 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/blocks/HTCraftingTable.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/blocks/HTCraftingTable.kt @@ -18,51 +18,28 @@ package one.oktw.galaxy.recipe.blocks -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer +import net.minecraft.recipe.Ingredient +import net.minecraft.recipe.RawShapedRecipe +import net.minecraft.recipe.ShapedRecipe import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World import one.oktw.galaxy.item.CustomBlockItem -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils -class HTCraftingTable : CraftingRecipe { - private val item = CustomBlockItem.HT_CRAFTING_TABLE.createItemStack() - - private val redStone = Ingredient(items = listOf(Items.REDSTONE)) - private val diamond = Ingredient(items = listOf(Items.DIAMOND)) - private val lapisLazuli = Ingredient(items = listOf(Items.LAPIS_LAZULI)) - private val ironIngot = Ingredient(items = listOf(Items.IRON_INGOT)) - private val obsidian = Ingredient(items = listOf(Items.OBSIDIAN)) - private val craftingTable = Ingredient(items = listOf(Items.CRAFTING_TABLE)) - private val list = listOf( - redStone, diamond, lapisLazuli, - ironIngot, craftingTable, ironIngot, - lapisLazuli, obsidian, redStone - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 3, 3, list) - - override fun craft(inventory: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "block/htct") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} +class HTCraftingTable : ShapedRecipe( + "", + CraftingRecipeCategory.BUILDING, + RawShapedRecipe.create( + mapOf( + Character.valueOf('r') to Ingredient.ofItems(Items.REDSTONE), + Character.valueOf('d') to Ingredient.ofItems(Items.DIAMOND), + Character.valueOf('l') to Ingredient.ofItems(Items.LAPIS_LAZULI), + Character.valueOf('i') to Ingredient.ofItems(Items.IRON_INGOT), + Character.valueOf('c') to Ingredient.ofItems(Items.CRAFTING_TABLE), + Character.valueOf('o') to Ingredient.ofItems(Items.OBSIDIAN), + ), + "rdl", + "ici", + "lor" + ), + CustomBlockItem.HT_CRAFTING_TABLE.createItemStack() +) diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Harvest.kt b/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Harvest.kt new file mode 100644 index 000000000..d1d1aec3a --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Harvest.kt @@ -0,0 +1,42 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2023 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.recipe.blocks + +import net.minecraft.item.Items +import net.minecraft.recipe.Ingredient.ofItems +import net.minecraft.recipe.RawShapedRecipe +import net.minecraft.recipe.ShapedRecipe +import net.minecraft.recipe.book.CraftingRecipeCategory +import one.oktw.galaxy.item.CustomBlockItem + +class Harvest : ShapedRecipe( + "", + CraftingRecipeCategory.BUILDING, + RawShapedRecipe.create( + mapOf( + Character.valueOf('c') to ofItems(Items.COPPER_INGOT), + Character.valueOf('o') to ofItems(Items.OBSERVER), + Character.valueOf('d') to ofItems(Items.DISPENSER), + ), + "ccc", + "cdo", + "ccc" + ), + CustomBlockItem.HARVEST.createItemStack() +) diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Trashcan.kt b/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Trashcan.kt new file mode 100644 index 000000000..2204f2215 --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/recipe/blocks/Trashcan.kt @@ -0,0 +1,43 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2023 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.recipe.blocks + +import net.minecraft.item.Items +import net.minecraft.recipe.Ingredient.ofItems +import net.minecraft.recipe.RawShapedRecipe +import net.minecraft.recipe.ShapedRecipe +import net.minecraft.recipe.book.CraftingRecipeCategory +import one.oktw.galaxy.item.CustomBlockItem + +class Trashcan : ShapedRecipe( + "", + CraftingRecipeCategory.BUILDING, + RawShapedRecipe.create( + mapOf( + Character.valueOf('g') to ofItems(Items.GLASS), + Character.valueOf('c') to ofItems(Items.CACTUS), + Character.valueOf('t') to ofItems(Items.TERRACOTTA), + Character.valueOf('s') to ofItems(Items.SAND, Items.RED_SAND) + ), + "ggg", + "gcg", + "tst" + ), + CustomBlockItem.TRASHCAN.createItemStack() +) diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/BookAndQuill.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/BookAndQuill.kt deleted file mode 100644 index 064432731..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/BookAndQuill.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class BookAndQuill : CraftingRecipe { - private val item = Items.WRITABLE_BOOK.defaultStack - - private val paper = Ingredient(items = listOf(Items.PAPER)) - private val leather = Ingredient(items = listOf(Items.LEATHER)) - private val feather = Ingredient(items = listOf(Items.FEATHER)) - private val inkSac = Ingredient(items = listOf(Items.INK_SAC)) - private val list = listOf(paper, paper, paper, leather, feather, inkSac) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapelessMatches(inv, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/writable_book") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/CarrotOnAStick.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/CarrotOnAStick.kt deleted file mode 100644 index 40f4ed4cc..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/CarrotOnAStick.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class CarrotOnAStick : CraftingRecipe { - private val item = Items.CARROT_ON_A_STICK.defaultStack!! - - private val air = Ingredient(items = listOf(Items.AIR)) - private val stick = Ingredient(items = listOf(Items.STICK)) - private val strings = Ingredient(items = listOf(Items.STRING)) - private val carrot = Ingredient(items = listOf(Items.CARROT)) - private val listLeft = listOf( - stick, air, air, - strings, stick, air, - strings, carrot, stick - ) - private val listRight = listOf( - air, air, stick, - air, stick, strings, - stick, carrot, strings - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = - (RecipeUtils.isItemShapedMatches(inv, 3, 3, listLeft) || RecipeUtils.isItemShapedMatches(inv, 3, 3, listRight)) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/carrot_on_a_stick") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.MISC -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Chest.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Chest.kt deleted file mode 100644 index 3de8351e6..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Chest.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.registry.tag.ItemTags -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Chest : CraftingRecipe { - private val item = Items.CHEST.defaultStack.apply { this.count = 4 } - - private val logs = Ingredient(tag = ItemTags.LOGS) - private val air = Ingredient(items = listOf(Items.AIR)) - private val list = listOf( - logs, logs, logs, - logs, air, logs, - logs, logs, logs - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 3, 3, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/chest") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Dispenser.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Dispenser.kt deleted file mode 100644 index 94a15f954..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Dispenser.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Dispenser : CraftingRecipe { - private val item = Items.DISPENSER.defaultStack - private val list = - listOf(Ingredient(items = listOf(Items.BOW)), Ingredient(items = listOf(Items.DROPPER))) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapelessMatches(inv, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/dispenser") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/DispenserWithBow.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/DispenserWithBow.kt deleted file mode 100644 index becb7261f..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/DispenserWithBow.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class DispenserWithBow : CraftingRecipe { - private val item = Items.DISPENSER.defaultStack - - private val air = Ingredient(items = listOf(Items.AIR)) - private val stick = Ingredient(items = listOf(Items.STICK)) - private val strings = Ingredient(items = listOf(Items.STRING)) - private val dropper = Ingredient(items = listOf(Items.DROPPER)) - private val listLeft = listOf( - air, stick, strings, - stick, dropper, strings, - air, stick, strings - ) - private val listRight = listOf( - strings, stick, air, - strings, dropper, stick, - strings, stick, air - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = - (RecipeUtils.isItemShapedMatches(inv, 3, 3, listLeft) || RecipeUtils.isItemShapedMatches(inv, 3, 3, listRight)) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/dispenser_with_bow") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Glass.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Glass.kt deleted file mode 100644 index de75433ca..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Glass.kt +++ /dev/null @@ -1,124 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Glass : CraftingRecipe { - private val dyes = hashMapOf( - Items.RED_DYE to Items.RED_STAINED_GLASS, - Items.GREEN_DYE to Items.GREEN_STAINED_GLASS, - Items.PURPLE_DYE to Items.PURPLE_STAINED_GLASS, - Items.CYAN_DYE to Items.CYAN_STAINED_GLASS, - Items.LIGHT_GRAY_DYE to Items.LIGHT_GRAY_STAINED_GLASS, - Items.GRAY_DYE to Items.GRAY_STAINED_GLASS, - Items.PINK_DYE to Items.PINK_STAINED_GLASS, - Items.LIME_DYE to Items.LIME_STAINED_GLASS, - Items.YELLOW_DYE to Items.YELLOW_STAINED_GLASS, - Items.LIGHT_BLUE_DYE to Items.LIGHT_BLUE_STAINED_GLASS, - Items.MAGENTA_DYE to Items.MAGENTA_STAINED_GLASS, - Items.ORANGE_DYE to Items.ORANGE_STAINED_GLASS, - Items.BLACK_DYE to Items.BLACK_STAINED_GLASS, - Items.BROWN_DYE to Items.BROWN_STAINED_GLASS, - Items.BLUE_DYE to Items.BLUE_STAINED_GLASS, - Items.WHITE_DYE to Items.WHITE_STAINED_GLASS - ) - - private val stainedGlass = listOf( - Items.WHITE_STAINED_GLASS, - Items.ORANGE_STAINED_GLASS, - Items.MAGENTA_STAINED_GLASS, - Items.LIGHT_BLUE_STAINED_GLASS, - Items.YELLOW_STAINED_GLASS, - Items.LIME_STAINED_GLASS, - Items.PINK_STAINED_GLASS, - Items.GRAY_STAINED_GLASS, - Items.LIGHT_GRAY_STAINED_GLASS, - Items.CYAN_STAINED_GLASS, - Items.PURPLE_STAINED_GLASS, - Items.BLUE_STAINED_GLASS, - Items.BROWN_STAINED_GLASS, - Items.GREEN_STAINED_GLASS, - Items.RED_STAINED_GLASS, - Items.BLACK_STAINED_GLASS - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean { - var match = false - dyes.forEach { (recipeItem, _) -> - val stainedGlass = Ingredient(items = stainedGlass) - val dye = Ingredient(items = listOf(recipeItem)) - val list = listOf( - stainedGlass, stainedGlass, stainedGlass, - stainedGlass, dye, stainedGlass, - stainedGlass, stainedGlass, stainedGlass, - ) - if (RecipeUtils.isItemShapedMatches(inv, 3, 3, list)) { - match = true - return@forEach - } - } - return match - } - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager): ItemStack { - var item = ItemStack.EMPTY - dyes.forEach { (recipeItem, result) -> - val stainedGlass = Ingredient(items = stainedGlass) - val dye = Ingredient(items = listOf(recipeItem)) - val list = listOf( - stainedGlass, stainedGlass, stainedGlass, - stainedGlass, dye, stainedGlass, - stainedGlass, stainedGlass, stainedGlass, - ) - if (RecipeUtils.isItemShapedMatches(inv, 3, 3, list)) { - item = result.defaultStack.apply { this.count = 8 } - return@forEach - } - } - return item - } - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = Items.GLASS.defaultStack.apply { this.count = 8 } - - override fun getId() = Identifier("galaxy", "easy_recipe/glass") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/GlassPane.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/GlassPane.kt deleted file mode 100644 index 503a1ae25..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/GlassPane.kt +++ /dev/null @@ -1,124 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class GlassPane : CraftingRecipe { - private val dyes = hashMapOf( - Items.RED_DYE to Items.RED_STAINED_GLASS_PANE, - Items.GREEN_DYE to Items.GREEN_STAINED_GLASS_PANE, - Items.PURPLE_DYE to Items.PURPLE_STAINED_GLASS_PANE, - Items.CYAN_DYE to Items.CYAN_STAINED_GLASS_PANE, - Items.LIGHT_GRAY_DYE to Items.LIGHT_GRAY_STAINED_GLASS_PANE, - Items.GRAY_DYE to Items.GRAY_STAINED_GLASS_PANE, - Items.PINK_DYE to Items.PINK_STAINED_GLASS_PANE, - Items.LIME_DYE to Items.LIME_STAINED_GLASS_PANE, - Items.YELLOW_DYE to Items.YELLOW_STAINED_GLASS_PANE, - Items.LIGHT_BLUE_DYE to Items.LIGHT_BLUE_STAINED_GLASS_PANE, - Items.MAGENTA_DYE to Items.MAGENTA_STAINED_GLASS_PANE, - Items.ORANGE_DYE to Items.ORANGE_STAINED_GLASS_PANE, - Items.BLACK_DYE to Items.BLACK_STAINED_GLASS_PANE, - Items.BROWN_DYE to Items.BROWN_STAINED_GLASS_PANE, - Items.BLUE_DYE to Items.BLUE_STAINED_GLASS_PANE, - Items.WHITE_DYE to Items.WHITE_STAINED_GLASS_PANE - ) - - private val stainedGlassPane = listOf( - Items.WHITE_STAINED_GLASS_PANE, - Items.ORANGE_STAINED_GLASS_PANE, - Items.MAGENTA_STAINED_GLASS_PANE, - Items.LIGHT_BLUE_STAINED_GLASS_PANE, - Items.YELLOW_STAINED_GLASS_PANE, - Items.LIME_STAINED_GLASS_PANE, - Items.PINK_STAINED_GLASS_PANE, - Items.GRAY_STAINED_GLASS_PANE, - Items.LIGHT_GRAY_STAINED_GLASS_PANE, - Items.CYAN_STAINED_GLASS_PANE, - Items.PURPLE_STAINED_GLASS_PANE, - Items.BLUE_STAINED_GLASS_PANE, - Items.BROWN_STAINED_GLASS_PANE, - Items.GREEN_STAINED_GLASS_PANE, - Items.RED_STAINED_GLASS_PANE, - Items.BLACK_STAINED_GLASS_PANE - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean { - var match = false - dyes.forEach { (recipeItem, _) -> - val glassPane = Ingredient(items = stainedGlassPane) - val dye = Ingredient(items = listOf(recipeItem)) - val list = listOf( - glassPane, glassPane, glassPane, - glassPane, dye, glassPane, - glassPane, glassPane, glassPane, - ) - if (RecipeUtils.isItemShapedMatches(inv, 3, 3, list)) { - match = true - return@forEach - } - } - return match - } - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager): ItemStack { - var item = ItemStack.EMPTY - dyes.forEach { (recipeItem, result) -> - val glassPane = Ingredient(items = stainedGlassPane) - val dye = Ingredient(items = listOf(recipeItem)) - val list = listOf( - glassPane, glassPane, glassPane, - glassPane, dye, glassPane, - glassPane, glassPane, glassPane, - ) - if (RecipeUtils.isItemShapedMatches(inv, 3, 3, list)) { - item = result.defaultStack.apply { this.count = 8 } - return@forEach - } - } - return item - } - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = Items.GLASS_PANE.defaultStack.apply { this.count = 8 } - - override fun getId() = Identifier("galaxy", "easy_recipe/glass_pane") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/GlassPaneRestore.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/GlassPaneRestore.kt deleted file mode 100644 index 58d476106..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/GlassPaneRestore.kt +++ /dev/null @@ -1,104 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class GlassPaneRestore : CraftingRecipe { - private val glassPane = hashMapOf( - Items.GLASS_PANE to Items.GLASS, - Items.RED_STAINED_GLASS_PANE to Items.RED_STAINED_GLASS, - Items.GREEN_STAINED_GLASS_PANE to Items.GREEN_STAINED_GLASS, - Items.PURPLE_STAINED_GLASS_PANE to Items.PURPLE_STAINED_GLASS, - Items.CYAN_STAINED_GLASS_PANE to Items.CYAN_STAINED_GLASS, - Items.LIGHT_GRAY_STAINED_GLASS_PANE to Items.LIGHT_GRAY_STAINED_GLASS, - Items.GRAY_STAINED_GLASS_PANE to Items.GRAY_STAINED_GLASS, - Items.PINK_STAINED_GLASS_PANE to Items.PINK_STAINED_GLASS, - Items.LIME_STAINED_GLASS_PANE to Items.LIME_STAINED_GLASS, - Items.YELLOW_STAINED_GLASS_PANE to Items.YELLOW_STAINED_GLASS, - Items.LIGHT_BLUE_STAINED_GLASS_PANE to Items.LIGHT_BLUE_STAINED_GLASS, - Items.MAGENTA_STAINED_GLASS_PANE to Items.MAGENTA_STAINED_GLASS, - Items.ORANGE_STAINED_GLASS_PANE to Items.ORANGE_STAINED_GLASS, - Items.BLACK_STAINED_GLASS_PANE to Items.BLACK_STAINED_GLASS, - Items.BROWN_STAINED_GLASS_PANE to Items.BROWN_STAINED_GLASS, - Items.BLUE_STAINED_GLASS_PANE to Items.BLUE_STAINED_GLASS, - Items.WHITE_STAINED_GLASS_PANE to Items.WHITE_STAINED_GLASS - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean { - var match = false - glassPane.forEach { (recipeItem, _) -> - val glassPane = Ingredient(items = listOf(recipeItem)) - val list = listOf( - glassPane, glassPane, - glassPane, glassPane, glassPane, - glassPane, glassPane, glassPane, - ) - if (RecipeUtils.isItemShapelessMatches(inv, list)) { - match = true - return@forEach - } - } - return match - } - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager): ItemStack { - var item = ItemStack.EMPTY - glassPane.forEach { (recipeItem, result) -> - val glassPane = Ingredient(items = listOf(recipeItem)) - val list = listOf( - glassPane, glassPane, - glassPane, glassPane, glassPane, - glassPane, glassPane, glassPane, - ) - if (RecipeUtils.isItemShapelessMatches(inv, list)) { - item = result.defaultStack.apply { this.count = 3 } - return@forEach - } - } - return item - } - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = Items.GLASS_PANE.defaultStack.apply { this.count = 3 } - - override fun getId() = Identifier("galaxy", "easy_recipe/glass_pane_restore") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Hopper.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Hopper.kt deleted file mode 100644 index a50eab18e..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Hopper.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.registry.tag.ItemTags -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Hopper : CraftingRecipe { - private val item = Items.HOPPER.defaultStack - - private val air = Ingredient(items = listOf(Items.AIR)) - private val logs = Ingredient(tag = ItemTags.LOGS) - private val ironIngot = Ingredient(items = listOf(Items.IRON_INGOT)) - private val list = listOf( - ironIngot, logs, ironIngot, - ironIngot, logs, ironIngot, - air, ironIngot, air - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 3, 3, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/hopper") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Ladder.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Ladder.kt deleted file mode 100644 index ca81c7b64..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Ladder.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.registry.tag.ItemTags -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Ladder : CraftingRecipe { - private val item = Items.LADDER.defaultStack.apply { this.count = 24 } - - private val air = Ingredient(items = listOf(Items.AIR)) - private val logs = Ingredient(tag = ItemTags.LOGS) - private val list = listOf( - logs, air, logs, - logs, logs, logs, - logs, air, logs - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 3, 3, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/ladder") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.MISC -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Minecart.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Minecart.kt deleted file mode 100644 index cdb46f8a3..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Minecart.kt +++ /dev/null @@ -1,91 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Minecart : CraftingRecipe { - private val minecartType = hashMapOf( - Items.CHEST to Items.CHEST_MINECART, - Items.FURNACE to Items.FURNACE_MINECART, - Items.HOPPER to Items.HOPPER_MINECART, - Items.TNT to Items.TNT_MINECART - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean { - var match = false - minecartType.forEach { (recipeItem, _) -> - val ironIngot = Ingredient(items = listOf(Items.IRON_INGOT)) - val type = Ingredient(items = listOf(recipeItem)) - val list = listOf( - ironIngot, type, ironIngot, - ironIngot, ironIngot, ironIngot - ) - if (RecipeUtils.isItemShapedMatches(inv, 3, 2, list)) { - match = true - return@forEach - } - } - return match - } - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager): ItemStack { - var item = ItemStack.EMPTY - minecartType.forEach { (recipeItem, result) -> - val ironIngot = Ingredient(items = listOf(Items.IRON_INGOT)) - val type = Ingredient(items = listOf(recipeItem)) - val list = listOf( - ironIngot, type, ironIngot, - ironIngot, ironIngot, ironIngot - ) - if (RecipeUtils.isItemShapedMatches(inv, 3, 2, list)) { - item = result.defaultStack - return@forEach - } - } - return item - } - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = Items.MINECART.defaultStack - - override fun getId() = Identifier("galaxy", "easy_recipe/minecart") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.MISC -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/RedStoneLamp.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/RedStoneLamp.kt deleted file mode 100644 index 3333f15da..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/RedStoneLamp.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class RedStoneLamp : CraftingRecipe { - private val item = Items.REDSTONE_LAMP.defaultStack - - private val air = Ingredient(items = listOf(Items.AIR)) - private val redStone = Ingredient(items = listOf(Items.REDSTONE)) - private val glowStoneDust = Ingredient(items = listOf(Items.GLOWSTONE_DUST)) - private val list = listOf( - redStone, glowStoneDust, redStone, - glowStoneDust, air, glowStoneDust, - redStone, glowStoneDust, redStone - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 3, 3, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/redstone_lamp") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/RedStoneRepeater.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/RedStoneRepeater.kt deleted file mode 100644 index fa670eb11..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/RedStoneRepeater.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class RedStoneRepeater : CraftingRecipe { - private val item = Items.REPEATER.defaultStack - - private val air = Ingredient(items = listOf(Items.AIR)) - private val redStone = Ingredient(items = listOf(Items.REDSTONE)) - private val redStoneTorch = Ingredient(items = listOf(Items.REDSTONE_TORCH)) - private val stick = Ingredient(items = listOf(Items.STICK)) - private val stone = Ingredient(items = listOf(Items.STONE)) - private val noTorch = listOf( - redStone, air, redStone, - stick, redStone, stick, - stone, stone, stone - ) - private val oneTorchLeft = listOf( - air, air, redStone, - redStoneTorch, redStone, stick, - stone, stone, stone - ) - private val oneTorchRight = listOf( - redStone, air, air, - stick, redStone, redStoneTorch, - stone, stone, stone - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = - (RecipeUtils.isItemShapedMatches(inv, 3, 3, noTorch) || RecipeUtils.isItemShapedMatches(inv, 3, 3, oneTorchLeft) || RecipeUtils.isItemShapedMatches( - inv, - 3, - 3, - oneTorchRight - )) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/redstone_repeater") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/SlabRestore.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/SlabRestore.kt deleted file mode 100644 index 1e888f9be..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/SlabRestore.kt +++ /dev/null @@ -1,132 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class SlabRestore : CraftingRecipe { - private val slabs = hashMapOf( - Items.CUT_COPPER_SLAB to Items.CUT_COPPER, - Items.EXPOSED_CUT_COPPER_SLAB to Items.EXPOSED_CUT_COPPER, - Items.WEATHERED_CUT_COPPER_SLAB to Items.WEATHERED_CUT_COPPER, - Items.OXIDIZED_CUT_COPPER_SLAB to Items.OXIDIZED_CUT_COPPER, - Items.WAXED_CUT_COPPER_SLAB to Items.WAXED_CUT_COPPER, - Items.WAXED_EXPOSED_CUT_COPPER_SLAB to Items.WAXED_EXPOSED_CUT_COPPER, - Items.WAXED_WEATHERED_CUT_COPPER_SLAB to Items.WAXED_WEATHERED_COPPER, - Items.WAXED_OXIDIZED_CUT_COPPER_SLAB to Items.WAXED_OXIDIZED_CUT_COPPER, - Items.OAK_SLAB to Items.OAK_PLANKS, - Items.SPRUCE_SLAB to Items.SPRUCE_PLANKS, - Items.BIRCH_SLAB to Items.BIRCH_PLANKS, - Items.JUNGLE_SLAB to Items.JUNGLE_PLANKS, - Items.ACACIA_SLAB to Items.ACACIA_PLANKS, - Items.DARK_OAK_SLAB to Items.DARK_OAK_PLANKS, - Items.CRIMSON_SLAB to Items.CRIMSON_PLANKS, - Items.WARPED_SLAB to Items.WARPED_PLANKS, - Items.STONE_SLAB to Items.STONE, - Items.SMOOTH_STONE_SLAB to Items.SMOOTH_STONE, - Items.SANDSTONE_SLAB to Items.SANDSTONE, - Items.CUT_SANDSTONE_SLAB to Items.CUT_SANDSTONE, - Items.COBBLESTONE_SLAB to Items.COBBLESTONE, - Items.BRICK_SLAB to Items.BRICKS, - Items.STONE_BRICK_SLAB to Items.STONE_BRICKS, - Items.NETHER_BRICK_SLAB to Items.NETHER_BRICKS, - Items.QUARTZ_SLAB to Items.QUARTZ_BLOCK, - Items.RED_SANDSTONE_SLAB to Items.RED_SANDSTONE, - Items.CUT_RED_SANDSTONE_SLAB to Items.CUT_RED_SANDSTONE, - Items.PURPUR_SLAB to Items.PURPUR_BLOCK, - Items.PRISMARINE_SLAB to Items.PRISMARINE, - Items.PRISMARINE_BRICK_SLAB to Items.PRISMARINE_BRICKS, - Items.DARK_PRISMARINE_SLAB to Items.DARK_PRISMARINE, - Items.POLISHED_GRANITE_SLAB to Items.POLISHED_GRANITE, - Items.SMOOTH_RED_SANDSTONE_SLAB to Items.SMOOTH_RED_SANDSTONE, - Items.MOSSY_STONE_BRICK_SLAB to Items.MOSSY_STONE_BRICKS, - Items.POLISHED_DIORITE_SLAB to Items.POLISHED_DIORITE, - Items.MOSSY_COBBLESTONE_SLAB to Items.MOSSY_COBBLESTONE, - Items.END_STONE_BRICK_SLAB to Items.END_STONE_BRICKS, - Items.SMOOTH_SANDSTONE_SLAB to Items.SMOOTH_SANDSTONE, - Items.SMOOTH_QUARTZ_SLAB to Items.SMOOTH_QUARTZ, - Items.GRANITE_SLAB to Items.GRANITE, - Items.ANDESITE_SLAB to Items.ANDESITE, - Items.RED_NETHER_BRICK_SLAB to Items.RED_NETHER_BRICKS, - Items.POLISHED_ANDESITE_SLAB to Items.POLISHED_ANDESITE, - Items.DIORITE_SLAB to Items.DIORITE, - Items.COBBLED_DEEPSLATE_SLAB to Items.COBBLED_DEEPSLATE, - Items.POLISHED_DEEPSLATE_SLAB to Items.POLISHED_DEEPSLATE, - Items.DEEPSLATE_BRICK_SLAB to Items.DEEPSLATE_BRICKS, - Items.DEEPSLATE_TILE_SLAB to Items.DEEPSLATE_TILES, - Items.BLACKSTONE_SLAB to Items.BLACKSTONE, - Items.POLISHED_BLACKSTONE_SLAB to Items.POLISHED_BLACKSTONE, - Items.POLISHED_BLACKSTONE_BRICK_SLAB to Items.POLISHED_BLACKSTONE_BRICKS - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean { - var match = false - slabs.forEach { (recipeItem, _) -> - val list = listOf( - Ingredient(items = listOf(recipeItem)), Ingredient(items = listOf(recipeItem)) - ) - if (RecipeUtils.isItemShapedMatches(inv, 2, 1, list)) { - match = true - return@forEach - } - } - return match - } - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager): ItemStack { - var item = ItemStack.EMPTY - slabs.forEach { (recipeItem, result) -> - val list = listOf( - Ingredient(items = listOf(recipeItem)), Ingredient(items = listOf(recipeItem)) - ) - if (RecipeUtils.isItemShapedMatches(inv, 2, 1, list)) { - item = result.defaultStack - return@forEach - } - } - return item - } - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = Items.OAK_PLANKS.defaultStack - - override fun getId() = Identifier("galaxy", "easy_recipe/slab_restore") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/StainedGlassPaneRestore.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/StainedGlassPaneRestore.kt deleted file mode 100644 index df7592e72..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/StainedGlassPaneRestore.kt +++ /dev/null @@ -1,113 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class StainedGlassPaneRestore : CraftingRecipe { - private val stainedGlassPane = listOf( - Items.WHITE_STAINED_GLASS_PANE, - Items.ORANGE_STAINED_GLASS_PANE, - Items.MAGENTA_STAINED_GLASS_PANE, - Items.LIGHT_BLUE_STAINED_GLASS_PANE, - Items.YELLOW_STAINED_GLASS_PANE, - Items.LIME_STAINED_GLASS_PANE, - Items.PINK_STAINED_GLASS_PANE, - Items.GRAY_STAINED_GLASS_PANE, - Items.LIGHT_GRAY_STAINED_GLASS_PANE, - Items.CYAN_STAINED_GLASS_PANE, - Items.PURPLE_STAINED_GLASS_PANE, - Items.BLUE_STAINED_GLASS_PANE, - Items.BROWN_STAINED_GLASS_PANE, - Items.GREEN_STAINED_GLASS_PANE, - Items.RED_STAINED_GLASS_PANE, - Items.BLACK_STAINED_GLASS_PANE - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean { - var match = false - val stainedGlassPane = Ingredient(items = stainedGlassPane) - val waterBucket = Ingredient(items = listOf(Items.WATER_BUCKET)) - - val list = listOf(waterBucket) - - for (count in 1..8) { - val countedList = list.toMutableList() - - for (addCount in 1..count) { - countedList.add(stainedGlassPane) - } - - if (RecipeUtils.isItemShapelessMatches(inv, countedList)) { - match = true - break - } - } - return match - } - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager): ItemStack { - var item = ItemStack.EMPTY - val stainedGlassPane = Ingredient(items = stainedGlassPane) - val waterBucket = Ingredient(items = listOf(Items.WATER_BUCKET)) - - val list = listOf(waterBucket) - - for (count in 1..8) { - val countedList = list.toMutableList() - - for (addCount in 1..count) { - countedList.add(stainedGlassPane) - } - - if (RecipeUtils.isItemShapelessMatches(inv, countedList)) { - item = Items.GLASS_PANE.defaultStack.apply { this.count = count } - break - } - } - return item - } - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = Items.GLASS_PANE.defaultStack.apply { this.count = 1 } - - override fun getId() = Identifier("galaxy", "easy_recipe/stained_glass_pane_restore") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/StainedGlassRestore.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/StainedGlassRestore.kt deleted file mode 100644 index e6e3ac6d6..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/StainedGlassRestore.kt +++ /dev/null @@ -1,114 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class StainedGlassRestore : CraftingRecipe { - private val stainedGlass = listOf( - Items.WHITE_STAINED_GLASS, - Items.ORANGE_STAINED_GLASS, - Items.MAGENTA_STAINED_GLASS, - Items.LIGHT_BLUE_STAINED_GLASS, - Items.YELLOW_STAINED_GLASS, - Items.LIME_STAINED_GLASS, - Items.PINK_STAINED_GLASS, - Items.GRAY_STAINED_GLASS, - Items.LIGHT_GRAY_STAINED_GLASS, - Items.CYAN_STAINED_GLASS, - Items.PURPLE_STAINED_GLASS, - Items.BLUE_STAINED_GLASS, - Items.BROWN_STAINED_GLASS, - Items.GREEN_STAINED_GLASS, - Items.RED_STAINED_GLASS, - Items.BLACK_STAINED_GLASS - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean { - var match = false - val stainedGlass = Ingredient(items = stainedGlass) - val waterBucket = Ingredient(items = listOf(Items.WATER_BUCKET)) - - val list = listOf(waterBucket) - - for (count in 1..8) { - val countedList = list.toMutableList() - - for (addCount in 1..count) { - countedList.add(stainedGlass) - } - - if (RecipeUtils.isItemShapelessMatches(inv, countedList)) { - match = true - break - } - } - - return match - } - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager): ItemStack { - var item = ItemStack.EMPTY - val stainedGlass = Ingredient(items = stainedGlass) - val waterBucket = Ingredient(items = listOf(Items.WATER_BUCKET)) - - val list = listOf(waterBucket) - - for (count in 1..8) { - val countedList = list.toMutableList() - - for (addCount in 1..count) { - countedList.add(stainedGlass) - } - - if (RecipeUtils.isItemShapelessMatches(inv, countedList)) { - item = Items.GLASS.defaultStack.apply { this.count = count } - break - } - } - return item - } - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = Items.GLASS.defaultStack.apply { this.count = 1 } - - override fun getId() = Identifier("galaxy", "easy_recipe/stained_glass_restore") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Stick.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Stick.kt deleted file mode 100644 index 188248cae..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/Stick.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.registry.tag.ItemTags -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Stick : CraftingRecipe { - private val item = Items.STICK.defaultStack.apply { this.count = 16 } - private val list = listOf( - Ingredient(tag = ItemTags.LOGS), - Ingredient(tag = ItemTags.LOGS) - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 1, 2, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/stick") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.MISC -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/TrappedChest.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/TrappedChest.kt deleted file mode 100644 index d547bc258..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/TrappedChest.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.registry.tag.ItemTags -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class TrappedChest : CraftingRecipe { - private val item = Items.TRAPPED_CHEST.defaultStack - - private val planks = Ingredient(tag = ItemTags.PLANKS) - private val tripWireHook = Ingredient(items = listOf(Items.TRIPWIRE_HOOK)) - private val list = listOf( - planks, planks, planks, - planks, tripWireHook, planks, - planks, planks, planks - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 3, 3, list) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/trapped_chest") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/WarpedFungusOnAStick.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/WarpedFungusOnAStick.kt deleted file mode 100644 index 8a99827b6..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/WarpedFungusOnAStick.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class WarpedFungusOnAStick : CraftingRecipe { - private val item = Items.WARPED_FUNGUS_ON_A_STICK.defaultStack - - private val air = Ingredient(items = listOf(Items.AIR)) - private val stick = Ingredient(items = listOf(Items.STICK)) - private val strings = Ingredient(items = listOf(Items.STRING)) - private val warpedFungus = Ingredient(items = listOf(Items.WARPED_FUNGUS)) - private val listLeft = listOf( - stick, air, air, - strings, stick, air, - strings, warpedFungus, stick - ) - private val listRight = listOf( - air, air, stick, - air, stick, strings, - stick, warpedFungus, strings - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = - (RecipeUtils.isItemShapedMatches(inv, 3, 3, listLeft) || RecipeUtils.isItemShapedMatches(inv, 3, 3, listRight)) - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = item.copy() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "easy_recipe/warped_fungus_on_a_stick") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/WoodenSlab.kt b/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/WoodenSlab.kt deleted file mode 100644 index 44203d864..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/easyRecipe/WoodenSlab.kt +++ /dev/null @@ -1,90 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.easyRecipe - -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer -import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.registry.tag.ItemTags -import net.minecraft.util.Identifier -import net.minecraft.world.World -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class WoodenSlab : CraftingRecipe { - private val slabs = hashMapOf( - ItemTags.OAK_LOGS to Items.OAK_SLAB, - ItemTags.SPRUCE_LOGS to Items.SPRUCE_SLAB, - ItemTags.BIRCH_LOGS to Items.BIRCH_SLAB, - ItemTags.JUNGLE_LOGS to Items.JUNGLE_SLAB, - ItemTags.ACACIA_LOGS to Items.ACACIA_SLAB, - ItemTags.DARK_OAK_LOGS to Items.DARK_OAK_SLAB, - ItemTags.CRIMSON_STEMS to Items.CRIMSON_SLAB, - ItemTags.WARPED_STEMS to Items.WARPED_SLAB - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean { - var match = false - slabs.forEach { (tag, _) -> - val list = listOf( - Ingredient(tag = tag), Ingredient(tag = tag), Ingredient(tag = tag) - ) - if (RecipeUtils.isItemShapedMatches(inv, 3, 1, list)) { - match = true - return@forEach - } - } - return match - } - - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager): ItemStack { - var item = ItemStack.EMPTY - slabs.forEach { (tag, result) -> - val list = listOf( - Ingredient(tag = tag), Ingredient(tag = tag), Ingredient(tag = tag) - ) - if (RecipeUtils.isItemShapedMatches(inv, 3, 1, list)) { - item = result.defaultStack.apply { this.count = 24 } - return@forEach - } - } - return item - } - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = Items.OAK_SLAB.defaultStack.apply { this.count = 24 } - - override fun getId() = Identifier("galaxy", "easy_recipe/wood_slab") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.BUILDING -} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/materials/CeramicPlate.kt b/src/main/kotlin/one/oktw/galaxy/recipe/materials/CeramicPlate.kt index 847902e70..8cacc8cd1 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/materials/CeramicPlate.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/materials/CeramicPlate.kt @@ -20,31 +20,22 @@ package one.oktw.galaxy.recipe.materials import net.minecraft.inventory.Inventory import net.minecraft.recipe.Ingredient -import net.minecraft.recipe.RecipeSerializer import net.minecraft.recipe.SmeltingRecipe import net.minecraft.recipe.book.CookingRecipeCategory -import net.minecraft.util.Identifier import net.minecraft.world.World import one.oktw.galaxy.item.CustomItemHelper import one.oktw.galaxy.item.Material -class CeramicPlate : - SmeltingRecipe( - Identifier("galaxy", "material/ceramic_plate"), - "", - CookingRecipeCategory.MISC, - Ingredient.ofStacks(Material.RAW_BASE_PLATE.createItemStack()), - Material.BASE_PLATE.createItemStack(), - 5.0F, - 200 - ) { - - override fun matches(inventory: Inventory?, world: World?): Boolean { - val input = inventory?.getStack(0) ?: return super.matches(inventory, world) +class CeramicPlate : SmeltingRecipe( + "", + CookingRecipeCategory.MISC, + Ingredient.ofStacks(Material.RAW_BASE_PLATE.createItemStack()), + Material.BASE_PLATE.createItemStack(), + 0.1F, + 200 +) { + override fun matches(inventory: Inventory, world: World): Boolean { + val input = inventory.getStack(0) ?: return false return CustomItemHelper.getItem(input) == Material.RAW_BASE_PLATE } - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/tools/Crowbar.kt b/src/main/kotlin/one/oktw/galaxy/recipe/tools/Crowbar.kt index 81cc79140..cf1099d37 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/tools/Crowbar.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/tools/Crowbar.kt @@ -18,47 +18,24 @@ package one.oktw.galaxy.recipe.tools -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.inventory.RecipeInputInventory import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer +import net.minecraft.recipe.RawShapedRecipe +import net.minecraft.recipe.ShapedRecipe import net.minecraft.recipe.book.CraftingRecipeCategory import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World import one.oktw.galaxy.item.Tool -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Crowbar : CraftingRecipe { - private val item = Tool.CROWBAR.createItemStack() - - private val air = Ingredient(items = listOf(Items.AIR)) - private val ironIngot = Ingredient(items = listOf(Items.IRON_INGOT)) - private val list = listOf( - ironIngot, ironIngot, - air, ironIngot, - air, ironIngot, - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 2, 3, list = list) +class Crowbar : ShapedRecipe( + "", + CraftingRecipeCategory.EQUIPMENT, + RawShapedRecipe.create( + mapOf(Character.valueOf('i') to net.minecraft.recipe.Ingredient.ofItems(Items.IRON_INGOT)), + "ii", + " i", + " i" + ), + Tool.CROWBAR.createItemStack() +) { override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = Tool.CROWBAR.createItemStack() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "item/crowbar") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented") - } - - override fun getCategory() = CraftingRecipeCategory.EQUIPMENT } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/tools/Wrench.kt b/src/main/kotlin/one/oktw/galaxy/recipe/tools/Wrench.kt index ad12f3675..f6f152955 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/tools/Wrench.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/tools/Wrench.kt @@ -18,48 +18,25 @@ package one.oktw.galaxy.recipe.tools -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.inventory.RecipeInputInventory import net.minecraft.item.Items -import net.minecraft.recipe.CraftingRecipe -import net.minecraft.recipe.RecipeSerializer +import net.minecraft.recipe.Ingredient +import net.minecraft.recipe.RawShapedRecipe +import net.minecraft.recipe.ShapedRecipe import net.minecraft.recipe.book.CraftingRecipeCategory import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.util.Identifier -import net.minecraft.world.World import one.oktw.galaxy.item.Tool -import one.oktw.galaxy.recipe.utils.Ingredient -import one.oktw.galaxy.recipe.utils.RecipeUtils - -class Wrench : CraftingRecipe { - private val item = Tool.WRENCH.createItemStack() - - private val air = Ingredient(items = listOf(Items.AIR)) - private val ironIngot = Ingredient(items = listOf(Items.IRON_INGOT)) - private val stick = Ingredient(items = listOf(Items.STICK)) - private val list = listOf( - ironIngot, air, ironIngot, - air, stick, air, - air, ironIngot, air - ) - - override fun matches(inv: RecipeInputInventory, world: World): Boolean = RecipeUtils.isItemShapedMatches(inv, 3, 3, list = list) +class Wrench : ShapedRecipe( + "", + CraftingRecipeCategory.EQUIPMENT, + RawShapedRecipe.create( + mapOf(Character.valueOf('i') to Ingredient.ofItems(Items.IRON_INGOT), Character.valueOf('s') to Ingredient.ofItems(Items.STICK)), + "i i", + " s ", + " i " + ), + Tool.WRENCH.createItemStack() +) { override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = Tool.WRENCH.createItemStack() - - @Environment(EnvType.CLIENT) - override fun fits(width: Int, height: Int): Boolean { - throw NotImplementedError() - } - - override fun getOutput(registryManager: DynamicRegistryManager) = item - - override fun getId() = Identifier("galaxy", "item/wrench") - - override fun getSerializer(): RecipeSerializer<*> { - TODO("Not yet implemented, support client mod.") - } - - override fun getCategory() = CraftingRecipeCategory.EQUIPMENT } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/utils/RecipeUtils.kt b/src/main/kotlin/one/oktw/galaxy/recipe/utils/RecipeUtils.kt deleted file mode 100644 index 8e0b26ed0..000000000 --- a/src/main/kotlin/one/oktw/galaxy/recipe/utils/RecipeUtils.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.recipe.utils - -import net.minecraft.inventory.RecipeInputInventory -import net.minecraft.item.ItemStack -import net.minecraft.item.Items - -object RecipeUtils { - fun isItemShapedMatches(inv: RecipeInputInventory, width: Int, height: Int, list: List): Boolean { - for (x in 0..(inv.width - width)) { - for (y in 0..(inv.height - height)) { - if (shapeMatchesSmall(inv, width, height, x, y, true, list)) return true - if (shapeMatchesSmall(inv, width, height, x, y, false, list)) return true - } - } - - return false - } - - private fun shapeMatchesSmall( - inv: RecipeInputInventory, - width: Int, - height: Int, - offsetX: Int, - offsetY: Int, - widthFromLast: Boolean, - list: List - ): Boolean { - for (x in 0 until inv.width) { - for (y in 0 until inv.height) { - val i = x - offsetX - val j = y - offsetY - var input = Ingredient(items = listOf(Items.AIR)) - if (i >= 0 && j >= 0 && i < width && j < height) { - input = if (widthFromLast) { - list[width - i - 1 + j * width] - } else { - list[i + j * width] - } - } - if (!input.matches(inv.getStack(x + y * inv.width))) return false - } - } - return true - } - - fun isItemShapelessMatches(inv: RecipeInputInventory, list: List): Boolean { - val inputItems = mutableListOf() - - for (i in 0 until inv.size()) { - val invItem = inv.getStack(i) - if (!invItem.isEmpty) { - inputItems += invItem - } - } - - if (inputItems.count() != list.count()) return false - list.forEach { ingredient -> - val predicate = inputItems.firstOrNull { ingredient.matches(it) } - if (predicate != null) { - inputItems.remove(predicate) - } - } - return inputItems.isEmpty() - } -} diff --git a/src/main/kotlin/one/oktw/galaxy/util/HarvestUtil.kt b/src/main/kotlin/one/oktw/galaxy/util/HarvestUtil.kt new file mode 100644 index 000000000..34cf63352 --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/util/HarvestUtil.kt @@ -0,0 +1,45 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2023 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.util + +import net.minecraft.block.* +import net.minecraft.server.world.ServerWorld +import net.minecraft.state.property.Properties.HORIZONTAL_FACING +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Direction + +object HarvestUtil { + fun isMature(world: ServerWorld, blockPos: BlockPos, blockState: BlockState): Boolean = when (blockState.block) { + Blocks.WHEAT, Blocks.CARROTS, Blocks.POTATOES, Blocks.BEETROOTS -> blockState.let((blockState.block as CropBlock)::isMature) + Blocks.COCOA -> blockState[CocoaBlock.AGE] >= 2 + Blocks.NETHER_WART -> blockState[NetherWartBlock.AGE] >= 3 + Blocks.MELON -> isNextTo(world, blockPos, Blocks.ATTACHED_MELON_STEM) + Blocks.PUMPKIN -> isNextTo(world, blockPos, Blocks.ATTACHED_PUMPKIN_STEM) + else -> false + } + + private fun isNextTo(world: ServerWorld, blockPos: BlockPos, block: Block): Boolean { + for (direction in arrayOf(Direction.EAST, Direction.WEST, Direction.NORTH, Direction.SOUTH)) { + val pos = blockPos.offset(direction) + val blockState = world.getBlockState(pos) + if (blockState.block == block && pos.offset(blockState.get(HORIZONTAL_FACING)) == blockPos) return true + } + return false + } +} diff --git a/src/main/kotlin/one/oktw/galaxy/util/LoreEditor.kt b/src/main/kotlin/one/oktw/galaxy/util/LoreEditor.kt index 44b4773db..fd1dc8305 100644 --- a/src/main/kotlin/one/oktw/galaxy/util/LoreEditor.kt +++ b/src/main/kotlin/one/oktw/galaxy/util/LoreEditor.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2023 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -47,7 +47,7 @@ class LoreEditor private constructor(val item: ItemStack) { private val list = item.nbt?.getCompound(DISPLAY_KEY)?.getList(LORE_KEY, NbtElement.STRING_TYPE.toInt()) ?: NbtList() fun addText(text: Text): LoreEditor { - this.list.add(NbtString.of(Text.Serializer.toJson(text))) + this.list.add(NbtString.of(Text.Serialization.toJsonString(text))) return this } @@ -68,7 +68,7 @@ class LoreEditor private constructor(val item: ItemStack) { for (i in 0 until list.size) { val string = list.getString(i) ?: continue try { - val text: MutableText = Text.Serializer.fromJson(string) ?: continue + val text: MutableText = Text.Serialization.fromJson(string) ?: continue textList.add(Texts.setStyleIfAbsent(text, Style.EMPTY.withColor(DARK_PURPLE).withItalic(true))) // default lore style } catch (e: JsonParseException) { continue // skip lore diff --git a/src/main/resources/recipe.mixin.json b/src/main/resources/recipe.mixin.json index adba931e5..be86022fa 100644 --- a/src/main/resources/recipe.mixin.json +++ b/src/main/resources/recipe.mixin.json @@ -4,7 +4,6 @@ "compatibilityLevel": "JAVA_16", "mixins": [ "MixinCustomRecipe_CraftingResultSlot", - "MixinCustomRecipe_PlayerManager", "MixinCustomRecipe_RecipeManager" ], "client": [], diff --git a/src/main/resources/tweak.mixin.json b/src/main/resources/tweak.mixin.json index 8bde79761..b8c7f8b37 100644 --- a/src/main/resources/tweak.mixin.json +++ b/src/main/resources/tweak.mixin.json @@ -13,6 +13,7 @@ "MixinCustomBlockEntity_BarrierBlock", "MixinCustomBlockEntity_Structure", "MixinFixBeacon_BeaconBlockEntity", + "MixinGlobalDataPack_VanillaDataPackProvider", "MixinItemStackEqualAllowNull_ItemStack", "MixinMapExistingChunk_FilledMapItem", "MixinOneSpawnChunk_MinecraftServer",