fix antigravel and upward falling blocks
This commit is contained in:
1 parent
ea24b19068
commit
313c54e8d6
8 files changed
+55
-57
No files matched your search
+1
-3
@@ -34,9 +34,7 @@ public class AntigravelBlock extends Block {
|
||||
|
||||
@Override
|
||||
protected BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) {
|
||||
if (direction == Direction.UP) {
|
||||
level.scheduleTick(pos, this, 2);
|
||||
}
|
||||
level.scheduleTick(pos, this, 2);
|
||||
return super.updateShape(state, direction, neighborState, level, pos, neighborPos);
|
||||
}
|
||||
|
||||
|
||||
+13
-11
@@ -11,6 +11,7 @@ import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -28,15 +29,17 @@ public class UpwardFallingBlockEntity extends Entity {
|
||||
private static final EntityDataAccessor<BlockState> DATA_BLOCK_STATE =
|
||||
SynchedEntityData.defineId(UpwardFallingBlockEntity.class, EntityDataSerializers.BLOCK_STATE);
|
||||
|
||||
private static final double RISE_SPEED = 0.5;
|
||||
private static final double RISE_ACCEL = 0.04;
|
||||
private static final double DRAG = 0.98;
|
||||
private static final int MAX_TICKS = 200;
|
||||
|
||||
public int time = 0;
|
||||
private boolean breaksOnLeaves = true;
|
||||
private double distanceTraveled = 0.0;
|
||||
|
||||
public UpwardFallingBlockEntity(EntityType<UpwardFallingBlockEntity> type, Level level) {
|
||||
super(type, level);
|
||||
this.noPhysics = true;
|
||||
this.blocksBuilding = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,10 +81,11 @@ public class UpwardFallingBlockEntity extends Entity {
|
||||
return;
|
||||
}
|
||||
|
||||
// Move upward directly — noPhysics=true means move() just calls setPos().
|
||||
// Runs on both sides so the client simulates the same deterministic rise
|
||||
// instead of relying on interpolated network updates, matching vanilla FallingBlockEntity.
|
||||
setPos(getX(), getY() + RISE_SPEED, getZ());
|
||||
double beforeY = getY();
|
||||
setDeltaMovement(getDeltaMovement().add(0.0, RISE_ACCEL, 0.0));
|
||||
move(MoverType.SELF, getDeltaMovement());
|
||||
setDeltaMovement(getDeltaMovement().scale(DRAG));
|
||||
distanceTraveled += Math.max(0.0, getY() - beforeY);
|
||||
|
||||
if (level().isClientSide) return;
|
||||
|
||||
@@ -93,7 +97,7 @@ public class UpwardFallingBlockEntity extends Entity {
|
||||
|
||||
damageEntitiesAlongPath(blockState);
|
||||
|
||||
BlockPos headPos = BlockPos.containing(getX(), getY() + getBbHeight(), getZ());
|
||||
BlockPos headPos = BlockPos.containing(getX(), getBoundingBox().maxY, getZ());
|
||||
BlockState above = level().getBlockState(headPos);
|
||||
|
||||
// Leaves block the entity but can't hold scaffolding — drop as item, unless this
|
||||
@@ -103,10 +107,9 @@ public class UpwardFallingBlockEntity extends Entity {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean hitCeiling = !above.isAir() && !above.getCollisionShape(level(), headPos).isEmpty();
|
||||
boolean hitScaffolding = above.getBlock() instanceof AntimetalScaffoldingBlock;
|
||||
|
||||
if (hitCeiling || hitScaffolding) {
|
||||
if (this.verticalCollision || hitScaffolding) {
|
||||
placeAtLanding(blockState, headPos.below());
|
||||
return;
|
||||
}
|
||||
@@ -138,8 +141,7 @@ public class UpwardFallingBlockEntity extends Entity {
|
||||
}
|
||||
|
||||
private float getImpactDamage(BlockState state) {
|
||||
float travelDistance = (float) this.time * (float) RISE_SPEED;
|
||||
float baseDamage = Math.max(0.0F, travelDistance - 1.5F);
|
||||
float baseDamage = Math.max(0.0F, (float) this.distanceTraveled - 1.5F);
|
||||
if (baseDamage <= 0.0F) {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
+17
-18
@@ -10,6 +10,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
@@ -17,6 +18,7 @@ public final class ThoraxisUndersideManager {
|
||||
public static final int GRAVITY_FLIP_Y = 0;
|
||||
private static final ResourceLocation THORAXIS_DIMENSION = ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "thoraxis");
|
||||
private static final AntarchyGravityTransition TRANSITION = new AntarchyGravityTransition(12);
|
||||
private static final int EFFECT_DURATION_TICKS = 40;
|
||||
private static final Set<UUID> UNDERSIDE_FORCED_GRAVITY = new HashSet<>();
|
||||
|
||||
private ThoraxisUndersideManager() {
|
||||
@@ -33,8 +35,19 @@ public final class ThoraxisUndersideManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean inUnderside = entity.getY() < GRAVITY_FLIP_Y;
|
||||
|
||||
if (entity instanceof LivingEntity living) {
|
||||
if (inUnderside) {
|
||||
living.addEffect(new MobEffectInstance(AntarchyObjects.INVERTED_EFFECT.get(), EFFECT_DURATION_TICKS, 0, true, false, false));
|
||||
} else if (living.hasEffect(AntarchyObjects.INVERTED_EFFECT.get())) {
|
||||
living.removeEffect(AntarchyObjects.INVERTED_EFFECT.get());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
UUID uuid = entity.getUUID();
|
||||
if (entity.getY() < GRAVITY_FLIP_Y) {
|
||||
if (inUnderside) {
|
||||
activeThisTick.add(uuid);
|
||||
UNDERSIDE_FORCED_GRAVITY.add(uuid);
|
||||
if (AntarchyGravityApi.getGravityDirection(entity) != AntarchyGravityDirection.UP
|
||||
@@ -44,11 +57,9 @@ public final class ThoraxisUndersideManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!UNDERSIDE_FORCED_GRAVITY.remove(uuid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (shouldReleaseGravity(entity)) {
|
||||
if (UNDERSIDE_FORCED_GRAVITY.remove(uuid)
|
||||
&& AntarchyGravityApi.getGravityDirection(entity) == AntarchyGravityDirection.UP
|
||||
&& AntarchyGravityApi.isGravityForced(entity)) {
|
||||
AntarchyGravityApi.setGravityDirection(entity, AntarchyGravityDirection.DOWN, false, TRANSITION);
|
||||
}
|
||||
}
|
||||
@@ -56,18 +67,6 @@ public final class ThoraxisUndersideManager {
|
||||
UNDERSIDE_FORCED_GRAVITY.retainAll(activeThisTick);
|
||||
}
|
||||
|
||||
private static boolean shouldReleaseGravity(Entity entity) {
|
||||
if (AntarchyGravityApi.getGravityDirection(entity) != AntarchyGravityDirection.UP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity instanceof LivingEntity living && living.hasEffect(AntarchyObjects.INVERTED_EFFECT.get())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return AntarchyGravityApi.isGravityForced(entity);
|
||||
}
|
||||
|
||||
public static boolean isThoraxis(ServerLevel level) {
|
||||
return level.dimension().location().equals(THORAXIS_DIMENSION);
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
"argument1": {
|
||||
"type": "minecraft:y_clamped_gradient",
|
||||
"from_y": -256,
|
||||
"to_y": -16,
|
||||
"to_y": -1,
|
||||
"from_value": -2.0,
|
||||
"to_value": 1.05
|
||||
},
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@
|
||||
"from_value": 0.0,
|
||||
"from_y": -8,
|
||||
"to_value": 1.0,
|
||||
"to_y": 24
|
||||
"to_y": 4
|
||||
},
|
||||
"argument2": -2.5
|
||||
},
|
||||
@@ -150,7 +150,7 @@
|
||||
"type": "minecraft:y_above",
|
||||
"add_stone_depth": false,
|
||||
"anchor": {
|
||||
"absolute": 4
|
||||
"absolute": 1
|
||||
},
|
||||
"surface_depth_multiplier": 0
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user