From 2f51ce0aa30c59cc36332fbe82cfa9ff831b5f89 Mon Sep 17 00:00:00 2001 From: Lithewings <2631810335@qq.com> Date: Tue, 6 Aug 2024 05:34:39 +0800 Subject: [PATCH] =?UTF-8?q?Merge=20remote-tracking=20branch=20'origin/mast?= =?UTF-8?q?er=E2=80=94'=20into=20master=E2=80=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/equilibrium/MITEequilibrium.java | 6 ++- .../equilibrium/event/BreakBlockEvent.java | 18 ++++---- src/main/java/com/equilibrium/item/Tools.java | 19 +++++---- .../item/tools_attribute/metal/MetalAxe.java | 16 ++++++- .../tools_attribute/metal/MetalDagger.java | 7 +++- .../item/tools_attribute/metal/MetalHoe.java | 15 ++++++- .../tools_attribute/metal/MetalPickAxe.java | 39 ++++++++++++++++-- .../tools_attribute/metal/MetalShovel.java | 23 +++++++++-- .../tools_attribute/metal/MetalSword.java | 23 +---------- .../mixin/MiningToolItemMixin.java | 13 ++++++ .../mixin/crop/CropBlockMixin.java | 31 ++++++++++++++ .../mixin/player/PlayerEntityMixin.java | 15 +++---- .../status/PhytonutrientStatusEffect.java | 21 ++++------ .../status/registerStatusEffect.java | 28 +++++++++++++ .../textures/mob_effect/phytonutrient.png | Bin 0 -> 587 bytes .../resources/miteequilibrium.mixins.json | 2 + 16 files changed, 205 insertions(+), 71 deletions(-) create mode 100644 src/main/java/com/equilibrium/mixin/MiningToolItemMixin.java create mode 100644 src/main/java/com/equilibrium/mixin/crop/CropBlockMixin.java create mode 100644 src/main/java/com/equilibrium/status/registerStatusEffect.java create mode 100644 src/main/resources/assets/miteequilibrium/textures/mob_effect/phytonutrient.png diff --git a/src/main/java/com/equilibrium/MITEequilibrium.java b/src/main/java/com/equilibrium/MITEequilibrium.java index 0fb5f47..b990bb3 100644 --- a/src/main/java/com/equilibrium/MITEequilibrium.java +++ b/src/main/java/com/equilibrium/MITEequilibrium.java @@ -33,6 +33,8 @@ import static com.equilibrium.entity.ModEntities.registerModEntities; + +import static com.equilibrium.status.registerStatusEffect.registerStatusEffects; import static com.equilibrium.tags.ModBlockTags.registerModBlockTags; import static com.equilibrium.tags.ModItemTags.registerModItemTags; import static com.equilibrium.util.LootTableModifier.modifierLootTables; @@ -89,8 +91,8 @@ public void onInitialize() { registerModBlockTags(); registerModItemTags(); - - + //注册(药水)效果 + registerStatusEffects(); diff --git a/src/main/java/com/equilibrium/event/BreakBlockEvent.java b/src/main/java/com/equilibrium/event/BreakBlockEvent.java index 5137643..b0f3e4b 100644 --- a/src/main/java/com/equilibrium/event/BreakBlockEvent.java +++ b/src/main/java/com/equilibrium/event/BreakBlockEvent.java @@ -47,49 +47,49 @@ public void afterBlockBreak(World world, PlayerEntity player, BlockPos pos, Bloc if(state.isIn(ModBlockTags.LOG_120)){ - itemStack.damage(120-1,player, EquipmentSlot.MAINHAND); + itemStack.damage(120,player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-120")); }else if(state.isIn(ModBlockTags.STONE_LIKE_240)){ - itemStack.damage(240-1,player, EquipmentSlot.MAINHAND); + itemStack.damage(240,player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-240")); } else if(state.isIn(ModBlockTags.STONE_LIKE_360)){ - itemStack.damage(360-1,player, EquipmentSlot.MAINHAND); + itemStack.damage(360,player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-360")); } else if(state.isIn(ModBlockTags.STONE_LIKE_480)){ - itemStack.damage(480-1,player, EquipmentSlot.MAINHAND); + itemStack.damage(480,player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-480")); } //240 360 480其余没有列出的,但是确实比较硬的物品,而且在三者子集里容易冲突 else if(state.isIn(BlockTags.NEEDS_STONE_TOOL)){ - itemStack.damage(240-1,player, EquipmentSlot.MAINHAND); + itemStack.damage(240,player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-240"));} else if(state.isIn(BlockTags.NEEDS_IRON_TOOL)) { - itemStack.damage(360 - 1, player, EquipmentSlot.MAINHAND); + itemStack.damage(360, player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-360")); } else if(state.isIn(BlockTags.NEEDS_DIAMOND_TOOL)) { - itemStack.damage(480 - 1, player, EquipmentSlot.MAINHAND); + itemStack.damage(480, player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-480")); } else if(state.isIn(ModBlockTags.NORMAL_30)){ - itemStack.damage(30-1,player, EquipmentSlot.MAINHAND); + itemStack.damage(30,player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-30")); } else if(state.isIn(ModBlockTags.NORMAL_60)){ - itemStack.damage(60-1,player, EquipmentSlot.MAINHAND); + itemStack.damage(60,player, EquipmentSlot.MAINHAND); player.sendMessage(Text.of("-60")); } diff --git a/src/main/java/com/equilibrium/item/Tools.java b/src/main/java/com/equilibrium/item/Tools.java index d9982f0..38c1d86 100644 --- a/src/main/java/com/equilibrium/item/Tools.java +++ b/src/main/java/com/equilibrium/item/Tools.java @@ -75,12 +75,12 @@ public class Tools { public static final Item MITHRIL_SWORD = createMetalSwordItem(ModToolMaterials.MITHRIL_SWORD,9,3f); public static final Item ADMANTIUM_SWORD =createMetalSwordItem(ModToolMaterials.ADAMANTIUM_SHOVEL,10,3f); - public static final Item COPPER_DAGGER = createMetalSwordItem(ModToolMaterials.COOPER_DAGGER,6,4f); - public static final Item GOLD_DAGGER = createMetalSwordItem(ModToolMaterials.GOLD_DAGGER,6,4f); - public static final Item SILVER_DAGGER = createMetalSwordItem(ModToolMaterials.SILVER_DAGGER,6,4f); - public static final Item IRON_DAGGER = createMetalSwordItem(ModToolMaterials.IRON_DAGGER,7,4f); - public static final Item MITHRIL_DAGGER = createMetalSwordItem(ModToolMaterials.MITHRIL_DAGGER,8,4f); - public static final Item ADMANTIUM_DAGGER =createMetalSwordItem(ModToolMaterials.ADAMANTIUM_DAGGER,9,4f); + public static final Item COPPER_DAGGER = createMetalDaggerItem(ModToolMaterials.COOPER_DAGGER,6,4f); + public static final Item GOLD_DAGGER = createMetalDaggerItem(ModToolMaterials.GOLD_DAGGER,6,4f); + public static final Item SILVER_DAGGER = createMetalDaggerItem(ModToolMaterials.SILVER_DAGGER,6,4f); + public static final Item IRON_DAGGER = createMetalDaggerItem(ModToolMaterials.IRON_DAGGER,7,4f); + public static final Item MITHRIL_DAGGER = createMetalDaggerItem(ModToolMaterials.MITHRIL_DAGGER,8,4f); + public static final Item ADMANTIUM_DAGGER =createMetalDaggerItem(ModToolMaterials.ADAMANTIUM_DAGGER,9,4f); @@ -125,7 +125,7 @@ public static Item createMetalShovelItem(ToolMaterial material, int finalDamage, public static Item createMetalPickAxeItem(ToolMaterial material, int finalDamage,float finalDamageSpeed){ - return new MetalPickAxe(material,BlockTags.PICKAXE_MINEABLE,new Item.Settings(). + return new MetalPickAxe(material,new Item.Settings(). attributeModifiers(MiningToolItem.createAttributeModifiers(material,-1+finalDamage,-4+finalDamageSpeed)) ); } @@ -135,7 +135,12 @@ public static Item createMetalSwordItem(ToolMaterial material, int finalDamage,f attributeModifiers(MiningToolItem.createAttributeModifiers(material,-1+finalDamage,-4+finalDamageSpeed)) ); } + public static Item createMetalDaggerItem(ToolMaterial material, int finalDamage,float finalDamageSpeed){ + return new MetalDagger(material,new Item.Settings(). + attributeModifiers(MiningToolItem.createAttributeModifiers(material,-1+finalDamage,-4+finalDamageSpeed)) + ); + } diff --git a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalAxe.java b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalAxe.java index 3bdb89f..267d86a 100644 --- a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalAxe.java +++ b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalAxe.java @@ -4,6 +4,8 @@ import com.google.common.collect.ImmutableMap; import net.minecraft.advancement.criterion.Criteria; import net.minecraft.block.*; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ToolComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -21,10 +23,11 @@ import net.minecraft.world.event.GameEvent; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.Map; import java.util.Optional; -public class MetalAxe extends MiningToolItem { +public class MetalAxe extends ToolItem { protected static final Map STRIPPED_BLOCKS = new ImmutableMap.Builder() .put(Blocks.OAK_WOOD, Blocks.STRIPPED_OAK_WOOD) .put(Blocks.OAK_LOG, Blocks.STRIPPED_OAK_LOG) @@ -50,7 +53,14 @@ public class MetalAxe extends MiningToolItem { .build(); public MetalAxe(ToolMaterial material, Settings settings) { - super(material, BlockTags.AXE_MINEABLE, settings); + super(material, settings.component(DataComponentTypes.TOOL, createToolComponent())); + + } + //ofAlwaysDropping 可以将为工具添加一个正确挖掘的"标签" + private static ToolComponent createToolComponent() { + return new ToolComponent( + List.of(ToolComponent.Rule.ofAlwaysDropping(BlockTags.AXE_MINEABLE, 4F)), 1.0F, 0 + ); } @Override public ActionResult useOnBlock(ItemUsageContext context) { @@ -80,6 +90,8 @@ public ActionResult useOnBlock(ItemUsageContext context) { } } + + private static boolean shouldCancelStripAttempt(ItemUsageContext context) { PlayerEntity playerEntity = context.getPlayer(); return context.getHand().equals(Hand.MAIN_HAND) && playerEntity.getOffHandStack().isOf(Items.SHIELD) && !playerEntity.shouldCancelInteraction(); diff --git a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalDagger.java b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalDagger.java index e761f5e..2ca96d0 100644 --- a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalDagger.java +++ b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalDagger.java @@ -11,7 +11,10 @@ import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.*; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ToolItem; +import net.minecraft.item.ToolMaterial; import net.minecraft.registry.tag.BlockTags; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -25,7 +28,7 @@ public MetalDagger(ToolMaterial toolMaterial, Item.Settings settings) { private static ToolComponent createToolComponent() { return new ToolComponent( - List.of(ToolComponent.Rule.ofAlwaysDropping(List.of(Blocks.COBWEB), 15.0F), ToolComponent.Rule.of(BlockTags.SWORD_EFFICIENT, 1.5F)), 1.0F, 2 + List.of(ToolComponent.Rule.ofAlwaysDropping(List.of(Blocks.COBWEB), 15.0F), ToolComponent.Rule.of(BlockTags.SWORD_EFFICIENT, 1.5F)), 1.0F, 0 ); } diff --git a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalHoe.java b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalHoe.java index e04cdda..8e838c7 100644 --- a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalHoe.java +++ b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalHoe.java @@ -6,6 +6,8 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ToolComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -19,11 +21,12 @@ import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; +import java.util.List; import java.util.Map; import java.util.function.Consumer; import java.util.function.Predicate; -public class MetalHoe extends MiningToolItem{ +public class MetalHoe extends ToolItem{ /** * A map of input blocks to predicate-consumer action pairs. * @@ -45,8 +48,16 @@ public class MetalHoe extends MiningToolItem{ ) ); + public MetalHoe(ToolMaterial toolMaterial, Item.Settings settings) { - super(toolMaterial, BlockTags.HOE_MINEABLE, settings); + super(toolMaterial,settings.component(DataComponentTypes.TOOL, createToolComponent())); + } + + + private static ToolComponent createToolComponent() { + return new ToolComponent( + List.of(ToolComponent.Rule.ofAlwaysDropping(BlockTags.HOE_MINEABLE, 4F)), 1.0F, 0 + ); } @Override diff --git a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalPickAxe.java b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalPickAxe.java index 59db3bd..b7633ce 100644 --- a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalPickAxe.java +++ b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalPickAxe.java @@ -1,18 +1,51 @@ package com.equilibrium.item.tools_attribute.metal; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ToolComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.MiningToolItem; +import net.minecraft.item.ToolItem; import net.minecraft.item.ToolMaterial; +import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; -public class MetalPickAxe extends MiningToolItem { +import java.util.List; - public MetalPickAxe(ToolMaterial material, TagKey effectiveBlocks, Settings settings) { - super(material, effectiveBlocks, settings); + + +public class MetalPickAxe extends ToolItem { + + public MetalPickAxe(ToolMaterial material,Settings settings) { + super(material,settings.component(DataComponentTypes.TOOL, createToolComponent())); } + + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + ToolComponent toolComponent = stack.get(DataComponentTypes.TOOL); + if (toolComponent == null) { + return false; + } else { + if (!world.isClient && state.getHardness(world, pos) != 0.0F) { + stack.damage(stack.isSuitableFor(state)? 0 : 480 , miner, EquipmentSlot.MAINHAND); + } + + return true; + } + } + private static ToolComponent createToolComponent() { + return new ToolComponent( + List.of(ToolComponent.Rule.ofAlwaysDropping(BlockTags.PICKAXE_MINEABLE, 4F)), 1.0F, 0 + ); + } + + + @Override public void postDamageEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) { stack.damage(150, attacker, EquipmentSlot.MAINHAND); diff --git a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalShovel.java b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalShovel.java index 2b9a7b5..1759302 100644 --- a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalShovel.java +++ b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalShovel.java @@ -6,12 +6,14 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.CampfireBlock; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ToolComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; -import net.minecraft.item.MiningToolItem; +import net.minecraft.item.ToolItem; import net.minecraft.item.ToolMaterial; import net.minecraft.registry.tag.BlockTags; import net.minecraft.sound.SoundCategory; @@ -23,9 +25,10 @@ import net.minecraft.world.WorldEvents; import net.minecraft.world.event.GameEvent; +import java.util.List; import java.util.Map; -public class MetalShovel extends MiningToolItem { +public class MetalShovel extends ToolItem { protected static final Map PATH_STATES = Maps.newHashMap( new ImmutableMap.Builder() .put(Blocks.GRASS_BLOCK, Blocks.DIRT_PATH.getDefaultState()) @@ -37,10 +40,24 @@ public class MetalShovel extends MiningToolItem { .build() ); + public MetalShovel(ToolMaterial toolMaterial, Settings settings) { - super(toolMaterial, BlockTags.SHOVEL_MINEABLE, settings); + super(toolMaterial,settings.component(DataComponentTypes.TOOL, createToolComponent())); + } + + private static ToolComponent createToolComponent() { + return new ToolComponent( + List.of(ToolComponent.Rule.ofAlwaysDropping(BlockTags.SHOVEL_MINEABLE,4F)), 1.0F, 0 + ); } + + + + + + + @Override public ActionResult useOnBlock(ItemUsageContext context) { World world = context.getWorld(); diff --git a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalSword.java b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalSword.java index 487a9c7..68176cc 100644 --- a/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalSword.java +++ b/src/main/java/com/equilibrium/item/tools_attribute/metal/MetalSword.java @@ -3,13 +3,9 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.AttributeModifierSlot; -import net.minecraft.component.type.AttributeModifiersComponent; import net.minecraft.component.type.ToolComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.ToolItem; @@ -27,27 +23,10 @@ public MetalSword(ToolMaterial toolMaterial, Settings settings) { private static ToolComponent createToolComponent() { return new ToolComponent( - List.of(ToolComponent.Rule.ofAlwaysDropping(List.of(Blocks.COBWEB), 15.0F), ToolComponent.Rule.of(BlockTags.SWORD_EFFICIENT, 1.5F)), 1.0F, 2 + List.of(ToolComponent.Rule.ofAlwaysDropping(List.of(Blocks.COBWEB), 15.0F), ToolComponent.Rule.of(BlockTags.SWORD_EFFICIENT, 1.5F)), 1.0F, 0 ); } - public static AttributeModifiersComponent createAttributeModifiers(ToolMaterial material, int baseAttackDamage, float attackSpeed) { - return AttributeModifiersComponent.builder() - .add( - EntityAttributes.GENERIC_ATTACK_DAMAGE, - new EntityAttributeModifier( - BASE_ATTACK_DAMAGE_MODIFIER_ID, (double)((float)baseAttackDamage + material.getAttackDamage()), EntityAttributeModifier.Operation.ADD_VALUE - ), - AttributeModifierSlot.MAINHAND - ) - .add( - EntityAttributes.GENERIC_ATTACK_SPEED, - new EntityAttributeModifier(BASE_ATTACK_SPEED_MODIFIER_ID, (double)attackSpeed, EntityAttributeModifier.Operation.ADD_VALUE), - AttributeModifierSlot.MAINHAND - ) - .build(); - } - @Override public boolean canMine(BlockState state, World world, BlockPos pos, PlayerEntity miner) { return !miner.isCreative(); diff --git a/src/main/java/com/equilibrium/mixin/MiningToolItemMixin.java b/src/main/java/com/equilibrium/mixin/MiningToolItemMixin.java new file mode 100644 index 0000000..bf80186 --- /dev/null +++ b/src/main/java/com/equilibrium/mixin/MiningToolItemMixin.java @@ -0,0 +1,13 @@ +package com.equilibrium.mixin; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.item.Item; +import net.minecraft.item.MiningToolItem; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +@Mixin(MiningToolItem.class) +public class MiningToolItemMixin { + +} diff --git a/src/main/java/com/equilibrium/mixin/crop/CropBlockMixin.java b/src/main/java/com/equilibrium/mixin/crop/CropBlockMixin.java new file mode 100644 index 0000000..0da5ace --- /dev/null +++ b/src/main/java/com/equilibrium/mixin/crop/CropBlockMixin.java @@ -0,0 +1,31 @@ +package com.equilibrium.mixin.crop; + +import net.minecraft.block.*; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import org.spongepowered.asm.mixin.Mixin; +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; + +@Mixin(CropBlock.class) +public abstract class CropBlockMixin extends PlantBlock implements Fertilizable { + protected CropBlockMixin(Settings settings) { + super(settings); + } + + + + + @Inject(method = "randomTick",at = @At(value = "HEAD"),cancellable = true) + protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if(random.nextInt(16)!=0){ + ci.cancel(); + } + } + + + +} diff --git a/src/main/java/com/equilibrium/mixin/player/PlayerEntityMixin.java b/src/main/java/com/equilibrium/mixin/player/PlayerEntityMixin.java index 56e5f2d..4a66414 100644 --- a/src/main/java/com/equilibrium/mixin/player/PlayerEntityMixin.java +++ b/src/main/java/com/equilibrium/mixin/player/PlayerEntityMixin.java @@ -1,6 +1,7 @@ package com.equilibrium.mixin.player; import com.equilibrium.event.MoonPhaseEvent; +import com.equilibrium.status.registerStatusEffect; import com.equilibrium.tags.ModItemTags; import com.equilibrium.util.PlayerMaxHealthHelper; import com.equilibrium.util.PlayerMaxHungerHelper; @@ -187,7 +188,8 @@ public void jump(CallbackInfo ci) { // break; // default:zombieEntity.setOnGround(true, Vec3d.of(blockpos1)); // } - + if(!this.getWorld().isClient) + this.phytonutrient=0; } @@ -417,7 +419,6 @@ public void tick(CallbackInfo ci) { - //最好不要无条件地重复执行gamerule moonType = getMoonType(this.getWorld()); if(moonType!=null) { @@ -516,14 +517,14 @@ public void tick(CallbackInfo ci) { this.phytonutrient = this.phytonutrient > 192000 ? 192000 : this.phytonutrient; //施加饥饿效果 if (this.phytonutrient < 100) { - if (!this.hasStatusEffect(StatusEffects.HUNGER)) { - StatusEffectInstance statusEffectInstance1 = new StatusEffectInstance(StatusEffects.HUNGER, -1, 1, false, false, false); - StatusEffectUtil.addEffectToPlayersWithinDistance((ServerWorld) this.getWorld(), this, this.getPos(), 4, statusEffectInstance1, -1); + if (!this.hasStatusEffect(registerStatusEffect.PHYTONUTRIENT)) { + StatusEffectInstance statusEffectInstance1 = new StatusEffectInstance(registerStatusEffect.PHYTONUTRIENT, -1, 1, false, false, false); + StatusEffectUtil.addEffectToPlayersWithinDistance((ServerWorld) this.getWorld(), this, this.getPos(), 16, statusEffectInstance1, -1); } } else { - if (this.hasStatusEffect(StatusEffects.HUNGER)) { - this.removeStatusEffect(StatusEffects.HUNGER); + if (this.hasStatusEffect(registerStatusEffect.PHYTONUTRIENT)) { + this.removeStatusEffect(registerStatusEffect.PHYTONUTRIENT); } } diff --git a/src/main/java/com/equilibrium/status/PhytonutrientStatusEffect.java b/src/main/java/com/equilibrium/status/PhytonutrientStatusEffect.java index 0f20512..b881a4a 100644 --- a/src/main/java/com/equilibrium/status/PhytonutrientStatusEffect.java +++ b/src/main/java/com/equilibrium/status/PhytonutrientStatusEffect.java @@ -6,38 +6,35 @@ import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; public class PhytonutrientStatusEffect extends StatusEffect { - protected PhytonutrientStatusEffect(StatusEffectCategory category, int color) { + protected PhytonutrientStatusEffect() { super( StatusEffectCategory.HARMFUL, // 药水效果是有益的还是有害的 5797459); } - private int applyTime = 0; - // 这个方法在每个 tick 都会调用,以检查是否应应用药水效果 @Override public boolean canApplyUpdateEffect(int duration, int amplifier) { - if (applyTime>100){ - applyTime=0; - return true; - }else{ - applyTime++; - return false; - } + return true; } + // 这个方法在应用药水效果时会被调用,所以我们可以在这里实现自定义功能。 @Override public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { - if (entity instanceof PlayerEntity) { - entity.damage(entity.getDamageSources().wither(),1); + if (entity instanceof PlayerEntity playerEntity) { + playerEntity.addExhaustion(0.005F * (float)(amplifier + 1)); return true; } return false; } + } diff --git a/src/main/java/com/equilibrium/status/registerStatusEffect.java b/src/main/java/com/equilibrium/status/registerStatusEffect.java new file mode 100644 index 0000000..9518725 --- /dev/null +++ b/src/main/java/com/equilibrium/status/registerStatusEffect.java @@ -0,0 +1,28 @@ +package com.equilibrium.status; + + +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectCategory; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.Identifier; + +public class registerStatusEffect { + public static final RegistryEntry PHYTONUTRIENT = register("phytonutrient",new PhytonutrientStatusEffect()); + + + + + private static RegistryEntry register(String id, StatusEffect statusEffect) { + return Registry.registerReference(Registries.STATUS_EFFECT, Identifier.of("miteequilibrium",id), statusEffect); + } + + + + + + public static void registerStatusEffects(){ + + } +} diff --git a/src/main/resources/assets/miteequilibrium/textures/mob_effect/phytonutrient.png b/src/main/resources/assets/miteequilibrium/textures/mob_effect/phytonutrient.png new file mode 100644 index 0000000000000000000000000000000000000000..2bf6a6bd3a403216278eca6684bddfd6aa506c4e GIT binary patch literal 587 zcmV-R0<`^!P)5lf7$GQ53*`H%&iXawsB)vi#`2+`Tp_i-`%jGnHmBF+opUILNCvYXE$&e&Bq*NG>qO z%;h+{4NH99AsePdWFTmEd`yz_Ip*pOve8jmmc^>2Q`1eh^fo^4klNcn!0nU~fa`0C zY;uN{WwE)lOF9<#y<@Vaw*^p+rFq&vNci{Je7DZ3r85%q0+0>`h(^8*`#PTZCFnnOA8EpRI$2aH?pRiL?a>Air?&vVwsdPsA+Zj!ajbk5}BLk z=F);VPE9FAHabdR*hACm{1u#>&vAQcf!XXd>R$5Fzh?!YU>K@r0}4QVUOUJiKFftn ziakW0K6!AgGf;sYKbV{1?Q|=)JjZJFbR;Y;1Ser-cBh>u%Sv7dhqE)JCiOtN-+`cMkf3 ZegV~Q?8v5>=}-Uw002ovPDHLkV1n9M3jP29 literal 0 HcmV?d00001 diff --git a/src/main/resources/miteequilibrium.mixins.json b/src/main/resources/miteequilibrium.mixins.json index b27c17e..8d2b197 100644 --- a/src/main/resources/miteequilibrium.mixins.json +++ b/src/main/resources/miteequilibrium.mixins.json @@ -8,9 +8,11 @@ "EntitySpawner", "GrassColorsMixin", "ItemMixin", + "MiningToolItemMixin", "MITEequilibriumMixin", "recipeModifier", "crafttime.ScreenHandlerMixin", + "crop.CropBlockMixin", "entitymixin.CowEntityMixin", "entitymixin.HostileAttributesMixin", "entitymixin.SkeletonEntityMixin",