Skip to content

Commit

Permalink
Apparitions can't go in or out of Ectoplasm Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Dec 22, 2024
1 parent 42a2f12 commit 0190d41
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.frozenblock.lib.block.api.shape.FrozenShapes;
import net.frozenblock.trailiertales.entity.Apparition;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.EntityCollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

public class EctoplasmBlock extends HalfTransparentBlock {
public static final VoxelShape COLLISION_SHAPE = Shapes.empty();
public static final float APPARITION_COLLISION_FROM_SIDE = 0.25F;
public static final int LIGHT_BLOCK = 2;
public static final double GRAVITY_SLOWDOWN = 0.4D;
public static final MapCodec<EctoplasmBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> instance.group(
propertiesCodec()
).apply(instance, EctoplasmBlock::new));

public EctoplasmBlock(@NotNull Properties properties) {
super(properties.pushReaction(PushReaction.DESTROY));
super(properties);
}

@NotNull
Expand All @@ -35,12 +37,19 @@ protected MapCodec<? extends EctoplasmBlock> codec() {
@Override
@NotNull
public VoxelShape getCollisionShape(@NotNull BlockState blockState, @NotNull BlockGetter blockGetter, @NotNull BlockPos blockPos, @NotNull CollisionContext collisionContext) {
VoxelShape shape = Shapes.empty();

if (collisionContext instanceof EntityCollisionContext entityCollisionContext) {
if (entityCollisionContext.getEntity() instanceof Apparition) {
return super.getCollisionShape(blockState, blockGetter, blockPos, collisionContext);
for (Direction direction : Direction.values()) {
if (!blockGetter.getBlockState(blockPos.relative(direction)).is(this)) {
shape = Shapes.or(shape, FrozenShapes.makePlaneFromDirection(direction, APPARITION_COLLISION_FROM_SIDE));
}
}
}
}
return COLLISION_SHAPE;

return shape;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,13 @@ public void move(MoverType movementType, Vec3 movement) {
this.minorHorizontalCollision = false;
}

this.setOnGroundWithMovement(this.verticalCollisionBelow, vec3);
if (this.isRemoved()) {
this.level().getProfiler().pop();
} else {
if (this.horizontalCollision) {
Vec3 vec32 = this.getDeltaMovement();
this.setDeltaMovement(horizontalCollisionX ? 0D : vec32.x, vec32.y, horizontalCollisionZ ? 0D : vec32.z);
}
this.tryCheckInsideBlocks();
float h = this.getBlockSpeedFactor();
this.setDeltaMovement(this.getDeltaMovement().multiply(h, 1D, h));

this.level().getProfiler().pop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ public class TTBlocks {
.sound(SoundType.WOOL)
.isSuffocating(Blocks::never)
.isViewBlocking(Blocks::never)
.pushReaction(PushReaction.DESTROY)
.dynamicShape()
.requiredFeatures(TTFeatureFlags.FEATURE_FLAG)
);

Expand Down

0 comments on commit 0190d41

Please sign in to comment.