Skip to content

Commit

Permalink
部分修改
Browse files Browse the repository at this point in the history
- 抱起女仆时,不播放 tacz 动画
- 女仆射出的子弹也不会伤害她的主人
- 妖精女仆有音效了,暂时使用兔子的:fix #510
  • Loading branch information
TartaricAcid committed Jul 3, 2024
1 parent da9f64b commit 9ebadea
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.builder.AnimationBuilder;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.builder.ILoopType;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.event.predicate.AnimationEvent;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.file.AnimationFile;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.resource.GeckoLibCache;
import com.tacz.guns.api.TimelessAPI;
import com.tacz.guns.api.entity.IGunOperator;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand All @@ -44,8 +46,10 @@ public static PlayState playGrenadeAnimation(AnimationEvent<GeckoMaidEntity> eve
*/
public static PlayState playGunMainAnimation(AnimationEvent<GeckoMaidEntity> event, String animationName, ILoopType loopType) {
String tacName = "tac:" + animationName;
ResourceLocation animation = event.getAnimatable().getAnimation();
if (GeckoLibCache.getInstance().getAnimations().get(animation).animations().containsKey(tacName)) {
GeckoMaidEntity animatable = event.getAnimatable();
ResourceLocation animation = animatable.getAnimation();
AnimationFile animationFile = GeckoLibCache.getInstance().getAnimations().get(animation);
if (!isMaidCarrying(animatable.getMaid()) && animationFile.animations().containsKey(tacName)) {
return playAnimation(event, tacName, loopType);
}
return playAnimation(event, animationName, loopType);
Expand Down Expand Up @@ -74,6 +78,9 @@ public static PlayState playGunHoldAnimation(AnimationEvent<GeckoMaidEntity> eve
if (maid == null) {
return PlayState.STOP;
}
if (isMaidCarrying(maid)) {
return PlayState.STOP;
}
Mob entity = maid.asEntity();
IGunOperator operator = IGunOperator.fromLivingEntity(entity);
long fireTick = operator.getSynShootCoolDown();
Expand Down Expand Up @@ -154,4 +161,9 @@ private static PlayState playAnimation(AnimationEvent<?> event, String animation
private static boolean isType(String type, GunTabType tabType) {
return type.equals(tabType.name().toLowerCase(Locale.ENGLISH));
}

private static boolean isMaidCarrying(IMaid maid) {
Mob entity = maid.asEntity();
return entity.getVehicle() instanceof Player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,44 @@
import com.tacz.guns.entity.EntityKineticBullet;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.IndirectEntityDamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class GunHurtMaidEvent {
/**
* 不伤害自己
*/
@SubscribeEvent
public void onMaidHurt(MaidHurtEvent event) {
DamageSource source = event.getSource();
EntityMaid maid = event.getMaid();
if (maid.getOwnerUUID() == null) {
return;
}
if (source instanceof IndirectEntityDamageSource damageSource && damageSource.getDirectEntity() instanceof EntityKineticBullet) {
if (isBulletDamage(source)) {
event.setCanceled(true);
}
}

/**
* 不伤害他人
*/
@SubscribeEvent
public void onPlayerHurt(LivingAttackEvent event) {
LivingEntity entity = event.getEntity();
DamageSource source = event.getSource();
if (entity instanceof Player player && isBulletDamage(source)) {
Entity causingEntity = source.getEntity();
if (causingEntity instanceof EntityMaid maid && maid.isOwnedBy(player)) {
event.setCanceled(true);
}
}
}

private boolean isBulletDamage(DamageSource source) {
return source instanceof IndirectEntityDamageSource damageSource && damageSource.getDirectEntity() instanceof EntityKineticBullet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import com.github.tartaricacid.touhoulittlemaid.entity.ai.goal.FairyAttackGoal;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.entity.projectile.DanmakuShoot;
import com.github.tartaricacid.touhoulittlemaid.init.InitSounds;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.Difficulty;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.damagesource.DamageSource;
Expand Down Expand Up @@ -157,4 +159,20 @@ public void setFairyTypeOrdinal(int ordinal) {
public boolean isFlying() {
return !this.onGround;
}

@Nullable
@Override
protected SoundEvent getAmbientSound() {
return InitSounds.FAIRY_AMBIENT.get();
}

@Override
protected SoundEvent getHurtSound(DamageSource pDamageSource) {
return InitSounds.FAIRY_HURT.get();
}

@Override
protected SoundEvent getDeathSound() {
return InitSounds.FAIRY_DEATH.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ public final class InitSounds {
public static final RegistryObject<SoundEvent> CAMERA_USE = registerSound("item.camera_use");
public static final RegistryObject<SoundEvent> ALBUM_OPEN = registerSound("item.album_open");
public static final RegistryObject<SoundEvent> ALTAR_CRAFT = registerSound("block.altar_craft");
public static final RegistryObject<SoundEvent> BOX_OPEN = registerSound("entity.box");
public static final RegistryObject<SoundEvent> COMPASS_POINT = registerSound("item.compass");
public static final RegistryObject<SoundEvent> GOMOKU = registerSound("block.gomoku");
public static final RegistryObject<SoundEvent> GOMOKU_RESET = registerSound("block.gomoku_reset");
public static final RegistryObject<SoundEvent> BOX_OPEN = registerSound("entity.box");
public static final RegistryObject<SoundEvent> COMPASS_POINT = registerSound("item.compass");
public static final RegistryObject<SoundEvent> FAIRY_AMBIENT = registerSound("entity.fairy.ambient");
public static final RegistryObject<SoundEvent> FAIRY_DEATH = registerSound("entity.fairy.death");
public static final RegistryObject<SoundEvent> FAIRY_HURT = registerSound("entity.fairy.hurt");

private static RegistryObject<SoundEvent> registerSound(String name) {
return SOUNDS.register(name, () -> new SoundEvent(new ResourceLocation(TouhouLittleMaid.MOD_ID, name)));
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@
"subtitle.touhou_little_maid.block.gomoku_reset": "Gomoku Reset Sound",
"subtitle.touhou_little_maid.entity.box": "Box Open Sound",
"subtitle.touhou_little_maid.item.compass": "Compass Select Point Sound",
"touhou_little_maid.subtitles.entity.fairy.ambient": "Fairy Ambient Sound",
"touhou_little_maid.subtitles.entity.fairy.death": "Fairy Death Sound",
"touhou_little_maid.subtitles.entity.fairy.hurt": "Fairy Hurt Sound",
"emi.category.touhou_little_maid.altar": "Altar Craft",
"jei.touhou_little_maid.altar_craft.title": "Altar Craft",
"jei.touhou_little_maid.altar_craft.result": "Result: %s",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@
"subtitle.touhou_little_maid.block.gomoku_reset": "五子棋:重置",
"subtitle.touhou_little_maid.entity.box": "盒子:打开",
"subtitle.touhou_little_maid.item.compass": "罗盘:选择点",
"touhou_little_maid.subtitles.entity.fairy.ambient": "妖精女仆:吱吱",
"touhou_little_maid.subtitles.entity.fairy.death": "妖精女仆:死亡",
"touhou_little_maid.subtitles.entity.fairy.hurt": "妖精女仆:受伤",
"emi.category.touhou_little_maid.altar": "祭坛合成",
"jei.touhou_little_maid.altar_craft.title": "祭坛合成",
"jei.touhou_little_maid.altar_craft.result": "结果:%s",
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/assets/touhou_little_maid/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,29 @@
"sounds": [
"touhou_little_maid:item/point"
]
},
"entity.fairy.ambient": {
"sounds": [
"minecraft:mob/rabbit/idle1",
"minecraft:mob/rabbit/idle2",
"minecraft:mob/rabbit/idle3",
"minecraft:mob/rabbit/idle4"
],
"subtitle": "touhou_little_maid.subtitles.entity.fairy.ambient"
},
"entity.fairy.death": {
"sounds": [
"minecraft:mob/rabbit/bunnymurder"
],
"subtitle": "touhou_little_maid.subtitles.entity.fairy.death"
},
"entity.fairy.hurt": {
"sounds": [
"minecraft:mob/rabbit/hurt1",
"minecraft:mob/rabbit/hurt2",
"minecraft:mob/rabbit/hurt3",
"minecraft:mob/rabbit/hurt4"
],
"subtitle": "touhou_little_maid.subtitles.entity.fairy.hurt"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9ebadea

Please sign in to comment.