Fix repulsion
This commit is contained in:
parent
dad0f91d93
commit
27a28d1f23
@ -6,7 +6,7 @@ minecraft_version=1.21
|
|||||||
yarn_mappings=1.21+build.9
|
yarn_mappings=1.21+build.9
|
||||||
loader_version=0.16.0
|
loader_version=0.16.0
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.6
|
mod_version=1.7
|
||||||
maven_group=systems.brn
|
maven_group=systems.brn
|
||||||
archives_base_name=plasticgun
|
archives_base_name=plasticgun
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
@ -88,17 +88,17 @@ public class PlasticGun implements ModInitializer {
|
|||||||
bullets.add(new BulletItem("force_container", 99, 0, 888, false, 0, 1));
|
bullets.add(new BulletItem("force_container", 99, 0, 888, false, 0, 1));
|
||||||
|
|
||||||
// Guns
|
// Guns
|
||||||
guns.add(new Gun("forcegun", 0, 2, 5, 20, 10, 888, 0, 0, 20, 0f, 0f, 5f, 10f, 0, 0)); // 0
|
guns.add(new Gun("forcegun", 0, 4, 5, 10, 10, 888, 5, 0, 2, 0f, 0f, 5f, 10f, 0, 0)); // 0
|
||||||
guns.add(new Gun("p2022", 0.2, 12, 5, 10, 41, 9, 5, 0, 0, 1f, 4, 0.1f, 0.25f, -1, 1)); // 1.8
|
guns.add(new Gun("p2022", 0.2, 12, 5, 10, 41, 9, 10, 0, 0, 1f, 4, 0.1f, 0.25f, -1, 1)); // 1.8
|
||||||
guns.add(new Gun("colt_1903", 0.3, 10, 5, 8, 38, 32, 5, 0, 0, 1, 3, 0.1f, 0.3f, -1, 1)); // 3
|
guns.add(new Gun("colt_1903", 0.3, 10, 5, 8, 38, 32, 10, 0, 0, 1, 3, 0.1f, 0.3f, -1, 1)); // 3
|
||||||
guns.add(new Gun("ak_47", 0.2, 4, 5, 30, 45, 762, 0, 0, 0, 1f, 2, 0.2f, 0.4f, -1, 1)); // 9
|
guns.add(new Gun("ak_47", 0.2, 4, 5, 30, 45, 762, 1, 0, 0, 1f, 2, 0.2f, 0.4f, -1, 1)); // 9
|
||||||
guns.add(new Gun("colt_45", 0.4, 9, 5, 7, 48, 45, 5, 0, 0, 1.5f, 2, 0.15f, 0.4f, -1, 1)); // 3.6
|
guns.add(new Gun("colt_45", 0.4, 9, 5, 7, 48, 45, 10, 0, 0, 1.5f, 2, 0.15f, 0.4f, -1, 1)); // 3.6
|
||||||
guns.add(new Gun("snub_nosed_revolver", 0.4, 7, 3, 5, 36, 38, 14, 0, 0, 1f, 2, 0.2f, 0.45f, -1, 1)); // 2.8
|
guns.add(new Gun("snub_nosed_revolver", 0.4, 7, 3, 5, 36, 38, 20, 0, 0, 1f, 2, 0.2f, 0.45f, -1, 1)); // 2.8
|
||||||
guns.add(new Gun("colt_peacemaker", 0.6, 8, 5, 6, 43, 45, 5, 0, 0, 0.9f, 2, 0.2f, 0.5f, -1, 1)); // 4.8
|
guns.add(new Gun("colt_peacemaker", 0.6, 8, 5, 6, 43, 45, 10, 0, 0, 0.9f, 2, 0.2f, 0.5f, -1, 1)); // 4.8
|
||||||
guns.add(new Gun("tokarev_tt_33", 0.7, 10, 5, 8, 45, 762, 5, 0, 0, 1.5f, 2.5f, 0.25f, 0.5f, -1, 1)); // 7
|
guns.add(new Gun("tokarev_tt_33", 0.7, 10, 5, 8, 45, 762, 10, 0, 0, 1.5f, 2.5f, 0.25f, 0.5f, -1, 1)); // 7
|
||||||
guns.add(new Gun("357_revolver", 1, 8, 5, 6, 45, 357, 14, 0, 0, 2, 4, 0.2f, 0.5f, -1, 1)); // 8
|
guns.add(new Gun("357_revolver", 1, 8, 5, 6, 45, 357, 20, 0, 0, 2, 4, 0.2f, 0.5f, -1, 1)); // 8
|
||||||
guns.add(new Gun("awp", 1, 4, 20, 1, 75, 762, 20, 0, 0, 2f, 8, 0.3f, 0.6f, -1, 1)); // 4
|
guns.add(new Gun("awp", 1, 4, 20, 1, 75, 762, 40, 0, 0, 2f, 8, 0.3f, 0.6f, -1, 1)); // 4
|
||||||
guns.add(new Gun("rpg9", 2, 4, 20, 1, 10, 999, 8, 20, 0, 3f, 0.5f, 1, 2, -1, 1)); // 8
|
guns.add(new Gun("rpg9", 2, 4, 20, 1, 10, 999, 20, 20, 0, 3f, 0.5f, 1, 2, -1, 1)); // 8
|
||||||
|
|
||||||
|
|
||||||
grenades.add(new GrenadeItem("grenade_m18", 1, 0.1f, 0.2f, 50, false, false, 0, 0, 100, 15, 30)); // 0.02
|
grenades.add(new GrenadeItem("grenade_m18", 1, 0.1f, 0.2f, 50, false, false, 0, 0, 100, 15, 30)); // 0.02
|
||||||
|
@ -104,7 +104,7 @@ public class BulletEntity extends PersistentProjectileEntity implements PolymerE
|
|||||||
this.setOnFire(true);
|
this.setOnFire(true);
|
||||||
super.onBlockHit(blockHitResult);
|
super.onBlockHit(blockHitResult);
|
||||||
this.setOnFire(false);
|
this.setOnFire(false);
|
||||||
hitDamage(blockHitResult.getPos(), explosionPower, repulsionPower, getWorld(), this, isIncendiary, 5, null);
|
hitDamage(blockHitResult.getPos(), explosionPower, repulsionPower, getWorld(), this, isIncendiary, null);
|
||||||
this.discard();
|
this.discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ public class BulletEntity extends PersistentProjectileEntity implements PolymerE
|
|||||||
}
|
}
|
||||||
|
|
||||||
super.onEntityHit(entityHitResult);
|
super.onEntityHit(entityHitResult);
|
||||||
hitDamage(entityHitResult.getPos(), explosionPower, repulsionPower, getWorld(), this, isIncendiary, 5, null);
|
hitDamage(entityHitResult.getPos(), explosionPower, repulsionPower, getWorld(), this, isIncendiary, null);
|
||||||
this.discard();
|
this.discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public class GrenadeEntity extends ThrowableProjectile implements PolymerEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void explode() {
|
private void explode() {
|
||||||
hitDamage(getPos(), explosionPower, repulsionPower, getWorld(), this, isIncendiary, effectRadius, isFragmentation ? new FragmentationExplosionBehavior() : new GrenadeExplosionBehavior());
|
hitDamage(getPos(), explosionPower, repulsionPower, getWorld(), this, isIncendiary, isFragmentation ? new FragmentationExplosionBehavior() : new GrenadeExplosionBehavior());
|
||||||
List<Entity> nearbyEntities = getEntitiesAround(this, effectRadius);
|
List<Entity> nearbyEntities = getEntitiesAround(this, effectRadius);
|
||||||
if (stunDuration > 0) {
|
if (stunDuration > 0) {
|
||||||
for (Entity entity : nearbyEntities) {
|
for (Entity entity : nearbyEntities) {
|
||||||
|
@ -9,14 +9,19 @@ import net.minecraft.client.render.model.json.ModelTransformationMode;
|
|||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
import net.minecraft.entity.attribute.EntityAttributes;
|
||||||
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
import net.minecraft.entity.data.DataTracker;
|
import net.minecraft.entity.data.DataTracker;
|
||||||
import net.minecraft.entity.decoration.DisplayEntity;
|
import net.minecraft.entity.decoration.DisplayEntity;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.inventory.Inventory;
|
import net.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.particle.ParticleTypes;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.tag.BlockTags;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.Pair;
|
import net.minecraft.util.Pair;
|
||||||
import net.minecraft.util.math.Box;
|
import net.minecraft.util.math.Box;
|
||||||
@ -26,6 +31,7 @@ import net.minecraft.util.math.random.Random;
|
|||||||
import net.minecraft.world.Difficulty;
|
import net.minecraft.world.Difficulty;
|
||||||
import net.minecraft.world.LocalDifficulty;
|
import net.minecraft.world.LocalDifficulty;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.explosion.AdvancedExplosionBehavior;
|
||||||
import net.minecraft.world.explosion.Explosion;
|
import net.minecraft.world.explosion.Explosion;
|
||||||
import net.minecraft.world.explosion.ExplosionBehavior;
|
import net.minecraft.world.explosion.ExplosionBehavior;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -34,7 +40,9 @@ import systems.brn.plasticgun.PlasticGun;
|
|||||||
import systems.brn.plasticgun.defence.WeaponArmor;
|
import systems.brn.plasticgun.defence.WeaponArmor;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import static net.minecraft.entity.projectile.AbstractWindChargeEntity.EXPLOSION_BEHAVIOR;
|
||||||
import static net.minecraft.world.explosion.Explosion.getExposure;
|
import static net.minecraft.world.explosion.Explosion.getExposure;
|
||||||
import static systems.brn.plasticgun.PlasticGun.MOD_ID;
|
import static systems.brn.plasticgun.PlasticGun.MOD_ID;
|
||||||
import static systems.brn.plasticgun.PlasticGun.weaponArmors;
|
import static systems.brn.plasticgun.PlasticGun.weaponArmors;
|
||||||
@ -136,36 +144,6 @@ public class Util {
|
|||||||
return entity.getEntityWorld().getOtherEntities(entity, box);
|
return entity.getEntityWorld().getOtherEntities(entity, box);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void applyKnockbackToEntities(Entity explodingEntity, Vec3d explosionPos, double power, double radius) {
|
|
||||||
List<Entity> entities = getEntitiesAround(explodingEntity, radius);
|
|
||||||
|
|
||||||
for (Entity entity : entities) {
|
|
||||||
double distanceRatio = Math.sqrt(entity.squaredDistanceTo(explosionPos)) / power;
|
|
||||||
if (distanceRatio > 1.0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
double dx = entity.getX() - explosionPos.x;
|
|
||||||
double dy = entity.getY() - explosionPos.y;
|
|
||||||
double dz = entity.getZ() - explosionPos.z;
|
|
||||||
double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
||||||
|
|
||||||
if (distance == 0.0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
dx /= distance;
|
|
||||||
dy /= distance;
|
|
||||||
dz /= distance;
|
|
||||||
|
|
||||||
double knockbackStrength = (1.0 - distanceRatio) * getExposure(explosionPos, entity);
|
|
||||||
double knockback = knockbackStrength * (1.0 - (entity instanceof LivingEntity livingEntity ? livingEntity.getAttributeValue(EntityAttributes.GENERIC_EXPLOSION_KNOCKBACK_RESISTANCE) : 0.0));
|
|
||||||
|
|
||||||
Vec3d knockbackVec = new Vec3d(dx * knockback, dy * knockback, dz * knockback);
|
|
||||||
entity.setVelocity(entity.getVelocity().add(knockbackVec));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setProjectileData(List<DataTracker.SerializedEntry<?>> data, boolean initial, float scale, ItemStack itemStack) {
|
public static void setProjectileData(List<DataTracker.SerializedEntry<?>> data, boolean initial, float scale, ItemStack itemStack) {
|
||||||
if (initial) {
|
if (initial) {
|
||||||
data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.TELEPORTATION_DURATION, 2));
|
data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.TELEPORTATION_DURATION, 2));
|
||||||
@ -176,13 +154,13 @@ public class Util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void hitDamage(Vec3d pos, double explosionPower, double repulsionPower, World worldTemp, @Nullable Entity entity, boolean isIncendiary, int radius, @Nullable ExplosionBehavior explosionBehavior) {
|
public static void hitDamage(Vec3d pos, double explosionPower, double repulsionPower, World worldTemp, @Nullable Entity entity, boolean isIncendiary, @Nullable ExplosionBehavior explosionBehavior) {
|
||||||
if (worldTemp instanceof ServerWorld world) {
|
if (worldTemp instanceof ServerWorld world) {
|
||||||
if (explosionPower > 0) {
|
if (explosionPower > 0) {
|
||||||
world.createExplosion(entity, Explosion.createDamageSource(world, entity), explosionBehavior, pos.getX(), pos.getY(), pos.getZ(), (float) explosionPower, isIncendiary, ServerWorld.ExplosionSourceType.TNT);
|
world.createExplosion(entity, Explosion.createDamageSource(world, entity), explosionBehavior, pos.getX(), pos.getY(), pos.getZ(), (float) explosionPower, isIncendiary, ServerWorld.ExplosionSourceType.TNT);
|
||||||
}
|
}
|
||||||
if (repulsionPower > 0) {
|
if (repulsionPower > 0) {
|
||||||
applyKnockbackToEntities(entity, pos, repulsionPower * 100, radius);
|
world.createExplosion(entity, null, new AdvancedExplosionBehavior(false, false, Optional.empty(), Optional.empty()), pos.getX(), pos.getY(), pos.getZ(), (float) repulsionPower, false, World.ExplosionSourceType.TRIGGER, ParticleTypes.GUST_EMITTER_SMALL, ParticleTypes.GUST_EMITTER_LARGE, SoundEvents.ENTITY_BREEZE_WIND_BURST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user