202/01/03
Some checks failed
Build / build (push) Failing after 1h8m30s

4.0.0.3->4.0.0.4
1.填完了对JEI适配的坑
(希望是Teacon的)最后一个版本
2.修补可能会存在的问题
This commit is contained in:
叁玖领域 2025-01-03 22:00:58 +08:00
parent 8490da915d
commit 6f69a24ed4
15 changed files with 177 additions and 63 deletions

View File

@ -1,4 +1,4 @@
# 版本 0.0.4.0.3 提前介绍c[没有BUG的话TeaCon最终版本将会是0.0.4] 【注意:本解釋簡繁混寫,因爲趕時間,所以並不怎麽規範,請諒解】
# 版本 0.0.4.0.4 提前介绍c[没有BUG的话TeaCon最终版本将会是0.0.4] 【注意:本解釋簡繁混寫,因爲趕時間,所以並不怎麽規範,請諒解】
## 简介
现在开始你可以用拴绳拴住玩家,也可以拴住自己了,不如尝试拴住彼此来通关我的世界吧(

View File

@ -35,7 +35,7 @@ mod_name=Leashed Player
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=0.0.4.0.3
mod_version=0.0.4.0.4
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@ -0,0 +1,32 @@
package com.r3944realms.leashedplayer.compat.jei;
import com.r3944realms.leashedplayer.LeashedPlayer;
import com.r3944realms.leashedplayer.compat.jei.common.PotionSubtypeInterpreter;
import com.r3944realms.leashedplayer.compat.jei.crafting.TippedLeashArrowRecipeMaker;
import com.r3944realms.leashedplayer.content.items.ModItemRegister;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.registration.IRecipeRegistration;
import mezz.jei.api.registration.ISubtypeRegistration;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
@JeiPlugin
public class JEIPlugin implements IModPlugin {
private static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(LeashedPlayer.MOD_ID, "jei_plugin");
@Override
public @NotNull ResourceLocation getPluginUid() {
return UID;
}
@Override
public void registerItemSubtypes(ISubtypeRegistration registration) {
registration.registerSubtypeInterpreter(ModItemRegister.TIPPED_LEASH_ROPE_ARROW.get(), PotionSubtypeInterpreter.INSTANCE);
}
@Override
public void registerRecipes(@NotNull IRecipeRegistration registration) {
registration.addRecipes(RecipeTypes.CRAFTING, TippedLeashArrowRecipeMaker.createRecipes());
}
}

View File

@ -0,0 +1,28 @@
package com.r3944realms.leashedplayer.compat.jei.common;
import mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter;
import mezz.jei.api.ingredients.subtypes.UidContext;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.PotionContents;
import org.jetbrains.annotations.NotNull;
public class PotionSubtypeInterpreter implements IIngredientSubtypeInterpreter<ItemStack> {
public static final PotionSubtypeInterpreter INSTANCE = new PotionSubtypeInterpreter();
private PotionSubtypeInterpreter() {
}
@Override
public @NotNull String apply(ItemStack itemStack, @NotNull UidContext context) {
if (itemStack.getComponentsPatch().isEmpty()) {
return IIngredientSubtypeInterpreter.NONE;
}
PotionContents contents = itemStack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
String itemDescriptionId = itemStack.getItem().getDescriptionId();
String potionEffectId = contents.potion().map(Holder::getRegisteredName).orElse("none");
return itemDescriptionId + ".effect_id." + potionEffectId;
}
}

View File

@ -0,0 +1,77 @@
package com.r3944realms.leashedplayer.compat.jei.crafting;
import com.r3944realms.leashedplayer.LeashedPlayer;
import com.r3944realms.leashedplayer.compat.jei.util.RegistryUtil;
import com.r3944realms.leashedplayer.content.items.ModItemRegister;
import net.minecraft.core.NonNullList;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.crafting.*;
import net.neoforged.neoforge.common.crafting.DataComponentIngredient;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public final class TippedLeashArrowRecipeMaker {
private static List<RecipeHolder<CraftingRecipe>> createRecipesA() {
String group = "jei.tipped.leash_rope_arrow_a";
ItemStack arrowStack = new ItemStack(ModItemRegister.LEASH_ROPE_ARROW.get());
Ingredient arrowIngredient = Ingredient.of(arrowStack);
Registry<Potion> potionRegistry = RegistryUtil.getRegistry(Registries.POTION);
return potionRegistry.holders()
.map(potion -> {
ItemStack input = PotionContents.createItemStack(Items.LINGERING_POTION, potion);
ItemStack output = PotionContents.createItemStack(ModItemRegister.TIPPED_LEASH_ROPE_ARROW.get(), potion);
output.setCount(8);
Ingredient potionIngredient = DataComponentIngredient.of(false, input);
NonNullList<Ingredient> inputs = NonNullList.of(Ingredient.EMPTY,
arrowIngredient, arrowIngredient, arrowIngredient,
arrowIngredient, potionIngredient, arrowIngredient,
arrowIngredient, arrowIngredient, arrowIngredient
);
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(LeashedPlayer.MOD_ID, group + "." + output.getDescriptionId());
ShapedRecipePattern recipe = new ShapedRecipePattern(3,3, inputs, Optional.empty());
CraftingRecipe recipe_ = new ShapedRecipe(group, CraftingBookCategory.MISC, recipe, output);
return new RecipeHolder<>(id, recipe_);
}).toList();
}
private static List<RecipeHolder<CraftingRecipe>> createRecipesB() {
String group = "jei.tipped.leash_rope_arrow_b";
ItemStack arrowStack = new ItemStack(Items.LEAD);
Ingredient arrowIngredient = Ingredient.of(arrowStack);
Registry<Potion> potionRegistry = RegistryUtil.getRegistry(Registries.POTION);
return potionRegistry.holders()
.map(potion -> {
ItemStack input = PotionContents.createItemStack(Items.TIPPED_ARROW, potion);
ItemStack output = PotionContents.createItemStack(ModItemRegister.TIPPED_LEASH_ROPE_ARROW.get(), potion);
output.setCount(1);
Ingredient potionIngredient = DataComponentIngredient.of(false, input);
NonNullList<Ingredient> inputs = NonNullList.of(Ingredient.EMPTY,
arrowIngredient,potionIngredient
);
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(LeashedPlayer.MOD_ID, group + "." + output.getDescriptionId());
CraftingRecipe recipe_ = new ShapelessRecipe(group, CraftingBookCategory.MISC, output, inputs);
return new RecipeHolder<>(id, recipe_);
}).toList();
}
public static List<RecipeHolder<CraftingRecipe>> createRecipes() {
List<RecipeHolder<CraftingRecipe>> ret = new ArrayList<>();
ret.addAll(createRecipesA());
ret.addAll(createRecipesB());
return ret;
}
private TippedLeashArrowRecipeMaker() {
}
}

View File

@ -0,0 +1,23 @@
package com.r3944realms.leashedplayer.compat.jei.util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
public class RegistryUtil {
public static <T> Registry<T> getRegistry(ResourceKey<? extends Registry<T>> key) {
RegistryAccess registryAccess = getRegistryAccess();
return registryAccess.registryOrThrow(key);
}
public static RegistryAccess getRegistryAccess() {
Minecraft minecraft = Minecraft.getInstance();
ClientLevel level = minecraft.level;
if (level == null) {
throw new IllegalStateException("Could not get registry, registry access is unavailable because the level is currently null");
}
return level.registryAccess();
}
}

View File

@ -21,7 +21,7 @@ public class NoLeashEffect extends MobEffect {
if(effect != null && effect.getDuration() != 0) {
if (pLivingEntity instanceof Leashable leashable) {
if (leashable.getLeashHolder() instanceof LeashRopeArrow arrow) {
arrow.setOwner(null);
arrow.dropLeashHandler();
leashable.dropLeash(true, false);
}
leashable.dropLeash(true, true);

View File

@ -292,8 +292,7 @@ public class LeashRopeArrow extends AbstractArrow {
if(leashDataEntity != null) {
pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow));
if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) {
leashDataEntity.playSound(SoundEvents.LEASH_KNOT_BREAK, 1, 1);
leashRopeArrow.setOwner(null);
leashRopeArrow.dropLeashHandler();
}
}
Entity leashKnotFence = PlayerLeashable.createLeashKnotFence((ServerLevel) this.level(), pResult.getBlockPos());
@ -336,8 +335,7 @@ public class LeashRopeArrow extends AbstractArrow {
if (this.getOwner() instanceof LivingEntity livingEntity ) {
MobEffectInstance effect = livingEntity.getEffect(ModEffectRegister.NO_LEASH_EFFECT);
if (effect != null && effect.getDuration() != 0) {
livingEntity.playSound(SoundEvents.LEASH_KNOT_BREAK, 1, 1);
this.setOwner(null);
this.dropLeashHandler();
}
}
if(entity instanceof LivingEntity livingEntity) {
@ -348,8 +346,7 @@ public class LeashRopeArrow extends AbstractArrow {
if(leashDataEntity != null) {
pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow));
if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) {
leashRopeArrow.playSound(SoundEvents.LEASH_KNOT_BREAK, 1, 1);
leashRopeArrow.setOwner(null);
leashRopeArrow.dropLeashHandler();
}
}
ILivingEntityExtension pLL = (ILivingEntityExtension) pL;
@ -361,8 +358,7 @@ public class LeashRopeArrow extends AbstractArrow {
if(leashDataEntity != null) {
pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow));
if (leashDataEntity instanceof LeashRopeArrow leashRopeArrow) {
leashRopeArrow.playSound(SoundEvents.LEASH_KNOT_BREAK, 1, 1);
leashRopeArrow.setOwner(null);
leashRopeArrow.dropLeashHandler();
}
}
ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack());
@ -379,8 +375,7 @@ public class LeashRopeArrow extends AbstractArrow {
if (leashDataEntity != null) {
leashable.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow));
if (leashDataEntity instanceof LeashRopeArrow leashRopeArrow) {
leashRopeArrow.playSound(SoundEvents.LEASH_KNOT_BREAK, 1, 1);
leashRopeArrow.setOwner(null);
leashRopeArrow.dropLeashHandler();
}
}
livingEntity.playSound(SoundEvents.LEASH_KNOT_PLACE, 1, 1);
@ -409,8 +404,7 @@ public class LeashRopeArrow extends AbstractArrow {
if (leashDataEntity != null) {
pL.dropLeash(true, true);
if (leashDataEntity instanceof LeashRopeArrow leashRopeArrow) {
leashRopeArrow.playSound(SoundEvents.LEASH_KNOT_BREAK, 1, 1);
leashRopeArrow.setOwner(null);
leashRopeArrow.dropLeashHandler();
}
}
ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack());
@ -456,5 +450,8 @@ public class LeashRopeArrow extends AbstractArrow {
super.handleEntityEvent(pId);
}
}
public void dropLeashHandler() {
this.playSound(SoundEvents.LEASH_KNOT_PLACE, 1, 1);
this.setOwner(null);
}
}

