mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 11:10:29 +00:00
Register item colour handlers on the event instead
Another step on my misguided quest to get rid of proxies
This commit is contained in:
parent
d5edbe700b
commit
6c2db93cbd
@ -8,6 +8,9 @@ package dan200.computercraft.client;
|
|||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.client.render.TurtleModelLoader;
|
import dan200.computercraft.client.render.TurtleModelLoader;
|
||||||
|
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
|
||||||
|
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
|
||||||
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
@ -18,6 +21,7 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.client.event.ColorHandlerEvent;
|
||||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
@ -109,6 +113,48 @@ public class ClientRegistry
|
|||||||
for( String model : EXTRA_MODELS ) loadBlockModel( event, model );
|
for( String model : EXTRA_MODELS ) loadBlockModel( event, model );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onItemColours( ColorHandlerEvent.Item event )
|
||||||
|
{
|
||||||
|
event.getItemColors().registerItemColorHandler(
|
||||||
|
( stack, layer ) -> layer == 0 ? 0xFFFFFF : ((ItemDiskLegacy) stack.getItem()).getColour( stack ),
|
||||||
|
ComputerCraft.Items.disk, ComputerCraft.Items.diskExpanded
|
||||||
|
);
|
||||||
|
|
||||||
|
event.getItemColors().registerItemColorHandler( ( stack, layer ) -> {
|
||||||
|
switch( layer )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
return 0xFFFFFF;
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
// Frame colour
|
||||||
|
int colour = ComputerCraft.Items.pocketComputer.getColour( stack );
|
||||||
|
return colour == -1 ? 0xFFFFFF : colour;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
// Light colour
|
||||||
|
int colour = ComputerCraft.Items.pocketComputer.getLightState( stack );
|
||||||
|
return colour == -1 ? Colour.Black.getHex() : colour;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, ComputerCraft.Items.pocketComputer );
|
||||||
|
|
||||||
|
// Setup turtle colours
|
||||||
|
event.getItemColors().registerItemColorHandler( ( stack, tintIndex ) -> {
|
||||||
|
if( tintIndex == 0 )
|
||||||
|
{
|
||||||
|
ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem();
|
||||||
|
int colour = turtle.getColour( stack );
|
||||||
|
if( colour != -1 ) return colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xFFFFFF;
|
||||||
|
}, ComputerCraft.Blocks.turtle, ComputerCraft.Blocks.turtleExpanded, ComputerCraft.Blocks.turtleAdvanced );
|
||||||
|
}
|
||||||
|
|
||||||
private static void registerItemModel( Item item, int damage, String name )
|
private static void registerItemModel( Item item, int damage, String name )
|
||||||
{
|
{
|
||||||
ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, name );
|
ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, name );
|
||||||
|
@ -6,12 +6,9 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.proxy;
|
package dan200.computercraft.client.proxy;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
|
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
|
||||||
import dan200.computercraft.shared.proxy.CCTurtleProxyCommon;
|
import dan200.computercraft.shared.proxy.CCTurtleProxyCommon;
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||||
|
|
||||||
public class CCTurtleProxyClient extends CCTurtleProxyCommon
|
public class CCTurtleProxyClient extends CCTurtleProxyCommon
|
||||||
@ -21,18 +18,6 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon
|
|||||||
{
|
{
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
// Setup turtle colours
|
|
||||||
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( ( stack, tintIndex ) -> {
|
|
||||||
if( tintIndex == 0 )
|
|
||||||
{
|
|
||||||
ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem();
|
|
||||||
int colour = turtle.getColour( stack );
|
|
||||||
if( colour != -1 ) return colour;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0xFFFFFF;
|
|
||||||
}, ComputerCraft.Blocks.turtle, ComputerCraft.Blocks.turtleExpanded, ComputerCraft.Blocks.turtleAdvanced );
|
|
||||||
|
|
||||||
// Setup renderers
|
// Setup renderers
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() );
|
||||||
}
|
}
|
||||||
|
@ -10,24 +10,16 @@ import dan200.computercraft.ComputerCraft;
|
|||||||
import dan200.computercraft.client.render.TileEntityCableRenderer;
|
import dan200.computercraft.client.render.TileEntityCableRenderer;
|
||||||
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
||||||
import dan200.computercraft.shared.command.CommandCopy;
|
import dan200.computercraft.shared.command.CommandCopy;
|
||||||
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
|
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
|
||||||
import dan200.computercraft.shared.util.Colour;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.color.IItemColor;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.client.ClientCommandHandler;
|
import net.minecraftforge.client.ClientCommandHandler;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||||
{
|
{
|
||||||
@ -45,33 +37,6 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
|||||||
{
|
{
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
|
||||||
|
|
||||||
// Setup
|
|
||||||
mc.getItemColors().registerItemColorHandler( new DiskColorHandler( ComputerCraft.Items.disk ), ComputerCraft.Items.disk );
|
|
||||||
mc.getItemColors().registerItemColorHandler( new DiskColorHandler( ComputerCraft.Items.diskExpanded ), ComputerCraft.Items.diskExpanded );
|
|
||||||
|
|
||||||
mc.getItemColors().registerItemColorHandler( ( stack, layer ) -> {
|
|
||||||
switch( layer )
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
return 0xFFFFFF;
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
// Frame colour
|
|
||||||
int colour = ComputerCraft.Items.pocketComputer.getColour( stack );
|
|
||||||
return colour == -1 ? 0xFFFFFF : colour;
|
|
||||||
}
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
// Light colour
|
|
||||||
int colour = ComputerCraft.Items.pocketComputer.getLightState( stack );
|
|
||||||
return colour == -1 ? Colour.Black.getHex() : colour;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, ComputerCraft.Items.pocketComputer );
|
|
||||||
|
|
||||||
// Setup renderers
|
// Setup renderers
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() );
|
||||||
@ -90,20 +55,5 @@ 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 colorMultiplier( @Nonnull ItemStack stack, int layer )
|
|
||||||
{
|
|
||||||
return layer == 0 ? 0xFFFFFF : disk.getColour( stack );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user