diff --git a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java index 4dcb559a9..7176f3e61 100644 --- a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java +++ b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java @@ -30,7 +30,7 @@ import dan200.computercraft.core.apis.ApiFactories; import dan200.computercraft.core.asm.GenericMethod; import dan200.computercraft.core.filesystem.FileMount; import dan200.computercraft.core.filesystem.ResourceMount; -import dan200.computercraft.mixin.MinecraftServerAccess; +import dan200.computercraft.fabric.mixin.MinecraftServerAccess; import dan200.computercraft.shared.BundledRedstone; import dan200.computercraft.shared.MediaProviders; import dan200.computercraft.shared.Peripherals; diff --git a/src/main/java/dan200/computercraft/api/client/TransformedModel.java b/src/main/java/dan200/computercraft/api/client/TransformedModel.java index 8f24cfabb..911bfbb90 100644 --- a/src/main/java/dan200/computercraft/api/client/TransformedModel.java +++ b/src/main/java/dan200/computercraft/api/client/TransformedModel.java @@ -10,7 +10,7 @@ import java.util.Objects; import javax.annotation.Nonnull; -import dan200.computercraft.mixin.AffineTransformationAccess; +import dan200.computercraft.fabric.mixin.AffineTransformationAccess; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.model.BakedModel; diff --git a/src/main/java/dan200/computercraft/client/ClientTableFormatter.java b/src/main/java/dan200/computercraft/client/ClientTableFormatter.java index 13f0ebc24..d3cd9b7bf 100644 --- a/src/main/java/dan200/computercraft/client/ClientTableFormatter.java +++ b/src/main/java/dan200/computercraft/client/ClientTableFormatter.java @@ -8,7 +8,7 @@ package dan200.computercraft.client; import javax.annotation.Nullable; -import dan200.computercraft.mixin.ChatHudAccess; +import dan200.computercraft.fabric.mixin.ChatHudAccess; import dan200.computercraft.shared.command.text.ChatHelpers; import dan200.computercraft.shared.command.text.TableBuilder; import dan200.computercraft.shared.command.text.TableFormatter; diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 9365806b0..af142d3ff 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -20,9 +20,11 @@ import dan200.computercraft.client.render.TileEntityMonitorRenderer; import dan200.computercraft.client.render.TileEntityTurtleRenderer; import dan200.computercraft.client.render.TurtleModelLoader; import dan200.computercraft.client.render.TurtlePlayerRenderer; +import dan200.computercraft.fabric.events.ClientUnloadWorldEvent; import dan200.computercraft.shared.ComputerCraftRegistry; import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.common.IColouredItem; +import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.computer.inventory.ContainerComputer; import dan200.computercraft.shared.computer.inventory.ContainerViewComputer; import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; @@ -32,6 +34,7 @@ import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientBlockEntityEvents; import net.minecraft.client.item.ModelPredicateProvider; import net.minecraft.client.render.RenderLayer; import net.minecraft.item.Item; @@ -47,14 +50,19 @@ import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegi import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry; import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; import net.fabricmc.fabric.mixin.object.builder.ModelPredicateProviderRegistrySpecificAccessor; @Environment (EnvType.CLIENT) public final class ComputerCraftProxyClient implements ClientModInitializer { - public static void initEvents() { + private static void initEvents() { + ClientBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register( ( blockEntity, world ) -> { + if(blockEntity instanceof TileGeneric ) { + ((TileGeneric)blockEntity).onChunkUnloaded(); + } + }); + ClientUnloadWorldEvent.EVENT.register( () -> ClientMonitor.destroyAll() ); } @Override @@ -96,13 +104,9 @@ public final class ComputerCraftProxyClient implements ClientModInitializer { () -> ComputerCraftRegistry.ModItems.POCKET_COMPUTER_ADVANCED); ClientRegistry.onItemColours(); - // TODO Verify this does things properly - ServerWorldEvents.UNLOAD.register(((minecraftServer, serverWorld) -> { - ClientMonitor.destroyAll(); - })); + initEvents(); } - // My IDE doesn't think so, but we do actually need these generics. private static void registerContainers() { ScreenRegistry.>register(ComputerCraftRegistry.ModContainers.COMPUTER, GuiComputer::create); @@ -125,15 +129,4 @@ public final class ComputerCraftProxyClient implements ClientModInitializer { ModelPredicateProviderRegistrySpecificAccessor.callRegister(item.get(), id, getter); } } - - // @Mod.EventBusSubscriber (modid = ComputerCraft.MOD_ID, value = Dist.CLIENT) - // public static final class ForgeHandlers { - // @SubscribeEvent - // public static void onWorldUnload(WorldEvent.Unload event) { - // if (event.getWorld() - // .isClient()) { - // ClientMonitor.destroyAll(); - // } - // } - // } } diff --git a/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java index 37670d02b..8eb76f6d0 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java @@ -6,7 +6,7 @@ package dan200.computercraft.client.render; -import dan200.computercraft.mixin.HeldItemRendererAccess; +import dan200.computercraft.fabric.mixin.HeldItemRendererAccess; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; diff --git a/src/main/java/dan200/computercraft/client/render/ModelTransformer.java b/src/main/java/dan200/computercraft/client/render/ModelTransformer.java index b8a766e0a..f455fd883 100644 --- a/src/main/java/dan200/computercraft/client/render/ModelTransformer.java +++ b/src/main/java/dan200/computercraft/client/render/ModelTransformer.java @@ -8,7 +8,7 @@ package dan200.computercraft.client.render; import java.util.List; -import dan200.computercraft.mixin.BakedQuadAccess; +import dan200.computercraft.fabric.mixin.BakedQuadAccess; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormatElement; diff --git a/src/main/java/dan200/computercraft/fabric/events/ClientUnloadWorldEvent.java b/src/main/java/dan200/computercraft/fabric/events/ClientUnloadWorldEvent.java new file mode 100644 index 000000000..bd2582dba --- /dev/null +++ b/src/main/java/dan200/computercraft/fabric/events/ClientUnloadWorldEvent.java @@ -0,0 +1,17 @@ +package dan200.computercraft.fabric.events; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; + +@FunctionalInterface +public interface ClientUnloadWorldEvent +{ + Event EVENT = EventFactory.createArrayBacked( ClientUnloadWorldEvent.class, + callbacks -> () -> { + for( ClientUnloadWorldEvent callback : callbacks) { + callback.onClientUnloadWorld(); + } + }); + + void onClientUnloadWorld(); +} diff --git a/src/main/java/dan200/computercraft/mixin/AffineTransformationAccess.java b/src/main/java/dan200/computercraft/fabric/mixin/AffineTransformationAccess.java similarity index 91% rename from src/main/java/dan200/computercraft/mixin/AffineTransformationAccess.java rename to src/main/java/dan200/computercraft/fabric/mixin/AffineTransformationAccess.java index a648daa1d..11f98a308 100644 --- a/src/main/java/dan200/computercraft/mixin/AffineTransformationAccess.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/AffineTransformationAccess.java @@ -1,4 +1,4 @@ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/dan200/computercraft/mixin/BakedQuadAccess.java b/src/main/java/dan200/computercraft/fabric/mixin/BakedQuadAccess.java similarity index 86% rename from src/main/java/dan200/computercraft/mixin/BakedQuadAccess.java rename to src/main/java/dan200/computercraft/fabric/mixin/BakedQuadAccess.java index 11c2abd52..67f8acbf9 100644 --- a/src/main/java/dan200/computercraft/mixin/BakedQuadAccess.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/BakedQuadAccess.java @@ -1,4 +1,4 @@ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/dan200/computercraft/mixin/ChatHudAccess.java b/src/main/java/dan200/computercraft/fabric/mixin/ChatHudAccess.java similarity index 88% rename from src/main/java/dan200/computercraft/mixin/ChatHudAccess.java rename to src/main/java/dan200/computercraft/fabric/mixin/ChatHudAccess.java index b2438b78a..08389f84b 100644 --- a/src/main/java/dan200/computercraft/mixin/ChatHudAccess.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/ChatHudAccess.java @@ -1,4 +1,4 @@ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; diff --git a/src/main/java/dan200/computercraft/mixin/HeldItemRendererAccess.java b/src/main/java/dan200/computercraft/fabric/mixin/HeldItemRendererAccess.java similarity index 94% rename from src/main/java/dan200/computercraft/mixin/HeldItemRendererAccess.java rename to src/main/java/dan200/computercraft/fabric/mixin/HeldItemRendererAccess.java index a54b1a51a..c7cb0e3e3 100644 --- a/src/main/java/dan200/computercraft/mixin/HeldItemRendererAccess.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/HeldItemRendererAccess.java @@ -1,4 +1,4 @@ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; diff --git a/src/main/java/dan200/computercraft/mixin/MinecraftServerAccess.java b/src/main/java/dan200/computercraft/fabric/mixin/MinecraftServerAccess.java similarity index 88% rename from src/main/java/dan200/computercraft/mixin/MinecraftServerAccess.java rename to src/main/java/dan200/computercraft/fabric/mixin/MinecraftServerAccess.java index 708ae6a1f..a0c5436a1 100644 --- a/src/main/java/dan200/computercraft/mixin/MinecraftServerAccess.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MinecraftServerAccess.java @@ -1,4 +1,4 @@ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/dan200/computercraft/mixin/MixinBlock.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinBlock.java similarity index 96% rename from src/main/java/dan200/computercraft/mixin/MixinBlock.java rename to src/main/java/dan200/computercraft/fabric/mixin/MixinBlock.java index 53da08f30..c9eadae2c 100644 --- a/src/main/java/dan200/computercraft/mixin/MixinBlock.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinBlock.java @@ -4,7 +4,7 @@ * Send enquiries to dratcliffe@gmail.com */ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import dan200.computercraft.shared.util.DropConsumer; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/dan200/computercraft/mixin/MixinEntity.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinEntity.java similarity index 96% rename from src/main/java/dan200/computercraft/mixin/MixinEntity.java rename to src/main/java/dan200/computercraft/fabric/mixin/MixinEntity.java index 79e3d7ff7..5f57443e8 100644 --- a/src/main/java/dan200/computercraft/mixin/MixinEntity.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinEntity.java @@ -4,7 +4,7 @@ * Send enquiries to dratcliffe@gmail.com */ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import dan200.computercraft.shared.util.DropConsumer; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/dan200/computercraft/mixin/MixinHeldItemRenderer.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinHeldItemRenderer.java similarity index 83% rename from src/main/java/dan200/computercraft/mixin/MixinHeldItemRenderer.java rename to src/main/java/dan200/computercraft/fabric/mixin/MixinHeldItemRenderer.java index a3c1fb813..bf0b86295 100644 --- a/src/main/java/dan200/computercraft/mixin/MixinHeldItemRenderer.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinHeldItemRenderer.java @@ -4,12 +4,11 @@ * Send enquiries to dratcliffe@gmail.com */ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import dan200.computercraft.client.render.ItemPocketRenderer; import dan200.computercraft.client.render.ItemPrintoutRenderer; import dan200.computercraft.shared.media.items.ItemPrintout; -import dan200.computercraft.shared.mixed.MixedFirstPersonRenderer; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -30,22 +29,12 @@ import net.fabricmc.api.Environment; @Mixin (HeldItemRenderer.class) @Environment (EnvType.CLIENT) -public class MixinHeldItemRenderer implements MixedFirstPersonRenderer { - @Override - public void renderArmFirstPerson_CC(MatrixStack stack, VertexConsumerProvider consumerProvider, int light, float equip, float swing, Arm hand) { - this.renderArmHoldingItem(stack, consumerProvider, light, equip, swing, hand); - } - +public class MixinHeldItemRenderer { @Shadow private void renderArmHoldingItem(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float equipProgress, float swingProgress, Arm arm) { } - @Override - public float getMapAngleFromPitch_CC(float pitch) { - return this.getMapAngle(pitch); - } - @Shadow private float getMapAngle(float pitch) { return 0; diff --git a/src/main/java/dan200/computercraft/mixin/MixinItemFrameEntityRenderer.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinItemFrameEntityRenderer.java similarity index 97% rename from src/main/java/dan200/computercraft/mixin/MixinItemFrameEntityRenderer.java rename to src/main/java/dan200/computercraft/fabric/mixin/MixinItemFrameEntityRenderer.java index be54ba591..9480ee9e4 100644 --- a/src/main/java/dan200/computercraft/mixin/MixinItemFrameEntityRenderer.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinItemFrameEntityRenderer.java @@ -4,7 +4,7 @@ * Send enquiries to dratcliffe@gmail.com */ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import dan200.computercraft.client.render.ItemPrintoutRenderer; import dan200.computercraft.shared.media.items.ItemPrintout; diff --git a/src/main/java/dan200/computercraft/fabric/mixin/MixinMinecraftClient.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinMinecraftClient.java new file mode 100644 index 000000000..d734632a7 --- /dev/null +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinMinecraftClient.java @@ -0,0 +1,37 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.fabric.mixin; + +import dan200.computercraft.client.FrameInfo; +import dan200.computercraft.fabric.events.ClientUnloadWorldEvent; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.world.ClientWorld; +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.CallbackInfo; + +import net.minecraft.client.MinecraftClient; + +@Mixin (MinecraftClient.class) +public abstract class MixinMinecraftClient +{ + @Inject (method = "render", at = @At ("HEAD")) + private void onRender(CallbackInfo info) { + FrameInfo.onRenderFrame(); + } + + @Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V", at = @At ("RETURN")) + private void disconnectAfter(Screen screen, CallbackInfo info) { + ClientUnloadWorldEvent.EVENT.invoker().onClientUnloadWorld(); + } + + @Inject(method = "joinWorld", at = @At("RETURN")) + private void joinWorldAfter(ClientWorld world, CallbackInfo info) { + ClientUnloadWorldEvent.EVENT.invoker().onClientUnloadWorld(); + } +} diff --git a/src/main/java/dan200/computercraft/mixin/MixinScreen.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinScreen.java similarity index 95% rename from src/main/java/dan200/computercraft/mixin/MixinScreen.java rename to src/main/java/dan200/computercraft/fabric/mixin/MixinScreen.java index 9d07929b5..eda9d189a 100644 --- a/src/main/java/dan200/computercraft/mixin/MixinScreen.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinScreen.java @@ -4,7 +4,7 @@ * Send enquiries to dratcliffe@gmail.com */ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import dan200.computercraft.shared.command.ClientCommands; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/dan200/computercraft/mixin/MixinServerWorld.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinServerWorld.java similarity index 95% rename from src/main/java/dan200/computercraft/mixin/MixinServerWorld.java rename to src/main/java/dan200/computercraft/fabric/mixin/MixinServerWorld.java index bf512b895..b59e42ffc 100644 --- a/src/main/java/dan200/computercraft/mixin/MixinServerWorld.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinServerWorld.java @@ -4,7 +4,7 @@ * Send enquiries to dratcliffe@gmail.com */ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import dan200.computercraft.shared.util.DropConsumer; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/dan200/computercraft/mixin/MixinWorld.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinWorld.java similarity index 97% rename from src/main/java/dan200/computercraft/mixin/MixinWorld.java rename to src/main/java/dan200/computercraft/fabric/mixin/MixinWorld.java index be271fca2..80d1aec77 100644 --- a/src/main/java/dan200/computercraft/mixin/MixinWorld.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinWorld.java @@ -4,7 +4,7 @@ * Send enquiries to dratcliffe@gmail.com */ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import java.util.Collection; diff --git a/src/main/java/dan200/computercraft/mixin/MixinWorldRenderer.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinWorldRenderer.java similarity index 98% rename from src/main/java/dan200/computercraft/mixin/MixinWorldRenderer.java rename to src/main/java/dan200/computercraft/fabric/mixin/MixinWorldRenderer.java index 76a0b569c..3f2180963 100644 --- a/src/main/java/dan200/computercraft/mixin/MixinWorldRenderer.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinWorldRenderer.java @@ -4,7 +4,7 @@ * Send enquiries to dratcliffe@gmail.com */ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import dan200.computercraft.client.render.CableHighlightRenderer; import dan200.computercraft.client.render.MonitorHighlightRenderer; diff --git a/src/main/java/dan200/computercraft/mixin/SignBlockEntityAccess.java b/src/main/java/dan200/computercraft/fabric/mixin/SignBlockEntityAccess.java similarity index 86% rename from src/main/java/dan200/computercraft/mixin/SignBlockEntityAccess.java rename to src/main/java/dan200/computercraft/fabric/mixin/SignBlockEntityAccess.java index 1bd22ce40..a5b405f8a 100644 --- a/src/main/java/dan200/computercraft/mixin/SignBlockEntityAccess.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/SignBlockEntityAccess.java @@ -1,4 +1,4 @@ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/dan200/computercraft/mixin/SoundEventAccess.java b/src/main/java/dan200/computercraft/fabric/mixin/SoundEventAccess.java similarity index 86% rename from src/main/java/dan200/computercraft/mixin/SoundEventAccess.java rename to src/main/java/dan200/computercraft/fabric/mixin/SoundEventAccess.java index dea532762..3fba7d8e2 100644 --- a/src/main/java/dan200/computercraft/mixin/SoundEventAccess.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/SoundEventAccess.java @@ -1,4 +1,4 @@ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/dan200/computercraft/mixin/WorldSavePathAccess.java b/src/main/java/dan200/computercraft/fabric/mixin/WorldSavePathAccess.java similarity index 88% rename from src/main/java/dan200/computercraft/mixin/WorldSavePathAccess.java rename to src/main/java/dan200/computercraft/fabric/mixin/WorldSavePathAccess.java index bc0a67855..06e8eb7a7 100644 --- a/src/main/java/dan200/computercraft/mixin/WorldSavePathAccess.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/WorldSavePathAccess.java @@ -1,4 +1,4 @@ -package dan200.computercraft.mixin; +package dan200.computercraft.fabric.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; diff --git a/src/main/java/dan200/computercraft/mixin/MixinMinecraftGame.java b/src/main/java/dan200/computercraft/mixin/MixinMinecraftGame.java deleted file mode 100644 index 1dc5fa12f..000000000 --- a/src/main/java/dan200/computercraft/mixin/MixinMinecraftGame.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.mixin; - -import dan200.computercraft.client.FrameInfo; -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.CallbackInfo; - -import net.minecraft.client.MinecraftClient; - -@Mixin (MinecraftClient.class) -public abstract class MixinMinecraftGame { - @Inject (method = "render", at = @At ("HEAD")) - private void onRender(CallbackInfo info) { - FrameInfo.onRenderFrame(); - } -} diff --git a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java index 0514bbf61..a2d37e532 100644 --- a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java @@ -28,6 +28,9 @@ public abstract class TileGeneric extends BlockEntity implements BlockEntityClie public void destroy() { } + public void onChunkUnloaded() { + } + public final void updateBlock() { this.markDirty(); BlockPos pos = this.getPos(); diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java index 0aee4362b..c12d44bc4 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -77,6 +77,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT } } + @Override + public void onChunkUnloaded() + { + unload(); + } + protected void unload() { if (this.m_instanceID >= 0) { if (!this.getWorld().isClient) { diff --git a/src/main/java/dan200/computercraft/shared/mixed/MixedFirstPersonRenderer.java b/src/main/java/dan200/computercraft/shared/mixed/MixedFirstPersonRenderer.java deleted file mode 100644 index c420d8cc4..000000000 --- a/src/main/java/dan200/computercraft/shared/mixed/MixedFirstPersonRenderer.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.mixed; - -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Arm; - -public interface MixedFirstPersonRenderer { - void renderArmFirstPerson_CC(MatrixStack stack, VertexConsumerProvider consumerProvider, int light, float equip, float swing, Arm hand); - - float getMapAngleFromPitch_CC(float pitch); -} diff --git a/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java b/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java index 35a11419c..0416c9ea5 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared.network.client; import javax.annotation.Nonnull; -import dan200.computercraft.mixin.SoundEventAccess; +import dan200.computercraft.fabric.mixin.SoundEventAccess; import dan200.computercraft.shared.network.NetworkMessage; import net.minecraft.client.MinecraftClient; diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java index e267c601d..9b23eaed7 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java @@ -83,6 +83,13 @@ public class TileCable extends TileGeneric implements IPeripheralTile { } } + @Override + public void onChunkUnloaded() + { + super.onChunkUnloaded(); + onRemove(); + } + private void onRemove() { if (this.world == null || !this.world.isClient) { this.m_node.remove(); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java index 47502b2dc..d258877ca 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java @@ -74,6 +74,13 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile { super.destroy(); } + @Override + public void onChunkUnloaded() + { + super.onChunkUnloaded(); + doRemove(); + } + private void doRemove() { if (this.world == null || !this.world.isClient) { this.m_node.remove(); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java index cddd4e3f5..d7331f5df 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -79,6 +79,23 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile { } } + @Override + public void markRemoved() { + super.markRemoved(); + if (this.m_clientMonitor != null && this.m_xIndex == 0 && this.m_yIndex == 0) { + this.m_clientMonitor.destroy(); + } + } + + @Override + public void onChunkUnloaded() { + super.onChunkUnloaded(); + if (this.m_clientMonitor != null && this.m_xIndex == 0 && this.m_yIndex == 0) { + this.m_clientMonitor.destroy(); + } + this.m_clientMonitor = null; + } + @Nonnull @Override public ActionResult onActivate(PlayerEntity player, Hand hand, BlockHitResult hit) { @@ -262,15 +279,6 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile { return ComputerCraft.monitorDistanceSq; } - @Override - @Environment (EnvType.CLIENT) - public void markRemoved() { - super.markRemoved(); - if (this.m_clientMonitor != null && this.m_xIndex == 0 && this.m_yIndex == 0) { - this.m_clientMonitor.destroy(); - } - } - // Sizing and placement stuff @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java index adbd32598..c39a750a5 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java @@ -18,7 +18,7 @@ import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.mixin.SoundEventAccess; +import dan200.computercraft.fabric.mixin.SoundEventAccess; import net.minecraft.block.enums.Instrument; import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket; @@ -100,13 +100,13 @@ public abstract class SpeakerPeripheral implements IPeripheral { float adjVolume = Math.min(volume, 3.0f); server.getPlayerManager() - .sendToAround(null, - pos.x, - pos.y, - pos.z, - adjVolume > 1.0f ? 16 * adjVolume : 16.0, - world.getRegistryKey(), - new PlaySoundIdS2CPacket(name, SoundCategory.RECORDS, pos, adjVolume, pitch)); + .sendToAround(null, + pos.x, + pos.y, + pos.z, + adjVolume > 1.0f ? 16 * adjVolume : 16.0, + world.getRegistryKey(), + new PlaySoundIdS2CPacket(name, SoundCategory.RECORDS, pos, adjVolume, pitch)); return null; }); @@ -141,7 +141,7 @@ public abstract class SpeakerPeripheral implements IPeripheral { Instrument instrument = null; for (Instrument testInstrument : Instrument.values()) { if (testInstrument.asString() - .equalsIgnoreCase(name)) { + .equalsIgnoreCase(name)) { instrument = testInstrument; break; } @@ -154,10 +154,10 @@ public abstract class SpeakerPeripheral implements IPeripheral { // If the resource location for note block notes changes, this method call will need to be updated boolean success = this.playSound(context, - ((SoundEventAccess)instrument.getSound()).getId(), - volume, - (float) Math.pow(2.0, (pitch - 12.0) / 12.0), - true); + ((SoundEventAccess)instrument.getSound()).getId(), + volume, + (float) Math.pow(2.0, (pitch - 12.0) / 12.0), + true); if (success) { this.m_notesThisTick.incrementAndGet(); } diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index f7db6fe8a..325f82904 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -17,6 +17,7 @@ import dan200.computercraft.shared.TurtlePermissions; import dan200.computercraft.shared.command.CommandComputerCraft; import dan200.computercraft.shared.command.arguments.ArgumentSerializers; import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; +import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.data.BlockNamedEntityLootCondition; import dan200.computercraft.shared.data.HasComputerIdLootCondition; import dan200.computercraft.shared.data.PlayerCreativeLootCondition; @@ -28,6 +29,7 @@ import dan200.computercraft.shared.turtle.FurnaceRefuelHandler; import dan200.computercraft.shared.turtle.SignInspectHandler; import dan200.computercraft.shared.util.TickScheduler; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerBlockEntityEvents; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.CommandBlockBlockEntity; import net.minecraft.item.Item; @@ -106,6 +108,12 @@ public final class ComputerCraftProxyCommon { ComputerCraftProxyCommon.server = null; }); + ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register( ( blockEntity, world ) -> { + if(blockEntity instanceof TileGeneric ) { + ((TileGeneric)blockEntity).onChunkUnloaded(); + } + }); + TurtleEvent.EVENT_BUS.register(FurnaceRefuelHandler.INSTANCE); TurtleEvent.EVENT_BUS.register(new TurtlePermissions()); TurtleEvent.EVENT_BUS.register(new SignInspectHandler()); diff --git a/src/main/java/dan200/computercraft/shared/turtle/SignInspectHandler.java b/src/main/java/dan200/computercraft/shared/turtle/SignInspectHandler.java index a55c67df9..a885ced84 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/SignInspectHandler.java +++ b/src/main/java/dan200/computercraft/shared/turtle/SignInspectHandler.java @@ -6,7 +6,7 @@ import java.util.Map; import com.google.common.eventbus.Subscribe; import dan200.computercraft.api.turtle.event.TurtleBlockEvent; -import dan200.computercraft.mixin.SignBlockEntityAccess; +import dan200.computercraft.fabric.mixin.SignBlockEntityAccess; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.SignBlockEntity; diff --git a/src/main/java/dan200/computercraft/shared/util/IDAssigner.java b/src/main/java/dan200/computercraft/shared/util/IDAssigner.java index 55724aa48..0ef5db760 100644 --- a/src/main/java/dan200/computercraft/shared/util/IDAssigner.java +++ b/src/main/java/dan200/computercraft/shared/util/IDAssigner.java @@ -21,7 +21,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import dan200.computercraft.ComputerCraft; -import dan200.computercraft.mixin.WorldSavePathAccess; +import dan200.computercraft.fabric.mixin.WorldSavePathAccess; import me.shedaniel.cloth.api.utils.v1.GameInstanceUtils; import net.minecraft.server.MinecraftServer; diff --git a/src/main/resources/computercraft.mixins.json b/src/main/resources/computercraft.mixins.json index e5771bd01..c9ae3995a 100644 --- a/src/main/resources/computercraft.mixins.json +++ b/src/main/resources/computercraft.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "dan200.computercraft.mixin", + "package": "dan200.computercraft.fabric.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ "MinecraftServerAccess", @@ -20,7 +20,7 @@ "HeldItemRendererAccess", "MixinHeldItemRenderer", "MixinItemFrameEntityRenderer", - "MixinMinecraftGame", + "MixinMinecraftClient", "MixinScreen", "MixinWorldRenderer" ],