This commit is contained in:
2025-03-03 22:16:00 +11:00
parent 6b4dfb054e
commit cb096ae6a8
42 changed files with 1278 additions and 2841 deletions

View File

@@ -1,14 +1,9 @@
package ru.magistu.siegemachines.entity;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.*;
import javax.annotation.Nullable;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
@@ -21,7 +16,6 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.ProtectionEnchantment;
import net.minecraft.world.level.*;
@@ -31,299 +25,263 @@ import net.minecraft.world.level.block.FireBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
public class Breakdown
{
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
public class Breakdown {
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
private final boolean fire;
private final Explosion.BlockInteraction blockInteraction;
private final RandomSource random = RandomSource.create();
private final Level level;
private final double x;
private final double y;
private final double z;
@Nullable
private final Entity source;
private final float radius;
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final ObjectArrayList<BlockPos> toBlow = new ObjectArrayList<>();
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
private final Vec3 position;
private final Explosion explosion;
private final Entity machine;
private final float power;
private final boolean fire;
private final Explosion.BlockInteraction blockInteraction;
private final RandomSource random = RandomSource.create();
private final Level level;
private final double x;
private final double y;
private final double z;
@Nullable
private final Entity source;
private final float radius;
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final ObjectArrayList<BlockPos> toBlow = new ObjectArrayList<>();
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
private final Vec3 position;
private final Explosion explosion;
private final Entity machine;
private final float power;
public Breakdown(Level p_i50007_1_, @Nullable Entity machine, @Nullable Entity p_i50007_2_, double p_i50007_3_, double p_i50007_5_, double p_i50007_7_, float p_i50007_9_, boolean p_i50007_10_, float power, Explosion.BlockInteraction p_i50007_11_) {
this(p_i50007_1_, p_i50007_2_, machine, (DamageSource)null, (ExplosionDamageCalculator)null, p_i50007_3_, p_i50007_5_, p_i50007_7_, p_i50007_9_, p_i50007_10_, power, p_i50007_11_);
}
public Breakdown(Level p_i50007_1_, @Nullable Entity machine, @Nullable Entity p_i50007_2_, double p_i50007_3_, double p_i50007_5_, double p_i50007_7_, float p_i50007_9_, boolean p_i50007_10_, float power, Explosion.BlockInteraction p_i50007_11_) {
this(p_i50007_1_, p_i50007_2_, machine, (DamageSource) null, (ExplosionDamageCalculator) null, p_i50007_3_, p_i50007_5_, p_i50007_7_, p_i50007_9_, p_i50007_10_, power, p_i50007_11_);
}
public Breakdown(Level p_i231610_1_, @Nullable Entity machine, @Nullable Entity p_i231610_2_, @Nullable DamageSource p_i231610_3_, @Nullable ExplosionDamageCalculator p_i231610_4_, double p_i231610_5_, double p_i231610_7_, double p_i231610_9_, float p_i231610_11_, boolean p_i231610_12_, float power, Explosion.BlockInteraction p_i231610_13_) {
this.explosion = new Explosion(p_i231610_1_, p_i231610_2_, p_i231610_3_, p_i231610_4_, p_i231610_5_, p_i231610_7_, p_i231610_9_, p_i231610_11_, p_i231610_12_, p_i231610_13_);
this.level = p_i231610_1_;
this.machine = machine;
this.source = p_i231610_2_;
this.radius = p_i231610_11_;
this.x = p_i231610_5_;
this.y = p_i231610_7_;
this.z = p_i231610_9_;
this.fire = p_i231610_12_;
this.power = power;
this.blockInteraction = p_i231610_13_;
this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? DamageSource.explosion((LivingEntity) p_i231610_2_) : p_i231610_3_;
this.damageCalculator = p_i231610_4_ == null ? this.makeDamageCalculator(p_i231610_2_) : p_i231610_4_;
this.position = new Vec3(this.x, this.y, this.z);
}
public Breakdown(Level p_i231610_1_, @Nullable Entity machine, @Nullable Entity p_i231610_2_, @Nullable DamageSource p_i231610_3_, @Nullable ExplosionDamageCalculator p_i231610_4_, double p_i231610_5_, double p_i231610_7_, double p_i231610_9_, float p_i231610_11_, boolean p_i231610_12_, float power, Explosion.BlockInteraction p_i231610_13_) {
this.explosion = new Explosion(p_i231610_1_, p_i231610_2_, p_i231610_3_, p_i231610_4_, p_i231610_5_, p_i231610_7_, p_i231610_9_, p_i231610_11_, p_i231610_12_, p_i231610_13_);
this.level = p_i231610_1_;
this.machine = machine;
this.source = p_i231610_2_;
this.radius = p_i231610_11_;
this.x = p_i231610_5_;
this.y = p_i231610_7_;
this.z = p_i231610_9_;
this.fire = p_i231610_12_;
this.power = power;
this.blockInteraction = p_i231610_13_;
// this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? DamageSource.explosion((LivingEntity) p_i231610_2_) : p_i231610_3_;
this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? level.damageSources().explosion(p_i231610_2_, p_i231610_2_) : p_i231610_3_; //TODO Возможно неправильно
this.damageCalculator = p_i231610_4_ == null ? this.makeDamageCalculator(p_i231610_2_) : p_i231610_4_;
this.position = new Vec3(this.x, this.y, this.z);
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity p_234894_1_) {
return (p_234894_1_ == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(p_234894_1_));
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity p_234894_1_) {
return (p_234894_1_ == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(p_234894_1_));
}
public static float getSeenPercent(Vec3 p_222259_0_, Entity p_222259_1_) {
AABB axisalignedbb = p_222259_1_.getBoundingBox();
double d0 = 1.0D / ((axisalignedbb.maxX - axisalignedbb.minX) * 2.0D + 1.0D);
double d1 = 1.0D / ((axisalignedbb.maxY - axisalignedbb.minY) * 2.0D + 1.0D);
double d2 = 1.0D / ((axisalignedbb.maxZ - axisalignedbb.minZ) * 2.0D + 1.0D);
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D)) {
int i = 0;
int j = 0;
public static float getSeenPercent(Vec3 p_222259_0_, Entity p_222259_1_) {
AABB axisalignedbb = p_222259_1_.getBoundingBox();
double d0 = 1.0D / ((axisalignedbb.maxX - axisalignedbb.minX) * 2.0D + 1.0D);
double d1 = 1.0D / ((axisalignedbb.maxY - axisalignedbb.minY) * 2.0D + 1.0D);
double d2 = 1.0D / ((axisalignedbb.maxZ - axisalignedbb.minZ) * 2.0D + 1.0D);
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D)) {
int i = 0;
int j = 0;
for(float f = 0.0F; f <= 1.0F; f = (float)((double)f + d0)) {
for(float f1 = 0.0F; f1 <= 1.0F; f1 = (float)((double)f1 + d1)) {
for(float f2 = 0.0F; f2 <= 1.0F; f2 = (float)((double)f2 + d2)) {
double d5 = Mth.lerp((double)f, axisalignedbb.minX, axisalignedbb.maxX);
double d6 = Mth.lerp((double)f1, axisalignedbb.minY, axisalignedbb.maxY);
double d7 = Mth.lerp((double)f2, axisalignedbb.minZ, axisalignedbb.maxZ);
Vec3 vector3d = new Vec3(d5 + d3, d6, d7 + d4);
if (p_222259_1_.level.clip(new ClipContext(vector3d, p_222259_0_, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, p_222259_1_)).getType() == HitResult.Type.MISS) {
++i;
}
for (float f = 0.0F; f <= 1.0F; f = (float) ((double) f + d0)) {
for (float f1 = 0.0F; f1 <= 1.0F; f1 = (float) ((double) f1 + d1)) {
for (float f2 = 0.0F; f2 <= 1.0F; f2 = (float) ((double) f2 + d2)) {
double d5 = Mth.lerp((double) f, axisalignedbb.minX, axisalignedbb.maxX);
double d6 = Mth.lerp((double) f1, axisalignedbb.minY, axisalignedbb.maxY);
double d7 = Mth.lerp((double) f2, axisalignedbb.minZ, axisalignedbb.maxZ);
Vec3 vector3d = new Vec3(d5 + d3, d6, d7 + d4);
if (p_222259_1_.level().clip(new ClipContext(vector3d, p_222259_0_, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, p_222259_1_)).getType() == HitResult.Type.MISS) {
++i;
}
++j;
}
++j;
}
}
}
}
return (float)i / (float)j;
} else {
return 0.0F;
}
}
return (float) i / (float) j;
} else {
return 0.0F;
}
}
public void explode()
{
Set<BlockPos> set = Sets.newHashSet();
int i = 16;
public void explode() {
Set<BlockPos> set = Sets.newHashSet();
int i = 16;
for(int j = 0; j < 16; ++j) {
for(int k = 0; k < 16; ++k) {
for(int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (double)((float)j / 15.0F * 2.0F - 1.0F);
double d1 = (double)((float)k / 15.0F * 2.0F - 1.0F);
double d2 = (double)((float)l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.power * this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.power * this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for(float f1 = 0.3F; f > 0.0F; f -= this.power * 0.5F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
BlockState blockstate = this.level.getBlockState(blockpos);
FluidState fluidstate = this.level.getFluidState(blockpos);
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this.explosion, this.level, blockpos, blockstate, fluidstate);
if (optional.isPresent()) {
f -= (optional.get() + 0.3F) * 0.3F;
}
for (float f1 = 0.3F; f > 0.0F; f -= this.power * 0.5F) {
BlockPos blockpos = new BlockPos((int) d4, (int) d6, (int) d8); //TODO ранее был double
BlockState blockstate = this.level.getBlockState(blockpos);
FluidState fluidstate = this.level.getFluidState(blockpos);
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this.explosion, this.level, blockpos, blockstate, fluidstate);
if (optional.isPresent()) {
f -= (optional.get() + 0.3F) * 0.3F;
}
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this.explosion, this.level, blockpos, blockstate, f)) {
set.add(blockpos);
}
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this.explosion, this.level, blockpos, blockstate, f)) {
set.add(blockpos);
}
d4 += d0 * (double)0.3F;
d6 += d1 * (double)0.3F;
d8 += d2 * (double)0.3F;
}
}
d4 += d0 * (double) 0.3F;
d6 += d1 * (double) 0.3F;
d8 += d2 * (double) 0.3F;
}
}
}
}
}
}
}
this.toBlow.addAll(set);
float f2 = 1.5f * this.radius;
int k1 = Mth.floor(this.x - (double)f2 - 1.0D);
int l1 = Mth.floor(this.x + (double)f2 + 1.0D);
int i2 = Mth.floor(this.y - (double)f2 - 1.0D);
int i1 = Mth.floor(this.y + (double)f2 + 1.0D);
int j2 = Mth.floor(this.z - (double)f2 - 1.0D);
int j1 = Mth.floor(this.z + (double)f2 + 1.0D);
List<Entity> list = this.level.getEntities(this.source, new AABB((double)k1, (double)i2, (double)j2, (double)l1, (double)i1, (double)j1));
Vec3 vector3d = new Vec3(this.x, this.y, this.z);
this.toBlow.addAll(set);
float f2 = 1.5f * this.radius;
int k1 = Mth.floor(this.x - (double) f2 - 1.0D);
int l1 = Mth.floor(this.x + (double) f2 + 1.0D);
int i2 = Mth.floor(this.y - (double) f2 - 1.0D);
int i1 = Mth.floor(this.y + (double) f2 + 1.0D);
int j2 = Mth.floor(this.z - (double) f2 - 1.0D);
int j1 = Mth.floor(this.z + (double) f2 + 1.0D);
List<Entity> list = this.level.getEntities(this.source, new AABB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
Vec3 vector3d = new Vec3(this.x, this.y, this.z);
for(int k2 = 0; k2 < list.size(); ++k2) {
Entity entity = list.get(k2);
if (!entity.ignoreExplosion() && !entity.equals(this.machine) && !entity.equals(this.source)) {
double d12 = (Mth.sqrt((float) entity.distanceToSqr(vector3d)) / f2);
if (d12 <= 1.0D) {
double d5 = entity.getX() - this.x;
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
double d9 = entity.getZ() - this.z;
double d13 = Mth.sqrt((float) (d5 * d5 + d7 * d7 + d9 * d9));
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = getSeenPercent(vector3d, entity);
double d10 = (1.0D - d12) * d14;
if (!(entity instanceof ItemEntity)) {
entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D)));
}
double d11 = d10;
if (entity instanceof LivingEntity) {
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity)entity, d10);
}
for (int k2 = 0; k2 < list.size(); ++k2) {
Entity entity = list.get(k2);
if (!entity.ignoreExplosion() && !entity.equals(this.machine) && !entity.equals(this.source)) {
double d12 = (Mth.sqrt((float) entity.distanceToSqr(vector3d)) / f2);
if (d12 <= 1.0D) {
double d5 = entity.getX() - this.x;
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
double d9 = entity.getZ() - this.z;
double d13 = Mth.sqrt((float) (d5 * d5 + d7 * d7 + d9 * d9));
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = getSeenPercent(vector3d, entity);
double d10 = (1.0D - d12) * d14;
if (!(entity instanceof ItemEntity)) {
entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D)));
}
double d11 = d10;
if (entity instanceof LivingEntity) {
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10);
}
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof Player) {
Player playerentity = (Player)entity;
if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.getAbilities().flying)) {
this.hitPlayers.put(playerentity, new Vec3(d5 * d10, d7 * d10, d9 * d10));
}
}
}
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof Player) {
Player playerentity = (Player) entity;
if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.getAbilities().flying)) {
this.hitPlayers.put(playerentity, new Vec3(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
}
}
}
public void finalizeExplosion(boolean p_77279_1_) {
if (this.level.isClientSide) {
//this.level.playLocalSound(this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F, false);
}
boolean flag = this.blockInteraction != Explosion.BlockInteraction.NONE;
if (p_77279_1_) {
if (!(this.radius < 2.0F) && flag) {
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
} else {
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
if (flag) {
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
Util.shuffle(this.toBlow, random);
for(BlockPos blockpos : this.toBlow) {
BlockState blockstate = this.level.getBlockState(blockpos);
Block block = blockstate.getBlock();
if (!blockstate.isAir()) {
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (this.level instanceof ServerLevel) {
BlockEntity tileentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerLevel)this.level)).withRandom(this.level.random).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (this.blockInteraction == Explosion.BlockInteraction.DESTROY) {
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
}
blockstate.getDrops(lootcontext$builder).forEach((p_229977_2_) -> {
addBlockDrops(objectarraylist, p_229977_2_, blockpos1);
});
}
this.level.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
this.level.getProfiler().pop();
public void finalizeExplosion(boolean p_77279_1_) {
boolean flag = this.blockInteraction != Explosion.BlockInteraction.KEEP; //TODO Стоял NONE, поставил KEEP, возможно неверно
if (p_77279_1_) {
if (!(this.radius < 2.0F) && flag) {
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
} else {
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
}
for(Pair<ItemStack, BlockPos> pair : objectarraylist) {
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
}
}
if (flag) {
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
Util.shuffle(this.toBlow, random);
if (this.fire) {
for(BlockPos blockpos2 : this.toBlow) {
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
this.level.setBlockAndUpdate(blockpos2, FireBlock.getState(this.level, blockpos2));
for (BlockPos blockpos : this.toBlow) {
BlockState blockstate = this.level.getBlockState(blockpos);
Block block = blockstate.getBlock();
if (!blockstate.isAir()) {
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (this.level instanceof ServerLevel) {
BlockEntity tileentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootParams.Builder lootcontext$builder = (new LootParams.Builder((ServerLevel) this.level)).withLuck(this.level.random.nextFloat()).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (this.blockInteraction == Explosion.BlockInteraction.DESTROY) {
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
}
blockstate.getDrops(lootcontext$builder).forEach((p_229977_2_) -> {
addBlockDrops(objectarraylist, p_229977_2_, blockpos1);
});
}
this.level.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
this.level.getProfiler().pop();
}
}
}
}
}
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> p_46068_, ItemStack p_46069_, BlockPos p_46070_) {
int i = p_46068_.size();
for(int j = 0; j < i; ++j) {
Pair<ItemStack, BlockPos> pair = p_46068_.get(j);
ItemStack itemstack = pair.getFirst();
if (ItemEntity.areMergable(itemstack, p_46069_)) {
ItemStack itemstack1 = ItemEntity.merge(itemstack, p_46069_, 16);
p_46068_.set(j, Pair.of(itemstack1, pair.getSecond()));
if (p_46069_.isEmpty()) {
return;
for (Pair<ItemStack, BlockPos> pair : objectarraylist) {
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
}
}
}
}
p_46068_.add(Pair.of(p_46069_, p_46070_));
}
public DamageSource getDamageSource() {
return this.damageSource;
}
public Map<Player, Vec3> getHitPlayers() {
return this.hitPlayers;
}
@Nullable
public LivingEntity getSourceMob() {
if (this.source == null) {
return null;
} else if (this.source instanceof PrimedTnt) {
return ((PrimedTnt)this.source).getOwner();
} else if (this.source instanceof LivingEntity) {
return (LivingEntity)this.source;
} else {
if (this.source instanceof Projectile) {
Entity entity = ((Projectile)this.source).getOwner();
if (entity instanceof LivingEntity) {
return (LivingEntity)entity;
if (this.fire) {
for (BlockPos blockpos2 : this.toBlow) {
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
this.level.setBlockAndUpdate(blockpos2, FireBlock.getState(this.level, blockpos2));
}
}
}
}
return null;
}
}
}
public void clearToBlow() {
this.toBlow.clear();
}
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> p_46068_, ItemStack p_46069_, BlockPos p_46070_) {
int i = p_46068_.size();
public List<BlockPos> getToBlow() {
return this.toBlow;
}
for (int j = 0; j < i; ++j) {
Pair<ItemStack, BlockPos> pair = p_46068_.get(j);
ItemStack itemstack = pair.getFirst();
if (ItemEntity.areMergable(itemstack, p_46069_)) {
ItemStack itemstack1 = ItemEntity.merge(itemstack, p_46069_, 16);
p_46068_.set(j, Pair.of(itemstack1, pair.getSecond()));
if (p_46069_.isEmpty()) {
return;
}
}
}
public Vec3 getPosition() {
return this.position;
}
p_46068_.add(Pair.of(p_46069_, p_46070_));
}
@Nullable
public Entity getExploder() {
return this.source;
}
public DamageSource getDamageSource() {
return this.damageSource;
}
public Vec3 getPosition() {
return this.position;
}
}

