diff --git a/src/main/java/net/mcreator/superbwarfare/client/model/item/LightSaberItemModel.java b/src/main/java/net/mcreator/superbwarfare/client/model/item/LightSaberItemModel.java index 4b8422df0..92d857a31 100644 --- a/src/main/java/net/mcreator/superbwarfare/client/model/item/LightSaberItemModel.java +++ b/src/main/java/net/mcreator/superbwarfare/client/model/item/LightSaberItemModel.java @@ -8,7 +8,7 @@ import software.bernie.geckolib.model.GeoModel; public class LightSaberItemModel extends GeoModel { @Override public ResourceLocation getAnimationResource(LightSaber animatable) { - return new ResourceLocation(ModUtils.MODID, "animations/lightsaber.animation.json"); + return null; } @Override diff --git a/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java b/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java index 60923faf8..9b2246714 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java @@ -2,7 +2,6 @@ package net.mcreator.superbwarfare.entity; import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.entity.projectile.MortarShellEntity; -import net.mcreator.superbwarfare.init.ModAttributes; import net.mcreator.superbwarfare.init.ModEntities; import net.mcreator.superbwarfare.init.ModItems; import net.mcreator.superbwarfare.init.ModSounds; @@ -46,6 +45,7 @@ import software.bernie.geckolib.util.GeckoLibUtil; public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEntity { public static final EntityDataAccessor ANIMATION = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT); + public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public String animationProcedure = "empty"; @@ -67,6 +67,7 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt super.defineSynchedData(); this.entityData.define(ANIMATION, "undefined"); this.entityData.define(FIRE_TIME, 0); + this.entityData.define(PITCH, 70f); } @Override @@ -137,6 +138,7 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt public void addAdditionalSaveData(CompoundTag compound) { super.addAdditionalSaveData(compound); compound.putInt("FireTime", this.entityData.get(FIRE_TIME)); + compound.putFloat("Pitch", this.entityData.get(PITCH)); } @Override @@ -145,6 +147,9 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt if (compound.contains("FireTime")) { this.entityData.set(FIRE_TIME, compound.getInt("FireTime")); } + if (compound.contains("Pitch")) { + this.entityData.set(PITCH, compound.getFloat("Pitch")); + } } @Override @@ -201,7 +206,7 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt @Override public void travel(Vec3 dir) { - this.setXRot(-Mth.clamp((float) this.getAttribute(ModAttributes.MORTAR_PITCH.get()).getBaseValue(), 20, 89)); + this.setXRot(-Mth.clamp((float) entityData.get(PITCH), 20, 89)); } @Override @@ -251,19 +256,6 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt return PlayState.STOP; } - private PlayState procedurePredicate(AnimationState event) { - if (!animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) { - event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure)); - if (event.getController().getAnimationState() == AnimationController.State.STOPPED) { - this.animationProcedure = "empty"; - event.getController().forceAnimationReset(); - } - } else if (animationProcedure.equals("empty")) { - return PlayState.STOP; - } - return PlayState.CONTINUE; - } - @Override protected void tickDeath() { ++this.deathTime; @@ -303,7 +295,6 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt @Override public void registerControllers(AnimatableManager.ControllerRegistrar data) { data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate)); - data.add(new AnimationController<>(this, "procedure", 0, this::procedurePredicate)); } @Override diff --git a/src/main/java/net/mcreator/superbwarfare/event/LivingEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/LivingEventHandler.java index 63a7ee344..12914a822 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/LivingEventHandler.java @@ -16,6 +16,7 @@ import net.minecraft.network.protocol.game.ClientboundStopSoundPacket; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; +import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageType; import net.minecraft.world.damagesource.DamageTypes; @@ -62,6 +63,7 @@ public class LivingEventHandler { } double damage = amount; + ItemStack stack = sourceentity instanceof LivingEntity living ? living.getMainHandItem() : ItemStack.EMPTY; if ((damageSource.is(ModDamageTypes.PROJECTILE_BOOM) @@ -86,10 +88,23 @@ public class LivingEventHandler { } else if (stack.is(ModTags.Items.USE_RIFLE_AMMO) || stack.getItem() == ModItems.BOCEK.get()) { damage = reduceDamageByDistance(amount, distance, 0.0025, 150); } - event.setAmount((float) damage); - stack.getOrCreateTag().putDouble("damagetotal", stack.getOrCreateTag().getDouble("damagetotal") + damage); } + // TODO 添加TACZ枪械非穿甲伤害的适配 + + if (damageSource.is(ModDamageTypes.GUN_FIRE) + || damageSource.is(ModDamageTypes.GUN_FIRE_HEADSHOT) + || damageSource.is(DamageTypes.ARROW) + || damageSource.is(DamageTypes.TRIDENT) + || damageSource.is(DamageTypes.THROWN) + ) { + damage = damage * (1 - Mth.clamp(entity.getAttributeValue(ModAttributes.BULLET_RESISTANCE.get()), 0, 1)); + } + + event.setAmount((float) damage); + + stack.getOrCreateTag().putDouble("damagetotal", stack.getOrCreateTag().getDouble("damagetotal") + damage); + if (entity instanceof TargetEntity && sourceentity instanceof Player player) { player.displayClientMessage(Component.literal("Damage:" + new java.text.DecimalFormat("##.#").format(damage) + " Distance:" + new java.text.DecimalFormat("##.#").format((entity.position()).distanceTo((sourceentity.position()))) + "M"), false); } diff --git a/src/main/java/net/mcreator/superbwarfare/init/ModAttributes.java b/src/main/java/net/mcreator/superbwarfare/init/ModAttributes.java index 1da1925de..c8c3703bd 100644 --- a/src/main/java/net/mcreator/superbwarfare/init/ModAttributes.java +++ b/src/main/java/net/mcreator/superbwarfare/init/ModAttributes.java @@ -1,6 +1,9 @@ package net.mcreator.superbwarfare.init; import net.mcreator.superbwarfare.ModUtils; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.RangedAttribute; import net.minecraftforge.event.entity.EntityAttributeModificationEvent; @@ -12,11 +15,13 @@ import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; +import java.util.List; + @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class ModAttributes { public static final DeferredRegister ATTRIBUTES = DeferredRegister.create(ForgeRegistries.ATTRIBUTES, ModUtils.MODID); - public static final RegistryObject MORTAR_PITCH = ATTRIBUTES.register("mortar_pitch", () -> (new RangedAttribute("attribute." + ModUtils.MODID + ".mortar_pitch", 70, 20, 89)).setSyncable(true)); + public static final RegistryObject BULLET_RESISTANCE = ATTRIBUTES.register("bullet_resistance", () -> (new RangedAttribute("attribute." + ModUtils.MODID + ".bullet_resistance", 0, 0, 1)).setSyncable(true)); @SubscribeEvent public static void register(FMLConstructModEvent event) { @@ -25,6 +30,13 @@ public class ModAttributes { @SubscribeEvent public static void addAttributes(EntityAttributeModificationEvent event) { - event.add(ModEntities.MORTAR.get(), MORTAR_PITCH.get()); + List> entityTypes = event.getTypes(); + entityTypes.forEach((e) -> { + Class baseClass = e.getBaseClass(); + if (baseClass.isAssignableFrom(LivingEntity.class)) { + event.add(e, BULLET_RESISTANCE.get()); + } + }); + } } diff --git a/src/main/java/net/mcreator/superbwarfare/item/LightSaber.java b/src/main/java/net/mcreator/superbwarfare/item/LightSaber.java index 1725f8084..6673d3280 100644 --- a/src/main/java/net/mcreator/superbwarfare/item/LightSaber.java +++ b/src/main/java/net/mcreator/superbwarfare/item/LightSaber.java @@ -20,10 +20,6 @@ import net.minecraftforge.client.extensions.common.IClientItemExtensions; import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; -import software.bernie.geckolib.core.animation.AnimationController; -import software.bernie.geckolib.core.animation.AnimationState; -import software.bernie.geckolib.core.animation.RawAnimation; -import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.UUID; @@ -55,37 +51,9 @@ public class LightSaber extends SwordItem implements GeoItem, AnimatedItem { transformType = type; } - private PlayState idlePredicate(AnimationState event) { - if (transformType != null && transformType.firstPerson()) { - if (this.animationProcedure.equals("empty")) { - event.getController().setAnimation(RawAnimation.begin().thenLoop("animation.lightsaber.idle")); - return PlayState.CONTINUE; - } - } - return PlayState.STOP; - } - - private PlayState procedurePredicate(AnimationState event) { - if (transformType != null && transformType.firstPerson()) { - if (!this.animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) { - event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure)); - if (event.getController().getAnimationState() == AnimationController.State.STOPPED) { - this.animationProcedure = "empty"; - event.getController().forceAnimationReset(); - } - } else if (this.animationProcedure.equals("empty")) { - return PlayState.STOP; - } - } - return PlayState.CONTINUE; - } @Override public void registerControllers(AnimatableManager.ControllerRegistrar data) { - var procedureController = new AnimationController<>(this, "procedureController", 0, this::procedurePredicate); - data.add(procedureController); - var idleController = new AnimationController<>(this, "idleController", 0, this::idlePredicate); - data.add(idleController); } @Override diff --git a/src/main/java/net/mcreator/superbwarfare/item/armor/RuChest6b43.java b/src/main/java/net/mcreator/superbwarfare/item/armor/RuChest6b43.java index 51ec81a2a..294374516 100644 --- a/src/main/java/net/mcreator/superbwarfare/item/armor/RuChest6b43.java +++ b/src/main/java/net/mcreator/superbwarfare/item/armor/RuChest6b43.java @@ -1,10 +1,16 @@ package net.mcreator.superbwarfare.item.armor; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.client.renderer.armor.RuChest6b43ArmorRenderer; +import net.mcreator.superbwarfare.init.ModAttributes; import net.mcreator.superbwarfare.tiers.ModArmorMaterial; import net.minecraft.client.model.HumanoidModel; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ItemStack; import net.minecraftforge.client.extensions.common.IClientItemExtensions; @@ -14,6 +20,7 @@ import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.renderer.GeoArmorRenderer; import software.bernie.geckolib.util.GeckoLibUtil; +import java.util.UUID; import java.util.function.Consumer; public class RuChest6b43 extends ArmorItem implements GeoItem { @@ -37,6 +44,18 @@ public class RuChest6b43 extends ArmorItem implements GeoItem { }); } + @Override + public Multimap getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) { + Multimap map = super.getDefaultAttributeModifiers(equipmentSlot); + UUID uuid = new UUID(equipmentSlot.toString().hashCode(), 0); + if (equipmentSlot == EquipmentSlot.CHEST) { + map = HashMultimap.create(map); + map.put(ModAttributes.BULLET_RESISTANCE.get(), new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER, 0.5f, AttributeModifier.Operation.ADDITION)); + + } + return map; + } + @Override public void registerControllers(AnimatableManager.ControllerRegistrar data) { } diff --git a/src/main/java/net/mcreator/superbwarfare/item/armor/RuHelmet6b47.java b/src/main/java/net/mcreator/superbwarfare/item/armor/RuHelmet6b47.java index b9d90091b..e2970e395 100644 --- a/src/main/java/net/mcreator/superbwarfare/item/armor/RuHelmet6b47.java +++ b/src/main/java/net/mcreator/superbwarfare/item/armor/RuHelmet6b47.java @@ -1,10 +1,16 @@ package net.mcreator.superbwarfare.item.armor; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.client.renderer.armor.RuHelmet6b47ArmorRenderer; +import net.mcreator.superbwarfare.init.ModAttributes; import net.mcreator.superbwarfare.tiers.ModArmorMaterial; import net.minecraft.client.model.HumanoidModel; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ItemStack; import net.minecraftforge.client.extensions.common.IClientItemExtensions; @@ -14,6 +20,7 @@ import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.renderer.GeoArmorRenderer; import software.bernie.geckolib.util.GeckoLibUtil; +import java.util.UUID; import java.util.function.Consumer; public class RuHelmet6b47 extends ArmorItem implements GeoItem { @@ -37,6 +44,18 @@ public class RuHelmet6b47 extends ArmorItem implements GeoItem { }); } + @Override + public Multimap getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) { + Multimap map = super.getDefaultAttributeModifiers(equipmentSlot); + UUID uuid = new UUID(equipmentSlot.toString().hashCode(), 0); + if (equipmentSlot == EquipmentSlot.HEAD) { + map = HashMultimap.create(map); + map.put(ModAttributes.BULLET_RESISTANCE.get(), new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER, 0.2f, AttributeModifier.Operation.ADDITION)); + + } + return map; + } + @Override public void registerControllers(AnimatableManager.ControllerRegistrar data) { } diff --git a/src/main/java/net/mcreator/superbwarfare/network/message/AdjustMortarAngleMessage.java b/src/main/java/net/mcreator/superbwarfare/network/message/AdjustMortarAngleMessage.java index 85d282ab8..8fc7ef115 100644 --- a/src/main/java/net/mcreator/superbwarfare/network/message/AdjustMortarAngleMessage.java +++ b/src/main/java/net/mcreator/superbwarfare/network/message/AdjustMortarAngleMessage.java @@ -1,7 +1,6 @@ package net.mcreator.superbwarfare.network.message; import net.mcreator.superbwarfare.client.gui.RangeHelper; -import net.mcreator.superbwarfare.init.ModAttributes; import net.mcreator.superbwarfare.init.ModSounds; import net.mcreator.superbwarfare.tools.SoundTool; import net.mcreator.superbwarfare.tools.TraceTool; @@ -15,6 +14,8 @@ import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; +import static net.mcreator.superbwarfare.entity.MortarEntity.PITCH; + public class AdjustMortarAngleMessage { private final double scroll; @@ -43,8 +44,8 @@ public class AdjustMortarAngleMessage { double angle = 0; if (looking instanceof LivingEntity living){ - living.getAttribute(ModAttributes.MORTAR_PITCH.get()).setBaseValue(Mth.clamp(living.getAttribute(ModAttributes.MORTAR_PITCH.get()).getBaseValue() + 0.5 * message.scroll,20,89)); - angle = living.getAttribute(ModAttributes.MORTAR_PITCH.get()).getBaseValue(); + living.getEntityData().set(PITCH, (float)Mth.clamp(living.getEntityData().get(PITCH) + 0.5 * message.scroll,20,89)); + angle = living.getEntityData().get(PITCH); } player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##.##").format(angle) + " Range:" + new java.text.DecimalFormat("##.#").format((int) RangeHelper.getRange(angle)) + "M"), true); diff --git a/src/main/resources/assets/superbwarfare/animations/lightsaber.animation.json b/src/main/resources/assets/superbwarfare/animations/lightsaber.animation.json deleted file mode 100644 index 108583e88..000000000 --- a/src/main/resources/assets/superbwarfare/animations/lightsaber.animation.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "format_version": "1.8.0", - "animations": { - "animation.lightsaber.idle": { - "loop": true, - "animation_length": 4, - "bones": { - "group2": { - "position": { - "vector": [0, 0, 0] - } - }, - "light": { - "rotation": { - "0.0": { - "vector": [0, 0, 0] - }, - "4.0": { - "vector": [0, -360, 0] - } - }, - "position": { - "0.0": { - "vector": [0, 0, 0] - }, - "4.0": { - "vector": [0, 0, 0] - } - }, - "scale": { - "0.0": { - "vector": [1, 1, 1] - }, - "1.0": { - "vector": [1, 1, 0.95], - "easing": "easeInSine" - }, - "2.0": { - "vector": [1, 1, 1], - "easing": "easeOutSine" - }, - "3.0": { - "vector": [0.95, 1, 1], - "easing": "easeInSine" - }, - "4.0": { - "vector": [1, 1, 1], - "easing": "easeOutSine" - } - } - } - } - } - }, - "geckolib_format_version": 2 -} \ No newline at end of file diff --git a/src/main/resources/assets/superbwarfare/lang/en_us.json b/src/main/resources/assets/superbwarfare/lang/en_us.json index 06f732af2..038216651 100644 --- a/src/main/resources/assets/superbwarfare/lang/en_us.json +++ b/src/main/resources/assets/superbwarfare/lang/en_us.json @@ -165,7 +165,7 @@ "des.superbwarfare.transcript.distance": "Distance: ", "des.superbwarfare.transcript.total": "Total: ", - "attribute.superbwarfare.spread": "Spread", + "attribute.superbwarfare.bullet_resistance": "Bullet Resistance", "block.superbwarfare.jump_pad": "Jump Pad", "block.superbwarfare.sandbag": "Sandbag", diff --git a/src/main/resources/assets/superbwarfare/lang/zh_cn.json b/src/main/resources/assets/superbwarfare/lang/zh_cn.json index 4e8fb4159..3c873333c 100644 --- a/src/main/resources/assets/superbwarfare/lang/zh_cn.json +++ b/src/main/resources/assets/superbwarfare/lang/zh_cn.json @@ -165,7 +165,7 @@ "des.superbwarfare.transcript.distance": "距离:", "des.superbwarfare.transcript.total": "总环数:", - "attribute.superbwarfare.spread": "散布", + "attribute.superbwarfare.bullet_resistance": "子弹防护", "block.superbwarfare.jump_pad": "弹射台", "block.superbwarfare.sandbag": "沙袋",