From 2ac04e1cd89b8aaaa684f4df1da774d042e4c197 Mon Sep 17 00:00:00 2001 From: topi-banana Date: Fri, 6 Sep 2024 18:51:24 +0900 Subject: [PATCH] first commit --- .github/workflows/build.yml | 32 ---- .github/workflows/gradle.yml | 3 - README.md | 7 +- build.gradle | 18 +- common.gradle | 56 +++--- gradle.properties | 15 +- settings.json | 6 +- .../VulpeusCarpetExtension.java | 98 +++++++++++ .../vulpeus_carpet/VulpeusCarpetSettings.java | 53 ++++++ .../vulpeus_carpet/commands/hatCommand.java | 128 ++++++++++++++ .../vulpeus_carpet/commands/sitCommand.java | 68 ++++++++ .../vulpeus_carpet/commands/viewCommand.java | 58 +++++++ .../commandSit/MixinArmorStandEntity.java | 91 ++++++++++ .../disableCrash/MixinMinecraftServer.java | 55 ++++++ .../IMixinBlockPatternTestTransform.java | 37 ++++ .../MixinEnderDragonFight.java | 153 +++++++++++++++++ .../playerActions/PlayerCommandMixin.java | 107 ++++++++++++ .../ServerPlayerEntityMixin.java | 48 ++++++ .../utils/rule/commandSit/SitEntity.java | 28 +++ .../utils/rule/defaultOpLevel/PlayerUtil.java | 42 +++++ .../BlockPatternHelper.java | 52 ++++++ .../utils/rule/playerActions/Container.java | 99 +++++++++++ .../vulpeus_carpet/utils/sendMessage.java | 36 ++++ .../template_mod/TemplateMod.java | 55 ------ .../mixins/MinecraftServerMixin.java | 53 ------ .../{template_mod => vulpeus_carpet}/icon.png | Bin .../assets/vulpeus_carpet/lang/en_us.yml | 25 +++ src/main/resources/fabric.mod.json | 25 ++- src/main/resources/template_mod.mixins.json | 14 -- src/main/resources/vulpeus_carpet.mixins.json | 19 +++ versions/1.14.4/gradle.properties | 14 -- versions/1.16.5/gradle.properties | 15 -- versions/1.17.1/gradle.properties | 15 -- versions/1.18.2/gradle.properties | 14 -- versions/1.19.4/gradle.properties | 3 +- .../MixinEnderDragonFight.java | 161 ++++++++++++++++++ versions/{1.15.2 => 1.20.1}/gradle.properties | 13 +- versions/1.20.6/gradle.properties | 5 +- versions/1.21.1/gradle.properties | 3 +- versions/mainProject | 2 +- 40 files changed, 1434 insertions(+), 292 deletions(-) create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetExtension.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetSettings.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/commands/hatCommand.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/commands/sitCommand.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/commands/viewCommand.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/mixins/commandSit/MixinArmorStandEntity.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/mixins/disableCrash/MixinMinecraftServer.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/IMixinBlockPatternTestTransform.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/MixinEnderDragonFight.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/mixins/playerActions/PlayerCommandMixin.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/mixins/playerActions/ServerPlayerEntityMixin.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/commandSit/SitEntity.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/defaultOpLevel/PlayerUtil.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/optimizedDragonRespawn/BlockPatternHelper.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/playerActions/Container.java create mode 100644 src/main/java/com/vulpeus/vulpeus_carpet/utils/sendMessage.java delete mode 100644 src/main/java/me/fallenbreath/template_mod/TemplateMod.java delete mode 100644 src/main/java/me/fallenbreath/template_mod/mixins/MinecraftServerMixin.java rename src/main/resources/assets/{template_mod => vulpeus_carpet}/icon.png (100%) create mode 100644 src/main/resources/assets/vulpeus_carpet/lang/en_us.yml delete mode 100644 src/main/resources/template_mod.mixins.json create mode 100644 src/main/resources/vulpeus_carpet.mixins.json delete mode 100644 versions/1.14.4/gradle.properties delete mode 100644 versions/1.16.5/gradle.properties delete mode 100644 versions/1.17.1/gradle.properties delete mode 100644 versions/1.18.2/gradle.properties create mode 100644 versions/1.19.4/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/MixinEnderDragonFight.java rename versions/{1.15.2 => 1.20.1}/gradle.properties (52%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 511d421..897daf3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,12 +12,6 @@ on: type: string required: false default: '' -# # [FEATURE] MIXIN_AUDITOR -# mixin_audit: -# description: run mixin audit for Minecraft server after build -# type: boolean -# required: false -# default: false jobs: build: @@ -57,38 +51,12 @@ jobs: BUILD_ID: ${{ github.run_number }} BUILD_RELEASE: ${{ inputs.release }} -# # [FEATURE] MIXIN_AUDITOR -# - name: Run mixin audit check for Minecraft server -# if: ${{ inputs.mixin_audit }} -# timeout-minutes: 10 -# run: | -# mkdir -p ./run -# echo eula=true > ./run/eula.txt -# ./gradlew runServerMixinAudit - - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: build-artifacts path: versions/*/build/libs/ -# # [FEATURE] FALLENS_MAVEN -# - name: Publish with gradle -# if: inputs.release || github.ref == 'refs/heads/dev' -# run: | -# if [ -z "${{ inputs.target_subproject }}" ]; then -# echo "Publishing all subprojects" -# ./gradlew publish -# else -# args=$(echo "${{ inputs.target_subproject }}" | tr ',' '\n' | sed 's/$/:publish/' | paste -sd ' ') -# echo "Publishing with arguments=$args" -# ./gradlew $args -# fi -# env: -# BUILD_ID: ${{ github.run_number }} -# BUILD_RELEASE: ${{ inputs.release }} -# FALLENS_MAVEN_TOKEN: ${{ secrets.FALLENS_MAVEN_TOKEN }} - summary: runs-on: ubuntu-22.04 needs: diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c8314b7..aa82de2 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -15,6 +15,3 @@ jobs: build: uses: ./.github/workflows/build.yml secrets: inherit -# # [FEATURE] MIXIN_AUDITOR -# with: -# mixin_audit: true diff --git a/README.md b/README.md index 2e1b927..2b66fa0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ -# Vulpeus carpet addition +# Vulpeus Carpet + +[![License](https://img.shields.io/github/license/Vulpeus-Server/vulpeus-carpet.svg)](http://www.gnu.org/licenses/lgpl-3.0.html) +[![Issues](https://img.shields.io/github/issues/Vulpeus-Server/vulpeus-carpet.svg)](https://github.com/Vulpeus-Server/vulpeus-carpet/issues) +[![workflow](https://github.com/Vulpeus-Server/vulpeus-carpet/actions/workflows/gradle.yml/badge.svg)](https://github.com/Vulpeus-Server/vulpeus-carpet/actions/workflows/gradle.yml) +[![Modrinth](https://img.shields.io/modrinth/dt/aZhtZo3k?label=Modrinth%20Downloads)](https://modrinth.com/mod/vulpeus-carpet) carpet addition made for vulpeus. Supported version is only main version of our server. diff --git a/build.gradle b/build.gradle index e57030b..0f6b141 100644 --- a/build.gradle +++ b/build.gradle @@ -12,22 +12,14 @@ plugins { } preprocess { - def mc114 = createNode('1.14.4', 1_14_04, '') - def mc115 = createNode('1.15.2', 1_15_02, '') - def mc116 = createNode('1.16.5', 1_16_05, '') - def mc117 = createNode('1.17.1', 1_17_01, '') - def mc118 = createNode('1.18.2', 1_18_02, '') def mc119 = createNode('1.19.4', 1_19_04, '') - def mc120 = createNode('1.20.6', 1_20_06, '') + def mc1201 = createNode('1.20.1', 1_20_01, '') + def mc1206 = createNode('1.20.6', 1_20_06, '') def mc121 = createNode('1.21.1', 1_21_01, '') - mc115.link(mc114, null) - mc115.link(mc116, null) - mc116.link(mc117, null) - mc117.link(mc118, null) - mc118.link(mc119, null) - mc119.link(mc120, null) - mc120.link(mc121, null) + mc119.link(mc1201, null) + mc1201.link(mc1206, null) + mc1206.link(mc121, null) } tasks.register('buildAndGather') { diff --git a/common.gradle b/common.gradle index 51b5a56..dcdb654 100644 --- a/common.gradle +++ b/common.gradle @@ -17,6 +17,9 @@ repositories { maven { url 'https://maven.fallenbreath.me/releases' } + maven { + url 'https://masa.dy.fi/maven' + } } // https://github.com/FabricMC/fabric-loader/issues/783 @@ -30,21 +33,27 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - // runtime mods -// if (mcVersion < 11904) { -// modRuntimeOnly(mcVersion < 11900 ? "com.github.astei:lazydfu:0.1.2" : "com.github.Fallen-Breath:lazydfu:a7cfc44c0c") -// } -// // [FEATURE] MIXIN_AUDITOR -// modRuntimeOnly 'me.fallenbreath:mixin-auditor:0.1.0' + modImplementation "carpet:fabric-carpet:${project.carpet_version}" // dependencies -// include(modImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_api_version))) -// include(modImplementation("me.fallenbreath:conditional-mixin-fabric:${project.conditionalmixin_version}")) -// include(annotationProcessor(implementation("io.github.llamalad7:mixinextras-fabric:${project.mixinextras_version}"))) + + // library mods + include(modImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_api_version))) + include(modImplementation("me.fallenbreath:conditional-mixin-fabric:${project.conditionalmixin_version}")) + include(annotationProcessor(implementation("io.github.llamalad7:mixinextras-fabric:${project.mixinextras_version}"))) + + if (mcVersion >= 11600) { + // the client-side command + include(modImplementation(fabricApi.module("fabric-api-base", project.fabric_api_version))) // command api dependency + include(modImplementation(fabricApi.module("fabric-command-api-v${mcVersion >= 11900 ? 2 : 1}", project.fabric_api_version))) + } + + // libraries + testImplementation "junit:junit:${project.junit_version}" } -String MIXIN_CONFIG_PATH = 'template_mod.mixins.json' -String LANG_DIR = 'assets/template_mod/lang' +String MIXIN_CONFIG_PATH = 'vulpeus_carpet.mixins.json' +String LANG_DIR = 'assets/vulpeus_carpet/lang' JavaVersion JAVA_COMPATIBILITY if (mcVersion >= 12005) { JAVA_COMPATIBILITY = JavaVersion.VERSION_21 @@ -58,22 +67,13 @@ if (mcVersion >= 12005) { JavaVersion MIXIN_COMPATIBILITY_LEVEL = JAVA_COMPATIBILITY loom { - def commonVmArgs = ['-Dmixin.debug.export=true', '-Dmixin.debug.countInjections=true'] + def commonVmArgs = ['-Dmixin.debug.export=true'] runConfigs.configureEach { // to make sure it generates all "Minecraft Client (:subproject_name)" applications ideConfigGenerated = true runDir '../../run' vmArgs commonVmArgs } -// // [FEATURE] MIXIN_AUDITOR -// runs { -// def auditVmArgs = ['-DmixinAuditor.audit=true'] -// serverMixinAudit { -// server() -// vmArgs auditVmArgs -// ideConfigGenerated false -// } -// } } remapJar { @@ -199,7 +199,7 @@ license { } ext { name = project.mod_name - author = 'Fallen_Breath' + author = 'VulpeusServer' year = Calendar.getInstance().get(Calendar.YEAR).toString() } } @@ -219,17 +219,5 @@ publishing { // select the repositories you want to publish to repositories { // mavenLocal() - -// // [FEATURE] FALLENS_MAVEN -// maven { -// url = fullArtifactVersion.endsWith("SNAPSHOT") ? "https://maven.fallenbreath.me/snapshots" : "https://maven.fallenbreath.me/releases" -// credentials(PasswordCredentials) { -// username = 'fallen' -// password = System.getenv("FALLENS_MAVEN_TOKEN") -// } -// authentication { -// basic(BasicAuthentication) -// } -// } } } diff --git a/gradle.properties b/gradle.properties index 3312ff8..935d1fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,15 +6,18 @@ loader_version=0.16.2 # Mod Properties - mod_id=template_mod - mod_name=TemplateMod + mod_id=vulpeus_carpet + mod_name=VulpeusCarpet mod_version=1.0.0 - maven_group=me.fallenbreath - archives_base_name=template_mod + maven_group=com.vulpeus + archives_base_name=vulpeus_carpet # Global Dependencies # https://github.com/Fallen-Breath/conditional-mixin -# conditionalmixin_version=0.6.3 + conditionalmixin_version = 0.6.2 # https://github.com/LlamaLad7/MixinExtras -# mixinextras_version=0.3.6 + mixinextras_version = 0.3.6 + + # https://mvnrepository.com/artifact/junit/junit + junit_version = 4.13.2 \ No newline at end of file diff --git a/settings.json b/settings.json index d08fab0..043080b 100644 --- a/settings.json +++ b/settings.json @@ -1,11 +1,7 @@ { "versions": [ - "1.14.4", - "1.15.2", - "1.16.5", - "1.17.1", - "1.18.2", "1.19.4", + "1.20.1", "1.20.6", "1.21.1" ] diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetExtension.java b/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetExtension.java new file mode 100644 index 0000000..1e29311 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetExtension.java @@ -0,0 +1,98 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet; + +import carpet.CarpetExtension; +import carpet.CarpetServer; +import carpet.utils.Translations; +import com.mojang.brigadier.CommandDispatcher; +import com.vulpeus.vulpeus_carpet.commands.hatCommand; +import com.vulpeus.vulpeus_carpet.commands.sitCommand; +import com.vulpeus.vulpeus_carpet.commands.viewCommand; +import com.vulpeus.vulpeus_carpet.utils.rule.defaultOpLevel.PlayerUtil; +import java.util.Map; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.Version; +import net.fabricmc.loader.api.metadata.ModMetadata; +import net.minecraft.GameVersion; +import net.minecraft.MinecraftVersion; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; + +public class VulpeusCarpetExtension implements CarpetExtension, ModInitializer { + + public static final String MOD_ID = "vulpeus_carpet"; + public static final String MOD_NAME; + public static final Version MOD_VERSION; + public static final GameVersion GAME_VERSION; + + static { + ModMetadata metadata = + FabricLoader.getInstance() + .getModContainer(MOD_ID) + .orElseThrow(RuntimeException::new) + .getMetadata(); + MOD_NAME = metadata.getName(); + MOD_VERSION = metadata.getVersion(); + GAME_VERSION = MinecraftVersion.CURRENT; + } + + public static void loadExtension() { + CarpetServer.manageExtension(new VulpeusCarpetExtension()); + } + + @Override + public String version() { + return MOD_ID; + } + + @Override + public void onInitialize() { + VulpeusCarpetExtension.loadExtension(); + } + + @Override + public void onGameStarted() { + CarpetServer.settingsManager.parseSettingsClass(VulpeusCarpetSettings.class); + } + + @Override + public void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess commandRegistryAccess) { + viewCommand.register(dispatcher); + hatCommand.register(dispatcher); + sitCommand.register(dispatcher); + } + + @Override + public void onPlayerLoggedIn(ServerPlayerEntity player) { + if (VulpeusCarpetSettings.defaultOpLevel != 0) { + PlayerUtil.setOpLevel(player, VulpeusCarpetSettings.defaultOpLevel); + } + } + + @Override + public Map canHasTranslations(String lang) { + return Translations.getTranslationFromResourcePath( + String.format("assets/%s/lang/%s.json", MOD_ID, lang)); + } +} \ No newline at end of file diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetSettings.java b/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetSettings.java new file mode 100644 index 0000000..df79499 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/VulpeusCarpetSettings.java @@ -0,0 +1,53 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet; + +import static carpet.api.settings.RuleCategory.COMMAND; +import static carpet.api.settings.RuleCategory.OPTIMIZATION; +import static carpet.api.settings.RuleCategory.SURVIVAL; + +import carpet.api.settings.Rule; + +public class VulpeusCarpetSettings { + + private static final String VULPEUS = "vulpeus"; + + @Rule(categories = {SURVIVAL, COMMAND, VULPEUS}) + public static String commandHat = "ops"; + + @Rule(categories = {SURVIVAL, COMMAND, VULPEUS}) + public static String commandSit = "ops"; + + @Rule(categories = {SURVIVAL, COMMAND, VULPEUS}) + public static String commandView = "ops"; + + @Rule(categories = {VULPEUS}, options = {"0", "1", "2", "3", "4"}) + public static int defaultOpLevel = 0; + + @Rule(categories = {VULPEUS}) + public static boolean disableCCECrash = false; + + @Rule(categories = {VULPEUS}) + public static boolean disableSOECrash = false; + + @Rule(categories = {OPTIMIZATION, VULPEUS}) + public static boolean optimizedDragonRespawn = false; +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/commands/hatCommand.java b/src/main/java/com/vulpeus/vulpeus_carpet/commands/hatCommand.java new file mode 100644 index 0000000..a872781 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/commands/hatCommand.java @@ -0,0 +1,128 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.commands; + +import carpet.utils.CommandHelper; +import com.mojang.brigadier.CommandDispatcher; +import com.vulpeus.vulpeus_carpet.VulpeusCarpetSettings; +import com.vulpeus.vulpeus_carpet.utils.sendMessage; +import net.minecraft.block.Block; +import net.minecraft.block.ShulkerBoxBlock; +import net.minecraft.enchantment.Enchantments; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.ItemEntity; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import org.jetbrains.annotations.Nullable; + +//#if MC>=12005 +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ContainerComponent; +import net.minecraft.server.world.ServerWorld; +//#else +//$$ import net.minecraft.world.World; +//$$ import net.minecraft.enchantment.EnchantmentHelper; +//$$ import net.minecraft.nbt.NbtCompound; +//#endif + +public class hatCommand { + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(CommandManager.literal("hat") + .requires(player -> CommandHelper.canUseCommand(player, VulpeusCarpetSettings.commandHat)) + .executes(context -> hatPlayer(context.getSource().getPlayer()))); + } + + public static int hatPlayer(@Nullable ServerPlayerEntity player) { + if (player == null || player.isSpectator()) { + return 0; + } + ItemStack hat = player.getEquippedStack(EquipmentSlot.HEAD); + ItemStack stack = player.getMainHandStack(); + + Item item = stack.getItem(); + + //#if MC>=12005 + if (hat.getEnchantments().getEnchantments().contains(Enchantments.BINDING_CURSE)) + //#else + //$$ if (EnchantmentHelper.fromNbt(hat.getEnchantments()).containsKey(Enchantments.BINDING_CURSE)) + //#endif + { + sendMessage.sendSourceMessage(player, "Already equipped with an Item with BINDING_CURSE"); + return 0; + } + if (item.equals(Items.TOTEM_OF_UNDYING)) { + sendMessage.sendSourceMessage(player, "Items that cannot be equipped: TOTEM_OF_UNDYING"); + return 0; + } + if (item instanceof BlockItem blockItem) { + Block block = blockItem.getBlock(); + if (block instanceof ShulkerBoxBlock) { + //#if MC>=12005 + ContainerComponent blockEntityData = stack.get(DataComponentTypes.CONTAINER); + //#else + //$$ NbtCompound blockEntityData = stack.getNbt(); + //#endif + + if (blockEntityData != null) { + //#if MC>=12005 + boolean isEmpty = blockEntityData.stream().toList().isEmpty(); + //#else + //$$ boolean isEmpty = blockEntityData.getCompound("BlockEntityTag").contains("Items"); + //#endif + + if (isEmpty) { + sendMessage.sendSourceMessage(player, + "Items that cannot be equipped: SHULKER_BOX(notEmpty)"); + return 0; + } + } + } + } + + ItemStack stackCopy = stack.copy(); + stackCopy.setCount(1); + player.equipStack(EquipmentSlot.HEAD, stackCopy); + if (!player.isCreative()) { + stack.decrement(1); + if (player.getInventory().getEmptySlot() < 0) { + //#if MC>=12005 + ServerWorld world = player.getServerWorld(); + //#else + //$$ World world = player.getWorld(); + //#endif + ItemEntity itemEntity = new ItemEntity(world, player.getX(), player.getY() + 1.0, + player.getZ(), hat.copy()); + itemEntity.setToDefaultPickupDelay(); + world.spawnEntity(itemEntity); + } else { + player.getInventory().insertStack(hat.copy()); + } + } + player.playerScreenHandler.sendContentUpdates(); + return 1; + } +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/commands/sitCommand.java b/src/main/java/com/vulpeus/vulpeus_carpet/commands/sitCommand.java new file mode 100644 index 0000000..784bc56 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/commands/sitCommand.java @@ -0,0 +1,68 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.commands; + +import carpet.utils.CommandHelper; +import com.mojang.brigadier.CommandDispatcher; +import com.vulpeus.vulpeus_carpet.VulpeusCarpetSettings; +import com.vulpeus.vulpeus_carpet.utils.rule.commandSit.SitEntity; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import org.jetbrains.annotations.Nullable; + +//#if MC>=12000 +import net.minecraft.server.world.ServerWorld; +//#else +//$$ import net.minecraft.world.World; +//#endif + +public class sitCommand { + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(CommandManager.literal("sit") + .requires(player -> CommandHelper.canUseCommand(player, VulpeusCarpetSettings.commandSit)) + .executes(context -> sitPlayer(context.getSource().getPlayer()))); + } + + public static int sitPlayer(@Nullable ServerPlayerEntity player) { + if (player == null || !player.isOnGround()) { + return 0; + } + + //#if MC>=12000 + ServerWorld world = player.getServerWorld(); + //#else + //$$ World world = player.getWorld(); + //#endif + + ArmorStandEntity armorStandEntity = new ArmorStandEntity(world, player.getX(), + player.getY() - 0.16, player.getZ()); + + ((SitEntity) armorStandEntity).setSitEntity(true); + world.spawnEntity(armorStandEntity); + player.setSneaking(false); + player.startRiding(armorStandEntity); + + return 1; + } +} \ No newline at end of file diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/commands/viewCommand.java b/src/main/java/com/vulpeus/vulpeus_carpet/commands/viewCommand.java new file mode 100644 index 0000000..a7530bf --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/commands/viewCommand.java @@ -0,0 +1,58 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.commands; + +import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; +import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; + +import carpet.CarpetSettings; +import carpet.utils.CommandHelper; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.vulpeus.vulpeus_carpet.VulpeusCarpetSettings; +import com.vulpeus.vulpeus_carpet.utils.sendMessage; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; + +public class viewCommand { + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(CommandManager.literal("view") + .requires(player -> CommandHelper.canUseCommand(player, VulpeusCarpetSettings.commandView)) + .then(CommandManager.argument("distance", integer(0, 32)).executes( + context -> executeChangeView(context.getSource().withLevel(3), + getInteger(context, "distance"))))); + } + + public static int executeChangeView(ServerCommandSource source, int distance) + throws CommandSyntaxException { + + MinecraftServer server = source.getServer(); + + server.getPlayerManager().setViewDistance(distance); + CarpetSettings.viewDistance = distance; + + sendMessage.sendGlobalMessage(server, "viewDistance is now " + distance); + + return 1; + } +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/mixins/commandSit/MixinArmorStandEntity.java b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/commandSit/MixinArmorStandEntity.java new file mode 100644 index 0000000..368f099 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/commandSit/MixinArmorStandEntity.java @@ -0,0 +1,91 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.mixins.commandSit; + +import com.vulpeus.vulpeus_carpet.utils.rule.commandSit.SitEntity; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.world.World; +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.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ArmorStandEntity.class) +public abstract class MixinArmorStandEntity extends LivingEntity implements SitEntity { + + private boolean sitEntity = false; + + protected MixinArmorStandEntity(EntityType entityType, World world) { + super(entityType, world); + } + + @Shadow + protected abstract void setMarker(boolean marker); + + @Override + public boolean isSitEntity() { + return sitEntity; + } + + @Override + public void setSitEntity(boolean isSitEntity) { + this.sitEntity = isSitEntity; + this.setMarker(isSitEntity); + this.setInvisible(isSitEntity); + } + + @Override + protected void removePassenger(Entity passenger) { + if (this.isSitEntity()) { + this.setPosition(this.getX(), this.getY() + 0.16, this.getZ()); + this.kill(); + } + super.removePassenger(passenger); + } + + @Inject(method = "tick", at = @At(value = "RETURN")) + private void onTick(CallbackInfo ci) { + Entity player = this.getFirstPassenger(); + if (this.sitEntity && player != null) { + this.setYaw(player.getHeadYaw()); + } + } + + @Inject(method = "writeCustomDataToNbt", at = @At(value = "RETURN")) + private void postWriteCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { + if (this.sitEntity) { + nbt.putBoolean("SitEntity", true); + } + } + + @Inject(method = "readCustomDataFromNbt", at = @At(value = "RETURN")) + private void postReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { + if (nbt.contains("SitEntity", NbtElement.BYTE_TYPE)) { + this.sitEntity = nbt.getBoolean("SitEntity"); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/mixins/disableCrash/MixinMinecraftServer.java b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/disableCrash/MixinMinecraftServer.java new file mode 100644 index 0000000..aced867 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/disableCrash/MixinMinecraftServer.java @@ -0,0 +1,55 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.mixins.disableCrash; + +import com.vulpeus.vulpeus_carpet.VulpeusCarpetSettings; +import com.vulpeus.vulpeus_carpet.utils.sendMessage; +import java.util.Iterator; +import java.util.function.BooleanSupplier; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(MinecraftServer.class) +public class MixinMinecraftServer { + + @Inject(method = {"tickWorlds"}, at = { + @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReport;create(Ljava/lang/Throwable;Ljava/lang/String;)Lnet/minecraft/util/crash/CrashReport;")}, locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + public void injectTickWorlds(BooleanSupplier shouldKeepTicking, CallbackInfo ci, + @SuppressWarnings("all") Iterator var2, ServerWorld serverWorld, Throwable throwable) { + + Throwable causeErr = throwable.getCause(); + + if (VulpeusCarpetSettings.disableCCECrash && causeErr instanceof ClassCastException) { + ci.cancel(); + sendMessage.sendGlobalMessage((MinecraftServer) (Object) this, "now CCE Crashed."); + return; + } + if (VulpeusCarpetSettings.disableSOECrash && causeErr instanceof StackOverflowError) { + ci.cancel(); + sendMessage.sendGlobalMessage((MinecraftServer) (Object) this, "now SOE Crashed."); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/IMixinBlockPatternTestTransform.java b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/IMixinBlockPatternTestTransform.java new file mode 100644 index 0000000..aa877df --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/IMixinBlockPatternTestTransform.java @@ -0,0 +1,37 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.mixins.optimizedDragonRespawn; + +import com.google.common.cache.LoadingCache; +import net.minecraft.block.pattern.BlockPattern; +import net.minecraft.block.pattern.CachedBlockPosition; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(BlockPattern.class) +public interface IMixinBlockPatternTestTransform { + + @Invoker("testTransform") + BlockPattern.Result invokeTestTransform(BlockPos frontTopLeft, Direction forwards, Direction up, + LoadingCache cache); +} \ No newline at end of file diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/MixinEnderDragonFight.java b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/MixinEnderDragonFight.java new file mode 100644 index 0000000..5cd2bc4 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/MixinEnderDragonFight.java @@ -0,0 +1,153 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.mixins.optimizedDragonRespawn; + +import com.vulpeus.vulpeus_carpet.VulpeusCarpetSettings; +import com.vulpeus.vulpeus_carpet.utils.rule.optimizedDragonRespawn.BlockPatternHelper; +import java.util.List; +import me.fallenbreath.conditionalmixin.api.annotation.Condition; +import me.fallenbreath.conditionalmixin.api.annotation.Restriction; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.EndGatewayBlockEntity; +import net.minecraft.block.entity.EndPortalBlockEntity; +import net.minecraft.block.pattern.BlockPattern; +import net.minecraft.entity.boss.dragon.EnderDragonFight; +import net.minecraft.entity.decoration.EndCrystalEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.Heightmap; +import net.minecraft.world.chunk.WorldChunk; +import net.minecraft.world.gen.feature.EndPortalFeature; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Restriction(require = @Condition(value = "minecraft", versionPredicates = ">=1.20")) +@Mixin(value = EnderDragonFight.class, priority = 888) +public abstract class MixinEnderDragonFight { + + @Shadow + @Final + private ServerWorld world; + + @Shadow + @Final + private BlockPattern endPortalPattern; + + @Nullable + @Shadow + private BlockPos exitPortalLocation; + + @Shadow + private boolean doLegacyCheck; + + @Unique + private int cacheChunkIteratorX = -8; + + @Unique + private int cacheChunkIteratorZ = -8; + + @Unique + private int cacheOriginIteratorY = -1; + + /** + * @author WenDavid + * @reason Optimize the search of end portal + */ + + @Overwrite + private @Nullable BlockPattern.Result findEndPortal() { + int i, j; + if (!VulpeusCarpetSettings.optimizedDragonRespawn) { + cacheChunkIteratorX = -8; + cacheChunkIteratorZ = -8; + } + for (i = cacheChunkIteratorX; i <= 8; ++i) { + for (j = cacheChunkIteratorZ; j <= 8; ++j) { + WorldChunk worldChunk = this.world.getChunk(i, j); + for (BlockEntity blockEntity : worldChunk.getBlockEntities().values()) { + if (VulpeusCarpetSettings.optimizedDragonRespawn + && blockEntity instanceof EndGatewayBlockEntity) { + continue; + } + if (blockEntity instanceof EndPortalBlockEntity) { + BlockPattern.Result result = this.endPortalPattern.searchAround(this.world, + blockEntity.getPos()); + if (result != null) { + BlockPos blockPos = result.translate(3, 3, 3).getBlockPos(); + if (this.exitPortalLocation == null) { + this.exitPortalLocation = blockPos; + } + //No need to judge whether optimizing option is open + cacheChunkIteratorX = i; + cacheChunkIteratorZ = j; + return result; + } + } + } + } + } + if (this.doLegacyCheck || this.exitPortalLocation == null) { + if (VulpeusCarpetSettings.optimizedDragonRespawn && cacheOriginIteratorY != -1) { + i = cacheOriginIteratorY; + } else { + i = this.world.getTopPosition(Heightmap.Type.MOTION_BLOCKING, + EndPortalFeature.offsetOrigin(BlockPos.ORIGIN)).getY(); + } + boolean notFirstSearch = false; + for (j = i; j >= 0; --j) { + BlockPattern.Result result2 = null; + if (VulpeusCarpetSettings.optimizedDragonRespawn && notFirstSearch) { + result2 = BlockPatternHelper.partialSearchAround(this.endPortalPattern, this.world, + new BlockPos(EndPortalFeature.offsetOrigin(BlockPos.ORIGIN).getX(), j, + EndPortalFeature.offsetOrigin(BlockPos.ORIGIN).getZ())); + } else { + result2 = this.endPortalPattern.searchAround(this.world, + new BlockPos(EndPortalFeature.offsetOrigin(BlockPos.ORIGIN).getX(), j, + EndPortalFeature.offsetOrigin(BlockPos.ORIGIN).getZ())); + } + if (result2 != null) { + if (this.exitPortalLocation == null) { + this.exitPortalLocation = result2.translate(3, 3, 3).getBlockPos(); + } + cacheOriginIteratorY = j; + return result2; + } + notFirstSearch = true; + } + } + + return null; + } + + @Inject(method = "respawnDragon(Ljava/util/List;)V", at = @At("HEAD")) + private void resetCache(List crystals, CallbackInfo ci) { + cacheChunkIteratorX = -8; + cacheChunkIteratorZ = -8; + cacheOriginIteratorY = -1; + } +} \ No newline at end of file diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/mixins/playerActions/PlayerCommandMixin.java b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/playerActions/PlayerCommandMixin.java new file mode 100644 index 0000000..f9be6c6 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/playerActions/PlayerCommandMixin.java @@ -0,0 +1,107 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.mixins.playerActions; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +import carpet.CarpetSettings; +import carpet.commands.PlayerCommand; +import carpet.helpers.EntityPlayerActionPack; +import carpet.utils.CommandHelper; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.vulpeus.vulpeus_carpet.utils.rule.playerActions.Container; +import java.util.function.Consumer; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(PlayerCommand.class) +public abstract class PlayerCommandMixin { + + @Shadow(remap = false) + private static int manipulate(CommandContext context, + Consumer action) { + return 0; + } + + @Unique + private static int action(CommandContext context, + EntityPlayerActionPack.ActionType type, EntityPlayerActionPack.Action action) { + return manipulate(context, ap -> ap.start(type, action)); + } + + @Inject(method = "register", at = @At("RETURN"), remap = false) + private static void registerEnhancements(CommandDispatcher dispatcher, + CommandRegistryAccess commandBuildContext, CallbackInfo ci) { + + LiteralArgumentBuilder command = literal("player").requires( + (player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandPlayer)).then( + argument("player", StringArgumentType.word()).then( + literal("fill").then(argument("fill", BoolArgumentType.bool()).executes((ctx) -> { + boolean value = BoolArgumentType.getBool(ctx, "fill"); + ServerPlayerEntity player = getPlayer(ctx); + if (value) { + Container.fill.addPlayer(player); + } else { + Container.fill.removePlayer(player); + } + return 1; + }))).then( + literal("clean").then(argument("clean", BoolArgumentType.bool()).executes((ctx) -> { + boolean value = BoolArgumentType.getBool(ctx, "clean"); + ServerPlayerEntity player = getPlayer(ctx); + if (value) { + Container.clean.addPlayer(player); + } else { + Container.clean.removePlayer(player); + } + return 1; + })))); + + dispatcher.register(command); + } + + @Inject(method = "makeActionCommand", at = @At("RETURN"), remap = false) + private static void makeActionCommandEnhancements(String actionName, + EntityPlayerActionPack.ActionType type, + CallbackInfoReturnable> cir) { + } + + @Unique + private static ServerPlayerEntity getPlayer(CommandContext ctx) { + String playerName = StringArgumentType.getString(ctx, "player"); + MinecraftServer server = ctx.getSource().getServer(); + return server.getPlayerManager().getPlayer(playerName); + } +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/mixins/playerActions/ServerPlayerEntityMixin.java b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/playerActions/ServerPlayerEntityMixin.java new file mode 100644 index 0000000..0322db5 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/mixins/playerActions/ServerPlayerEntityMixin.java @@ -0,0 +1,48 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.mixins.playerActions; + +import com.vulpeus.vulpeus_carpet.utils.rule.playerActions.Container; +import java.util.OptionalInt; +import net.minecraft.screen.NamedScreenHandlerFactory; +import net.minecraft.screen.ShulkerBoxScreenHandler; +import net.minecraft.server.network.ServerPlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ServerPlayerEntity.class) +public abstract class ServerPlayerEntityMixin { + + @Inject(method = "openHandledScreen", at = @At("RETURN")) + public void openHandledScreen(NamedScreenHandlerFactory factory, + CallbackInfoReturnable cir) { + ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; + if (player.currentScreenHandler instanceof ShulkerBoxScreenHandler screenHandler) { + if (Container.fill.containsPlayer(player)) { + Container.fill.fillAll(player, screenHandler); + } else if (Container.clean.containsPlayer(player)) { + Container.clean.cleanAll(player, screenHandler); + } + } + } +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/commandSit/SitEntity.java b/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/commandSit/SitEntity.java new file mode 100644 index 0000000..7a9cd22 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/commandSit/SitEntity.java @@ -0,0 +1,28 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.utils.rule.commandSit; + +public interface SitEntity { + + boolean isSitEntity(); + + void setSitEntity(boolean sitEntity); +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/defaultOpLevel/PlayerUtil.java b/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/defaultOpLevel/PlayerUtil.java new file mode 100644 index 0000000..229df4a --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/defaultOpLevel/PlayerUtil.java @@ -0,0 +1,42 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.utils.rule.defaultOpLevel; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.OperatorEntry; +import net.minecraft.server.OperatorList; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ServerPlayerEntity; + +public class PlayerUtil { + + public static void setOpLevel(ServerPlayerEntity player, int opLevel) { + setOpLevel(player, opLevel, false); + } + + public static void setOpLevel(ServerPlayerEntity player, int opLevel, boolean bypassPlayerLimit) { + MinecraftServer server = player.getServer(); + PlayerManager manager = server.getPlayerManager(); + OperatorList ops = manager.getOpList(); + ops.add(new OperatorEntry(player.getGameProfile(), opLevel, bypassPlayerLimit)); + manager.sendCommandTree(player); + } +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/optimizedDragonRespawn/BlockPatternHelper.java b/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/optimizedDragonRespawn/BlockPatternHelper.java new file mode 100644 index 0000000..6aacc19 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/optimizedDragonRespawn/BlockPatternHelper.java @@ -0,0 +1,52 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.utils.rule.optimizedDragonRespawn; + +import com.google.common.cache.LoadingCache; +import com.vulpeus.vulpeus_carpet.mixins.optimizedDragonRespawn.IMixinBlockPatternTestTransform; +import net.minecraft.block.pattern.BlockPattern; +import net.minecraft.block.pattern.CachedBlockPosition; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.WorldView; + +public class BlockPatternHelper { + + public static BlockPattern.Result partialSearchAround(BlockPattern pattern, WorldView world, + BlockPos pos) { + LoadingCache loadingCache = BlockPattern.makeCache(world, false); + int i = Math.max(Math.max(pattern.getWidth(), pattern.getHeight()), pattern.getDepth()); + for (BlockPos blockPos : BlockPos.iterate(pos, pos.add(i - 1, 0, i - 1))) { + for (Direction direction : Direction.values()) { + for (Direction direction2 : Direction.values()) { + BlockPattern.Result result; + if (direction2 == direction || direction2 == direction.getOpposite() || + (result = ((IMixinBlockPatternTestTransform) pattern).invokeTestTransform(blockPos, + direction, direction2, loadingCache)) == null) { + continue; + } + return result; + } + } + } + return null; + } +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/playerActions/Container.java b/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/playerActions/Container.java new file mode 100644 index 0000000..70ac114 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/utils/rule/playerActions/Container.java @@ -0,0 +1,99 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.utils.rule.playerActions; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ShulkerBoxScreenHandler; +import net.minecraft.screen.slot.Slot; +import net.minecraft.screen.slot.SlotActionType; +import net.minecraft.server.network.ServerPlayerEntity; + +public class Container { + + public static final int THROW_CTRL_Q = 1; + + public static class fill { + + private static final List players = new ArrayList<>(); + + public static void fillAll(ServerPlayerEntity player, ShulkerBoxScreenHandler screenHandler) { + for (int index = 63 - 36; index < 63; index++) { // 63-36=27 + // for (int index = 63 - 36; index < screenHandler.slots.size(); index++) { + Slot slot = screenHandler.getSlot(index); + // Slot slot = screenHandler.slots.get(index); + if (slot.hasStack()) { + ItemStack itemStack = slot.getStack(); + if (itemStack.getItem().canBeNested()) { + screenHandler.quickMove(player, index); + if (slot.hasStack()) { + player.closeHandledScreen(); + } + } else { + screenHandler.onSlotClick(index, THROW_CTRL_Q, SlotActionType.THROW, player); + } + } + } + } + + public static void addPlayer(ServerPlayerEntity player) { + players.add(player); + } + + public static void removePlayer(ServerPlayerEntity player) { + players.remove(player); + } + + public static boolean containsPlayer(ServerPlayerEntity player) { + return players.contains(player); + } + } + + public static class clean { + + private static final List players = new ArrayList<>(); + + public static void cleanAll(ServerPlayerEntity player, ShulkerBoxScreenHandler screenHandler) { + for (int index = 0; index < 27; index++) { + // for (int index = 63 - 36; index < screenHandler.slots.size(); index++) { + Slot slot = screenHandler.getSlot(index); + // Slot slot = screenHandler.slots.get(index); + if (slot.hasStack()) { + screenHandler.onSlotClick(index, THROW_CTRL_Q, SlotActionType.THROW, player); + } + } + screenHandler.onSlotClick(0, THROW_CTRL_Q, SlotActionType.THROW, player); + } + + public static void addPlayer(ServerPlayerEntity player) { + players.add(player); + } + + public static void removePlayer(ServerPlayerEntity player) { + players.remove(player); + } + + public static boolean containsPlayer(ServerPlayerEntity player) { + return players.contains(player); + } + } +} diff --git a/src/main/java/com/vulpeus/vulpeus_carpet/utils/sendMessage.java b/src/main/java/com/vulpeus/vulpeus_carpet/utils/sendMessage.java new file mode 100644 index 0000000..a74ca06 --- /dev/null +++ b/src/main/java/com/vulpeus/vulpeus_carpet/utils/sendMessage.java @@ -0,0 +1,36 @@ +/* + * This file is part of the VulpeusCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * VulpeusCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VulpeusCarpet 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VulpeusCarpet. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.utils; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; + +public class sendMessage { + + public static void sendGlobalMessage(MinecraftServer server, String message) { + server.getPlayerManager().getPlayerList().forEach(player -> sendSourceMessage(player, message)); + } + + public static void sendSourceMessage(ServerPlayerEntity player, String message) { + player.sendMessage(Text.of(message), false); + } +} diff --git a/src/main/java/me/fallenbreath/template_mod/TemplateMod.java b/src/main/java/me/fallenbreath/template_mod/TemplateMod.java deleted file mode 100644 index 31ed875..0000000 --- a/src/main/java/me/fallenbreath/template_mod/TemplateMod.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of the TemplateMod project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 Fallen_Breath and contributors - * - * TemplateMod is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * TemplateMod 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with TemplateMod. If not, see . - */ - -package me.fallenbreath.template_mod; - -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.metadata.ModMetadata; - -//#if MC >= 11802 -//$$ import com.mojang.logging.LogUtils; -//$$ import org.slf4j.Logger; -//#else -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -//#endif - -public class TemplateMod implements ModInitializer -{ - public static final Logger LOGGER = - //#if MC >= 11802 - //$$ LogUtils.getLogger(); - //#else - LogManager.getLogger(); - //#endif - - public static final String MOD_ID = "template_mod"; - public static String MOD_VERSION = "unknown"; - public static String MOD_NAME = "unknown"; - - @Override - public void onInitialize() - { - ModMetadata metadata = FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow(RuntimeException::new).getMetadata(); - MOD_NAME = metadata.getName(); - MOD_VERSION = metadata.getVersion().getFriendlyString(); - } -} diff --git a/src/main/java/me/fallenbreath/template_mod/mixins/MinecraftServerMixin.java b/src/main/java/me/fallenbreath/template_mod/mixins/MinecraftServerMixin.java deleted file mode 100644 index 3214fae..0000000 --- a/src/main/java/me/fallenbreath/template_mod/mixins/MinecraftServerMixin.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of the TemplateMod project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 Fallen_Breath and contributors - * - * TemplateMod is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * TemplateMod 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with TemplateMod. If not, see . - */ - -package me.fallenbreath.template_mod.mixins; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.MinecraftServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftServer.class) -public abstract class MinecraftServerMixin -{ - @Inject( - //#if MC >= 11600 - //$$ method = "runServer", - //#else - method = "run", - //#endif - at = @At("HEAD") - ) - private void onRun(CallbackInfo ci) - { - //#if MC >= 11500 - System.err.println("Hello world from mc11500 branch"); - //#elseif MC >= 11400 - //$$ System.err.println("Hello world from mc11400 branch"); - //#endif - - CompoundTag nbt = new CompoundTag(); - nbt.putString("key", "value"); - System.err.println("nbt: " + nbt); - } -} diff --git a/src/main/resources/assets/template_mod/icon.png b/src/main/resources/assets/vulpeus_carpet/icon.png similarity index 100% rename from src/main/resources/assets/template_mod/icon.png rename to src/main/resources/assets/vulpeus_carpet/icon.png diff --git a/src/main/resources/assets/vulpeus_carpet/lang/en_us.yml b/src/main/resources/assets/vulpeus_carpet/lang/en_us.yml new file mode 100644 index 0000000..43ce8ac --- /dev/null +++ b/src/main/resources/assets/vulpeus_carpet/lang/en_us.yml @@ -0,0 +1,25 @@ +carpet: + category: + vulpeus: vulpeus + + rule: + commandHat: + desc: Enable `/hat` command. Ported from essential addons. + + commandSit: + desc: Enable `/sit` command. Ported from PCA. + + commandView: + desc: Enable `/view` command to change viewDistance of carpet. + + defaultOpLevel: + desc: Set the OP level granted when you join the server. can be re-granted by rejoining and can override `op-permission-level` in the server.properties. + + disableCCECrash: + desc: yeet the server crash caused by ClassCastException. + + disableSOECrash: + desc: yeet the server crash caused by StackOverflowError. + + optimizedDragonRespawn: + desc: Optimize dragon respawn method. Ported from carpet AMS addition. \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c2ad6c7..aafb077 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -4,29 +4,40 @@ "version": "${version}", "name": "${name}", - "description": "Template for my fabric mods", + "description": "carpet addition made for vulpeus.", "authors": [ - "Fallen_Breath" + "VulpeusServer" ], "contact": { - "homepage": "https://modrinth.com", - "sources": "https://github.com/Fallen-Breath/fabric-mod-template" + "homepage": "https://vulpeus.com", + "issues": "https://github.com/Vulpeus-Server/vulpeus-carpet/issues", + "sources": "https://github.com/Vulpeus-Server/vulpeus-carpet" }, - "icon": "assets/template_mod/icon.png", + "icon": "assets/vulpeus_carpet/icon.png", "environment": "*", "entrypoints": { "main": [ - "me.fallenbreath.template_mod.TemplateMod" + "com.vulpeus.vulpeus_carpet.VulpeusCarpetExtension" ] }, "mixins": [ - "template_mod.mixins.json" + "vulpeus_carpet.mixins.json" ], "depends": { "fabricloader": ">=0.11.4", "minecraft": "${minecraft_dependency}" + }, + + "custom": { + "modmenu": { + "links": { + "modmenu.discord": "https://discord.gg/craftershub", + "modmenu.modrinth": "https://modrinth.com/project/vulpeus-carpet" + }, + "parent": "carpet" + } } } diff --git a/src/main/resources/template_mod.mixins.json b/src/main/resources/template_mod.mixins.json deleted file mode 100644 index ec9fdd3..0000000 --- a/src/main/resources/template_mod.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "me.fallenbreath.template_mod.mixins", - "compatibilityLevel": "{{COMPATIBILITY_LEVEL}}", - "mixins": [ - "MinecraftServerMixin" - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/src/main/resources/vulpeus_carpet.mixins.json b/src/main/resources/vulpeus_carpet.mixins.json new file mode 100644 index 0000000..53087bd --- /dev/null +++ b/src/main/resources/vulpeus_carpet.mixins.json @@ -0,0 +1,19 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.vulpeus.vulpeus_carpet.mixins", + "compatibilityLevel": "{{COMPATIBILITY_LEVEL}}", + "mixins": [ + "commandSit.MixinArmorStandEntity", + "disableCrash.MixinMinecraftServer", + "optimizedDragonRespawn.IMixinBlockPatternTestTransform", + "optimizedDragonRespawn.MixinEnderDragonFight", + "playerActions.PlayerCommandMixin", + "playerActions.ServerPlayerEntityMixin" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/1.14.4/gradle.properties b/versions/1.14.4/gradle.properties deleted file mode 100644 index d3776dd..0000000 --- a/versions/1.14.4/gradle.properties +++ /dev/null @@ -1,14 +0,0 @@ -# Fabric Properties - # check these on https://fallen-breath.github.io/fabric-versions/?&version=1.14.4 - minecraft_version=1.14.4 - yarn_mappings=1.14.4+build.18 - -# Fabric Mod Metadata - minecraft_dependency=1.14.x - -# Build Information - # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.14.4 - -# Dependencies - # fabric_api_version=0.28.5+1.14 diff --git a/versions/1.16.5/gradle.properties b/versions/1.16.5/gradle.properties deleted file mode 100644 index 07e18e1..0000000 --- a/versions/1.16.5/gradle.properties +++ /dev/null @@ -1,15 +0,0 @@ -# Fabric Properties - # check these on https://fallen-breath.github.io/fabric-versions/?&version=1.16.5 - minecraft_version=1.16.5 - yarn_mappings=1.16.5+build.10 - -# Fabric Mod Metadata - minecraft_dependency=1.16.x - -# Build Information - # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.16.4\n1.16.5 - -# Dependencies - # fabric_api_version=0.42.0+1.16 - diff --git a/versions/1.17.1/gradle.properties b/versions/1.17.1/gradle.properties deleted file mode 100644 index 3dae319..0000000 --- a/versions/1.17.1/gradle.properties +++ /dev/null @@ -1,15 +0,0 @@ -# Fabric Properties - # check these on https://fallen-breath.github.io/fabric-versions/?&version=1.17.1 - minecraft_version=1.17.1 - yarn_mappings=1.17.1+build.65 - -# Fabric Mod Metadata - minecraft_dependency=1.17.x - -# Build Information - # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.17.1 - -# Dependencies - # fabric_api_version=0.46.1+1.17 - diff --git a/versions/1.18.2/gradle.properties b/versions/1.18.2/gradle.properties deleted file mode 100644 index 6ee521a..0000000 --- a/versions/1.18.2/gradle.properties +++ /dev/null @@ -1,14 +0,0 @@ -# Fabric Properties - # check these on https://fallen-breath.github.io/fabric-versions/?&version=1.18.2 - minecraft_version=1.18.2 - yarn_mappings=1.18.2+build.4 - -# Fabric Mod Metadata - minecraft_dependency=1.18.x - -# Build Information - # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.18.2 - -# Dependencies - # fabric_api_version=0.76.0+1.18.2 diff --git a/versions/1.19.4/gradle.properties b/versions/1.19.4/gradle.properties index 8bfbb95..0aa3f6f 100644 --- a/versions/1.19.4/gradle.properties +++ b/versions/1.19.4/gradle.properties @@ -11,4 +11,5 @@ game_versions=1.19.4 # Dependencies - # fabric_api_version=0.87.2+1.19.4 + fabric_api_version=0.87.2+1.19.4 + carpet_version=1.19.4-1.4.100+v230314 diff --git a/versions/1.19.4/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/MixinEnderDragonFight.java b/versions/1.19.4/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/MixinEnderDragonFight.java new file mode 100644 index 0000000..5625f57 --- /dev/null +++ b/versions/1.19.4/src/main/java/com/vulpeus/vulpeus_carpet/mixins/optimizedDragonRespawn/MixinEnderDragonFight.java @@ -0,0 +1,161 @@ +/* + * This file is part of the TemplateMod project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TemplateMod is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TemplateMod 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TemplateMod. If not, see . + */ + +package com.vulpeus.vulpeus_carpet.mixins.optimizedDragonRespawn; + +import com.vulpeus.vulpeus_carpet.VulpeusCarpetSettings; +import com.vulpeus.vulpeus_carpet.utils.rule.optimizedDragonRespawn.BlockPatternHelper; +import java.util.List; +import me.fallenbreath.conditionalmixin.api.annotation.Condition; +import me.fallenbreath.conditionalmixin.api.annotation.Restriction; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.EndGatewayBlockEntity; +import net.minecraft.block.entity.EndPortalBlockEntity; +import net.minecraft.block.pattern.BlockPattern; +import net.minecraft.entity.boss.dragon.EnderDragonFight; +import net.minecraft.entity.decoration.EndCrystalEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.Heightmap; +import net.minecraft.world.chunk.WorldChunk; +import net.minecraft.world.gen.feature.EndPortalFeature; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Restriction(require = @Condition(value = "minecraft", versionPredicates = "<1.20")) +@Mixin(value = EnderDragonFight.class, priority = 888) +public abstract class MixinEnderDragonFight { + + @Shadow @Final private ServerWorld world; + + @Shadow @Final private BlockPattern endPortalPattern; + + @Nullable @Shadow private BlockPos exitPortalLocation; + + @Shadow private boolean doLegacyCheck; + + @Unique private int cacheChunkIteratorX = -8; + + @Unique private int cacheChunkIteratorZ = -8; + + @Unique private int cacheOriginIteratorY = -1; + + /** + * @author WenDavid + * @reason Optimize the search of end portal + */ + @Overwrite + private @Nullable BlockPattern.Result findEndPortal() { + int i; + int j; + if (!VulpeusCarpetSettings.optimizedDragonRespawn) { + cacheChunkIteratorX = -8; + cacheChunkIteratorZ = -8; + } + for (i = cacheChunkIteratorX; i <= 8; ++i) { + for (j = cacheChunkIteratorZ; j <= 8; ++j) { + WorldChunk worldChunk = this.world.getChunk(i, j); + for (BlockEntity blockEntity : worldChunk.getBlockEntities().values()) { + if (VulpeusCarpetSettings.optimizedDragonRespawn + && blockEntity instanceof EndGatewayBlockEntity) { + continue; + } + if (blockEntity instanceof EndPortalBlockEntity) { + BlockPattern.Result result = + this.endPortalPattern.searchAround(this.world, blockEntity.getPos()); + if (result != null) { + BlockPos blockPos = result.translate(3, 3, 3).getBlockPos(); + if (this.exitPortalLocation == null) { + this.exitPortalLocation = blockPos; + } + // No need to judge whether optimizing option is open + cacheChunkIteratorX = i; + cacheChunkIteratorZ = j; + return result; + } + } + } + } + } + if (this.doLegacyCheck || this.exitPortalLocation == null) { + if (VulpeusCarpetSettings.optimizedDragonRespawn && cacheOriginIteratorY != -1) { + i = cacheOriginIteratorY; + } else { + i = + this.world + .getTopPosition( + Heightmap.Type.MOTION_BLOCKING, offsetOrigin()) + .getY(); + } + boolean notFirstSearch = false; + for (j = i; j >= 0; --j) { + BlockPattern.Result result2 = null; + if (VulpeusCarpetSettings.optimizedDragonRespawn && notFirstSearch) { + result2 = + BlockPatternHelper.partialSearchAround( + this.endPortalPattern, + this.world, + new BlockPos( + offsetOrigin().getX(), + j, + offsetOrigin().getZ())); + } else { + result2 = + this.endPortalPattern.searchAround( + this.world, + new BlockPos( + offsetOrigin().getX(), + j, + offsetOrigin().getZ())); + } + if (result2 != null) { + if (this.exitPortalLocation == null) { + this.exitPortalLocation = result2.translate(3, 3, 3).getBlockPos(); + } + cacheOriginIteratorY = j; + return result2; + } + notFirstSearch = true; + } + } + + return null; + } + + @Inject(method = "respawnDragon(Ljava/util/List;)V", at = @At("HEAD")) + private void resetCache(List crystals, CallbackInfo ci) { + cacheChunkIteratorX = -8; + cacheChunkIteratorZ = -8; + cacheOriginIteratorY = -1; + } + + @Unique + private static BlockPos offsetOrigin() { + return EndPortalFeature.ORIGIN.add((Vec3i) BlockPos.ORIGIN); + } +} \ No newline at end of file diff --git a/versions/1.15.2/gradle.properties b/versions/1.20.1/gradle.properties similarity index 52% rename from versions/1.15.2/gradle.properties rename to versions/1.20.1/gradle.properties index caee1d2..98ddf92 100644 --- a/versions/1.15.2/gradle.properties +++ b/versions/1.20.1/gradle.properties @@ -1,14 +1,15 @@ # Fabric Properties - # check these on https://fallen-breath.github.io/fabric-versions/?&version=1.15.2 - minecraft_version=1.15.2 - yarn_mappings=1.15.2+build.17 + # check these on https://fallen-breath.github.io/fabric-versions/?&version=1.21.1 + minecraft_version=1.20.1 + yarn_mappings=1.20.1+build.10 # Fabric Mod Metadata - minecraft_dependency=1.15.x + minecraft_dependency=1.20.x # Build Information # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.15.2 + game_versions=1.20\n1.20.1 # Dependencies - # fabric_api_version=0.28.5+1.15 + fabric_api_version=0.92.2+1.20.1 + carpet_version=1.20-1.4.112+v230608 \ No newline at end of file diff --git a/versions/1.20.6/gradle.properties b/versions/1.20.6/gradle.properties index 6b3c91a..f658556 100644 --- a/versions/1.20.6/gradle.properties +++ b/versions/1.20.6/gradle.properties @@ -8,7 +8,8 @@ # Build Information # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.20.6 + game_versions=1.20.5\n1.20.6 # Dependencies - # fabric_api_version=0.100.4+1.20.6 \ No newline at end of file + fabric_api_version=0.100.4+1.20.6 + carpet_version=1.20.6-1.4.141+v240429 \ No newline at end of file diff --git a/versions/1.21.1/gradle.properties b/versions/1.21.1/gradle.properties index 24b2c75..d2b54c7 100644 --- a/versions/1.21.1/gradle.properties +++ b/versions/1.21.1/gradle.properties @@ -11,4 +11,5 @@ game_versions=1.21\n1.21.1 # Dependencies - # fabric_api_version=0.102.1+1.21.1 \ No newline at end of file + fabric_api_version=0.102.1+1.21.1 + carpet_version=1.21-1.4.147+v240613 \ No newline at end of file diff --git a/versions/mainProject b/versions/mainProject index 4761f0e..87967a7 100644 --- a/versions/mainProject +++ b/versions/mainProject @@ -1 +1 @@ -1.15.2 \ No newline at end of file +1.21.1 \ No newline at end of file