View File

@@ -1,11 +1,5 @@
package ru.magistu.siegemachines.entity;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.entity.machine.*;
import ru.magistu.siegemachines.entity.projectile.Cannonball;
import ru.magistu.siegemachines.entity.projectile.GiantArrow;
import ru.magistu.siegemachines.entity.projectile.GiantStone;
import ru.magistu.siegemachines.entity.projectile.Stone;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
@@ -14,9 +8,14 @@ import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.entity.machine.*;
import ru.magistu.siegemachines.entity.projectile.Cannonball;
import ru.magistu.siegemachines.entity.projectile.GiantArrow;
import ru.magistu.siegemachines.entity.projectile.GiantStone;
import ru.magistu.siegemachines.entity.projectile.Stone;
public class EntityTypes
{
public class EntityTypes {
public static final DeferredRegister<EntityType<?>> DEFERRED_REGISTER = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, SiegeMachines.ID);
public static final RegistryObject<EntityType<Cannonball>> CANNONBALL = addRegistry("cannonball", Cannonball::new, 0.5f, 0.5f);
@@ -31,21 +30,18 @@ public class EntityTypes
public static final RegistryObject<EntityType<Ballista>> BALLISTA = addRegistry("ballista", Ballista::new, 1.5f, 1.5f, 10);
public static final RegistryObject<EntityType<BatteringRam>> BATTERING_RAM = addRegistry("battering_ram", BatteringRam::new, 4.0f, 3.0f, 10);
public static final RegistryObject<EntityType<SiegeLadder>> SIEGE_LADDER = addRegistry("siege_ladder", SiegeLadder::new, 3.0f, 3.0f, 10);
public static final RegistryObject<EntityType<Seat>> SEAT = addRegistry("seat", Seat::new, 0.0f, 0.0f);
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey)
{
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey) {
return addRegistry(name, constructor, sizex, sizey, 1);
}
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey, int trackingrange)
{
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey, int trackingrange) {
return DEFERRED_REGISTER.register(name, () -> EntityType.Builder.of(constructor, MobCategory.MISC).clientTrackingRange(trackingrange).sized(sizex, sizey).build(new ResourceLocation(SiegeMachines.ID, name).toString()));
}
public static void register(IEventBus eventBus)
{
public static void register(IEventBus eventBus) {
DEFERRED_REGISTER.register(eventBus);
}
}

