Try to make Phonos compat work again

For some reason, the Phonos compat classes aren't getting remapped correctly, causing a crash.
This commit is contained in:
Motschen
2022-11-20 18:55:17 +01:00
parent 2eb56f0d95
commit 94c6929099
11 changed files with 145 additions and 127 deletions

View File

@@ -2,6 +2,9 @@ architectury {
injectInjectables = false
common(rootProject.enabled_platforms.split(","))
}
repositories {
flatDir { dirs 'localMaven'}
}
loom {
}
@@ -11,6 +14,7 @@ dependencies {
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
// Remove the next line if you don't want to depend on the API
//modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"
modCompileOnlyApi "maven.modrinth:phonos:${rootProject.phonos_version}"
compileClasspath(project(path: ":common", configuration: "namedElements")) { transitive false }
}

Binary file not shown.

View File

@@ -0,0 +1,25 @@
package eu.midnightdust.visualoverhaul.compat.phonos.block;
import io.github.foundationgames.phonos.block.PhonosBlocks;
import io.github.foundationgames.phonos.block.RadioJukeboxBlock;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
public class RadioJukeboxTop extends Block {
public static final BooleanProperty PLAYING = RadioJukeboxBlock.PLAYING;
public static final IntProperty CHANNEL = RadioJukeboxBlock.CHANNEL;
public RadioJukeboxTop() {
super(AbstractBlock.Settings.copy(PhonosBlocks.RADIO_JUKEBOX));
this.setDefaultState(this.stateManager.getDefaultState());
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(PLAYING, CHANNEL);
}
}

View File

@@ -0,0 +1,77 @@
package eu.midnightdust.visualoverhaul.compat.phonos.block.renderer;
import eu.midnightdust.visualoverhaul.compat.phonos.block.RadioJukeboxTop;
import eu.midnightdust.visualoverhaul.compat.phonos.init.PhonosCompatInit;
import eu.midnightdust.visualoverhaul.config.VOConfig;
import io.github.foundationgames.phonos.block.RadioJukeboxBlock;
import io.github.foundationgames.phonos.block.entity.RadioJukeboxBlockEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.random.Random;
@Environment(EnvType.CLIENT)
public class RadioJukeboxBlockEntityRenderer implements BlockEntityRenderer<RadioJukeboxBlockEntity> {
private ItemStack record;
private float rotation = 0;
private BlockState blockState;
private final MinecraftClient client = MinecraftClient.getInstance();
public RadioJukeboxBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {
super();
}
@Override
public void render(RadioJukeboxBlockEntity jukebox, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
if (VOConfig.jukebox && client.world != null) {
matrices.push();
Vec3f vecPos = matrices.peek().getNormalMatrix().decomposeLinearTransformation().getMiddle();
BlockPos pos = new BlockPos(vecPos.getX(), vecPos.getY(), vecPos.getZ());
int lightAbove = WorldRenderer.getLightmapCoordinates(client.world, pos.up());
// Tries to get the disc using the serverside method
if (jukebox.getStack(jukebox.getPlayingSong()) != ItemStack.EMPTY) {
record = jukebox.getStack(jukebox.getPlayingSong()).copy();
record.setCount(2);
}
// If the sound is stopped or no sound is playing, the stack is set to an empty stack //
else {
record = ItemStack.EMPTY;
}
matrices.translate(0.5f, 1.03f, 0.5f);
matrices.scale(0.75f, 0.75f, 0.75f);
if (jukebox.isPlaying()) {
rotation = (client.world.getTime() + tickDelta) * 4;
}
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(rotation));
client.getItemRenderer().renderItem(record, ModelTransformation.Mode.GROUND, lightAbove, overlay, matrices, vertexConsumers, 0);
matrices.pop();
if (VOConfig.jukebox_fake_block && client.world.getBlockState(pos.up()).getBlock() == Blocks.AIR) {
blockState = client.world.getBlockState(pos);
matrices.push();
matrices.translate(0f, 1f, 0f);
if (record == ItemStack.EMPTY) {
client.getBlockRenderManager().renderBlock(PhonosCompatInit.RadioJukeboxTop.getDefaultState().with(RadioJukeboxTop.PLAYING, false).with(RadioJukeboxTop.CHANNEL, blockState.get(RadioJukeboxBlock.CHANNEL)), pos.up(), client.world, matrices, vertexConsumers.getBuffer(RenderLayer.getCutout()), false, Random.create());
} else {
client.getBlockRenderManager().renderBlock(PhonosCompatInit.RadioJukeboxTop.getDefaultState().with(RadioJukeboxTop.PLAYING, true).with(RadioJukeboxTop.CHANNEL, blockState.get(RadioJukeboxBlock.CHANNEL)), pos.up(), client.world, matrices, vertexConsumers.getBuffer(RenderLayer.getCutout()), false, Random.create());
}
matrices.pop();
}
}
}
}

View File

@@ -0,0 +1,23 @@
package eu.midnightdust.visualoverhaul.compat.phonos.init;
import eu.midnightdust.visualoverhaul.compat.phonos.block.RadioJukeboxTop;
import eu.midnightdust.visualoverhaul.compat.phonos.block.renderer.RadioJukeboxBlockEntityRenderer;
import io.github.foundationgames.phonos.block.PhonosBlocks;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
import net.minecraft.block.Block;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class PhonosCompatInit {
public static Block RadioJukeboxTop = new RadioJukeboxTop();
public static void init() {
Registry.register(Registry.BLOCK, new Identifier("visualoverhaul","radio_jukebox_top"), RadioJukeboxTop);
BlockRenderLayerMap.INSTANCE.putBlock(PhonosBlocks.RADIO_JUKEBOX, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(RadioJukeboxTop, RenderLayer.getCutout());
BlockEntityRendererRegistry.register(PhonosBlocks.RADIO_JUKEBOX_ENTITY, RadioJukeboxBlockEntityRenderer::new);
}
}