Skip to content

Commit

Permalink
Update to 1.21.4
Browse files Browse the repository at this point in the history
-- Item models aren't working yet
  • Loading branch information
Choonster committed Dec 7, 2024
1 parent 04db83d commit 918ca83
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 154 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ dependencies {
// TODO: Jade doesn't support Forge any more
// implementation fg.deobf("curse.maven:jade-324717:${jade_file_id}")

implementation "com.github.glitchfiend:TerraBlender-forge:1.21.3-${terrablender_version}"
implementation "com.github.glitchfiend:TerraBlender-forge:1.21.4-${terrablender_version}"

// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ org.gradle.daemon=false
## Environment Properties

# The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.21.3
minecraft_version=1.21.4

# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21.3,1.22)
minecraft_version_range=[1.21.4,1.22)

# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=53.0.25
forge_version=54.0.6

# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[0,)
Expand All @@ -40,11 +40,11 @@ mapping_channel=official

# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=1.21.3
mapping_version=1.21.4

jei_version=19.21.0.247

terrablender_version=4.2.0.1
terrablender_version=4.3.0.0

# Minecraft uses Apache HTTP Client 4.5.13, so we have to use the same version of the Fluent API
httpclient_version=4.5.13
Expand All @@ -62,7 +62,7 @@ mod_name=TestMod3
mod_license=MIT

# The mod version. See https://semver.org/
mod_version=21.0.0
mod_version=22.0.0

# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,84 @@
package choonster.testmod3.client.init;

import choonster.testmod3.TestMod3;
import choonster.testmod3.client.item.RevealHiddenBlocksItemPropertyFunction;
import choonster.testmod3.client.item.TicksSinceLastUseItemPropertyFunction;
import choonster.testmod3.init.ModItems;
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
import choonster.testmod3.client.renderer.item.properties.numeric.TicksSinceLastUse;
import com.mojang.serialization.MapCodec;
import net.minecraft.client.renderer.item.properties.conditional.ConditionalItemModelProperties;
import net.minecraft.client.renderer.item.properties.conditional.ConditionalItemModelProperty;
import net.minecraft.client.renderer.item.properties.numeric.RangeSelectItemModelProperties;
import net.minecraft.client.renderer.item.properties.numeric.RangeSelectItemModelProperty;
import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperties;
import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperty;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ExtraCodecs;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;

/**
* Registers this mod's {@link ClampedItemPropertyFunction}s.
* Registers this mod's {@link ConditionalItemModelProperty}, {@link RangeSelectItemModelProperty} and
* {@link SelectItemModelProperty} implementations.
*
* @author Choonster
*/
@Mod.EventBusSubscriber(modid = TestMod3.MODID, bus = Bus.MOD, value = Dist.CLIENT)
public class ModItemModelProperties {
private static final ExtraCodecs.LateBoundIdMapper<ResourceLocation, MapCodec<? extends SelectItemModelProperty.Type<?, ?>>> SELECT_ID_MAPPER;
private static final ExtraCodecs.LateBoundIdMapper<ResourceLocation, MapCodec<? extends ConditionalItemModelProperty>> CONDITIONAL_ID_MAPPER;
private static final ExtraCodecs.LateBoundIdMapper<ResourceLocation, MapCodec<? extends RangeSelectItemModelProperty>> RANGE_SELECT_ID_MAPPER;

// TODO: Refactor if/when Forge adds a proper event for this
@SubscribeEvent
public static void registerItemModelProperties(final FMLClientSetupEvent event) {
event.enqueueWork(() -> {
RevealHiddenBlocksItemPropertyFunction.registerForItem(ModItems.HIDDEN_BLOCK_REVEALER.get());
TicksSinceLastUseItemPropertyFunction.registerForItem(ModItems.MODEL_TEST.get());
TicksSinceLastUseItemPropertyFunction.registerForItem(ModItems.SLINGSHOT.get());
// RevealHiddenBlocksItemPropertyFunction.registerForItem(ModItems.HIDDEN_BLOCK_REVEALER.get());
registerRangeSelect("ticks_since_last_use", TicksSinceLastUse.MAP_CODEC);

// TicksSinceLastUse.registerForItem(ModItems.MODEL_TEST.get());
// TicksSinceLastUse.registerForItem(ModItems.SLINGSHOT.get());
});
}

private static <T extends RangeSelectItemModelProperty> void registerRangeSelect(
final String name,
final MapCodec<T> mapCodec
) {
RANGE_SELECT_ID_MAPPER.put(ResourceLocation.fromNamespaceAndPath(TestMod3.MODID, name), mapCodec);
}

static {
try {
@SuppressWarnings("unchecked") final var selectIdMapper =
(ExtraCodecs.LateBoundIdMapper<ResourceLocation, MapCodec<? extends SelectItemModelProperty.Type<?, ?>>>)
ObfuscationReflectionHelper.findField(
SelectItemModelProperties.class,
"ID_MAPPER"
).get(null);

SELECT_ID_MAPPER = selectIdMapper;

@SuppressWarnings("unchecked") final var conditionalIdMapper =
(ExtraCodecs.LateBoundIdMapper<ResourceLocation, MapCodec<? extends ConditionalItemModelProperty>>)
ObfuscationReflectionHelper.findField(
ConditionalItemModelProperties.class,
"ID_MAPPER"
).get(null);

CONDITIONAL_ID_MAPPER = conditionalIdMapper;

@SuppressWarnings("unchecked") final var rangeSelectIdMapper =
(ExtraCodecs.LateBoundIdMapper<ResourceLocation, MapCodec<? extends RangeSelectItemModelProperty>>)
ObfuscationReflectionHelper.findField(
RangeSelectItemModelProperties.class,
"ID_MAPPER"
).get(null);

RANGE_SELECT_ID_MAPPER = rangeSelectIdMapper;
} catch (final IllegalAccessException e) {
throw new RuntimeException("Failed to initialise Item Property ID Mappers", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
/**
* {@link ClampedItemPropertyFunction} to get whether hidden blocks are being revealed by an item's {@link ModDataComponents#REVEAL_HIDDEN_BLOCKS} component.
*/
public class RevealHiddenBlocksItemPropertyFunction {
// TODO: Replace with HasComponent
@Deprecated(forRemoval = true)
public record RevealHiddenBlocksItemPropertyFunction() {
/**
* The ID of this function.
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

/**
* Registers {@link BlockColor}/{@link ItemColor} handlers for this mod's blocks/items.
* Registers {@link BlockColor} handlers for this mod's blocks.
*
* @author Choonster
*/
Expand All @@ -36,7 +36,7 @@ public static void registerBlockColourHandlers(final RegisterColorHandlersEvent.
return BiomeColors.getAverageGrassColor(blockAccess, pos);
}

return GrassColor.get(0.5d, 1.0d);
return GrassColor.getDefaultColor();
};

event.register(grassColourHandler, ModBlocks.WATER_GRASS.get());
Expand All @@ -51,12 +51,14 @@ public static void registerBlockColourHandlers(final RegisterColorHandlersEvent.
public static void registerItemColourHandlers(final RegisterColorHandlersEvent.Item event) {
final BlockColors blockColors = event.getBlockColors();


// Use the Block's colour handler for an ItemBlock
final ItemColor itemBlockColourHandler = (stack, tintIndex) -> {
final BlockState state = ((BlockItem) stack.getItem()).getBlock().defaultBlockState();
return blockColors.getColor(state, null, null, tintIndex);
};

// TODO: Replace with GrassColorSource
event.register(itemBlockColourHandler, ModBlocks.WATER_GRASS.get());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package choonster.testmod3.client.renderer.item.properties.numeric;

import choonster.testmod3.TestMod3;
import choonster.testmod3.init.ModDataComponents;
import choonster.testmod3.world.item.component.lastusetime.LastUseTimeProperties;
import com.mojang.serialization.MapCodec;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.item.properties.numeric.RangeSelectItemModelProperty;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

/**
* {@link RangeSelectItemModelProperty} to get the ticks since the last use of the item,
* as recorded by the item's {@link LastUseTimeProperties} component.
* <p>
* Returns 0.0 if the item was last used 0 ticks ago and 1.0 if the item was last used 20 or more ticks ago.
* Returns 1.0 if the required information isn't available.
*/
public record TicksSinceLastUse() implements RangeSelectItemModelProperty {
public static final MapCodec<TicksSinceLastUse> MAP_CODEC = MapCodec.unit(new TicksSinceLastUse());

/**
* The ID of this function.
*/
@Deprecated(forRemoval = true)
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(TestMod3.MODID, "ticks_since_last_use");

@Override
public float get(
final ItemStack stack,
@Nullable final ClientLevel clientLevel,
@Nullable final LivingEntity entity,
final int seed
) {
final var level = clientLevel != null ? clientLevel : entity != null ? entity.level() : null;

if (level == null) {
return 1.0f;
}

return Optional.ofNullable(stack.get(ModDataComponents.LAST_USE_TIME_PROPERTIES.get()))
.map(properties -> (level.getGameTime() - properties.lastUseTime()) / 20.0f)
.orElse(1.0f);
}

@Override
public MapCodec<? extends RangeSelectItemModelProperty> type() {
return MAP_CODEC;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package choonster.testmod3.client.item;
package choonster.testmod3.client.renderer.item.properties.numeric;

import net.minecraft.FieldsAreNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package choonster.testmod3.data;

import choonster.testmod3.init.ModEquipmentAssets;
import net.minecraft.client.resources.model.EquipmentClientInfo;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.equipment.EquipmentAsset;

import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;

/**
* Generates this mod's equipment assets.
*
* @author Choonster
*/
public class TestMod3EquipmentAssetProvider implements DataProvider {
private final PackOutput.PathProvider pathProvider;

public TestMod3EquipmentAssetProvider(final PackOutput output) {
pathProvider = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, "equipment");
}

@Override
public CompletableFuture<?> run(final CachedOutput output) {
final var map = new HashMap<ResourceKey<EquipmentAsset>, EquipmentClientInfo>();

bootstrap((id, equipmentClientInfo) -> {
if (map.putIfAbsent(id, equipmentClientInfo) != null) {
throw new IllegalStateException("Tried to register equipment asset twice for id: " + id);
}
});

return DataProvider.saveAll(output, EquipmentClientInfo.CODEC, pathProvider::json, map);
}

@Override
public String getName() {
return "TestMod3 Equipment Asset Definitions";
}

private static void bootstrap(final BiConsumer<ResourceKey<EquipmentAsset>, EquipmentClientInfo> consumer) {
consumer.accept(ModEquipmentAssets.REPLACEMENT, onlyHumanoid("chainmail"));
}

private static EquipmentClientInfo onlyHumanoid(final String textureName) {
return EquipmentClientInfo.builder()
.addHumanoidLayers(ResourceLocation.withDefaultNamespace(textureName))
.build();
}
}
Loading

0 comments on commit 918ca83

Please sign in to comment.