重写阔剑地雷对主人伤害取消

This commit is contained in:
Light_Quanta 2024-05-11 02:56:46 +08:00
parent 199b935b63
commit 2452434531
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 31 additions and 52 deletions

View file

@ -4,12 +4,15 @@ import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.procedures.ClaymoreDangShiTiGengXinKeShiProcedure; import net.mcreator.target.procedures.ClaymoreDangShiTiGengXinKeShiProcedure;
import net.mcreator.target.procedures.ClaymoreDangShiTiSiWangShiProcedure; import net.mcreator.target.procedures.ClaymoreDangShiTiSiWangShiProcedure;
import net.mcreator.target.procedures.ClaymoreYouJiShiTiShiProcedure; import net.mcreator.target.procedures.ClaymoreYouJiShiTiShiProcedure;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
@ -24,6 +27,9 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
@ -36,6 +42,7 @@ import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
// TODO 重写阔剑地雷 // TODO 重写阔剑地雷
@Mod.EventBusSubscriber
public class ClaymoreEntity extends TamableAnimal implements GeoEntity, AnimatedEntity { public class ClaymoreEntity extends TamableAnimal implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.STRING);
@ -294,4 +301,28 @@ public class ClaymoreEntity extends TamableAnimal implements GeoEntity, Animated
public AnimatableInstanceCache getAnimatableInstanceCache() { public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache; return this.cache;
} }
@SubscribeEvent
public static void onEntityAttacked(LivingAttackEvent event) {
var damagesource = event.getSource();
var entity = event.getEntity();
var sourceentity = event.getSource().getEntity();
if (damagesource == null || entity == null || sourceentity == null) return;
if (entity instanceof ClaymoreEntity tamEnt && tamEnt.getOwner() == sourceentity) {
if (tamEnt.getOwner() instanceof Player player && player.isCreative()) {
if (entity instanceof ClaymoreEntity claymore && damagesource.is(ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation("target:deleted_mod_element")))) {
entity.setYRot(sourceentity.getYRot());
entity.setXRot(entity.getXRot());
entity.setYBodyRot(entity.getYRot());
entity.setYHeadRot(entity.getYRot());
entity.yRotO = entity.getYRot();
entity.xRotO = entity.getXRot();
claymore.yBodyRotO = claymore.getYRot();
claymore.yHeadRotO = claymore.getYRot();
}
event.setCanceled(true);
}
}
}
} }

View file

@ -1,52 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.entity.ClaymoreEntity;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.damagesource.DamageSource;
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.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import javax.annotation.Nullable;
@Mod.EventBusSubscriber
public class QuxiaoshanghaiProcedure {
@SubscribeEvent
public static void onEntityAttacked(LivingAttackEvent event) {
if (event != null && event.getEntity() != null) {
execute(event, event.getSource(), event.getEntity(), event.getSource().getEntity());
}
}
public static void execute(DamageSource damagesource, Entity entity, Entity sourceentity) {
execute(null, damagesource, entity, sourceentity);
}
private static void execute(@Nullable Event event, DamageSource damagesource, Entity entity, Entity sourceentity) {
if (damagesource == null || entity == null || sourceentity == null)
return;
if (entity instanceof ClaymoreEntity tamEnt && tamEnt.getOwner() == sourceentity) {
if (tamEnt.getOwner() instanceof Player player && player.isCreative()) {
if (entity instanceof ClaymoreEntity _entity && damagesource.is(ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation("target:deleted_mod_element")))) {
entity.setYRot(sourceentity.getYRot());
entity.setXRot(entity.getXRot());
entity.setYBodyRot(entity.getYRot());
entity.setYHeadRot(entity.getYRot());
entity.yRotO = entity.getYRot();
entity.xRotO = entity.getXRot();
_entity.yBodyRotO = _entity.getYRot();
_entity.yHeadRotO = _entity.getYRot();
}
if (event != null && event.isCancelable()) {
event.setCanceled(true);
}
}
}
}
}