mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-28 12:27:39 +00:00
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:
@@ -14,6 +14,7 @@ import dan200.computercraft.shared.computer.core.ClientComputer;
|
|||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||||
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
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.media.items.ItemPrintout;
|
||||||
import dan200.computercraft.shared.network.ComputerCraftPacket;
|
import dan200.computercraft.shared.network.ComputerCraftPacket;
|
||||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
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.ItemMeshDefinition;
|
||||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
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.EntityPlayer;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.item.Item;
|
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.FMLCommonHandler;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
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 org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -62,12 +66,12 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
|||||||
public ComputerCraftProxyClient()
|
public ComputerCraftProxyClient()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// IComputerCraftProxy implementation
|
// IComputerCraftProxy implementation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
super.init();
|
super.init();
|
||||||
m_tick = 0;
|
m_tick = 0;
|
||||||
m_renderFrame = 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",
|
"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
|
// Setup renderers
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
||||||
|
|
||||||
@@ -225,7 +233,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
|||||||
ModelBakery.registerItemVariants( item, resources );
|
ModelBakery.registerItemVariants( item, resources );
|
||||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register( item, definition );
|
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register( item, definition );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClient()
|
public boolean isClient()
|
||||||
{
|
{
|
||||||
@@ -255,7 +263,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
|||||||
{
|
{
|
||||||
return m_fixedWidthFontRenderer;
|
return m_fixedWidthFontRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRecordInfo( ItemStack recordStack )
|
public String getRecordInfo( ItemStack recordStack )
|
||||||
{
|
{
|
||||||
@@ -267,7 +275,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
|||||||
return super.getRecordInfo( recordStack );
|
return super.getRecordInfo( recordStack );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos )
|
public void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos )
|
||||||
{
|
{
|
||||||
@@ -278,19 +286,19 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
|||||||
mc.ingameGUI.setRecordPlayingMessage( recordInfo );
|
mc.ingameGUI.setRecordPlayingMessage( recordInfo );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive )
|
public Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive )
|
||||||
{
|
{
|
||||||
return new GuiDiskDrive( inventory, drive );
|
return new GuiDiskDrive( inventory, drive );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getComputerGUI( TileComputer computer )
|
public Object getComputerGUI( TileComputer computer )
|
||||||
{
|
{
|
||||||
return new GuiComputer( computer );
|
return new GuiComputer( computer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer )
|
public Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer )
|
||||||
{
|
{
|
||||||
@@ -405,7 +413,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
|||||||
FMLCommonHandler.instance().bus().register( handlers );
|
FMLCommonHandler.instance().bus().register( handlers );
|
||||||
MinecraftForge.EVENT_BUS.register( handlers );
|
MinecraftForge.EVENT_BUS.register( handlers );
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ForgeHandlers
|
public class ForgeHandlers
|
||||||
{
|
{
|
||||||
public 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public abstract class BlockGeneric extends Block implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 );
|
TileEntity tile = world.getTileEntity( pos );
|
||||||
if( tile != null && tile instanceof TileGeneric )
|
if( tile != null && tile instanceof TileGeneric )
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new turtle
|
// 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();
|
Block block = world.getBlockState( pos ).getBlock();
|
||||||
if( block == oldBlock )
|
if( block == oldBlock )
|
||||||
@@ -525,6 +525,7 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
oldWorld.setBlockToAir( oldPos );
|
oldWorld.setBlockToAir( oldPos );
|
||||||
|
|
||||||
// Make sure everybody knows about it
|
// Make sure everybody knows about it
|
||||||
|
newTurtle.updateBlock();
|
||||||
newTurtle.updateInput();
|
newTurtle.updateInput();
|
||||||
newTurtle.updateOutput();
|
newTurtle.updateOutput();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user