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.
This commit is contained in:
SquidDev 2017-05-01 15:26:38 +01:00
parent 9b5f4a877c
commit 77d225d1fe
3 changed files with 38 additions and 12 deletions

View File

@ -14,6 +14,7 @@
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.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.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;
@ -172,6 +176,10 @@ public ModelResourceLocation getModelLocation( ItemStack stack )
"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() );
@ -491,4 +499,21 @@ public void onRenderTick( TickEvent.RenderTickEvent event )
}
}
}
@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);
}
}
}

View File

@ -152,7 +152,7 @@ public final boolean onBlockActivated( World world, BlockPos pos, IBlockState st
}
@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 )

View File

@ -505,7 +505,7 @@ public boolean teleportTo( World world, BlockPos pos )
}
// 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 boolean teleportTo( World world, BlockPos pos )
oldWorld.setBlockToAir( oldPos );
// Make sure everybody knows about it
newTurtle.updateBlock();
newTurtle.updateInput();
newTurtle.updateOutput();
return true;