Fix some problems with pocket computer model properties
- We were setting state twice, rather than state and coloured. - Fabric forces us to use the clamped item property getter, which doesn't work with our computer state, as it takes a value [0, 2]. - Fixup new pocket computer textures to match original ones. Co-authored-by: Jummit <jummit@web.de>
| @@ -40,11 +40,16 @@ import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; | ||||
| import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; | ||||
| import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback; | ||||
| import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry; | ||||
| import net.minecraft.client.multiplayer.ClientLevel; | ||||
| import net.minecraft.client.renderer.RenderType; | ||||
| import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; | ||||
| import net.minecraft.resources.ResourceLocation; | ||||
| import net.minecraft.world.entity.LivingEntity; | ||||
| import net.minecraft.world.inventory.InventoryMenu; | ||||
| import net.minecraft.world.item.Item; | ||||
| import net.minecraft.world.item.ItemStack; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
|  | ||||
| import java.util.function.Supplier; | ||||
|  | ||||
| @@ -101,7 +106,7 @@ public final class ComputerCraftProxyClient implements ClientModInitializer | ||||
|                 .ordinal(), | ||||
|             () -> Registry.ModItems.POCKET_COMPUTER_NORMAL, | ||||
|             () -> Registry.ModItems.POCKET_COMPUTER_ADVANCED ); | ||||
|         registerItemProperty( "state", | ||||
|         registerItemProperty( "coloured", | ||||
|             ( stack, world, player, integer ) -> IColouredItem.getColourBasic( stack ) != -1 ? 1 : 0, | ||||
|             () -> Registry.ModItems.POCKET_COMPUTER_NORMAL, | ||||
|             () -> Registry.ModItems.POCKET_COMPUTER_ADVANCED ); | ||||
| @@ -132,9 +137,25 @@ public final class ComputerCraftProxyClient implements ClientModInitializer | ||||
|     private static void registerItemProperty( String name, ClampedItemPropertyFunction getter, Supplier<? extends Item>... items ) | ||||
|     { | ||||
|         ResourceLocation id = new ResourceLocation( ComputerCraft.MOD_ID, name ); | ||||
|         // Terrible hack, but some of our properties return values greater than 1, so we don't want to clamp. | ||||
|         var unclampedGetter = new ClampedItemPropertyFunction() | ||||
|         { | ||||
|             @Override | ||||
|             @Deprecated | ||||
|             public float call( @NotNull ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i ) | ||||
|             { | ||||
|                 return getter.unclampedCall( itemStack, clientLevel, livingEntity, i ); | ||||
|             } | ||||
|  | ||||
|             @Override | ||||
|             public float unclampedCall( ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i ) | ||||
|             { | ||||
|                 return getter.unclampedCall( itemStack, clientLevel, livingEntity, i ); | ||||
|             } | ||||
|         }; | ||||
|         for( Supplier<? extends Item> item : items ) | ||||
|         { | ||||
|             FabricModelPredicateProviderRegistry.register( item.get(), id, getter ); | ||||
|             FabricModelPredicateProviderRegistry.register( item.get(), id, unclampedGetter ); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| Before Width: | Height: | Size: 283 B After Width: | Height: | Size: 668 B | 
| Before Width: | Height: | Size: 249 B After Width: | Height: | Size: 624 B | 
| Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 614 B | 
| Before Width: | Height: | Size: 125 B After Width: | Height: | Size: 548 B | 
| Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 484 B | 
| Before Width: | Height: | Size: 260 B After Width: | Height: | Size: 656 B | 
| Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 583 B | 
 Jonathan Coates
					Jonathan Coates