Cleanup Renderer API testmod ()

This commit is contained in:
Technici4n 2022-11-24 16:04:44 +01:00 committed by GitHub
parent 168b712abd
commit 91f53ef5b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 136 deletions

View file

@ -1,31 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.test.renderer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* Extension interface for a world to notify the world that a block needs to be re-rendered.
*/
public interface WorldRenderExtensions {
static void scheduleBlockRerender(World world, BlockPos pos) {
((WorldRenderExtensions) world).scheduleBlockRerender(pos);
}
void scheduleBlockRerender(BlockPos pos);
}

View file

@ -1,38 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.test.renderer.mixin;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
@Mixin(ClientWorld.class)
abstract class ClientWorldMixin extends WorldMixin {
@Shadow
@Final
private WorldRenderer worldRenderer;
@Override
public void scheduleBlockRerender(BlockPos pos) {
// Update the block at the position to trigger chunk re-render.
this.worldRenderer.updateBlock(null, pos, null, null, 0);
}
}

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.test.renderer.mixin;
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.fabricmc.fabric.test.renderer.WorldRenderExtensions;
@Mixin(World.class)
abstract class WorldMixin implements WorldRenderExtensions {
@Override
public void scheduleBlockRerender(BlockPos pos) {
// Do nothing, the client world will do things here
}
}

View file

@ -49,25 +49,22 @@ public final class FrameBlock extends Block implements BlockEntityProvider, Fabr
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient()) {
return ActionResult.PASS;
}
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof FrameBlockEntity) {
if (world.getBlockEntity(pos) instanceof FrameBlockEntity frame) {
ItemStack stack = player.getStackInHand(hand);
Block handBlock = Block.getBlockFromItem(stack.getItem());
@Nullable
Block currentBlock = ((FrameBlockEntity) blockEntity).getBlock();
Block currentBlock = frame.getBlock();
if (stack.isEmpty()) {
// Try to remove if the stack in hand is empty
if (currentBlock != null) {
player.getInventory().offerOrDrop(new ItemStack(currentBlock));
((FrameBlockEntity) blockEntity).setBlock(null);
return ActionResult.SUCCESS;
if (!world.isClient()) {
player.getInventory().offerOrDrop(new ItemStack(currentBlock));
frame.setBlock(null);
}
return ActionResult.success(world.isClient());
}
return ActionResult.PASS;
@ -83,12 +80,17 @@ public final class FrameBlock extends Block implements BlockEntityProvider, Fabr
return ActionResult.FAIL;
}
if (currentBlock != null) {
player.getInventory().offerOrDrop(new ItemStack(currentBlock));
stack.decrement(1);
if (!world.isClient()) {
if (currentBlock != null) {
player.getInventory().offerOrDrop(new ItemStack(currentBlock));
}
frame.setBlock(handBlock);
}
((FrameBlockEntity) blockEntity).setBlock(handBlock);
return ActionResult.SUCCESS;
return ActionResult.success(world.isClient());
}
return ActionResult.FAIL;

View file

@ -30,7 +30,6 @@ import net.minecraft.registry.Registries;
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity;
import net.fabricmc.fabric.api.util.NbtType;
import net.fabricmc.fabric.test.renderer.WorldRenderExtensions;
public final class FrameBlockEntity extends BlockEntity implements RenderAttachmentBlockEntity {
@Nullable
@ -51,7 +50,8 @@ public final class FrameBlockEntity extends BlockEntity implements RenderAttachm
}
if (this.getWorld() != null && this.getWorld().isClient()) {
WorldRenderExtensions.scheduleBlockRerender(this.getWorld(), this.getPos());
// This call forces a chunk remesh.
world.updateListeners(pos, null, null, 0);
}
}
@ -59,6 +59,9 @@ public final class FrameBlockEntity extends BlockEntity implements RenderAttachm
public void writeNbt(NbtCompound tag) {
if (this.block != null) {
tag.putString("block", Registries.BLOCK.getId(this.block).toString());
} else {
// Always need something in the tag, otherwise S2C syncing will never apply the packet.
tag.putInt("block", -1);
}
}

View file

@ -1,14 +0,0 @@
{
"required": true,
"package": "net.fabricmc.fabric.test.renderer.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"WorldMixin"
],
"client": [
"ClientWorldMixin"
],
"injectors": {
"defaultRequire": 1
}
}

View file

@ -16,8 +16,5 @@
"client": [
"net.fabricmc.fabric.test.renderer.simple.client.RendererClientTest"
]
},
"mixins": [
"fabric-renderer-api-v1-testmod.mixins.json"
]
}
}