parent
e47c370a96
commit
4997714e43
@ -53,6 +53,7 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
private BigDecimal mass = NORMAL_MASS;
|
||||
private double gravitation_strength = 1;
|
||||
private boolean suppress_updates = true;
|
||||
public boolean spin_direction = false;
|
||||
|
||||
public double getGravitationStrength() {
|
||||
return gravitation_strength;
|
||||
@ -321,12 +322,15 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
// shared functions
|
||||
public CompoundTag writeBlackHoleData(CompoundTag tag) {
|
||||
tag.putString("mass", mass.toString());
|
||||
tag.putBoolean("spin_direction", spin_direction);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void readBlackHoleData(CompoundTag tag) {
|
||||
if (tag.get("mass") instanceof StringTag str)
|
||||
setMass(new BigDecimal(str.getAsString()));
|
||||
|
||||
spin_direction = tag.getBoolean("spin_direction");
|
||||
}
|
||||
|
||||
// disk io
|
||||
@ -384,12 +388,25 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
return affected_bounds_aabb;
|
||||
}
|
||||
|
||||
private void setDeltaMovement(Entity living, Vec3 center, double distance) {
|
||||
private void setDeltaMovement(Entity living, Vec3 center, double distance, boolean weaker) {
|
||||
//final double mult = Math.min(2, (30 * this.gravitation_strength) / Math.max(1, Math.pow(distance, 2)));
|
||||
// Сила притяжения
|
||||
final double mult = Math.pow(1 - distance / (30 * this.gravitation_strength), 2) * this.gravitation_strength / 8;
|
||||
|
||||
// Притяжение к ядру
|
||||
final var delta = living.position().vectorTo(center).normalize();
|
||||
living.setDeltaMovement(living.getDeltaMovement().add(delta.multiply(mult, mult, mult)));
|
||||
|
||||
if (distance < this.gravitation_strength) {
|
||||
living.setDeltaMovement(living.getDeltaMovement().add(delta.multiply(mult, mult, mult)));
|
||||
} else {
|
||||
// Закручивание
|
||||
final var rotate = spin_direction ? delta.yRot((float) (Math.PI / 2)) : delta.yRot((float) (-Math.PI / 2));
|
||||
|
||||
if (weaker)
|
||||
living.setDeltaMovement(living.getDeltaMovement().add(rotate.multiply(mult * 0.4f, mult * 0.4f, mult * 0.4f)).add(delta.multiply(mult * 0.33f, mult * 0.33f, mult * 0.33f)));
|
||||
else
|
||||
living.setDeltaMovement(living.getDeltaMovement().add(rotate.multiply(mult * 0.4f, mult * 0.4f, mult * 0.4f)).add(delta.multiply(mult, mult, mult)));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends BlockEntity> void clientTicker(Level level, BlockPos blockPos, BlockState blockState, T t) {
|
||||
@ -399,12 +416,12 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
|
||||
if (!ply.getAbilities().mayfly) {
|
||||
final double distance = ply.position().distanceTo(center);
|
||||
tile.setDeltaMovement(ply, center, distance);
|
||||
tile.setDeltaMovement(ply, center, distance, true);
|
||||
}
|
||||
|
||||
for (var item : tile.level.getEntitiesOfClass(ItemEntity.class, tile.affected_bounds_aabb)) {
|
||||
final double distance = item.position().distanceTo(center);
|
||||
tile.setDeltaMovement(item, center, distance);
|
||||
tile.setDeltaMovement(item, center, distance, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -421,7 +438,7 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
final double distance = living.position().distanceTo(center);
|
||||
|
||||
if (!(living instanceof Player ply) || !ply.getAbilities().mayfly) {
|
||||
tile.setDeltaMovement(living, center, distance);
|
||||
tile.setDeltaMovement(living, center, distance, false);
|
||||
}
|
||||
|
||||
if (distance < tile.gravitation_strength + 1) {
|
||||
@ -431,7 +448,7 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
|
||||
for (var item : level.getEntitiesOfClass(ItemEntity.class, tile.affected_bounds_aabb)) {
|
||||
final double distance = item.position().distanceTo(center);
|
||||
tile.setDeltaMovement(item, center, distance);
|
||||
tile.setDeltaMovement(item, center, distance, false);
|
||||
|
||||
if (distance < tile.gravitation_strength + 1) {
|
||||
if (item.hurt(Registry.DAMAGE_EVENT_HORIZON, (float) (tile.gravitation_strength / distance)) && item.isRemoved()) {
|
||||
|
Loading…
Reference in New Issue
Block a user