Sound support + OffHand camo. #8

Merged
Adrien1106 merged 5 commits from dev into master 2024-03-04 17:04:14 +01:00
9 changed files with 216 additions and 4 deletions
Showing only changes of commit 6ca266b676 - Show all commits

View File

@ -9,7 +9,7 @@ loader_version=0.15.6
# Mod Properties
modrinth_id = jCpoCBpn
mod_version = 1.3.1
mod_version = 1.3.5
maven_group = fr.adrien1106
archives_base_name = ReFramed
mod_id = reframed

View File

@ -25,7 +25,7 @@ import java.util.function.BiConsumer;
import java.util.stream.Collectors;
/**
* TODO self culling, fix other models, better connected textures, preload items, walking sound, state replacement
* TODO self culling, fix other models, better connected textures, preload items
*/
public class ReFramed implements ModInitializer {
public static final String MODID = "reframed";

View File

@ -35,7 +35,7 @@ public class ReFramedEntity extends BlockEntity implements ThemeableBlockEntity
protected static final byte REDSTONE_MASK = 0b010;
protected static final byte SOLIDITY_MASK = 0b100;
protected static final String BLOCKSTATE_KEY = "s";
public static final String BLOCKSTATE_KEY = "s";
protected static final String BITFIELD_KEY = "b";
public ReFramedEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {

View File

@ -0,0 +1,48 @@
package fr.adrien1106.reframed.mixin;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import static fr.adrien1106.reframed.block.ReFramedEntity.BLOCKSTATE_KEY;
@Mixin(BlockItem.class)
public class BlockItemMixin {
@Shadow @Final @Deprecated private Block block;
@Inject(
method = "writeNbtToBlockEntity",
at = @At(
value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/item/BlockItem;getBlockEntityNbt(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/nbt/NbtCompound;",
shift = At.Shift.AFTER
)
)
private static void placeBlockWithOffHandCamo(World world, PlayerEntity player, BlockPos pos, ItemStack stack, CallbackInfoReturnable<Boolean> cir, @Local LocalRef<NbtCompound> compound) {
if (compound.get() != null
|| player.getOffHandStack().isEmpty()
|| !(player.getOffHandStack().getItem() instanceof BlockItem block)
|| block.getBlock() instanceof BlockEntityProvider
|| !Block.isShapeFullCube(block.getBlock().getDefaultState().getCollisionShape(world, pos))
) return;
NbtCompound new_comp = new NbtCompound();
new_comp.put(BLOCKSTATE_KEY + 1, NbtHelper.fromBlockState(block.getBlock().getDefaultState()));
compound.set(new_comp);
}
}

View File

@ -0,0 +1,48 @@
package fr.adrien1106.reframed.mixin.sound;
import com.llamalad7.mixinextras.sugar.Local;
import fr.adrien1106.reframed.block.ReFramedBlock;
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.BlockItem;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(BlockItem.class)
public class BlockItemMixin {
@Redirect(
method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/BlockState;getSoundGroup()Lnet/minecraft/sound/BlockSoundGroup;"
)
)
public BlockSoundGroup getCamoPlaceSound(BlockState state, @Local World world, @Local BlockPos pos) {
if (state.getBlock() instanceof ReFramedBlock frame_block
&& world.getBlockEntity(pos) instanceof ThemeableBlockEntity frame_entity
) {
BlockState camo_state = frame_entity.getTheme(frame_block.getTopThemeIndex(state));
state = camo_state.getBlock() != Blocks.AIR ? camo_state : state;
}
return state.getSoundGroup();
}
@Redirect(
method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/item/BlockItem;getPlaceSound(Lnet/minecraft/block/BlockState;)Lnet/minecraft/sound/SoundEvent;"
)
)
private SoundEvent getCamoSoundEvent(BlockItem item, BlockState state, @Local BlockSoundGroup group) {
// I don't know why it wasn't doing that by default
return group.getPlaceSound();
}
}

View File

@ -0,0 +1,38 @@
package fr.adrien1106.reframed.mixin.sound;
import com.llamalad7.mixinextras.sugar.Local;
import fr.adrien1106.reframed.block.ReFramedBlock;
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(Entity.class)
public abstract class EntityMixin {
@Shadow public abstract World getWorld();
@Redirect(
method = "playStepSound",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/BlockState;getSoundGroup()Lnet/minecraft/sound/BlockSoundGroup;"
)
)
private BlockSoundGroup playStepCamoSound(BlockState state, @Local(argsOnly = true) BlockPos pos) {
if (state.getBlock() instanceof ReFramedBlock frame_block
&& getWorld().getBlockEntity(pos) instanceof ThemeableBlockEntity frame_entity
) {
BlockState camo_state = frame_entity.getTheme(frame_block.getTopThemeIndex(state));
state = camo_state.getBlock() != Blocks.AIR ? camo_state : state;
}
return state.getSoundGroup();
}
}

View File

@ -0,0 +1,34 @@
package fr.adrien1106.reframed.mixin.sound;
import fr.adrien1106.reframed.block.ReFramedBlock;
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(LivingEntity.class)
public class LivingEntityMixin {
@Redirect(
method = "playBlockFallSound",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"
), remap = false
)
private BlockState playCamoFallSound(World world, BlockPos pos) {
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof ReFramedBlock frame_block
&& world.getBlockEntity(pos) instanceof ThemeableBlockEntity frame_entity
) {
BlockState camo_state = frame_entity.getTheme(frame_block.getTopThemeIndex(state));
state = camo_state.getBlock() != Blocks.AIR ? camo_state : state;
}
return state;
}
}

View File

@ -0,0 +1,39 @@
package fr.adrien1106.reframed.mixin.sound;
import com.llamalad7.mixinextras.sugar.Local;
import fr.adrien1106.reframed.block.ReFramedBlock;
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(WorldRenderer.class)
public class WorldRendererMixin {
@Shadow @Nullable private ClientWorld world;
@Redirect(
method = "processWorldEvent",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/BlockState;getSoundGroup()Lnet/minecraft/sound/BlockSoundGroup;"
)
)
private BlockSoundGroup getCamoBreakSound(BlockState state, @Local(argsOnly = true) BlockPos pos) {
if (state.getBlock() instanceof ReFramedBlock frame_block
&& world.getBlockEntity(pos) instanceof ThemeableBlockEntity frame_entity
) {
BlockState camo_state = frame_entity.getTheme(frame_block.getTopThemeIndex(state));
state = camo_state.getBlock() != Blocks.AIR ? camo_state : state;
}
return state.getSoundGroup();
}
}

View File

@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_17",
"plugin": "fr.adrien1106.reframed.mixin.CompatMixinPlugin",
"mixins": [
"BlockItemMixin",
"WallBlockAccessor",
"particles.MixinEntity",
"particles.MixinLivingEntity"
@ -23,7 +24,11 @@
"render.BlockRenderInfoMixin",
"render.MultipartBakedModelMixin",
"render.TerrainRenderContextMixin",
"render.WorldRendererMixin"
"render.WorldRendererMixin",
"sound.BlockItemMixin",
"sound.EntityMixin",
"sound.LivingEntityMixin",
"sound.WorldRendererMixin"
],
"injectors": {
"defaultRequire": 1