View File

@ -1,6 +1,5 @@
package com.r3944realms.leashedplayer.content.items.type;
import com.r3944realms.leashedplayer.content.entities.LeashRopeArrow;
import com.r3944realms.leashedplayer.content.entities.ModEntityRegister;
import com.r3944realms.leashedplayer.content.entities.NestleRopeArrow;
import net.minecraft.core.Direction;

View File

@ -20,7 +20,6 @@ import com.r3944realms.leashedplayer.network.server.DecreaseLeashRopeLength;
import com.r3944realms.leashedplayer.network.server.IncreaseLeashRopeLength;
import com.r3944realms.leashedplayer.utils.Enum.LanguageEnum;
import com.r3944realms.leashedplayer.utils.Enum.ModPartEnum;
import io.github.kunosayo.nestle.item.NestleItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import org.jetbrains.annotations.NotNull;

View File

@ -1,27 +0,0 @@
package com.r3944realms.leashedplayer.integration.jei;
import com.r3944realms.leashedplayer.LeashedPlayer;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.registration.IRecipeRegistration;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
@JeiPlugin
public class JEIPlugin implements IModPlugin {
private static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(LeashedPlayer.MOD_ID, "jei_plugin");
@Override
public @NotNull ResourceLocation getPluginUid() {
return UID;
}
@Override
public void registerRecipes(@NotNull IRecipeRegistration registration) {
var level = Minecraft.getInstance().level;
assert level != null;
var recipeManager = level.getRecipeManager();
}
}

