From e01895d71981fc02270ab706f1a99b9ccc3d30ca Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Mon, 28 Feb 2022 10:33:08 +0000 Subject: [PATCH] Remove turtle_player EntityType This was added in the 1.13 update and I'm still not sure why. Other mods seem to get away without it, so I think it's fine to remove. Also remove the fake net manager, as that's part of Forge nowadays. Fixes #1044. --- .../computercraft/client/ClientRegistry.java | 4 - .../computercraft/shared/CommonHooks.java | 16 +- .../dan200/computercraft/shared/Registry.java | 16 - .../shared/turtle/core/TurtlePlayer.java | 11 - .../shared/util/FakeNetHandler.java | 348 ------------------ 5 files changed, 12 insertions(+), 383 deletions(-) delete mode 100644 src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java diff --git a/src/main/java/dan200/computercraft/client/ClientRegistry.java b/src/main/java/dan200/computercraft/client/ClientRegistry.java index d6fabaa2f..362de0760 100644 --- a/src/main/java/dan200/computercraft/client/ClientRegistry.java +++ b/src/main/java/dan200/computercraft/client/ClientRegistry.java @@ -10,7 +10,6 @@ import dan200.computercraft.client.gui.*; 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.shared.Registry; import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.computer.inventory.ContainerComputerBase; @@ -33,7 +32,6 @@ import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; @@ -140,8 +138,6 @@ public final class ClientRegistry net.minecraftforge.fml.client.registry.ClientRegistry.bindTileEntityRenderer( Registry.ModTiles.TURTLE_NORMAL.get(), TileEntityTurtleRenderer::new ); net.minecraftforge.fml.client.registry.ClientRegistry.bindTileEntityRenderer( Registry.ModTiles.TURTLE_ADVANCED.get(), TileEntityTurtleRenderer::new ); - RenderingRegistry.registerEntityRenderingHandler( Registry.ModEntities.TURTLE_PLAYER.get(), TurtlePlayerRenderer::new ); - registerItemProperty( "state", ( stack, world, player ) -> ItemPocketComputer.getState( stack ).ordinal(), Registry.ModItems.POCKET_COMPUTER_NORMAL, Registry.ModItems.POCKET_COMPUTER_ADVANCED diff --git a/src/main/java/dan200/computercraft/shared/CommonHooks.java b/src/main/java/dan200/computercraft/shared/CommonHooks.java index d9a4870a6..842a8af3d 100644 --- a/src/main/java/dan200/computercraft/shared/CommonHooks.java +++ b/src/main/java/dan200/computercraft/shared/CommonHooks.java @@ -16,6 +16,7 @@ import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork; +import net.minecraft.entity.EntityType; import net.minecraft.inventory.container.Container; import net.minecraft.loot.ConstantRange; import net.minecraft.loot.LootPool; @@ -24,10 +25,7 @@ import net.minecraft.loot.TableLootEntry; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.event.AddReloadListenerEvent; -import net.minecraftforge.event.LootTableLoadEvent; -import net.minecraftforge.event.RegisterCommandsEvent; -import net.minecraftforge.event.TickEvent; +import net.minecraftforge.event.*; import net.minecraftforge.event.entity.player.PlayerContainerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -146,4 +144,14 @@ public final class CommonHooks { event.addListener( ResourceMount.RELOAD_LISTENER ); } + + @SubscribeEvent + public static void onMissingEntityMappingsEvent( RegistryEvent.MissingMappings> event ) + { + ResourceLocation id = new ResourceLocation( ComputerCraft.MOD_ID, "turtle_player" ); + for( RegistryEvent.MissingMappings.Mapping> mapping : event.getMappings( ComputerCraft.MOD_ID ) ) + { + if( mapping.key.equals( id ) ) mapping.ignore(); + } + } } diff --git a/src/main/java/dan200/computercraft/shared/Registry.java b/src/main/java/dan200/computercraft/shared/Registry.java index 635930fcb..3d838fa58 100644 --- a/src/main/java/dan200/computercraft/shared/Registry.java +++ b/src/main/java/dan200/computercraft/shared/Registry.java @@ -60,7 +60,6 @@ import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker; import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe; import dan200.computercraft.shared.turtle.blocks.BlockTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtle; -import dan200.computercraft.shared.turtle.core.TurtlePlayer; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; import dan200.computercraft.shared.turtle.items.ItemTurtle; import dan200.computercraft.shared.turtle.recipes.TurtleRecipe; @@ -70,8 +69,6 @@ import dan200.computercraft.shared.util.*; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.entity.EntityClassification; -import net.minecraft.entity.EntityType; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.*; import net.minecraft.item.crafting.IRecipeSerializer; @@ -296,18 +293,6 @@ public final class Registry ComputerCraftAPI.registerPocketUpgrade( ComputerCraft.PocketUpgrades.speaker = new PocketSpeaker() ); } - public static class ModEntities - { - static final DeferredRegister> ENTITIES = DeferredRegister.create( ForgeRegistries.ENTITIES, ComputerCraft.MOD_ID ); - - public static final RegistryObject> TURTLE_PLAYER = ENTITIES.register( "turtle_player", () -> - EntityType.Builder.createNothing( EntityClassification.MISC ) - .noSave() - .noSummon() - .sized( 0, 0 ) - .build( ComputerCraft.MOD_ID + ":turtle_player" ) ); - } - public static class ModContainers { static final DeferredRegister> CONTAINERS = DeferredRegister.create( ForgeRegistries.CONTAINERS, ComputerCraft.MOD_ID ); @@ -418,7 +403,6 @@ public final class Registry ModBlocks.BLOCKS.register( bus ); ModTiles.TILES.register( bus ); ModItems.ITEMS.register( bus ); - ModEntities.ENTITIES.register( bus ); ModContainers.CONTAINERS.register( bus ); } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java index f388e8367..ba9b513c6 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java @@ -8,14 +8,11 @@ package dan200.computercraft.shared.turtle.core; import com.mojang.authlib.GameProfile; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.turtle.ITurtleAccess; -import dan200.computercraft.shared.Registry; import dan200.computercraft.shared.util.DirectionUtil; -import dan200.computercraft.shared.util.FakeNetHandler; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.EntitySize; -import net.minecraft.entity.EntityType; import net.minecraft.entity.Pose; import net.minecraft.entity.passive.horse.AbstractHorseEntity; import net.minecraft.entity.player.ServerPlayerEntity; @@ -54,7 +51,6 @@ public final class TurtlePlayer extends FakePlayer GameProfile profile = turtle.getOwningPlayer(); TurtlePlayer player = new TurtlePlayer( world, getProfile( profile ) ); - player.connection = new FakeNetHandler( player ); player.setState( turtle ); if( profile != null && profile.getId() != null ) @@ -203,13 +199,6 @@ public final class TurtlePlayer extends FakePlayer inventory.setChanged(); } - @Nonnull - @Override - public EntityType getType() - { - return Registry.ModEntities.TURTLE_PLAYER.get(); - } - @Override public Vector3d position() { diff --git a/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java b/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java deleted file mode 100644 index 46a8fe924..000000000 --- a/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ -package dan200.computercraft.shared.util; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; -import net.minecraft.network.*; -import net.minecraft.network.play.ServerPlayNetHandler; -import net.minecraft.network.play.client.*; -import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.common.util.FakePlayer; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public class FakeNetHandler extends ServerPlayNetHandler -{ - public FakeNetHandler( @Nonnull FakePlayer player ) - { - super( player.getLevel().getServer(), new FakeNetworkManager(), player ); - } - - @Override - public void tick() - { - } - - @Override - public void disconnect( @Nonnull ITextComponent reason ) - { - } - - @Override - public void onDisconnect( @Nonnull ITextComponent reason ) - { - } - - @Override - public void send( @Nonnull IPacket packet ) - { - } - - @Override - public void send( @Nonnull IPacket packet, @Nullable GenericFutureListener> whenSent ) - { - } - - @Override - public void handlePlayerInput( @Nonnull CInputPacket packet ) - { - } - - @Override - public void handleMoveVehicle( @Nonnull CMoveVehiclePacket packet ) - { - } - - @Override - public void handleAcceptTeleportPacket( @Nonnull CConfirmTeleportPacket packet ) - { - } - - @Override - public void handleSeenAdvancements( @Nonnull CSeenAdvancementsPacket packet ) - { - } - - @Override - public void handleCustomCommandSuggestions( @Nonnull CTabCompletePacket packet ) - { - } - - @Override - public void handleSetCommandBlock( @Nonnull CUpdateCommandBlockPacket packet ) - { - } - - @Override - public void handleSetCommandMinecart( @Nonnull CUpdateMinecartCommandBlockPacket packet ) - { - } - - @Override - public void handlePickItem( @Nonnull CPickItemPacket packet ) - { - } - - @Override - public void handleRenameItem( @Nonnull CRenameItemPacket packet ) - { - } - - @Override - public void handleSetBeaconPacket( @Nonnull CUpdateBeaconPacket packet ) - { - } - - @Override - public void handleSetStructureBlock( @Nonnull CUpdateStructureBlockPacket packet ) - { - } - - @Override - public void handleSetJigsawBlock( @Nonnull CUpdateJigsawBlockPacket packet ) - { - } - - @Override - public void handleSelectTrade( @Nonnull CSelectTradePacket packet ) - { - } - - @Override - public void handleEditBook( @Nonnull CEditBookPacket packet ) - { - } - - @Override - public void handleEntityTagQuery( @Nonnull CQueryEntityNBTPacket packet ) - { - } - - @Override - public void handleBlockEntityTagQuery( @Nonnull CQueryTileEntityNBTPacket packet ) - { - } - - @Override - public void handleMovePlayer( @Nonnull CPlayerPacket packet ) - { - } - - @Override - public void handlePlayerAction( @Nonnull CPlayerDiggingPacket packet ) - { - } - - @Override - public void handleUseItemOn( @Nonnull CPlayerTryUseItemOnBlockPacket packet ) - { - } - - @Override - public void handleUseItem( @Nonnull CPlayerTryUseItemPacket packet ) - { - } - - @Override - public void handleTeleportToEntityPacket( @Nonnull CSpectatePacket packet ) - { - } - - @Override - public void handleResourcePackResponse( @Nonnull CResourcePackStatusPacket packet ) - { - } - - @Override - public void handlePaddleBoat( @Nonnull CSteerBoatPacket packet ) - { - } - - @Override - public void handleSetCarriedItem( @Nonnull CHeldItemChangePacket packet ) - { - } - - @Override - public void handleChat( @Nonnull CChatMessagePacket packet ) - { - } - - @Override - public void handleAnimate( @Nonnull CAnimateHandPacket packet ) - { - } - - @Override - public void handlePlayerCommand( @Nonnull CEntityActionPacket packet ) - { - } - - @Override - public void handleInteract( @Nonnull CUseEntityPacket packet ) - { - } - - @Override - public void handleClientCommand( @Nonnull CClientStatusPacket packet ) - { - } - - @Override - public void handleContainerClose( @Nonnull CCloseWindowPacket packet ) - { - } - - @Override - public void handleContainerClick( @Nonnull CClickWindowPacket packet ) - { - } - - @Override - public void handlePlaceRecipe( @Nonnull CPlaceRecipePacket packet ) - { - } - - @Override - public void handleContainerButtonClick( @Nonnull CEnchantItemPacket packet ) - { - } - - @Override - public void handleSetCreativeModeSlot( @Nonnull CCreativeInventoryActionPacket packet ) - { - } - - @Override - public void handleContainerAck( @Nonnull CConfirmTransactionPacket packet ) - { - } - - @Override - public void handleSignUpdate( @Nonnull CUpdateSignPacket packet ) - { - } - - @Override - public void handleKeepAlive( @Nonnull CKeepAlivePacket packet ) - { - } - - @Override - public void handlePlayerAbilities( @Nonnull CPlayerAbilitiesPacket packet ) - { - } - - @Override - public void handleClientInformation( @Nonnull CClientSettingsPacket packet ) - { - } - - @Override - public void handleCustomPayload( @Nonnull CCustomPayloadPacket packet ) - { - } - - @Override - public void handleChangeDifficulty( @Nonnull CSetDifficultyPacket packet ) - { - } - - @Override - public void handleLockDifficulty( @Nonnull CLockDifficultyPacket packet ) - { - } - - private static class FakeNetworkManager extends NetworkManager - { - private INetHandler handler; - private ITextComponent closeReason; - - FakeNetworkManager() - { - super( PacketDirection.CLIENTBOUND ); - } - - @Override - public void channelActive( @Nonnull ChannelHandlerContext context ) - { - } - - @Override - public void setProtocol( @Nonnull ProtocolType state ) - { - } - - @Override - public void channelInactive( @Nonnull ChannelHandlerContext context ) - { - } - - @Override - public void exceptionCaught( @Nonnull ChannelHandlerContext context, @Nonnull Throwable err ) - { - } - - @Override - protected void channelRead0( @Nonnull ChannelHandlerContext context, @Nonnull IPacket packet ) - { - } - - @Override - public void setListener( @Nonnull INetHandler handler ) - { - this.handler = handler; - } - - @Override - public void send( @Nonnull IPacket packet ) - { - } - - @Override - public void send( @Nonnull IPacket packet, @Nullable GenericFutureListener> whenSent ) - { - } - - @Override - public void tick() - { - } - - @Override - public void disconnect( @Nonnull ITextComponent message ) - { - closeReason = message; - } - - @Nonnull - @Override - public INetHandler getPacketListener() - { - return handler; - } - - @Nullable - @Override - public ITextComponent getDisconnectedReason() - { - return closeReason; - } - - @Override - public void setReadOnly() - { - } - - @Override - public void setupCompression( int threshold ) - { - } - } -}