Skip to content

Commit

Permalink
Blocks now disappear client-side when bumped
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Nov 12, 2024
1 parent 7442574 commit 3f95353
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 9 deletions.
33 changes: 31 additions & 2 deletions src/main/java/com/floralquafloral/BlockBumping.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.moveable.MarioMainClientData;
import com.floralquafloral.util.MarioSFX;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;

import java.util.HashMap;
import java.util.Map;

public abstract class BlockBumping {
public static final Map<BlockPos, BumpedBlockData> BUMPED_BLOCKS = new HashMap<>();
public static BlockPos SAVED_POSITION = null;

public static void registerPackets() {

Expand All @@ -22,8 +32,27 @@ public static void attempt(MarioMainClientData data, Vec3d movement) {

}

public static void bumpBlock(MarioData data, BlockPos position, boolean isCeiling, int strength) {
MarioQuaMario.LOGGER.info("{} bumped block {}", data.getMario(), position);
public static void bumpBlocks(MarioMainClientData data, ClientWorld world, Iterable<BlockPos> blocks, Direction direction, int strength) {
int bumpCount = 0;
double bumpX = 0, bumpY = 0, bumpZ = 0;
for(BlockPos bumpPos : blocks) {
bumpPos = new BlockPos(bumpPos);
BUMPED_BLOCKS.put(bumpPos, new BumpedBlockData());
Vec3d centerPos = bumpPos.toCenterPos();
bumpCount++;
bumpX += centerPos.x; bumpY += centerPos.y; bumpZ += centerPos.z;
BlockState bumpBlockState = world.getBlockState(bumpPos);
world.updateListeners(bumpPos, bumpBlockState, bumpBlockState, Block.NOTIFY_ALL);
}

if(bumpCount > 0) {
long seed = Random.create().nextLong();
data.playSoundEvent(
MarioSFX.BUMP, SoundCategory.BLOCKS,
bumpX / bumpCount, bumpY / bumpCount, bumpZ / bumpCount,
1.0F, 1.0F, seed
);
}
}

public static class BumpedBlockData {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/floralquafloral/mixin/BlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.floralquafloral.mixin;

import com.floralquafloral.BlockBumping;
import com.floralquafloral.MarioQuaMario;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

@Mixin(Block.class)
public abstract class BlockMixin {
/**
* this implementation is YUCKY i would strongly prefer something in the chunk building stuff or something.
* maybe in SectionBuilder? to make it think the block is transparent when building?
* as opposed to this dumb approach. >:(
* but i don't know how to do that. ;-;
*/
@Inject(method = "shouldDrawSide", at = @At("HEAD"), cancellable = true)
private static void uwuuber(BlockState state, BlockView world, BlockPos pos, Direction side, BlockPos otherPos, CallbackInfoReturnable<Boolean> cir) {
if(BlockBumping.BUMPED_BLOCKS.containsKey(otherPos)) cir.setReturnValue(true);
}
}
66 changes: 61 additions & 5 deletions src/main/java/com/floralquafloral/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,30 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.block.BlockState;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockCollisionSpliterator;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Mixin(Entity.class)
public abstract class EntityMixin {
@Inject(at = @At("HEAD"), method = "setSwimming(Z)V", cancellable = true)
Expand Down Expand Up @@ -74,7 +82,17 @@ private void preventStepSounds(BlockPos pos, BlockState state, CallbackInfo ci)

@Inject(method = "move", at = @At("HEAD"), cancellable = true)
private void executeStompsOnServer(MovementType movementType, Vec3d movement, CallbackInfo ci) {
if((Entity) (Object) this instanceof ServerPlayerEntity mario && shouldStompHook) {
Entity entity = (Entity) (Object) this;
// if(entity instanceof ServerPlayerEntity) {
//// Iterable<VoxelShape> uwu = entity.getWorld().getBlockCollisions(entity, entity.getBoundingBox());
// Iterable<BlockPos> uwu = () -> new BlockCollisionSpliterator<>(entity.getWorld(), entity, entity.getBoundingBox().stretch(movement), false, (pos, voxelShape) -> pos);
//
// for(BlockPos uwuuber : uwu) {
// MarioQuaMario.LOGGER.info("POS: " + uwuuber);
// entity.getWorld().breakBlock(uwuuber, true, entity);
// }
// }
if(entity instanceof ServerPlayerEntity mario && shouldStompHook) {
MarioData data = MarioDataManager.getMarioData(mario);
if(data.useMarioPhysics()) {
ParsedAction action = data.getAction();
Expand All @@ -87,13 +105,51 @@ private void executeStompsOnServer(MovementType movementType, Vec3d movement, Ca
}
}

@WrapOperation(method = "checkBlockCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onEntityCollision(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;)V"))
private void executeBumpsOnClient(BlockState instance, World world, BlockPos blockPos, Entity entity, Operation<Void> original) {
if(entity instanceof ServerPlayerEntity mario) {
// world.breakBlock(blockPos, true, mario);
@Inject(method = "move", at = @At("TAIL"))
private void uwuubersaur(MovementType movementType, Vec3d movement, CallbackInfo ci) {
if((Entity) (Object) this instanceof ClientPlayerEntity mario) {
if(mario.verticalCollision && !mario.groundCollision) {
BlockBumping.bumpBlocks(
(MarioMainClientData) MarioDataManager.getMarioData(mario),
mario.clientWorld,
() -> new BlockCollisionSpliterator<>(mario.getWorld(), mario, mario.getBoundingBox().stretch(0, 0.15, 0), false, (pos, voxelShape) -> pos),
Direction.UP,
2
);


// Iterable<BlockPos> uwu = () -> new BlockCollisionSpliterator<>(mario.getWorld(), mario, mario.getBoundingBox().stretch(0, 0.15, 0), false, (pos, voxelShape) -> pos);
//
// boolean affectMario = true;

// for(BlockPos uwuuber : uwu) {
//// MarioQuaMario.LOGGER.info("POS: " + uwuuber + "\n" + mario.getWorld().getBlockState(uwuuber));
// BlockBumping.bumpBlock(MarioDataManager.getMarioData(mario), uwuuber, Direction.UP, 2);
// break;
//// mario.getWorld().breakBlock(uwuuber, true, mario);
// }
}
}
}


// @WrapOperation(method = "checkBlockCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onEntityCollision(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;)V"))
// private void executeBumpsOnClient(BlockState instance, World world, BlockPos blockPos, Entity entity, Operation<Void> original) {
// if(entity instanceof ServerPlayerEntity mario) {
//// world.breakBlock(blockPos, true, mario);
// }
// }

// @Inject(method = "findCollisionsForMovement", at = @At("TAIL"))
// private static void testasaur(@Nullable Entity entity, World world, List<VoxelShape> regularCollisions, Box movingEntityBoundingBox, CallbackInfoReturnable<List<VoxelShape>> cir) {
// if(entity instanceof ClientPlayerEntity clientPlayer) {
// MarioQuaMario.LOGGER.info("findCollisionsForMovement on Mario!");
// for(VoxelShape shape : cir.getReturnValue()) {
// MarioQuaMario.LOGGER.info("Uwu: " + shape.);
// }
// }
// }

@Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("HEAD"))
private void setMountedAction(Entity entity, boolean force, CallbackInfoReturnable<Boolean> cir) {
if((Entity) (Object) this instanceof PlayerEntity mario) {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/floralquafloral/mixin/SectionBuilderMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.floralquafloral.mixin;

import com.floralquafloral.BlockBumping;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.BlockRenderType;
import net.minecraft.client.render.chunk.SectionBuilder;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(SectionBuilder.class)
public class SectionBuilderMixin {
@ModifyExpressionValue(method = "build", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getRenderType()Lnet/minecraft/block/BlockRenderType;"))
private BlockRenderType preventRender(BlockRenderType original, @Local(ordinal = 2) BlockPos pos) {
if(BlockBumping.BUMPED_BLOCKS.containsKey(pos)) return BlockRenderType.INVISIBLE;
return original;
}

// @ModifyExpressionValue(method = "build", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayers;getBlockLayer(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/RenderLayer;"))
// private RenderLayer gooble(RenderLayer original, @Local(ordinal = 2) BlockPos pos) {
// return RenderLayer.getSolid();
// }
}
1 change: 1 addition & 0 deletions src/main/java/com/floralquafloral/util/MarioSFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public final class MarioSFX {
public static final SoundEvent SKID_SAND = makeMovementSound("skid_sand");
public static final SoundEvent SKID_SNOW = makeMovementSound("skid_snow");
public static final SoundEvent SKID_WALL = makeMovementSound("skid_wall");
public static final SoundEvent BUMP = makeMovementSound("bump");

public static final SoundEvent NORMAL_POWER = makePowerSound("normal_power");
public static final SoundEvent REVERT = makePowerSound("revert");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/floralquafloral/util/MixedEasing.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private interface EasingFunction {
}

public static float mixedEase(float x, MixedEasing first, MixedEasing second) {
return (float) (x < 0.5 ? first.FUNCTION.ease(x) : second.FUNCTION.ease(x));
// return (float) (x < 0.5 ? first.FUNCTION.ease(x) : second.FUNCTION.ease(x));
return x * (float) first.FUNCTION.ease(x) + (1 - x) * (float) second.FUNCTION.ease(x);
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/qua_mario/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"subtitles.qua_mario.movement.skid_sand": "Skidding",
"subtitles.qua_mario.movement.skid_snow": "Skidding",
"subtitles.qua_mario.movement.skid_wall": "Sliding",
"subtitles.qua_mario.movement.bump": "Block bumped",
"subtitles.qua_mario.power_up.normal_power": "Powering up",
"subtitles.qua_mario.power_up.revert": "Powering down",
"subtitles.qua_mario.stomp.stomp": "Something gets stomped",
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/qua_mario/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
"qua_mario:sfx/movement/skid_wall"
]
},
"sfx.movement.bump": {
"subtitle": "subtitles.qua_mario.movement.bump",
"sounds": [
"qua_mario:sfx/movement/bump"
]
},
"sfx.power_up.normal_power": {
"subtitle": "subtitles.qua_mario.power_up.normal_power",
"sounds": [
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [

]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [

]
}
4 changes: 3 additions & 1 deletion src/main/resources/qua_mario.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"defaultRequire": 1
},
"client": [
"BlockMixin",
"CameraMixin",
"ClientPlayerEntityMixin",
"ClientPlayNetworkHandlerMixin",
"InGameHudMixin",
"LivingEntityRendererMixin"
"LivingEntityRendererMixin",
"SectionBuilderMixin"
]
}

0 comments on commit 3f95353

Please sign in to comment.