优化代码
This commit is contained in:
parent
3b29c8e7c4
commit
aa5214e5f2
6 changed files with 44 additions and 30 deletions
|
@ -47,6 +47,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
|
||||
import java.util.Comparator;
|
||||
|
||||
// TODO 重置生物
|
||||
public class SenpaiEntity extends Spider implements GeoEntity, AnimatedEntity {
|
||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.STRING);
|
||||
|
|
|
@ -49,6 +49,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
import javax.annotation.Nullable;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
// TODO 重置靶子
|
||||
@Mod.EventBusSubscriber
|
||||
public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedEntity {
|
||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.BOOLEAN);
|
||||
|
@ -109,6 +110,10 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
|
|||
this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), TargetModSounds.HIT.get(), SoundSource.BLOCKS, 2, 1, false);
|
||||
}
|
||||
|
||||
if (this.getPersistentData().getDouble("targetdown") > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source.is(DamageTypes.IN_FIRE))
|
||||
return false;
|
||||
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
|
||||
|
@ -129,6 +134,7 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
|
|||
return false;
|
||||
if (source.is(DamageTypes.WITHER_SKULL))
|
||||
return false;
|
||||
|
||||
return super.hurt(source, amount);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import software.bernie.geckolib.core.animation.RawAnimation;
|
|||
import software.bernie.geckolib.core.object.PlayState;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
// TODO 重置靶子
|
||||
public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEntity {
|
||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.STRING);
|
||||
|
|
|
@ -3,7 +3,6 @@ package net.mcreator.target.event;
|
|||
import net.mcreator.target.init.TargetModMobEffects;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.client.model.item.*;
|
||||
import net.minecraft.client.CameraType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
@ -427,10 +426,14 @@ public class ClientEventHandler {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void onFovUpdate(ViewportEvent.ComputeFov event) {
|
||||
if (!event.usedConfiguredFov()) return;
|
||||
if (!event.usedConfiguredFov()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
|
@ -445,11 +448,18 @@ public class ClientEventHandler {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void handleRenderCrossHair(RenderGuiOverlayEvent.Pre event) {
|
||||
if (event.getOverlay() != VanillaGuiOverlay.CROSSHAIR.type()) return;
|
||||
if (event.getOverlay() != VanillaGuiOverlay.CROSSHAIR.type()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null) return;
|
||||
if (!mc.options.getCameraType().isFirstPerson()) return;
|
||||
if (mc.player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mc.options.getCameraType().isFirstPerson()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mc.player.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||
event.setCanceled(true);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.mcreator.target.event;
|
||||
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.entity.Target1Entity;
|
||||
import net.mcreator.target.init.TargetModDamageTypes;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
|
@ -26,12 +25,10 @@ import net.minecraft.world.entity.LivingEntity;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
@ -39,12 +36,12 @@ import net.minecraftforge.network.PacketDistributor;
|
|||
@Mod.EventBusSubscriber
|
||||
public class LivingEntityEventHandler {
|
||||
@SubscribeEvent
|
||||
public static void onEntityAttacked(LivingHurtEvent event) {
|
||||
public static void onEntityHurt(LivingHurtEvent event) {
|
||||
if (event == null || event.getEntity() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderDamageIndicator(event);
|
||||
target1DamageImmune(event, event.getEntity());
|
||||
reduceBulletDamage(event, event.getSource(), event.getEntity(), event.getSource().getEntity(), event.getAmount());
|
||||
}
|
||||
|
||||
|
@ -53,7 +50,8 @@ public class LivingEntityEventHandler {
|
|||
if (event == null || event.getEntity() == null) {
|
||||
return;
|
||||
}
|
||||
claymoreDamage(event, event.getEntity().level(), event.getSource(), event.getEntity(), event.getSource().getEntity(), event.getAmount());
|
||||
|
||||
claymoreDamage(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -61,11 +59,15 @@ public class LivingEntityEventHandler {
|
|||
if (event == null || event.getEntity() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
killIndication(event.getSource().getEntity());
|
||||
handlePlayerKillEntity(event);
|
||||
}
|
||||
|
||||
private static void reduceBulletDamage(LivingHurtEvent event, DamageSource damagesource, LivingEntity entity, Entity sourceentity, double amount) {
|
||||
if (damagesource == null || entity == null || sourceentity == null) return;
|
||||
if (damagesource == null || entity == null || sourceentity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = amount;
|
||||
ItemStack stack = sourceentity instanceof LivingEntity living ? living.getMainHandItem() : ItemStack.EMPTY;
|
||||
|
@ -101,21 +103,18 @@ public class LivingEntityEventHandler {
|
|||
return amount / (1 + rate * Math.max(0, distance - minDistance));
|
||||
}
|
||||
|
||||
private static void target1DamageImmune(Event event, Entity entity) {
|
||||
if (entity == null) return;
|
||||
if (entity instanceof Target1Entity && entity.getPersistentData().getDouble("targetdown") > 0) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
private static void claymoreDamage(LivingAttackEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
DamageSource source = event.getSource();
|
||||
Entity sourceentity = source.getDirectEntity();
|
||||
|
||||
private static void claymoreDamage(LivingAttackEvent event, LevelAccessor world, DamageSource damagesource, Entity entity, Entity sourceentity, double amount) {
|
||||
if (damagesource == null || entity == null || sourceentity == null)
|
||||
if (event.getEntity() == null || entity == null || sourceentity == null) {
|
||||
return;
|
||||
if ((damagesource.is(DamageTypes.EXPLOSION) || damagesource.is(DamageTypes.PLAYER_EXPLOSION)) && entity.getPersistentData().getDouble("claymore") > 0) {
|
||||
if (event != null && event.isCancelable()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
entity.hurt(TargetModDamageTypes.causeMineDamage(world.registryAccess(), sourceentity), (float) amount);
|
||||
}
|
||||
|
||||
if ((source.is(DamageTypes.EXPLOSION) || source.is(DamageTypes.PLAYER_EXPLOSION)) && entity.getPersistentData().getDouble("claymore") > 0) {
|
||||
event.setCanceled(true);
|
||||
entity.hurt(TargetModDamageTypes.causeMineDamage(entity.level().registryAccess(), sourceentity), event.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,8 +209,7 @@ public class LivingEntityEventHandler {
|
|||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handlePlayerKillEntity(LivingDeathEvent event) {
|
||||
private static void handlePlayerKillEntity(LivingDeathEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
DamageSource source = event.getSource();
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import net.mcreator.target.init.TargetModItems;
|
|||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.tools.GunsTool;
|
||||
import net.mcreator.target.tools.SoundTool;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -446,5 +445,4 @@ public class PlayerEventHandler {
|
|||
recoilThread.start();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue