1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-28 08:12:18 +00:00

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].

Solves half of #26, but will require some texture fixups too.
This commit is contained in:
Jonathan Coates 2021-12-19 13:04:19 +00:00
parent 6a4b5927bf
commit cfc9e2ad0d
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -39,11 +39,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;
@ -99,7 +104,7 @@ public final class ComputerCraftProxyClient implements ClientModInitializer
.ordinal(),
() -> ComputerCraftRegistry.ModItems.POCKET_COMPUTER_NORMAL,
() -> ComputerCraftRegistry.ModItems.POCKET_COMPUTER_ADVANCED );
registerItemProperty( "state",
registerItemProperty( "coloured",
( stack, world, player, integer ) -> IColouredItem.getColourBasic( stack ) != -1 ? 1 : 0,
() -> ComputerCraftRegistry.ModItems.POCKET_COMPUTER_NORMAL,
() -> ComputerCraftRegistry.ModItems.POCKET_COMPUTER_ADVANCED );
@ -130,9 +135,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 );
}
}
}