优化冗余代码
This commit is contained in:
parent
90c234018d
commit
941563a9f8
3 changed files with 6 additions and 34 deletions
|
@ -581,7 +581,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
protected void explosionBulletBlock(Entity projectile, float damage, int heLevel, float monsterMultiple, Vec3 hitVec) {
|
protected void explosionBulletBlock(Entity projectile, float damage, int heLevel, float monsterMultiple, Vec3 hitVec) {
|
||||||
CustomExplosion explosion = new CustomExplosion(projectile.level(), projectile,
|
CustomExplosion explosion = new CustomExplosion(projectile.level(), projectile,
|
||||||
ModDamageTypes.causeProjectileBoomDamage(projectile.level().registryAccess(), projectile, this.getShooter()), (float) ((0.9 * damage) * (1 + 0.1 * heLevel)),
|
ModDamageTypes.causeProjectileBoomDamage(projectile.level().registryAccess(), projectile, this.getShooter()), (float) ((0.9 * damage) * (1 + 0.1 * heLevel)),
|
||||||
hitVec.x, hitVec.y, hitVec.z, (float) ((1.5 + 0.02 * damage) * (1 + 0.05 * heLevel))).setDamageMultiplier(monsterMultiple).isBulletExplode(true);
|
hitVec.x, hitVec.y, hitVec.z, (float) ((1.5 + 0.02 * damage) * (1 + 0.05 * heLevel))).setDamageMultiplier(monsterMultiple).bulletExplode();
|
||||||
explosion.explode();
|
explosion.explode();
|
||||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(projectile.level(), explosion);
|
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(projectile.level(), explosion);
|
||||||
explosion.finalizeExplosion(false);
|
explosion.finalizeExplosion(false);
|
||||||
|
@ -591,7 +591,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
protected void explosionBulletEntity(Entity projectile, Entity target, float damage, int heLevel, float monsterMultiple) {
|
protected void explosionBulletEntity(Entity projectile, Entity target, float damage, int heLevel, float monsterMultiple) {
|
||||||
CustomExplosion explosion = new CustomExplosion(projectile.level(), projectile,
|
CustomExplosion explosion = new CustomExplosion(projectile.level(), projectile,
|
||||||
ModDamageTypes.causeProjectileBoomDamage(projectile.level().registryAccess(), projectile, this.getShooter()), (float) ((0.8 * damage) * (1 + 0.1 * heLevel)),
|
ModDamageTypes.causeProjectileBoomDamage(projectile.level().registryAccess(), projectile, this.getShooter()), (float) ((0.8 * damage) * (1 + 0.1 * heLevel)),
|
||||||
target.getX(), target.getY(), target.getZ(), (float) ((1.5 + 0.02 * damage) * (1 + 0.05 * heLevel))).setDamageMultiplier(monsterMultiple).isBulletExplode(true);
|
target.getX(), target.getY(), target.getZ(), (float) ((1.5 + 0.02 * damage) * (1 + 0.05 * heLevel))).setDamageMultiplier(monsterMultiple).bulletExplode();
|
||||||
explosion.explode();
|
explosion.explode();
|
||||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(projectile.level(), explosion);
|
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(projectile.level(), explosion);
|
||||||
explosion.finalizeExplosion(false);
|
explosion.finalizeExplosion(false);
|
||||||
|
|
|
@ -12,14 +12,12 @@ import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.HasCustomInventoryScreen;
|
import net.minecraft.world.entity.HasCustomInventoryScreen;
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.entity.vehicle.ContainerEntity;
|
import net.minecraft.world.entity.vehicle.ContainerEntity;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.entity.HopperBlockEntity;
|
|
||||||
import net.minecraft.world.level.gameevent.GameEvent;
|
import net.minecraft.world.level.gameevent.GameEvent;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||||
|
@ -28,8 +26,6 @@ import net.minecraftforge.items.wrapper.InvWrapper;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Math;
|
import org.joml.Math;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ContainerMobileEntity extends MobileVehicleEntity implements HasCustomInventoryScreen, ContainerEntity {
|
public class ContainerMobileEntity extends MobileVehicleEntity implements HasCustomInventoryScreen, ContainerEntity {
|
||||||
|
|
||||||
public static final int CONTAINER_SIZE = 102;
|
public static final int CONTAINER_SIZE = 102;
|
||||||
|
@ -83,10 +79,6 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus
|
||||||
public void baseTick() {
|
public void baseTick() {
|
||||||
super.baseTick();
|
super.baseTick();
|
||||||
|
|
||||||
if (this.canPickUpItems()) {
|
|
||||||
this.pickUpItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var stack : this.getItemStacks()) {
|
for (var stack : this.getItemStacks()) {
|
||||||
int neededEnergy = this.getMaxEnergy() - this.getEnergy();
|
int neededEnergy = this.getMaxEnergy() - this.getEnergy();
|
||||||
if (neededEnergy <= 0) break;
|
if (neededEnergy <= 0) break;
|
||||||
|
@ -105,21 +97,6 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus
|
||||||
this.refreshDimensions();
|
this.refreshDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canPickUpItems() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pickUpItems() {
|
|
||||||
List<ItemEntity> list = this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(0.2F, 0.1, 0.2F));
|
|
||||||
if (!list.isEmpty()) {
|
|
||||||
for (ItemEntity entity : list) {
|
|
||||||
if (!this.level().isClientSide) {
|
|
||||||
HopperBlockEntity.addItem(this, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openCustomInventoryScreen(Player pPlayer) {
|
public void openCustomInventoryScreen(Player pPlayer) {
|
||||||
pPlayer.openMenu(this);
|
pPlayer.openMenu(this);
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class CustomExplosion extends Explosion {
|
public class CustomExplosion extends Explosion {
|
||||||
|
|
||||||
private final Level level;
|
private final Level level;
|
||||||
private final double x;
|
private final double x;
|
||||||
private final double y;
|
private final double y;
|
||||||
|
@ -42,7 +43,6 @@ public class CustomExplosion extends Explosion {
|
||||||
private final float damage;
|
private final float damage;
|
||||||
private int fireTime;
|
private int fireTime;
|
||||||
private float damageMultiplier;
|
private float damageMultiplier;
|
||||||
private boolean bullet;
|
|
||||||
|
|
||||||
public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, @Nullable ExplosionDamageCalculator pDamageCalculator,
|
public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, @Nullable ExplosionDamageCalculator pDamageCalculator,
|
||||||
float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius,
|
float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius,
|
||||||
|
@ -80,9 +80,7 @@ public class CustomExplosion extends Explosion {
|
||||||
this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, BlockInteraction.KEEP);
|
this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, BlockInteraction.KEEP);
|
||||||
|
|
||||||
final Vec3 center = new Vec3(pToBlowX, pToBlowY, pToBlowZ);
|
final Vec3 center = new Vec3(pToBlowX, pToBlowY, pToBlowZ);
|
||||||
|
|
||||||
for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(radius), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) {
|
for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(radius), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) {
|
||||||
|
|
||||||
if (target instanceof ServerPlayer serverPlayer && !(target == pSource && pSource.getVehicle() != null)) {
|
if (target instanceof ServerPlayer serverPlayer && !(target == pSource && pSource.getVehicle() != null)) {
|
||||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(20 + 0.02 * damage, pRadius,10 + 0.03 * damage, pToBlowX, pToBlowY, pToBlowZ));
|
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(20 + 0.02 * damage, pRadius,10 + 0.03 * damage, pToBlowX, pToBlowY, pToBlowZ));
|
||||||
}
|
}
|
||||||
|
@ -99,8 +97,7 @@ public class CustomExplosion extends Explosion {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomExplosion isBulletExplode(boolean bullet) {
|
public CustomExplosion bulletExplode() {
|
||||||
this.bullet = bullet;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,14 +169,12 @@ public class CustomExplosion extends Explosion {
|
||||||
double yDistance = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
|
double yDistance = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
|
||||||
double zDistance = entity.getZ() - this.z;
|
double zDistance = entity.getZ() - this.z;
|
||||||
double distance = Math.sqrt(xDistance * xDistance + yDistance * yDistance + zDistance * zDistance);
|
double distance = Math.sqrt(xDistance * xDistance + yDistance * yDistance + zDistance * zDistance);
|
||||||
|
|
||||||
if (distance != 0.0D) {
|
if (distance != 0.0D) {
|
||||||
xDistance /= distance;
|
|
||||||
yDistance /= distance;
|
|
||||||
zDistance /= distance;
|
|
||||||
double seenPercent = Mth.clamp(getSeenPercent(position, entity), 0.01 * ExplosionConfig.EXPLOSION_PENETRATION_RATIO.get(), Double.POSITIVE_INFINITY);
|
double seenPercent = Mth.clamp(getSeenPercent(position, entity), 0.01 * ExplosionConfig.EXPLOSION_PENETRATION_RATIO.get(), Double.POSITIVE_INFINITY);
|
||||||
double damagePercent = (1.0D - distanceRate) * seenPercent;
|
double damagePercent = (1.0D - distanceRate) * seenPercent;
|
||||||
|
|
||||||
double damageFinal = (damagePercent * damagePercent + damagePercent) / 2.0D * damage;
|
double damageFinal = (damagePercent * damagePercent + damagePercent) / 2.0D * damage;
|
||||||
|
|
||||||
if (entity instanceof Monster monster) {
|
if (entity instanceof Monster monster) {
|
||||||
monster.hurt(this.damageSource, (float) damageFinal * (1 + 0.2f * this.damageMultiplier));
|
monster.hurt(this.damageSource, (float) damageFinal * (1 + 0.2f * this.damageMultiplier));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue