From 77d225d1fed87c3dc8aebed652059b7dbc3c5270 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 1 May 2017 15:26:38 +0100 Subject: [PATCH] Listen to correct block update We now listen to neighborChanged instead of onNeighborChange. This means computers correctly detect redstone updates. However, this leads to issues when moving turtles, so we defer the block update until the turtle has finished moving. --- .../proxy/ComputerCraftProxyClient.java | 45 ++++++++++++++----- .../shared/common/BlockGeneric.java | 2 +- .../shared/turtle/core/TurtleBrain.java | 3 +- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 213c32522..70e3ed6cb 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -14,6 +14,7 @@ import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.items.ItemComputer; import dan200.computercraft.shared.media.inventory.ContainerHeldItem; +import dan200.computercraft.shared.media.items.ItemDiskLegacy; import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.network.ComputerCraftPacket; import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive; @@ -28,6 +29,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.Item; @@ -47,6 +49,8 @@ import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.opengl.GL11; import java.io.File; @@ -62,12 +66,12 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon public ComputerCraftProxyClient() { } - + // IComputerCraftProxy implementation - + @Override public void init() - { + { super.init(); m_tick = 0; m_renderFrame = 0; @@ -172,6 +176,10 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon "advanced_pocket_computer_off", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking", "advanced_pocket_computer_on_modem_on", "advanced_pocket_computer_blinking_modem_on", } ); + // Setup item colours + mc.getItemColors().registerItemColorHandler(new DiskColorHandler(ComputerCraft.Items.disk), ComputerCraft.Items.disk); + mc.getItemColors().registerItemColorHandler(new DiskColorHandler(ComputerCraft.Items.diskExpanded), ComputerCraft.Items.diskExpanded); + // Setup renderers ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() ); @@ -225,7 +233,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon ModelBakery.registerItemVariants( item, resources ); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register( item, definition ); } - + @Override public boolean isClient() { @@ -255,7 +263,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon { return m_fixedWidthFontRenderer; } - + @Override public String getRecordInfo( ItemStack recordStack ) { @@ -267,7 +275,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon return super.getRecordInfo( recordStack ); } } - + @Override public void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos ) { @@ -278,19 +286,19 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon mc.ingameGUI.setRecordPlayingMessage( recordInfo ); } } - + @Override public Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive ) { return new GuiDiskDrive( inventory, drive ); } - + @Override public Object getComputerGUI( TileComputer computer ) { return new GuiComputer( computer ); } - + @Override public Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer ) { @@ -405,7 +413,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon FMLCommonHandler.instance().bus().register( handlers ); MinecraftForge.EVENT_BUS.register( handlers ); } - + public class ForgeHandlers { public ForgeHandlers() @@ -491,4 +499,21 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon } } } + + @SideOnly(Side.CLIENT) + private static class DiskColorHandler implements IItemColor + { + private final ItemDiskLegacy disk; + + private DiskColorHandler(ItemDiskLegacy disk) + { + this.disk = disk; + } + + @Override + public int getColorFromItemstack(ItemStack stack, int layer) + { + return layer == 0 ? 0xFFFFFF : disk.getColor(stack); + } + } } diff --git a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java index 7ef9304a6..0df9032ca 100644 --- a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java @@ -152,7 +152,7 @@ public abstract class BlockGeneric extends Block implements } @Override - public final void onNeighborChange( IBlockAccess world, BlockPos pos, BlockPos neighborPos ) + public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index 3ce166657..1c440d06f 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -505,7 +505,7 @@ public class TurtleBrain implements ITurtleAccess } // Create a new turtle - if( world.isBlockLoaded( pos ) && world.setBlockState( pos, oldBlock.getDefaultState(), 3 ) ) + if( world.isBlockLoaded( pos ) && world.setBlockState( pos, oldBlock.getDefaultState(), 0 ) ) { Block block = world.getBlockState( pos ).getBlock(); if( block == oldBlock ) @@ -525,6 +525,7 @@ public class TurtleBrain implements ITurtleAccess oldWorld.setBlockToAir( oldPos ); // Make sure everybody knows about it + newTurtle.updateBlock(); newTurtle.updateInput(); newTurtle.updateOutput(); return true;