View File

@ -1,13 +0,0 @@
package com.r3944realms.leashedplayer.integration.jei;
import com.r3944realms.leashedplayer.LeashedPlayer;
import com.r3944realms.leashedplayer.content.items.repcipe.TippedLeashRopeArrowRecipe;
import mezz.jei.api.recipe.RecipeType;
public class JEIRecipeTypes {
public static final RecipeType<TippedLeashRopeArrowRecipe.TippedLeashRopeArrowARecipe> TIPPED_LEASH_ROPE_ARROW_A =
RecipeType.create(LeashedPlayer.MOD_ID, "tipped_leash_rope_arrow_a", TippedLeashRopeArrowRecipe.TippedLeashRopeArrowARecipe.class);
public static final RecipeType<TippedLeashRopeArrowRecipe.TippedLeashRopeArrowBRecipe> TIPPED_LEASH_ROPE_ARROW_B =
RecipeType.create(LeashedPlayer.MOD_ID, "tipped_leash_rope_arrow_b", TippedLeashRopeArrowRecipe.TippedLeashRopeArrowBRecipe.class);
}

View File

@ -1,5 +0,0 @@
package com.r3944realms.leashedplayer.integration.jei.category;
public class LeashedPlayerCategory {
}

View File

@ -1,5 +1,6 @@
package com.r3944realms.leashedplayer.mixin.item;
import com.r3944realms.leashedplayer.content.entities.LeashRopeArrow;
import com.r3944realms.leashedplayer.modInterface.PlayerLeashable;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
@ -46,6 +47,9 @@ public class MixinLeadItem implements Equipable {
PlayerLeashable playerLeashable = (PlayerLeashable) pPlayer;
if(leashDataEntity != null) {
playerLeashable.dropLeash(true, true);
if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) {
leashRopeArrow.dropLeashHandler();
}
}
//获取拴绳结实体
LeashFenceKnotEntity leashfenceknotentity = LeashFenceKnotEntity.getOrCreateKnot(pLevel, pPos);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 63 KiB