mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-26 00:46:54 +00:00
Replace our ItemOverrideList overrides with property getters
This ends up being slightly cleaner as we can rely on Minecraft's own model dependency system. Also reduces reliance on Forge's APIs, which _potentially_ makes porting a little easier.
This commit is contained in:
parent
d9f03f3ec7
commit
37e25136ed
@ -11,12 +11,10 @@ import dan200.computercraft.client.gui.*;
|
||||
import dan200.computercraft.client.render.*;
|
||||
import dan200.computercraft.shared.command.CommandCopy;
|
||||
import dan200.computercraft.shared.command.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.ComputerState;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
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;
|
||||
@ -99,20 +97,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
public void registerModels( ModelRegistryEvent event )
|
||||
{
|
||||
// Register item models
|
||||
registerItemModel( ComputerCraft.Blocks.computer, new ItemMeshDefinition()
|
||||
{
|
||||
private ModelResourceLocation computer = new ModelResourceLocation( "computercraft:computer", "inventory" );
|
||||
private ModelResourceLocation advanced_computer = new ModelResourceLocation( "computercraft:advanced_computer", "inventory" );
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack )
|
||||
{
|
||||
ItemComputer itemComputer = (ItemComputer) stack.getItem();
|
||||
ComputerFamily family = itemComputer.getFamily( stack.getItemDamage() );
|
||||
return (family == ComputerFamily.Advanced) ? advanced_computer : computer;
|
||||
}
|
||||
}, new String[] { "computer", "advanced_computer" } );
|
||||
registerItemModel( ComputerCraft.Blocks.computer, "computer" );
|
||||
registerItemModel( ComputerCraft.Blocks.peripheral, 0, "peripheral" );
|
||||
registerItemModel( ComputerCraft.Blocks.peripheral, 1, "wireless_modem" );
|
||||
registerItemModel( ComputerCraft.Blocks.peripheral, 2, "monitor" );
|
||||
@ -131,72 +116,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
registerItemModel( ComputerCraft.Items.printout, 0, "printout" );
|
||||
registerItemModel( ComputerCraft.Items.printout, 1, "pages" );
|
||||
registerItemModel( ComputerCraft.Items.printout, 2, "book" );
|
||||
registerItemModel( ComputerCraft.Items.pocketComputer, new ItemMeshDefinition()
|
||||
{
|
||||
private ModelResourceLocation pocket_computer_off = new ModelResourceLocation( "computercraft:pocket_computer", "inventory" );
|
||||
private ModelResourceLocation pocket_computer_on = new ModelResourceLocation( "computercraft:pocket_computer_on", "inventory" );
|
||||
private ModelResourceLocation pocket_computer_blinking = new ModelResourceLocation( "computercraft:pocket_computer_blinking", "inventory" );
|
||||
private ModelResourceLocation advanced_pocket_computer_off = new ModelResourceLocation( "computercraft:advanced_pocket_computer", "inventory" );
|
||||
private ModelResourceLocation advanced_pocket_computer_on = new ModelResourceLocation( "computercraft:advanced_pocket_computer_on", "inventory" );
|
||||
private ModelResourceLocation advanced_pocket_computer_blinking = new ModelResourceLocation( "computercraft:advanced_pocket_computer_blinking", "inventory" );
|
||||
private ModelResourceLocation colour_pocket_computer_off = new ModelResourceLocation( "computercraft:pocket_computer_colour", "inventory" );
|
||||
private ModelResourceLocation colour_pocket_computer_on = new ModelResourceLocation( "computercraft:pocket_computer_colour_on", "inventory" );
|
||||
private ModelResourceLocation colour_pocket_computer_blinking = new ModelResourceLocation( "computercraft:pocket_computer_colour_blinking", "inventory" );
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack )
|
||||
{
|
||||
ItemPocketComputer itemPocketComputer = (ItemPocketComputer) stack.getItem();
|
||||
ComputerState state = itemPocketComputer.getState( stack );
|
||||
if( itemPocketComputer.getColour( stack ) == -1 )
|
||||
{
|
||||
switch( itemPocketComputer.getFamily( stack ) )
|
||||
{
|
||||
case Advanced:
|
||||
switch( state )
|
||||
{
|
||||
case Off:
|
||||
default:
|
||||
return advanced_pocket_computer_off;
|
||||
case On:
|
||||
return advanced_pocket_computer_on;
|
||||
case Blinking:
|
||||
return advanced_pocket_computer_blinking;
|
||||
}
|
||||
case Normal:
|
||||
default:
|
||||
switch( state )
|
||||
{
|
||||
case Off:
|
||||
default:
|
||||
return pocket_computer_off;
|
||||
case On:
|
||||
return pocket_computer_on;
|
||||
case Blinking:
|
||||
return pocket_computer_blinking;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( state )
|
||||
{
|
||||
case Off:
|
||||
default:
|
||||
return colour_pocket_computer_off;
|
||||
case On:
|
||||
return colour_pocket_computer_on;
|
||||
case Blinking:
|
||||
return colour_pocket_computer_blinking;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, new String[] {
|
||||
"pocket_computer", "pocket_computer_on", "pocket_computer_blinking",
|
||||
"advanced_pocket_computer", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking",
|
||||
"pocket_computer_colour", "pocket_computer_colour_on", "pocket_computer_colour_blinking",
|
||||
} );
|
||||
registerItemModel( ComputerCraft.Items.pocketComputer, "pocket_computer" );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -271,22 +191,6 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
} );
|
||||
}
|
||||
|
||||
private void registerItemModel( Block block, ItemMeshDefinition definition, String[] names )
|
||||
{
|
||||
registerItemModel( Item.getItemFromBlock( block ), definition, names );
|
||||
}
|
||||
|
||||
private void registerItemModel( Item item, ItemMeshDefinition definition, String[] names )
|
||||
{
|
||||
ResourceLocation[] resources = new ResourceLocation[names.length];
|
||||
for( int i = 0; i < resources.length; i++ )
|
||||
{
|
||||
resources[i] = new ResourceLocation( "computercraft", names[i] );
|
||||
}
|
||||
ModelBakery.registerItemVariants( item, resources );
|
||||
ModelLoader.setCustomMeshDefinition( item, definition );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClient()
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -26,7 +27,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class ItemComputer extends ItemComputerBase
|
||||
{
|
||||
public static int HIGHEST_DAMAGE_VALUE_ID = 16382;
|
||||
public static final int HIGHEST_DAMAGE_VALUE_ID = 16382;
|
||||
|
||||
public ItemComputer( Block block )
|
||||
{
|
||||
@ -35,6 +36,8 @@ public class ItemComputer extends ItemComputerBase
|
||||
setHasSubtypes( true );
|
||||
setTranslationKey( "computercraft:computer" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
addPropertyOverride( new ResourceLocation( ComputerCraft.MOD_ID, "family" ), ( stack, world, player ) ->
|
||||
getFamily( stack ) == ComputerFamily.Advanced ? 1 : 0 );
|
||||
}
|
||||
|
||||
public ItemStack create( int id, String label, ComputerFamily family )
|
||||
|
@ -25,13 +25,11 @@ import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.IItemPropertyGetter;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@ -48,6 +46,8 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
setHasSubtypes( true );
|
||||
setTranslationKey( "computercraft:pocket_computer" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
addPropertyOverride( new ResourceLocation( ComputerCraft.MOD_ID, "state" ), COMPUTER_STATE );
|
||||
addPropertyOverride( new ResourceLocation( ComputerCraft.MOD_ID, "type" ), COMPUTER_TYPE );
|
||||
}
|
||||
|
||||
public ItemStack create( int id, String label, int colour, ComputerFamily family, IPocketUpgrade upgrade )
|
||||
@ -563,4 +563,17 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
tag.setInteger( "colour", colour );
|
||||
}
|
||||
}
|
||||
|
||||
private static final IItemPropertyGetter COMPUTER_STATE = ( stack, world, player ) -> {
|
||||
ItemPocketComputer itemPocketComputer = (ItemPocketComputer) stack.getItem();
|
||||
ComputerState state = itemPocketComputer.getState( stack );
|
||||
|
||||
return state.ordinal();
|
||||
};
|
||||
|
||||
private static final IItemPropertyGetter COMPUTER_TYPE = ( stack, world, player ) -> {
|
||||
ItemPocketComputer item = (ItemPocketComputer) stack.getItem();
|
||||
if( item.getColour( stack ) != -1 ) return 2;
|
||||
return item.getFamily( stack ) == ComputerFamily.Advanced ? 1 : 0;
|
||||
};
|
||||
}
|
||||
|
@ -1,3 +1,13 @@
|
||||
{
|
||||
"parent": "computercraft:block/computer_blinking"
|
||||
"parent": "computercraft:block/computer_blinking",
|
||||
"overrides": [
|
||||
{
|
||||
"model": "computercraft:item/computer",
|
||||
"predicate": { "computercraft:family": 0 }
|
||||
},
|
||||
{
|
||||
"model": "computercraft:item/advanced_computer",
|
||||
"predicate": { "computercraft:family": 1 }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -3,5 +3,45 @@
|
||||
"textures": {
|
||||
"layer0": "computercraft:items/pocket_computer_frame",
|
||||
"layer1": "computercraft:items/pocket_computer"
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"model": "computercraft:item/pocket_computer",
|
||||
"predicate": { "computercraft:state": 0, "computercraft:type": 0 }
|
||||
},
|
||||
{
|
||||
"model": "computercraft:item/pocket_computer_on",
|
||||
"predicate": { "computercraft:state": 1, "computercraft:type": 0 }
|
||||
},
|
||||
{
|
||||
"model": "computercraft:item/pocket_computer_blinking",
|
||||
"predicate": { "computercraft:state": 2, "computercraft:type": 0 }
|
||||
},
|
||||
|
||||
{
|
||||
"model": "computercraft:item/advanced_pocket_computer",
|
||||
"predicate": { "computercraft:state": 0, "computercraft:type": 1 }
|
||||
},
|
||||
{
|
||||
"model": "computercraft:item/advanced_pocket_computer_on",
|
||||
"predicate": { "computercraft:state": 1, "computercraft:type": 1 }
|
||||
},
|
||||
{
|
||||
"model": "computercraft:item/advanced_pocket_computer_blinking",
|
||||
"predicate": { "computercraft:state": 2, "computercraft:type": 1 }
|
||||
},
|
||||
|
||||
{
|
||||
"model": "computercraft:item/pocket_computer_colour",
|
||||
"predicate": { "computercraft:state": 0, "computercraft:type": 2 }
|
||||
},
|
||||
{
|
||||
"model": "computercraft:item/pocket_computer_colour_on",
|
||||
"predicate": { "computercraft:state": 1, "computercraft:type": 2 }
|
||||
},
|
||||
{
|
||||
"model": "computercraft:item/pocket_computer_colour_blinking",
|
||||
"predicate": { "computercraft:state": 2, "computercraft:type": 2 }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user