View File

@@ -1,11 +1,10 @@
package ru.magistu.siegemachines.entity;
import ru.magistu.siegemachines.client.gui.machine.crosshair.Crosshair;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import ru.magistu.siegemachines.client.gui.machine.crosshair.Crosshair;
public interface IReloading
{
public interface IReloading {
@OnlyIn(Dist.CLIENT)
Crosshair createCrosshair();
}

View File

@@ -1,22 +1,19 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import ru.magistu.siegemachines.item.ModItems;
public class Cannonball extends Missile
{
public Cannonball(EntityType<Cannonball> type, Level level)
{
public class Cannonball extends Missile {
public Cannonball(EntityType<Cannonball> type, Level level) {
super(type, level);
this.item = ModItems.CANNONBALL.get();
}
public Cannonball(EntityType<Cannonball> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item)
{
super(entitytype, level, pos, entity, MissileType.CANNONBALL, item);
}
public Cannonball(EntityType<Cannonball> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item) {
super(entitytype, level, pos, entity, MissileType.CANNONBALL, item);
}
}

View File

@@ -1,7 +1,6 @@
package ru.magistu.siegemachines.entity.projectile;
public enum FlightType
{
public enum FlightType {
NONE,
AHEAD,
SPINNING

View File

@@ -1,42 +1,38 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import ru.magistu.siegemachines.item.ModItems;
public class GiantArrow extends AbstractArrow
{
private final Packet<?> spawningpacket = NetworkHooks.getEntitySpawningPacket(this);
public class GiantArrow extends AbstractArrow {
private final Packet<ClientGamePacketListener> spawningpacket = NetworkHooks.getEntitySpawningPacket(this);
public GiantArrow(EntityType<GiantArrow> type, Level level)
{
public GiantArrow(EntityType<GiantArrow> type, Level level) {
super(type, level);
}
public GiantArrow(EntityType<GiantArrow> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item)
{
super(entitytype, entity, level);
public GiantArrow(EntityType<GiantArrow> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item) {
super(entitytype, entity, level);
this.setPos(pos.x, pos.y, pos.z);
this.setBaseDamage(5.0F);
}
}
@Override
protected @NotNull ItemStack getPickupItem()
{
protected @NotNull ItemStack getPickupItem() {
return new ItemStack(ModItems.GIANT_ARROW.get());
}
@Override
public @NotNull Packet<?> getAddEntityPacket()
{
return spawningpacket;
}
public @NotNull Packet<ClientGamePacketListener> getAddEntityPacket() {
return spawningpacket;
}
}

View File

@@ -1,23 +1,20 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import ru.magistu.siegemachines.item.ModItems;
public class GiantStone extends Missile
{
public GiantStone(EntityType<GiantStone> entitytype, Level level)
{
super(entitytype, level);
this.item = ModItems.GIANT_STONE.get();
}
public class GiantStone extends Missile {
public GiantStone(EntityType<GiantStone> entitytype, Level level) {
super(entitytype, level);
this.item = ModItems.GIANT_STONE.get();
}
public GiantStone(EntityType<GiantStone> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item)
{
super(entitytype, level, pos, entity, MissileType.GIANT_STONE, item);
}
public GiantStone(EntityType<GiantStone> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item) {
super(entitytype, level, pos, entity, MissileType.GIANT_STONE, item);
}
}

View File

@@ -1,13 +1,12 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
public interface IProjectileFactory<T extends Projectile>
{
T create(EntityType<T> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item);
public interface IProjectileFactory<T extends Projectile> {
T create(EntityType<T> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item);
}

View File

@@ -1,14 +1,12 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import net.minecraft.world.level.ExplosionDamageCalculator;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.BlockParticleOption;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
@@ -23,6 +21,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.ExplosionDamageCalculator;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
@@ -32,185 +31,154 @@ import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import ru.magistu.siegemachines.item.ModItems;
import javax.annotation.Nullable;
public abstract class Missile extends ThrowableItemProjectile
{
public MissileType type = MissileType.STONE;
public Item item = ModItems.STONE.get();
public abstract class Missile extends ThrowableItemProjectile {
public MissileType type = MissileType.STONE;
public Item item = ModItems.STONE.get();
public Missile(EntityType<? extends Missile> entitytype, Level level)
{
super(entitytype, level);
}
public Missile(EntityType<? extends Missile> entitytype, Level level) {
super(entitytype, level);
}
public Missile(EntityType<? extends Missile> entitytype, Level level, Vector3d pos, LivingEntity entity, MissileType type, Item item)
{
super(entitytype, entity, level);
this.type = type;
this.item = item;
this.setPos(pos.x, pos.y, pos.z);
}
public Missile(EntityType<? extends Missile> entitytype, Level level, Vec3 pos, LivingEntity entity, MissileType type, Item item) {
super(entitytype, entity, level);
this.type = type;
this.item = item;
this.setPos(pos.x, pos.y, pos.z);
}
@Override
public @NotNull Item getDefaultItem()
{
return this.item;
}
@Override
public @NotNull Item getDefaultItem() {
return this.item;
}
@Override
public @NotNull Packet<?> getAddEntityPacket()
{
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
public @NotNull Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
public void onHit(HitResult result)
{
float f = 2.0F;
if (result.getType() == HitResult.Type.ENTITY)
{
EntityHitResult entityRTR = (EntityHitResult)result;
Vec3 pos = entityRTR.getLocation();
Entity entity = entityRTR.getEntity();
float damage = this.type.specs.mass.get() * (float) this.getDeltaMovement().length();
@Override
public void onHit(HitResult result) {
float f = 2.0F;
if (result.getType() == HitResult.Type.ENTITY) {
EntityHitResult entityRTR = (EntityHitResult) result;
Vec3 pos = entityRTR.getLocation();
Entity entity = entityRTR.getEntity();
float damage = this.type.specs.mass.get() * (float) this.getDeltaMovement().length();
DamageSource damagesource = DamageSource.thrown(this, this.getOwner());
if (this.type.armorpiercing >= 1.0f)
{
damagesource = damagesource.bypassArmor();
}
else if (this.type.armorpiercing > 0.0f && entity instanceof LivingEntity livingentity)
{
if(livingentity instanceof Player player) {
if(player.isBlocking() && (item == ModItems.GIANT_ARROW.get() || item == Items.ARROW) && (player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof ShieldItem || player.isBlocking() && player.getItemInHand(InteractionHand.OFF_HAND).getItem() instanceof ShieldItem)) {
return;
}
}
damage -= (1.0f - this.type.armorpiercing) * (damage - CombatRules.getDamageAfterAbsorb(damage, 0, 0));
}
// DamageSource damagesource = DamageSource.thrown(this, this.getOwner()); //TODO
DamageSource damagesource = level().damageSources().thrown(this, this.getOwner());
if (this.type.armorpiercing >= 1.0f) {
// damagesource = damagesource.bypassArmor(); TODO хз что тут
} else if (this.type.armorpiercing > 0.0f && entity instanceof LivingEntity livingentity) {
if (livingentity instanceof Player player) {
if (player.isBlocking() && (item == ModItems.GIANT_ARROW.get() || item == Items.ARROW) && (player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof ShieldItem || player.isBlocking() && player.getItemInHand(InteractionHand.OFF_HAND).getItem() instanceof ShieldItem)) {
return;
}
}
damage -= (1.0f - this.type.armorpiercing) * (damage - CombatRules.getDamageAfterAbsorb(damage, 0, 0));
}
if (!this.level.isClientSide() && this.type.explosive)
{
this.explode(pos.x, pos.y, pos.z, 3.0F, Explosion.BlockInteraction.NONE);
this.remove(RemovalReason.KILLED);
}
if (!this.level().isClientSide() && this.type.explosive) {
this.explode(pos.x, pos.y, pos.z, 3.0F, Explosion.BlockInteraction.KEEP); //TODO
this.remove(RemovalReason.KILLED);
}
entity.hurt(damagesource, damage);
Vec3 vector3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) this.type.knockback * 0.6D);
if (vector3d.lengthSqr() > 0.0D)
{
entity.push(vector3d.x, 0.1D, vector3d.z);
}
}
entity.hurt(damagesource, damage);
Vec3 vector3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) this.type.knockback * 0.6D);
if (vector3d.lengthSqr() > 0.0D) {
entity.push(vector3d.x, 0.1D, vector3d.z);
}
}
if (result.getType() == HitResult.Type.BLOCK)
{
BlockHitResult blockRTR = (BlockHitResult)result;
BlockPos blockpos = blockRTR.getBlockPos();
BlockState blockstate = this.level.getBlockState(blockpos);
boolean smoothimpact = (blockstate == Blocks.SAND.defaultBlockState() ||
blockstate == Blocks.RED_SAND.defaultBlockState() ||
blockstate == Blocks.DIRT.defaultBlockState() ||
blockstate == Blocks.GRASS_BLOCK.defaultBlockState() ||
blockstate == Blocks.DIRT_PATH.defaultBlockState() ||
blockstate == Blocks.COARSE_DIRT.defaultBlockState() ||
blockstate == Blocks.SNOW_BLOCK.defaultBlockState()) &&
blockRTR.getDirection() == Direction.UP;
if (result.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockRTR = (BlockHitResult) result;
BlockPos blockpos = blockRTR.getBlockPos();
BlockState blockstate = this.level().getBlockState(blockpos);
boolean smoothimpact = (blockstate == Blocks.SAND.defaultBlockState() ||
blockstate == Blocks.RED_SAND.defaultBlockState() ||
blockstate == Blocks.DIRT.defaultBlockState() ||
blockstate == Blocks.GRASS_BLOCK.defaultBlockState() ||
blockstate == Blocks.DIRT_PATH.defaultBlockState() ||
blockstate == Blocks.COARSE_DIRT.defaultBlockState() ||
blockstate == Blocks.SNOW_BLOCK.defaultBlockState()) &&
blockRTR.getDirection() == Direction.UP;
if (blockRTR.getDirection() == Direction.UP)
{
if (this.type.explosive)
{
for (int r = 0; r < this.type.specs.explosionpower.get(); ++r)
{
for (float a = 0; a < 2 * Math.PI; a += Math.PI / 4)
{
BlockPos pos = blockRTR.getBlockPos().offset(r * Math.cos(a), 0, -r * Math.sin(a));
if (this.level.getBlockState(pos) == Blocks.GRASS_BLOCK.defaultBlockState())
{
this.level.setBlockAndUpdate(pos, Blocks.DIRT.defaultBlockState());
}
}
}
}
if (!this.level.isClientSide())
{
this.remove(RemovalReason.KILLED);
if (smoothimpact && this.type.explosive)
{
if (blockRTR.getDirection() == Direction.UP) {
if (this.type.explosive) {
for (int r = 0; r < this.type.specs.explosionpower.get(); ++r) {
for (float a = 0; a < 2 * Math.PI; a += Math.PI / 4) {
BlockPos pos = blockRTR.getBlockPos().offset((int) (r * Math.cos(a)), 0, (int) (-r * Math.sin(a))); //TODO был не int
if (this.level().getBlockState(pos) == Blocks.GRASS_BLOCK.defaultBlockState()) {
this.level().setBlockAndUpdate(pos, Blocks.DIRT.defaultBlockState());
}
}
}
}
if (!this.level().isClientSide()) {
this.remove(RemovalReason.KILLED);
if (smoothimpact && this.type.explosive) {
this.explode(blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get() * f, Explosion.BlockInteraction.NONE);
}
}
else if (smoothimpact)
{
this.dustExplosion(new BlockParticleOption(ParticleTypes.BLOCK, blockstate).setPos(blockpos), blockpos, this.type.specs.explosionpower.get() / 2, 50);
}
}
if (!this.level.isClientSide() && !smoothimpact && this.type.explosive)
{
this.explode(blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get() * f, Explosion.BlockInteraction.BREAK);
}
}
this.explode(blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get() * f, Explosion.BlockInteraction.KEEP); //TODO
}
} else if (smoothimpact) {
this.dustExplosion(new BlockParticleOption(ParticleTypes.BLOCK, blockstate).setPos(blockpos), blockpos, this.type.specs.explosionpower.get() / 2, 50);
}
}
if (!this.level().isClientSide() && !smoothimpact && this.type.explosive) {
this.explode(blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get() * f, Explosion.BlockInteraction.DESTROY);
}
}
if (result.getType() == HitResult.Type.MISS)
{
this.level.playSound((Player)this.getOwner(), this.getOnPos(), SoundEvents.ANVIL_BREAK, SoundSource.AMBIENT, 1.0f, 1.0f);
if(!this.level.isClientSide())
{
this.remove(RemovalReason.KILLED);
}
}
if (!this.level.isClientSide())
{
this.remove(RemovalReason.KILLED);
}
}
if (result.getType() == HitResult.Type.MISS) {
this.level().playSound((Player) this.getOwner(), this.getOnPos(), SoundEvents.ANVIL_BREAK, SoundSource.AMBIENT, 1.0f, 1.0f);
if (!this.level().isClientSide()) {
this.remove(RemovalReason.KILLED);
}
}
if (!this.level().isClientSide()) {
this.remove(RemovalReason.KILLED);
}
}
private void dustExplosion(ParticleOptions particle, BlockPos blockpos, double speed, int amount)
{
this.dustExplosion(particle, blockpos.getX(), blockpos.getY(), blockpos.getZ(), speed, amount);
}
private void dustExplosion(ParticleOptions particle, BlockPos blockpos, double speed, int amount) {
this.dustExplosion(particle, blockpos.getX(), blockpos.getY(), blockpos.getZ(), speed, amount);
}
private void dustExplosion(ParticleOptions particle, double x, double y, double z, double speed, int amount)
{
for (int i = 0; i < amount; ++i)
{
Vec3 movement = this.getDeltaMovement();
double d0 = x - 0.05 + this.level.random.nextDouble() * 0.3;
double d1 = y + 1.0;
double d2 = z - 0.05 + this.level.random.nextDouble() * 0.3;
double d3 = movement.x * this.level.random.nextDouble() * speed;
double d4 = -movement.y * this.level.random.nextDouble() * speed * 10.0f;
double d5 = movement.z * this.level.random.nextDouble() * speed;
this.level.addParticle(particle, d0, d1, d2, d3, d4, d5);
}
}
private void dustExplosion(ParticleOptions particle, double x, double y, double z, double speed, int amount) {
for (int i = 0; i < amount; ++i) {
Vec3 movement = this.getDeltaMovement();
double d0 = x - 0.05 + this.level().random.nextDouble() * 0.3;
double d1 = y + 1.0;
double d2 = z - 0.05 + this.level().random.nextDouble() * 0.3;
double d3 = movement.x * this.level().random.nextDouble() * speed;
double d4 = -movement.y * this.level().random.nextDouble() * speed * 10.0f;
double d5 = movement.z * this.level().random.nextDouble() * speed;
this.level().addParticle(particle, d0, d1, d2, d3, d4, d5);
}
}
@Override
public void tick()
{
if (this.type.flighttype == FlightType.SPINNING)
{
this.setXRot(this.getXRot() + 0.5f);
}
@Override
public void tick() {
if (this.type.flighttype == FlightType.SPINNING) {
this.setXRot(this.getXRot() + 0.5f);
}
super.tick();
}
super.tick();
}
public MissileExplosion explode(double x, double y, double z, float radius, Explosion.BlockInteraction mode)
{
return this.explode(null, null, x, y, z, radius, false, mode);
}
public MissileExplosion explode(double x, double y, double z, float radius, Explosion.BlockInteraction mode) {
return this.explode(null, null, x, y, z, radius, false, mode);
}
public MissileExplosion explode(@Nullable DamageSource source, @Nullable ExplosionDamageCalculator context, double x, double y, double z, float size, boolean fired, Explosion.BlockInteraction mode)
{
MissileExplosion explosion = new MissileExplosion(this.level, this.getOwner(), source, context, x, y, z, size, fired, mode);
if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(level, explosion)) return explosion;
explosion.explode();
explosion.finalizeExplosion(true);
return explosion;
}
public MissileExplosion explode(@Nullable DamageSource source, @Nullable ExplosionDamageCalculator context, double x, double y, double z, float size, boolean fired, Explosion.BlockInteraction mode) {
MissileExplosion explosion = new MissileExplosion(this.level(), this.getOwner(), source, context, x, y, z, size, fired, mode);
if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(level(), explosion)) return explosion;
explosion.explode();
explosion.finalizeExplosion(true);
return explosion;
}
}

View File

@@ -17,7 +17,6 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.ProtectionEnchantment;
import net.minecraft.world.level.*;
@@ -27,7 +26,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult;
@@ -37,394 +36,327 @@ import ru.magistu.siegemachines.entity.machine.Machine;
import javax.annotation.Nullable;
import java.util.*;
public class MissileExplosion extends Explosion
{
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
private final boolean fire;
private final BlockInteraction blockInteraction;
private final Random random = new Random();
private final Level level;
private final double x;
private final double y;
private final double z;
@Nullable
private final Entity source;
private final float radius;
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final List<BlockPos> toBlow = Lists.newArrayList();
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
private final Vec3 position;
private float damagemultiplier = 1.0f;
public class MissileExplosion extends Explosion {
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
private final boolean fire;
private final BlockInteraction blockInteraction;
private final Random random = new Random();
private final Level level;
private final double x;
private final double y;
private final double z;
@Nullable
private final Entity source;
private final float radius;
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final List<BlockPos> toBlow = Lists.newArrayList();
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
private final Vec3 position;
private float damagemultiplier = 1.0f;
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius)
{
this(level, source, x, y, z, radius, false, BlockInteraction.DESTROY);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius) {
this(level, source, x, y, z, radius, false, BlockInteraction.DESTROY);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, List<BlockPos> pPositions)
{
this(level, source, x, y, z, radius, false, BlockInteraction.DESTROY, pPositions);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, List<BlockPos> pPositions) {
this(level, source, x, y, z, radius, false, BlockInteraction.DESTROY, pPositions);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction, List<BlockPos> pPositions)
{
this(level, source, x, y, z, radius, fired, blockinteraction);
this.toBlow.addAll(pPositions);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction, List<BlockPos> pPositions) {
this(level, source, x, y, z, radius, fired, blockinteraction);
this.toBlow.addAll(pPositions);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction)
{
this(level, source, null, null, x, y, z, radius, fired, blockinteraction);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction) {
this(level, source, null, null, x, y, z, radius, fired, blockinteraction);
}
public MissileExplosion(Level level, @Nullable Entity source, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator damagecalculator, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction)
{
super(level, source, damagesource, damagecalculator, x, y, z, radius, fired, blockinteraction);
this.level = level;
this.source = source;
this.radius = radius;
this.x = x;
this.y = y;
this.z = z;
this.fire = fired;
this.blockInteraction = blockinteraction;
this.damageSource = damagesource == null ? DamageSource.explosion(this) : damagesource;
this.damageCalculator = damagecalculator == null ? this.makeDamageCalculator(source) : damagecalculator;
this.position = new Vec3(this.x, this.y, this.z);
if (source != null && source.isPassenger())
{
Entity vehicle = source.getVehicle();
if (vehicle instanceof Machine)
{
this.damagemultiplier = ((Machine) vehicle).type.specs.damagemultiplier.get();
}
}
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity pEntity)
{
return pEntity == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(pEntity);
}
public static float getSeenPercent(Vec3 pExplosionVector, Entity pEntity)
{
AABB aabb = pEntity.getBoundingBox();
double d0 = 1.0D / ((aabb.maxX - aabb.minX) * 2.0D + 1.0D);
double d1 = 1.0D / ((aabb.maxY - aabb.minY) * 2.0D + 1.0D);
double d2 = 1.0D / ((aabb.maxZ - aabb.minZ) * 2.0D + 1.0D);
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D))
{
int i = 0;
int j = 0;
for (double d5 = 0.0D; d5 <= 1.0D; d5 += d0)
{
for (double d6 = 0.0D; d6 <= 1.0D; d6 += d1)
{
for (double d7 = 0.0D; d7 <= 1.0D; d7 += d2)
{
double d8 = Mth.lerp(d5, aabb.minX, aabb.maxX);
double d9 = Mth.lerp(d6, aabb.minY, aabb.maxY);
double d10 = Mth.lerp(d7, aabb.minZ, aabb.maxZ);
Vec3 vec3 = new Vec3(d8 + d3, d9, d10 + d4);
if (pEntity.level.clip(new ClipContext(vec3, pExplosionVector, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, pEntity)).getType() == HitResult.Type.MISS)
{
++i;
}
++j;
}
public MissileExplosion(Level level, @Nullable Entity source, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator damagecalculator, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction) {
super(level, source, damagesource, damagecalculator, x, y, z, radius, fired, blockinteraction);
this.level = level;
this.source = source;
this.radius = radius;
this.x = x;
this.y = y;
this.z = z;
this.fire = fired;
this.blockInteraction = blockinteraction;
// this.damageSource = damagesource == null ? DamageSource.explosion(this) : damagesource; TODO
this.damageSource = damagesource == null ? level.damageSources().explosion(this) : damagesource;
this.damageCalculator = damagecalculator == null ? this.makeDamageCalculator(source) : damagecalculator;
this.position = new Vec3(this.x, this.y, this.z);
if (source != null && source.isPassenger()) {
Entity vehicle = source.getVehicle();
if (vehicle instanceof Machine) {
this.damagemultiplier = ((Machine) vehicle).type.specs.damagemultiplier.get();
}
}
}
}
return (float)i / (float)j;
}
else
{
return 0.0F;
}
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity pEntity) {
return pEntity == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(pEntity);
}
/**
* Does the first part of the explosion (destroy blocks)
*/
@Override
public void explode()
{
this.level.gameEvent(this.source, GameEvent.EXPLODE, new BlockPos(this.x, this.y, this.z));
Set<BlockPos> set = Sets.newHashSet();
public static float getSeenPercent(Vec3 pExplosionVector, Entity pEntity) {
AABB aabb = pEntity.getBoundingBox();
double d0 = 1.0D / ((aabb.maxX - aabb.minX) * 2.0D + 1.0D);
double d1 = 1.0D / ((aabb.maxY - aabb.minY) * 2.0D + 1.0D);
double d2 = 1.0D / ((aabb.maxZ - aabb.minZ) * 2.0D + 1.0D);
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D)) {
int i = 0;
int j = 0;
for (int j = 0; j < 16; ++j)
{
for (int k = 0; k < 16; ++k)
{
for (int l = 0; l < 16; ++l)
{
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15)
{
double d0 = (float) j / 15.0F * 2.0F - 1.0F;
double d1 = (float) k / 15.0F * 2.0F - 1.0F;
double d2 = (float) l / 15.0F * 2.0F - 1.0F;
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 /= d3;
d1 /= d3;
d2 /= d3;
float f = this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (double d5 = 0.0D; d5 <= 1.0D; d5 += d0) {
for (double d6 = 0.0D; d6 <= 1.0D; d6 += d1) {
for (double d7 = 0.0D; d7 <= 1.0D; d7 += d2) {
double d8 = Mth.lerp(d5, aabb.minX, aabb.maxX);
double d9 = Mth.lerp(d6, aabb.minY, aabb.maxY);
double d10 = Mth.lerp(d7, aabb.minZ, aabb.maxZ);
Vec3 vec3 = new Vec3(d8 + d3, d9, d10 + d4);
if (pEntity.level().clip(new ClipContext(vec3, pExplosionVector, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, pEntity)).getType() == HitResult.Type.MISS) {
++i;
}
for (; f > 0.0F; f -= 0.22500001F)
{
BlockPos blockpos = new BlockPos(d4, d6, d8);
BlockState blockstate = this.level.getBlockState(blockpos);
FluidState fluidstate = this.level.getFluidState(blockpos);
if (!this.level.isInWorldBounds(blockpos))
{
break;
}
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this, this.level, blockpos, blockstate, fluidstate);
if (optional.isPresent())
{
f -= (optional.get() + 0.3F) * 0.3F;
}
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this, this.level, blockpos, blockstate, f))
{
set.add(blockpos);
}
d4 += d0 * (double)0.3F;
d6 += d1 * (double)0.3F;
d8 += d2 * (double)0.3F;
}
}
++j;
}
}
}
}
}
this.toBlow.addAll(set);
float f2 = this.radius * 2.0F;
int k1 = Mth.floor(this.x - (double)f2 - 1.0D);
int l1 = Mth.floor(this.x + (double)f2 + 1.0D);
int i2 = Mth.floor(this.y - (double)f2 - 1.0D);
int i1 = Mth.floor(this.y + (double)f2 + 1.0D);
int j2 = Mth.floor(this.z - (double)f2 - 1.0D);
int j1 = Mth.floor(this.z + (double)f2 + 1.0D);
List<Entity> list = this.level.getEntities(this.source, new AABB(k1, i2, j2, l1, i1, j1));
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.level, this, list, f2);
Vec3 vec3 = new Vec3(this.x, this.y, this.z);
return (float) i / (float) j;
} else {
return 0.0F;
}
}
for (Entity entity : list)
{
if (!entity.ignoreExplosion())
{
double d12 = Math.sqrt(entity.distanceToSqr(vec3)) / (double) f2;
if (d12 <= 1.0D)
{
double d5 = entity.getX() - this.x;
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
double d9 = entity.getZ() - this.z;
double d13 = Math.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D)
{
d5 /= d13;
d7 /= d13;
d9 /= d13;
double d14 = getSeenPercent(vec3, entity);
double d10 = (1.0D - d12) * d14;
entity.hurt(this.getDamageSource(), this.damagemultiplier * (int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D));
double d11 = d10;
if (entity instanceof LivingEntity)
{
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10);
}
/**
* Does the first part of the explosion (destroy blocks)
*/
@Override
public void explode() {
this.level.gameEvent(this.source, GameEvent.EXPLODE, new BlockPos((int) this.x, (int) this.y, (int) this.z));
Set<BlockPos> set = Sets.newHashSet();
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof Player)
{
Player player = (Player) entity;
if (!player.isSpectator() && (!player.isCreative() || !player.getAbilities().flying))
{
this.hitPlayers.put(player, new Vec3(d5 * d10, d7 * d10, d9 * d10));
}
}
}
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (float) j / 15.0F * 2.0F - 1.0F;
double d1 = (float) k / 15.0F * 2.0F - 1.0F;
double d2 = (float) l / 15.0F * 2.0F - 1.0F;
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 /= d3;
d1 /= d3;
d2 /= d3;
float f = this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos((int) d4, (int) d6, (int) d8); //TODO
BlockState blockstate = this.level.getBlockState(blockpos);
FluidState fluidstate = this.level.getFluidState(blockpos);
if (!this.level.isInWorldBounds(blockpos)) {
break;
}
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this, this.level, blockpos, blockstate, fluidstate);
if (optional.isPresent()) {
f -= (optional.get() + 0.3F) * 0.3F;
}
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this, this.level, blockpos, blockstate, f)) {
set.add(blockpos);
}
d4 += d0 * (double) 0.3F;
d6 += d1 * (double) 0.3F;
d8 += d2 * (double) 0.3F;
}
}
}
}
}
}
}
}
this.toBlow.addAll(set);
float f2 = this.radius * 2.0F;
int k1 = Mth.floor(this.x - (double) f2 - 1.0D);
int l1 = Mth.floor(this.x + (double) f2 + 1.0D);
int i2 = Mth.floor(this.y - (double) f2 - 1.0D);
int i1 = Mth.floor(this.y + (double) f2 + 1.0D);
int j2 = Mth.floor(this.z - (double) f2 - 1.0D);
int j1 = Mth.floor(this.z + (double) f2 + 1.0D);
List<Entity> list = this.level.getEntities(this.source, new AABB(k1, i2, j2, l1, i1, j1));
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.level, this, list, f2);
Vec3 vec3 = new Vec3(this.x, this.y, this.z);
/**
* Does the second part of the explosion (sound, particles, drop spawn)
*/
@Override
public void finalizeExplosion(boolean pSpawnParticles)
{
if (this.level.isClientSide)
{
this.level.playLocalSound(this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F, false);
}
for (Entity entity : list) {
if (!entity.ignoreExplosion()) {
double d12 = Math.sqrt(entity.distanceToSqr(vec3)) / (double) f2;
if (d12 <= 1.0D) {
double d5 = entity.getX() - this.x;
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
double d9 = entity.getZ() - this.z;
double d13 = Math.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 /= d13;
d7 /= d13;
d9 /= d13;
double d14 = getSeenPercent(vec3, entity);
double d10 = (1.0D - d12) * d14;
entity.hurt(this.getDamageSource(), this.damagemultiplier * (int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D));
double d11 = d10;
if (entity instanceof LivingEntity) {
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10);
}
boolean flag = this.blockInteraction != BlockInteraction.NONE;
if (pSpawnParticles)
{
if (!(this.radius < 2.0F) && flag)
{
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
else
{
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
if (flag)
{
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
Collections.shuffle(this.toBlow, new Random(this.level.random.nextInt()));
for (BlockPos blockpos : this.toBlow)
{
BlockState blockstate = this.level.getBlockState(blockpos);
Block block = blockstate.getBlock();
if (!blockstate.isAir())
{
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (blockstate.canDropFromExplosion(this.level, blockpos, this) && this.level instanceof ServerLevel)
{
BlockEntity blockentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerLevel)this.level)).withRandom(this.level.random).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (this.blockInteraction == BlockInteraction.DESTROY)
{
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
}
blockstate.getDrops(lootcontext$builder).forEach((p_46074_) -> {
addBlockDrops(objectarraylist, p_46074_, blockpos1);
});
}
blockstate.onBlockExploded(this.level, blockpos, this);
this.level.getProfiler().pop();
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof Player) {
Player player = (Player) entity;
if (!player.isSpectator() && (!player.isCreative() || !player.getAbilities().flying)) {
this.hitPlayers.put(player, new Vec3(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
for (Pair<ItemStack, BlockPos> pair : objectarraylist)
{
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
}
}
}
if (this.fire)
{
for (BlockPos blockpos2 : this.toBlow)
{
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below()))
{
this.level.setBlockAndUpdate(blockpos2, BaseFireBlock.getState(this.level, blockpos2));
/**
* Does the second part of the explosion (sound, particles, drop spawn)
*/
@Override
public void finalizeExplosion(boolean pSpawnParticles) {
if (this.level.isClientSide) {
this.level.playLocalSound(this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F, false);
}
boolean flag = this.blockInteraction != BlockInteraction.KEEP; //TODO
if (pSpawnParticles) {
if (!(this.radius < 2.0F) && flag) {
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
} else {
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
}
}
}
if (flag) {
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
Collections.shuffle(this.toBlow, new Random(this.level.random.nextInt()));
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> pDropPositionArray, ItemStack pStack, BlockPos pPos)
{
int i = pDropPositionArray.size();
for (BlockPos blockpos : this.toBlow) {
BlockState blockstate = this.level.getBlockState(blockpos);
Block block = blockstate.getBlock();
if (!blockstate.isAir()) {
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (blockstate.canDropFromExplosion(this.level, blockpos, this) && this.level instanceof ServerLevel) {
BlockEntity blockentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootParams.Builder lootcontext$builder = (new LootParams.Builder((ServerLevel) this.level)).withLuck(this.level.random.nextFloat()).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (this.blockInteraction == BlockInteraction.DESTROY) {
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
}
for (int j = 0; j < i; ++j)
{
Pair<ItemStack, BlockPos> pair = pDropPositionArray.get(j);
ItemStack itemstack = pair.getFirst();
if (ItemEntity.areMergable(itemstack, pStack))
{
ItemStack itemstack1 = ItemEntity.merge(itemstack, pStack, 16);
pDropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond()));
if (pStack.isEmpty())
{
return;
blockstate.getDrops(lootcontext$builder).forEach((p_46074_) -> {
addBlockDrops(objectarraylist, p_46074_, blockpos1);
});
}
blockstate.onBlockExploded(this.level, blockpos, this);
this.level.getProfiler().pop();
}
}
}
}
pDropPositionArray.add(Pair.of(pStack, pPos));
}
@Override
public DamageSource getDamageSource()
{
return this.damageSource;
}
@Override
public Map<Player, Vec3> getHitPlayers()
{
return this.hitPlayers;
}
/**
* Returns either the entity that placed the explosive block, the entity that caused the explosion or null.
*/
@Nullable
@Override
public LivingEntity getSourceMob()
{
if (this.source == null)
{
return null;
}
else if (this.source instanceof PrimedTnt)
{
return ((PrimedTnt)this.source).getOwner();
}
else if (this.source instanceof LivingEntity)
{
return (LivingEntity)this.source;
}
else
{
if (this.source instanceof Projectile)
{
Entity entity = ((Projectile)this.source).getOwner();
if (entity instanceof LivingEntity)
{
return (LivingEntity)entity;
for (Pair<ItemStack, BlockPos> pair : objectarraylist) {
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
}
}
}
return null;
}
}
if (this.fire) {
for (BlockPos blockpos2 : this.toBlow) {
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
this.level.setBlockAndUpdate(blockpos2, BaseFireBlock.getState(this.level, blockpos2));
}
}
}
@Override
public void clearToBlow()
{
this.toBlow.clear();
}
}
@Override
public List<BlockPos> getToBlow()
{
return this.toBlow;
}
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> pDropPositionArray, ItemStack pStack, BlockPos pPos) {
int i = pDropPositionArray.size();
@Override
public Vec3 getPosition()
{
return this.position;
}
for (int j = 0; j < i; ++j) {
Pair<ItemStack, BlockPos> pair = pDropPositionArray.get(j);
ItemStack itemstack = pair.getFirst();
if (ItemEntity.areMergable(itemstack, pStack)) {
ItemStack itemstack1 = ItemEntity.merge(itemstack, pStack, 16);
pDropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond()));
if (pStack.isEmpty()) {
return;
}
}
}
@Nullable
@Override
public Entity getExploder()
{
return this.source;
}
pDropPositionArray.add(Pair.of(pStack, pPos));
}
@Override
public DamageSource getDamageSource() {
return this.damageSource;
}
@Override
public Map<Player, Vec3> getHitPlayers() {
return this.hitPlayers;
}
// /**
// * Returns either the entity that placed the explosive block, the entity that caused the explosion or null.
// */
// @Nullable
// @Override
// public LivingEntity getSourceMob() {
// if (this.source == null) {
// return null;
// } else if (this.source instanceof PrimedTnt) {
// return ((PrimedTnt) this.source).getOwner();
// } else if (this.source instanceof LivingEntity) {
// return (LivingEntity) this.source;
// } else {
// if (this.source instanceof Projectile) {
// Entity entity = ((Projectile) this.source).getOwner();
// if (entity instanceof LivingEntity) {
// return (LivingEntity) entity;
// }
// }
//
// return null;
// }
// }
@Override
public void clearToBlow() {
this.toBlow.clear();
}
@Override
public List<BlockPos> getToBlow() {
return this.toBlow;
}
@Override
public Vec3 getPosition() {
return this.position;
}
@Nullable
@Override
public Entity getExploder() {
return this.source;
}
}

View File

@@ -3,12 +3,10 @@ package ru.magistu.siegemachines.entity.projectile;
import ru.magistu.siegemachines.config.MissileSpecs;
import ru.magistu.siegemachines.config.SpecsConfig;
public enum MissileType
{
public enum MissileType {
CANNONBALL(SpecsConfig.CANNONBALL, 1.5f, true, FlightType.SPINNING, 1.0f),
STONE(SpecsConfig.STONE, 1.5f, true, FlightType.SPINNING, 1.0f),
GIANT_STONE(SpecsConfig.GIANT_STONE, 3.0f, true, FlightType.SPINNING, 1.0f);
//GIANT_ARROW(SpecsConfig.GIANT_ARROW, 1.5f, false, FlightType.AHEAD, 0.5f);
public final MissileSpecs specs;
public final float knockback;
@@ -16,8 +14,7 @@ public enum MissileType
public final FlightType flighttype;
public final float armorpiercing;
MissileType(MissileSpecs specs, float knockback, boolean explosive, FlightType headingtype, float armorpiercing)
{
MissileType(MissileSpecs specs, float knockback, boolean explosive, FlightType headingtype, float armorpiercing) {
this.specs = specs;
this.knockback = knockback;
this.explosive = explosive;

View File

@@ -1,19 +1,18 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import ru.magistu.siegemachines.entity.EntityTypes;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Arrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import ru.magistu.siegemachines.entity.EntityTypes;
import ru.magistu.siegemachines.item.ModItems;
public class ProjectileBuilder<T extends Projectile>
{
public class ProjectileBuilder<T extends Projectile> {
public final static ProjectileBuilder<Stone> NONE = new ProjectileBuilder<>(Items.AIR, EntityTypes.STONE.get(), Stone::new);
public final static ProjectileBuilder<?>[] NO_AMMO = new ProjectileBuilder[]{};
@@ -37,21 +36,18 @@ public class ProjectileBuilder<T extends Projectile>
public final EntityType<T> entitytype;
public final IProjectileFactory<T> factory;
public ProjectileBuilder(Item item, EntityType<T> entitytype, IProjectileFactory<T> factory)
{
public ProjectileBuilder(Item item, EntityType<T> entitytype, IProjectileFactory<T> factory) {
this(item, item, entitytype, factory);
}
public ProjectileBuilder(Item item, Item projectilitem, EntityType<T> entitytype, IProjectileFactory<T> factory)
{
public ProjectileBuilder(Item item, Item projectilitem, EntityType<T> entitytype, IProjectileFactory<T> factory) {
this.item = item;
this.projectilitem = projectilitem;
this.entitytype = entitytype;
this.factory = factory;
}
public T build(Level level, Vector3d pos, LivingEntity entity)
{
public T build(Level level, Vec3 pos, LivingEntity entity) {
return this.factory.create(this.entitytype, level, pos, entity, this.item);
}
}

View File

@@ -1,22 +1,19 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import ru.magistu.siegemachines.item.ModItems;
public class Stone extends Missile
{
public Stone(EntityType<Stone> entitytype, Level level)
{
super(entitytype, level);
this.item = ModItems.STONE.get();
}
public class Stone extends Missile {
public Stone(EntityType<Stone> entitytype, Level level) {
super(entitytype, level);
this.item = ModItems.STONE.get();
}
public Stone(EntityType<Stone> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item)
{
super(entitytype, level, pos, entity, MissileType.STONE, item);
}
public Stone(EntityType<Stone> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item) {
super(entitytype, level, pos, entity, MissileType.STONE, item);
}
}