From 604976e7a66d86b360417b48ce3ee4036641de91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?HuTao=E4=BB=8A=E5=A4=A9=E5=90=83=E4=BB=80=E4=B9=88?= <1184726415@qq.com> Date: Thu, 13 Oct 2022 20:27:53 +0800 Subject: [PATCH] v0.1.6.2 --- build.gradle | 2 +- .../assets/extrabotany/lang/en_us.json | 1 + .../assets/extrabotany/lang/zh_cn.json | 1 + .../common/base/ManaRulerHandler.java | 17 +++- .../extrabotany/common/baubles/NatureOrb.java | 80 ++++++++++++------- .../common/blocks/tile/TilePowerFrame.java | 1 - .../events/EntityAddEffectReturnEvent.java | 22 +++++ .../common/events/EntityEffectEvent.java | 17 ---- .../extrabotany/datagen/DataGenerators.java | 3 +- .../forge/mixin/client/MixinLivingEntity.java | 14 +--- 10 files changed, 93 insertions(+), 65 deletions(-) create mode 100644 src/main/java/chick/extrabotany/common/events/EntityAddEffectReturnEvent.java delete mode 100644 src/main/java/chick/extrabotany/common/events/EntityEffectEvent.java diff --git a/build.gradle b/build.gradle index 0b48fe0..846b10b 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ apply plugin: 'maven-publish' // apply MixinGradle apply plugin: 'org.spongepowered.mixin' -version = '1.18.2-0.1.6.2' +version = '1.18.2-0.1.6.3' group = 'extrabotany' //'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'extrabotany' diff --git a/src/generated/resources/assets/extrabotany/lang/en_us.json b/src/generated/resources/assets/extrabotany/lang/en_us.json index aed9b2c..8ca5e27 100644 --- a/src/generated/resources/assets/extrabotany/lang/en_us.json +++ b/src/generated/resources/assets/extrabotany/lang/en_us.json @@ -455,6 +455,7 @@ "item.extrabotany.potato_chip": "Potato Chip", "item.extrabotany.power_glove": "Power Glove", "item.extrabotany.primo_gem": "Primogem", + "item.extrabotany.puredaisy_pendant": "Pure Daisy Pendant", "item.extrabotany.pylon": "Sims", "item.extrabotany.red_scarf": "Red Scarf", "item.extrabotany.reward_bag_a": "Reward Bag Eins", diff --git a/src/generated/resources/assets/extrabotany/lang/zh_cn.json b/src/generated/resources/assets/extrabotany/lang/zh_cn.json index c4fab45..94a228b 100644 --- a/src/generated/resources/assets/extrabotany/lang/zh_cn.json +++ b/src/generated/resources/assets/extrabotany/lang/zh_cn.json @@ -457,6 +457,7 @@ "item.extrabotany.potato_chip": "\u85AF\u7247", "item.extrabotany.power_glove": "\u5F3A\u529B\u624B\u5957", "item.extrabotany.primo_gem": "\u539F\u77F3", + "item.extrabotany.puredaisy_pendant": "\u767D\u96CF\u83CA\u9879\u94FE", "item.extrabotany.pylon": "\u6A21\u62DF\u4EBA\u751F", "item.extrabotany.red_scarf": "\u7EA2\u9886\u5DFE", "item.extrabotany.reward_bag_a": "\u5956\u52B1\u888BEins", diff --git a/src/main/java/chick/extrabotany/common/base/ManaRulerHandler.java b/src/main/java/chick/extrabotany/common/base/ManaRulerHandler.java index 7605336..2f1fb1a 100644 --- a/src/main/java/chick/extrabotany/common/base/ManaRulerHandler.java +++ b/src/main/java/chick/extrabotany/common/base/ManaRulerHandler.java @@ -1,7 +1,10 @@ package chick.extrabotany.common.base; +import chick.extrabotany.common.baubles.NatureOrb; +import chick.extrabotany.xplat.IXplatAbstractions; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.event.entity.player.ItemTooltipEvent; @@ -24,11 +27,17 @@ public class ManaRulerHandler var stack = event.getItemStack(); if (stack.getItem() instanceof ItemManaRing) { - var cap = stack.getCapability(BotaniaForgeCapabilities.MANA_ITEM); - if (cap.resolve().isPresent()) + var cap = vazkii.botania.xplat.IXplatAbstractions.INSTANCE.findManaItem(stack); + if (cap != null) { - var item = cap.resolve().get(); - event.getToolTip().add(2, new TextComponent("Mana:" + item.getMana() + "/" + item.getMaxMana()).withStyle(ChatFormatting.AQUA)); + event.getToolTip().add(2, new TextComponent("Mana:" + cap.getMana() + "/" + cap.getMaxMana()).withStyle(ChatFormatting.AQUA)); + } + } else if (stack.getItem() instanceof NatureOrb) + { + var cap = IXplatAbstractions.INSTANCE.findNatureOrbItem(stack); + if (cap != null) + { + event.getToolTip().add(2, new TranslatableComponent("extrabotany.nature_orb", cap.getNature(), cap.getMaxNature()).withStyle(ChatFormatting.GRAY)); } } } diff --git a/src/main/java/chick/extrabotany/common/baubles/NatureOrb.java b/src/main/java/chick/extrabotany/common/baubles/NatureOrb.java index f7a3c79..60f8cd8 100644 --- a/src/main/java/chick/extrabotany/common/baubles/NatureOrb.java +++ b/src/main/java/chick/extrabotany/common/baubles/NatureOrb.java @@ -1,5 +1,6 @@ package chick.extrabotany.common.baubles; +import chick.extrabotany.ExtraBotany; import chick.extrabotany.api.cap.INatureOrbItem; import chick.extrabotany.common.entities.ego.EntityEGO; import chick.extrabotany.xplat.IXplatAbstractions; @@ -7,11 +8,9 @@ import net.minecraft.ChatFormatting; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; -import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionResult; -import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.CreativeModeTab; @@ -21,8 +20,15 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.PotionEvent; +import net.minecraftforge.eventbus.api.Event; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import vazkii.botania.api.mana.ManaItemHandler; +import vazkii.botania.client.fx.SparkleParticleData; +import vazkii.botania.common.handler.EquipmentHandler; +import vazkii.botania.common.handler.ModSounds; import vazkii.botania.common.helper.ItemNBTHelper; import vazkii.botania.common.item.equipment.bauble.ItemBauble; @@ -37,13 +43,11 @@ public class NatureOrb extends ItemBauble public NatureOrb(Properties props) { super(props); + MinecraftForge.EVENT_BUS.addListener(this::clearBadPotions); } - @Override - public void appendHoverText(ItemStack stack, Level world, List tooltip, TooltipFlag flags) + private void addText(@Nullable INatureOrbItem manaItem, List tooltip) { - super.appendHoverText(stack, world, tooltip, flags); - var manaItem = IXplatAbstractions.INSTANCE.findNatureOrbItem(stack); if (manaItem != null) { tooltip.add(new TranslatableComponent("extrabotany.nature_orb", manaItem.getNature(), manaItem.getMaxNature()).withStyle(ChatFormatting.GRAY)); @@ -99,33 +103,53 @@ public class NatureOrb extends ItemBauble } } } - if (orbItem.getNature() > 400000) - { - if (player.tickCount % 40 == 0) - { - clearPotions(stack, player); - } - } } } } - public void clearPotions(ItemStack stack, Player player) + public void clearBadPotions(PotionEvent.PotionApplicableEvent event) { - var orb = IXplatAbstractions.INSTANCE.findNatureOrbItem(stack); - if (orb != null) + LivingEntity living = event.getEntityLiving(); + var stack = EquipmentHandler.findOrEmpty(this, event.getEntityLiving()); + if (stack != null) { - player.getActiveEffects().stream() - .filter(effect -> !effect.getEffect().isBeneficial()) - .filter(effect -> effect.getCurativeItems().stream().anyMatch(e -> e.is(Items.MILK_BUCKET))) - .map(MobEffectInstance::getEffect) - .distinct().forEach(potion -> + var orb = IXplatAbstractions.INSTANCE.findNatureOrbItem(stack); + int am = event.getPotionEffect().getAmplifier() + 1; + float t = ((float) event.getPotionEffect().getDuration() / 600.0F); + + int consume = (int) (1000 * am * am * t); + if (orb != null && orb.getNature() >= consume) + { + var ef = event.getPotionEffect().getEffect(); + if (!ef.isBeneficial() && ef.getCurativeItems().stream().anyMatch(p -> p.is(Items.MILK_BUCKET))) + { + if (living instanceof Player p) { - player.removeEffect(potion); - orb.addNature(-1000); - player.getCooldowns().addCooldown(this, 3); - ((ServerLevel) player.level).getChunkSource().broadcastAndSend(player, new ClientboundRemoveMobEffectPacket(player.getId(), potion)); - }); + if (p.getCooldowns().getCooldownPercent(this, 0) > 0) + { + return; + } + p.getCooldowns().addCooldown(this, 5 * 20); + ManaItemHandler.instance().dispatchManaExact(stack, p, consume / am, true); + } + event.setResult(Event.Result.DENY); + orb.addNature(-consume); + + living.level.playSound(null, living.getX(), living.getY(), living.getZ(), ModSounds.holyCloak, SoundSource.PLAYERS, 1F, 1F); + for (int i = 0; i < 30; i++) + { + double x = living.getX() + Math.random() * living.getBbWidth() * 2 - living.getBbWidth(); + double y = living.getY() + Math.random() * living.getBbHeight(); + double z = living.getZ() + Math.random() * living.getBbWidth() * 2 - living.getBbWidth(); + boolean yellow = Math.random() > 0.5; + float r = yellow ? 1F : 0.3F; + float g = yellow ? 1F : 0.3F; + float b = yellow ? 0.3F : 1F; + SparkleParticleData data = SparkleParticleData.sparkle(0.8F + (float) Math.random() * 0.4F, r, g, b, 3); + living.level.addParticle(data, x, y, z, 0, 0, 0); + } + } + } } } @@ -173,7 +197,7 @@ public class NatureOrb extends ItemBauble @Override public void addNature(int x) { - ItemNBTHelper.setInt(stack, TAG_NATURE, Math.min(getMaxNature(), getNature() + x) / stack.getCount()); + ItemNBTHelper.setInt(stack, TAG_NATURE, Mth.clamp(getNature() + x, 0, getMaxNature()) / stack.getCount()); } @Override diff --git a/src/main/java/chick/extrabotany/common/blocks/tile/TilePowerFrame.java b/src/main/java/chick/extrabotany/common/blocks/tile/TilePowerFrame.java index e8f7cc4..4f46a96 100644 --- a/src/main/java/chick/extrabotany/common/blocks/tile/TilePowerFrame.java +++ b/src/main/java/chick/extrabotany/common/blocks/tile/TilePowerFrame.java @@ -177,7 +177,6 @@ public class TilePowerFrame extends TileSimpleInventory { boolean multi = MULTIBLOCK_ADV.get().validate(level, worldPosition) != null; - ExtraBotany.LOGGER.debug("sb250 multi:" + multi); int redstoneSignal = 0; for (Direction dir : Direction.values()) { diff --git a/src/main/java/chick/extrabotany/common/events/EntityAddEffectReturnEvent.java b/src/main/java/chick/extrabotany/common/events/EntityAddEffectReturnEvent.java new file mode 100644 index 0000000..a2e5bc9 --- /dev/null +++ b/src/main/java/chick/extrabotany/common/events/EntityAddEffectReturnEvent.java @@ -0,0 +1,22 @@ +package chick.extrabotany.common.events; + +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraftforge.event.entity.living.LivingEvent; +import net.minecraftforge.eventbus.api.Event; + +/** + * post when addEffect ends + */ +public class EntityAddEffectReturnEvent extends LivingEvent +{ + public MobEffectInstance mobEffectInstance; + + public EntityAddEffectReturnEvent(MobEffectInstance mobEffectInstance, LivingEntity entity) + { + super(entity); + this.mobEffectInstance = mobEffectInstance; + } + +} diff --git a/src/main/java/chick/extrabotany/common/events/EntityEffectEvent.java b/src/main/java/chick/extrabotany/common/events/EntityEffectEvent.java deleted file mode 100644 index c73b408..0000000 --- a/src/main/java/chick/extrabotany/common/events/EntityEffectEvent.java +++ /dev/null @@ -1,17 +0,0 @@ -package chick.extrabotany.common.events; - -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.Entity; -import net.minecraftforge.eventbus.api.Event; - -public class EntityEffectEvent extends Event -{ - public MobEffectInstance mobEffectInstance; - public Entity entity; - - public EntityEffectEvent(MobEffectInstance mobEffectInstance, Entity entity) - { - this.mobEffectInstance = mobEffectInstance; - this.entity = entity; - } -} diff --git a/src/main/java/chick/extrabotany/datagen/DataGenerators.java b/src/main/java/chick/extrabotany/datagen/DataGenerators.java index 89527a1..41466c3 100644 --- a/src/main/java/chick/extrabotany/datagen/DataGenerators.java +++ b/src/main/java/chick/extrabotany/datagen/DataGenerators.java @@ -1,6 +1,7 @@ package chick.extrabotany.datagen; import chick.extrabotany.ExtraBotany; +import chick.extrabotany.common.base.ConfigHandler; import chick.extrabotany.common.optional.EXBOTCompat; import chick.extrabotany.common.optional.tconstruct.TConCompat; import chick.extrabotany.datagen.lang.EN_USLanguageProvider; @@ -40,7 +41,7 @@ public class DataGenerators generator.addProvider(new ZH_CNLanguageProvider(generator, "zh_cn")); } - if (ModList.get().isLoaded(EXBOTCompat.TCON_ID)) + if (ModList.get().isLoaded(EXBOTCompat.TCON_ID) && ConfigHandler.COMMON.doCompat.get()) { TConCompat.tConDatagen(event); } diff --git a/src/main/java/chick/extrabotany/forge/mixin/client/MixinLivingEntity.java b/src/main/java/chick/extrabotany/forge/mixin/client/MixinLivingEntity.java index 5fbf301..59c1c80 100644 --- a/src/main/java/chick/extrabotany/forge/mixin/client/MixinLivingEntity.java +++ b/src/main/java/chick/extrabotany/forge/mixin/client/MixinLivingEntity.java @@ -1,22 +1,10 @@ package chick.extrabotany.forge.mixin.client; -import chick.extrabotany.common.events.EntityEffectEvent; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraftforge.common.MinecraftForge; 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; -import vazkii.botania.api.item.TinyPotatoRenderEvent; @Mixin(LivingEntity.class) public class MixinLivingEntity { - @Inject(at = @At("HEAD"), method = "addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z") - private void onGetEffect(MobEffectInstance mobEffectInstance, Entity entity, CallbackInfoReturnable cir) - { - MinecraftForge.EVENT_BUS.post(new EntityEffectEvent(mobEffectInstance, entity)); - } + }