Forge 1.19

* Bump pack.mcmeta formats
* 1.19 biome modifiers
* Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable
* Add docs and package-info to client extension interfaces package
* Move RenderBlockOverlayEvent hooks to ForgeHooksClient
* Add package-infos to client events package
* Rename SoundLoadEvent to SoundEngineLoadEvent

This reduces confusion from consumers which may think the
name SoundLoadEvent refers to an individual sound being loaded rather
than the sound engine.
* Document and change SoundLoadEvent to fire on mod bus

Previously, it fired on both the mod bus and the Forge bus, which is
confusing for consumers.
* Delete SoundSetupEvent

Looking at its original implementation shows that there isn't an
appropriate place in the new sound code to reinsert the event, and the
place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent.
* Perform some cleanup on client events

 - Removed nullable annotations from ClientPlayerNetworkEvent
 - Renamed #getPartialTicks methods to #getPartialTick, to be consistent
  with vanilla's naming of the partial tick
 - Cleanup documentation to remove line breaks, use the
  spelling 'cancelled' over
  'canceled', and improve docs on existing and
   new methods.
* Remove EntityEvent.CanUpdate

Closes MinecraftForge/MinecraftForge#6394
* Switch to Jetbrains nullability annotations
* New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent
* Remove ForgeWorldPresetScreens
* Remove IForgeRegistryEntry
* Remove use of List<Throwable> in FML's CompletableFutures
* Add docs to mod loading stages, stages, and phases
* Gradle 7.4.2
* Use SLF4J in FMLLoader and other subprojects
* Switch dynamic versions in subprojects to pinned ones
* Switch ForgeRoot and MDK to FG plugin markers
* Configure Forge javadoc task

The task now uses a custom stylesheet with MCForge elements, and
configured to combine the generation from the four FML subprojects
(fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project
into the javadoc output.
* Update docs/md files, for 1.19 update and the move away from IRC to Discord.
* Make "Potentially dangerous alternative prefix" a debug warning, not info.

Co-authored-by: Curle <[email protected]>
Co-authored-by: sciwhiz12 <[email protected]>
Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
committed 2022-06-07 15:31:26 -05:00
1 parent 270e778ac5
commit 4ed9117799
1485 files changed
+14960 -15446

No files matched your search

@@ -5,14 +5,12 @@
package net.minecraftforge.client.model;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Random;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import com.mojang.math.Transformation;
import net.minecraft.client.renderer.block.model.BakedQuad;
@@ -21,6 +19,7 @@ import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.Direction;
import org.jetbrains.annotations.Nullable;
public class BakedItemModel implements BakedModel
{
@@ -55,7 +54,7 @@ public class BakedItemModel implements BakedModel
@Override public ItemOverrides getOverrides() { return overrides; }
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
{
if (side == null)
{
@@ -93,7 +92,7 @@ public class BakedItemModel implements BakedModel
}
@Override
public List<BakedQuad> getQuads (@Nullable BlockState state, @Nullable Direction side, Random rand)
public List<BakedQuad> getQuads (@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
{
if(side == null)
{
@@ -5,12 +5,10 @@
package net.minecraftforge.client.model;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Random;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
@@ -21,6 +19,8 @@ import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraftforge.client.model.data.IModelData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class BakedModelWrapper<T extends BakedModel> implements BakedModel
{
@@ -32,7 +32,7 @@ public abstract class BakedModelWrapper<T extends BakedModel> implements BakedMo
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
{
return originalModel.getQuads(state, side, rand);
}
@@ -98,21 +98,21 @@ public abstract class BakedModelWrapper<T extends BakedModel> implements BakedMo
}
@Override
public TextureAtlasSprite getParticleIcon(@Nonnull IModelData data)
public TextureAtlasSprite getParticleIcon(@NotNull IModelData data)
{
return originalModel.getParticleIcon(data);
}
@Nonnull
@NotNull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
{
return originalModel.getQuads(state, side, rand, extraData);
}
@Nonnull
@NotNull
@Override
public IModelData getModelData(@Nonnull BlockAndTintGetter level, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData modelData)
public IModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull IModelData modelData)
{
return originalModel.getModelData(level, pos, state, modelData);
}
@@ -11,7 +11,6 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.client.model.geometry.IModelGeometry;
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
@@ -23,6 +22,7 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.Nullable;
public class BlockModelConfiguration implements IModelConfiguration
{
@@ -11,6 +11,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.datafixers.util.Pair;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.server.packs.resources.ResourceManager;
@@ -22,8 +23,6 @@ import net.minecraftforge.client.model.data.*;
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
import net.minecraftforge.client.model.geometry.IMultipartModelGeometry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
@@ -36,6 +35,8 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CompositeModel implements IDynamicBakedModel
{
@@ -58,9 +59,9 @@ public class CompositeModel implements IDynamicBakedModel
this.transforms = combinedTransform;
}
@Nonnull
@NotNull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
{
List<BakedQuad> quads = new ArrayList<>();
for(Map.Entry<String, BakedModel> entry : bakedParts.entrySet())
@@ -70,9 +71,9 @@ public class CompositeModel implements IDynamicBakedModel
return quads;
}
@Nonnull
@NotNull
@Override
public IModelData getModelData(@Nonnull BlockAndTintGetter level, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData modelData)
public IModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull IModelData modelData)
{
CompositeModelData composite = new CompositeModelData();
for(Map.Entry<String, BakedModel> entry : bakedParts.entrySet())
@@ -28,8 +28,6 @@ import net.minecraftforge.registries.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
@@ -40,6 +38,8 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class DynamicBucketModel implements IModelGeometry<DynamicBucketModel>
{
@@ -51,7 +51,7 @@ public final class DynamicBucketModel implements IModelGeometry<DynamicBucketMod
private static final float NORTH_Z_FLUID = 7.498f / 16f;
private static final float SOUTH_Z_FLUID = 8.502f / 16f;
@Nonnull
@NotNull
private final Fluid fluid;
private final boolean flipGas;
@@ -244,7 +244,7 @@ public final class DynamicBucketModel implements IModelGeometry<DynamicBucketMod
return FluidUtil.getFluidContained(stack)
.map(fluidStack -> {
Fluid fluid = fluidStack.getFluid();
String name = fluid.getRegistryName().toString();
String name = ForgeRegistries.FLUIDS.getKey(fluid).toString();
if (!cache.containsKey(name))
{
@@ -11,12 +11,10 @@ import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import javax.annotation.Nullable;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import com.mojang.math.Transformation;
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
@@ -51,6 +49,7 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.Nullable;
public final class FluidModel implements IModelGeometry<FluidModel>
{
@@ -186,7 +185,7 @@ public final class FluidModel implements IModelGeometry<FluidModel>
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData modelData)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, IModelData modelData)
{
if (side != null)
{
@@ -450,7 +449,7 @@ public final class FluidModel implements IModelGeometry<FluidModel>
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
{
return side == null ? ImmutableList.of() : faceQuads.get(side);
}
@@ -23,8 +23,6 @@ import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import static net.minecraftforge.fml.Logging.MODELLOADING;
import net.minecraft.client.resources.model.BakedModel;
@@ -32,6 +30,7 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.Nullable;
public final class ForgeModelBakery extends ModelBakery
{
@@ -10,8 +10,7 @@ import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.resources.model.Material;
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
/*
* Interface that provides generic access to the data within BlockModel,
@@ -26,7 +26,6 @@ import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
@@ -38,6 +37,7 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.Nullable;
/**
* Forge reimplementation of vanilla {@link ItemModelGenerator}, i.e. builtin/generated models,
@@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.datafixers.util.Pair;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
@@ -22,12 +23,11 @@ import net.minecraft.core.Direction;
import com.mojang.math.Transformation;
import net.minecraftforge.client.model.data.IDynamicBakedModel;
import net.minecraftforge.client.model.data.IModelData;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class ItemMultiLayerBakedModel implements IDynamicBakedModel
{
@@ -54,7 +54,7 @@ public class ItemMultiLayerBakedModel implements IDynamicBakedModel
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData modelData)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, IModelData modelData)
{
List<BakedQuad> quads = Lists.newArrayList();
layerModels.forEach(lm -> quads.addAll(lm.getFirst().getQuads(state, side, rand, modelData)));
@@ -12,8 +12,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
import net.minecraft.client.Minecraft;
@@ -27,14 +25,15 @@ import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import org.jetbrains.annotations.Nullable;
@EventBusSubscriber(modid = "forge", bus = Bus.FORGE, value = Dist.CLIENT)
public class ModelDataManager
{
private static WeakReference<Level> currentLevel = new WeakReference<>(null);
private static final Map<ChunkPos, Set<BlockPos>> needModelDataRefresh = new ConcurrentHashMap<>();
private static final Map<ChunkPos, Map<BlockPos, IModelData>> modelDataCache = new ConcurrentHashMap<>();
private static void cleanCaches(Level level)
@@ -48,7 +47,7 @@ public class ModelDataManager
modelDataCache.clear();
}
}
public static void requestModelDataRefresh(BlockEntity te)
{
Preconditions.checkNotNull(te, "Tile entity must not be null");
@@ -58,9 +57,9 @@ public class ModelDataManager
needModelDataRefresh.computeIfAbsent(new ChunkPos(te.getBlockPos()), $ -> Collections.synchronizedSet(new HashSet<>()))
.add(te.getBlockPos());
}
private static void refreshModelData(Level level, ChunkPos chunk)
{
{
cleanCaches(level);
Set<BlockPos> needUpdate = needModelDataRefresh.remove(chunk);
@@ -81,22 +80,22 @@ public class ModelDataManager
}
}
}
@SubscribeEvent
public static void onChunkUnload(ChunkEvent.Unload event)
{
if (!event.getChunk().getWorldForge().isClientSide()) return;
ChunkPos chunk = event.getChunk().getPos();
needModelDataRefresh.remove(chunk);
modelDataCache.remove(chunk);
}
public static @Nullable IModelData getModelData(Level level, BlockPos pos)
{
return getModelData(level, new ChunkPos(pos)).get(pos);
}
public static Map<BlockPos, IModelData> getModelData(Level level, ChunkPos pos)
{
Preconditions.checkArgument(level.isClientSide, "Cannot request model data for server level");
@@ -28,7 +28,6 @@ import net.minecraftforge.client.model.geometry.ISimpleModelGeometry;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.common.model.TransformationHelper;
import javax.annotation.Nullable;
import java.lang.reflect.Type;
import java.util.*;
import java.util.function.Function;
@@ -49,6 +48,7 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.Nullable;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -7,14 +7,12 @@ package net.minecraftforge.client.model;
import java.util.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.collect.*;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.datafixers.util.Pair;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.renderer.RenderType;
import com.mojang.math.Transformation;
@@ -45,6 +43,8 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A model that can be rendered in multiple {@link RenderType}.
@@ -132,9 +132,9 @@ public final class MultiLayerModel implements IModelGeometry<MultiLayerModel>
}).collect(Collectors.toList());
}
@Nonnull
@NotNull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
{
RenderType layer = MinecraftForgeClient.getRenderType();
if (layer == null)
@@ -6,11 +6,11 @@
package net.minecraftforge.client.model;
import java.util.EnumMap;
import java.util.Random;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.multiplayer.ClientLevel;
@@ -22,15 +22,14 @@ import net.minecraftforge.client.model.data.IDynamicBakedModel;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.common.model.TransformationHelper;
import javax.annotation.Nullable;
import java.util.List;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemOverride;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelState;
import org.jetbrains.annotations.Nullable;
public class PerspectiveMapWrapper implements IDynamicBakedModel
{
@@ -124,7 +123,7 @@ public class PerspectiveMapWrapper implements IDynamicBakedModel
@Override public TextureAtlasSprite getParticleIcon() { return parent.getParticleIcon(); }
@SuppressWarnings("deprecation")
@Override public ItemTransforms getTransforms() { return parent.getTransforms(); }
@Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData extraData)
@Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, IModelData extraData)
{
return parent.getQuads(state, side, rand, extraData);
}
@@ -13,7 +13,7 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.datafixers.util.Pair;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.server.packs.resources.ResourceManager;
@@ -22,21 +22,18 @@ import net.minecraft.util.GsonHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.client.model.geometry.IModelGeometry;
import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Function;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.Nullable;
public class SeparatePerspectiveModel implements IModelGeometry<SeparatePerspectiveModel>
{
@@ -94,7 +91,7 @@ public class SeparatePerspectiveModel implements IModelGeometry<SeparatePerspect
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
{
return Collections.emptyList();
}
@@ -12,8 +12,8 @@ import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.client.textures.UnitSprite;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.util.Map;
/**
@@ -1,787 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.client.model.b3d;
import com.google.common.base.Objects;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexFormatElement;
import com.mojang.math.Matrix4f;
import com.mojang.math.Transformation;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.*;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.CompositeModelState;
import net.minecraftforge.client.model.ForgeModelBakery;
import net.minecraftforge.client.model.ModelLoadingException;
import net.minecraftforge.client.model.PerspectiveMapWrapper;
import net.minecraftforge.client.model.b3d.B3DModel.*;
import net.minecraftforge.client.model.data.IDynamicBakedModel;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
import net.minecraftforge.common.model.TransformationHelper;
import net.minecraftforge.common.property.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
/*
* Loader for Blitz3D models.
*/
@Deprecated(forRemoval = true, since = "1.18")
public enum B3DLoader
{
INSTANCE;
private static final Logger LOGGER = LogManager.getLogger();
private ResourceManager manager;
private final Set<String> enabledDomains = new HashSet<>();
private final Map<ResourceLocation, B3DModel> cache = new HashMap<>();
public UnbakedModel loadModel(ResourceLocation modelLocation) throws Exception
{
ResourceLocation file = new ResourceLocation(modelLocation.getNamespace(), modelLocation.getPath());
if(!cache.containsKey(file))
{
Resource resource = null;
try
{
try
{
resource = manager.getResource(file);
}
catch(FileNotFoundException e)
{
if(modelLocation.getPath().startsWith("models/block/"))
resource = manager.getResource(new ResourceLocation(file.getNamespace(), "models/item/" + file.getPath().substring("models/block/".length())));
else if(modelLocation.getPath().startsWith("models/item/"))
resource = manager.getResource(new ResourceLocation(file.getNamespace(), "models/block/" + file.getPath().substring("models/item/".length())));
else throw e;
}
B3DModel.Parser parser = new B3DModel.Parser(resource.getInputStream());
B3DModel model = parser.parse();
cache.put(file, model);
}
catch(IOException e)
{
cache.put(file, null);
throw e;
}
finally
{
IOUtils.closeQuietly(resource);
}
}
B3DModel model = cache.get(file);
if(model == null) throw new ModelLoadingException("Error loading model previously: " + file);
if(!(model.getRoot().getKind() instanceof Mesh))
{
return new ModelWrapper(modelLocation, model, ImmutableSet.of(), true, true, true, 1);
}
return new ModelWrapper(modelLocation, model, ImmutableSet.of(model.getRoot().getName()), true, true, true, 1);
}
public static final class B3DState implements ModelState
{
@Nullable
private final Animation animation;
private final int frame;
private final int nextFrame;
private final float progress;
@Nullable
private final ModelState parent;
public B3DState(@Nullable Animation animation, int frame)
{
this(animation, frame, frame, 0);
}
public B3DState(@Nullable Animation animation, int frame, ModelState parent)
{
this(animation, frame, frame, 0, parent);
}
public B3DState(@Nullable Animation animation, int frame, int nextFrame, float progress)
{
this(animation, frame, nextFrame, progress, null);
}
public B3DState(@Nullable Animation animation, int frame, int nextFrame, float progress, @Nullable ModelState parent)
{
this.animation = animation;
this.frame = frame;
this.nextFrame = nextFrame;
this.progress = Mth.clamp(progress, 0, 1);
this.parent = getParent(parent);
}
@Nullable
private ModelState getParent(@Nullable ModelState parent)
{
if (parent == null) return null;
else if (parent instanceof B3DState) return ((B3DState)parent).parent;
return parent;
}
@Nullable
public Animation getAnimation()
{
return animation;
}
public int getFrame()
{
return frame;
}
public int getNextFrame()
{
return nextFrame;
}
public float getProgress()
{
return progress;
}
@Nullable
public ModelState getParent()
{
return parent;
}
@Override
public Transformation getRotation()
{
if(parent != null)
{
return parent.getRotation();
}
return Transformation.identity();
}
@Override
public Transformation getPartTransformation(Object part)
{
// TODO make more use of Optional
if(!(part instanceof NodeJoint))
{
return Transformation.identity();
}
Node<?> node = ((NodeJoint)part).getNode();
Transformation nodeTransform;
if(progress < 1e-5 || frame == nextFrame)
{
nodeTransform = getNodeMatrix(node, frame);
}
else if(progress > 1 - 1e-5)
{
nodeTransform = getNodeMatrix(node, nextFrame);
}
else
{
nodeTransform = getNodeMatrix(node, frame);
nodeTransform = TransformationHelper.slerp(nodeTransform,getNodeMatrix(node, nextFrame), progress);
}
if(parent != null && node.getParent() == null)
{
return parent.getPartTransformation(part).compose(nodeTransform);
}
return nodeTransform;
}
private static LoadingCache<Triple<Animation, Node<?>, Integer>, Transformation> cache = CacheBuilder.newBuilder()
.maximumSize(16384)
.expireAfterAccess(2, TimeUnit.MINUTES)
.build(new CacheLoader<Triple<Animation, Node<?>, Integer>, Transformation>()
{
@Override
public Transformation load(Triple<Animation, Node<?>, Integer> key) throws Exception
{
return getNodeMatrix(key.getLeft(), key.getMiddle(), key.getRight());
}
});
public Transformation getNodeMatrix(Node<?> node)
{
return getNodeMatrix(node, frame);
}
public Transformation getNodeMatrix(Node<?> node, int frame)
{
return cache.getUnchecked(Triple.of(animation, node, frame));
}
public static Transformation getNodeMatrix(@Nullable Animation animation, Node<?> node, int frame)
{
Transformation ret = Transformation.identity();
Key key = null;
if(animation != null) key = animation.getKeys().get(frame, node);
else if(node.getAnimation() != null) key = node.getAnimation().getKeys().get(frame, node);
if(key != null)
{
Node<?> parent = node.getParent();
if(parent != null)
{
// parent model-global current pose
Transformation pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
ret = ret.compose(pm);
// joint offset in the parent coords
ret = ret.compose(new Transformation(parent.getPos(), parent.getRot(), parent.getScale(), null));
}
// current node local pose
ret = ret.compose(new Transformation(key.getPos(), key.getRot(), key.getScale(), null));
// this part moved inside the model
// inverse bind of the current node
/*Matrix4f rm = new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null).getMatrix();
rm.invert();
ret = ret.compose(new TRSRTransformation(rm));
if(parent != null)
{
// inverse bind of the parent
rm = new TRSRTransformation(parent.getPos(), parent.getRot(), parent.getScale(), null).getMatrix();
rm.invert();
ret = ret.compose(new TRSRTransformation(rm));
}*/
// TODO cache
Transformation invBind = new NodeJoint(node).getInvBindPose();
ret = ret.compose(invBind);
}
else
{
Node<?> parent = node.getParent();
if(parent != null)
{
// parent model-global current pose
Transformation pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
ret = ret.compose(pm);
// joint offset in the parent coords
ret = ret.compose(new Transformation(parent.getPos(), parent.getRot(), parent.getScale(), null));
}
ret = ret.compose(new Transformation(node.getPos(), node.getRot(), node.getScale(), null));
// TODO cache
Transformation invBind = new NodeJoint(node).getInvBindPose();
ret = ret.compose(invBind);
}
return ret;
}
}
static final class NodeJoint
{
private final Node<?> node;
public NodeJoint(Node<?> node)
{
this.node = node;
}
public Transformation getInvBindPose()
{
Matrix4f m = new Transformation(node.getPos(), node.getRot(), node.getScale(), null).getMatrix();
m.invert();
Transformation pose = new Transformation(m);
if(node.getParent() != null)
{
Transformation parent = new NodeJoint(node.getParent()).getInvBindPose();
pose = pose.compose(parent);
}
return pose;
}
public Optional<NodeJoint> getParent()
{
// FIXME cache?
if(node.getParent() == null) return Optional.empty();
return Optional.of(new NodeJoint(node.getParent()));
}
public Node<?> getNode()
{
return node;
}
public int hashCode()
{
return node.hashCode();
}
public boolean equals(Object obj)
{
if (this == obj) return true;
if (!super.equals(obj)) return false;
if (getClass() != obj.getClass()) return false;
NodeJoint other = (NodeJoint) obj;
return Objects.equal(node, other.node);
}
}
private static final class ModelWrapper implements UnbakedModel
{
private final ResourceLocation modelLocation;
private final B3DModel model;
private final ImmutableSet<String> meshes;
private final ImmutableMap<String, String> textures;
private final boolean smooth;
private final boolean gui3d;
private final boolean isSideLit;
private final int defaultKey;
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, boolean smooth, boolean gui3d, boolean isSideLit, int defaultKey)
{
this(modelLocation, model, meshes, smooth, gui3d, isSideLit, defaultKey, buildTextures(model.getTextures()));
}
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, boolean smooth, boolean gui3d, boolean isSideLit, int defaultKey, ImmutableMap<String, String> textures)
{
this.modelLocation = modelLocation;
this.model = model;
this.meshes = meshes;
this.isSideLit = isSideLit;
this.textures = textures;
this.smooth = smooth;
this.gui3d = gui3d;
this.defaultKey = defaultKey;
}
private static ImmutableMap<String, String> buildTextures(List<Texture> textures)
{
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for(Texture t : textures)
{
String path = t.getPath();
String location = getLocation(path);
if(!location.startsWith("#")) location = "#" + location;
builder.put(path, location);
}
return builder.build();
}
private static String getLocation(String path)
{
if(path.endsWith(".png")) path = path.substring(0, path.length() - ".png".length());
return path;
}
@SuppressWarnings("deprecation")
@Override
public Collection<Material> getMaterials(Function<ResourceLocation, UnbakedModel> modelGetter, Set<com.mojang.datafixers.util.Pair<String, String>> missingTextureErrors)
{
return textures.values().stream().filter(loc -> !loc.startsWith("#"))
.map(t -> new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(t)))
.collect(Collectors.toList());
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return Collections.emptyList();
}
@SuppressWarnings("deprecation")
@Nullable
@Override
public BakedModel bake(ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation)
{
ImmutableMap.Builder<String, TextureAtlasSprite> builder = ImmutableMap.builder();
TextureAtlasSprite missing = spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, MissingTextureAtlasSprite.getLocation()));
for(Map.Entry<String, String> e : textures.entrySet())
{
if(e.getValue().startsWith("#"))
{
LOGGER.fatal("unresolved texture '{}' for b3d model '{}'", e.getValue(), this.modelLocation);
builder.put(e.getKey(), missing);
}
else
{
builder.put(e.getKey(), spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(e.getValue()))));
}
}
builder.put("missingno", missing);
return new BakedWrapper(model.getRoot(), modelTransform, smooth, gui3d, isSideLit, meshes, builder.build());
}
public ModelWrapper retexture(ImmutableMap<String, String> textures)
{
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for(Map.Entry<String, String> e : this.textures.entrySet())
{
String path = e.getKey();
String loc = getLocation(path);
// FIXME: Backward compatibilty: support finding textures that start with #, even though this is not how vanilla works
if(loc.startsWith("#") && (textures.containsKey(loc) || textures.containsKey(loc.substring(1))))
{
String alt = loc.substring(1);
String newLoc = textures.get(loc);
if(newLoc == null) newLoc = textures.get(alt);
if(newLoc == null) newLoc = path.substring(1);
builder.put(e.getKey(), newLoc);
}
else
{
builder.put(e);
}
}
return new ModelWrapper(modelLocation, model, meshes, smooth, gui3d, isSideLit, defaultKey, builder.build());
}
public ModelWrapper process(ImmutableMap<String, String> data)
{
ImmutableSet<String> newMeshes = this.meshes;
int newDefaultKey = this.defaultKey;
boolean hasChanged = false;
if(data.containsKey("mesh"))
{
JsonElement e = new JsonParser().parse(data.get("mesh"));
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isString())
{
return new ModelWrapper(modelLocation, model, ImmutableSet.of(e.getAsString()), smooth, gui3d, isSideLit, defaultKey, textures);
}
else if (e.isJsonArray())
{
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for(JsonElement s : e.getAsJsonArray())
{
if(s.isJsonPrimitive() && s.getAsJsonPrimitive().isString())
{
builder.add(s.getAsString());
}
else
{
LOGGER.fatal("unknown mesh definition '{}' in array for b3d model '{}'", s.toString(), modelLocation);
return this;
}
}
newMeshes = builder.build();
hasChanged = true;
}
else
{
LOGGER.fatal("unknown mesh definition '{}' for b3d model '{}'", e.toString(), modelLocation);
return this;
}
}
if(data.containsKey("key"))
{
JsonElement e = new JsonParser().parse(data.get("key"));
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isNumber())
{
newDefaultKey = e.getAsNumber().intValue();
hasChanged = true;
}
else
{
LOGGER.fatal("unknown keyframe definition '{}' for b3d model '{}'", e.toString(), modelLocation);
return this;
}
}
return hasChanged ? new ModelWrapper(modelLocation, model, newMeshes, smooth, gui3d, isSideLit, newDefaultKey, textures) : this;
}
public ModelState getDefaultState()
{
return new B3DState(model.getRoot().getAnimation(), defaultKey, defaultKey, 0);
}
public ModelWrapper smoothLighting(boolean value)
{
if(value == smooth)
{
return this;
}
return new ModelWrapper(modelLocation, model, meshes, value, gui3d, isSideLit, defaultKey, textures);
}
public ModelWrapper gui3d(boolean value)
{
if(value == gui3d)
{
return this;
}
return new ModelWrapper(modelLocation, model, meshes, smooth, value, isSideLit, defaultKey, textures);
}
}
private static final class BakedWrapper implements IDynamicBakedModel
{
private final Node<?> node;
private final ModelState state;
private final boolean smooth;
private final boolean gui3d;
private final boolean isSideLit;
private final ImmutableSet<String> meshes;
private final ImmutableMap<String, TextureAtlasSprite> textures;
private final LoadingCache<Integer, B3DState> cache;
private ImmutableList<BakedQuad> quads;
public record HiddenModelPart(ImmutableList<String> path) { }
public BakedWrapper(final Node<?> node, final ModelState state, final boolean smooth, final boolean gui3d, boolean isSideLit, final ImmutableSet<String> meshes, final ImmutableMap<String, TextureAtlasSprite> textures)
{
this(node, state, smooth, gui3d, isSideLit, meshes, textures, CacheBuilder.newBuilder()
.maximumSize(128)
.expireAfterAccess(2, TimeUnit.MINUTES)
.build(new CacheLoader<Integer, B3DState>()
{
@Override
public B3DState load(Integer frame) throws Exception
{
ModelState parent = state;
Animation newAnimation = node.getAnimation();
if(parent instanceof B3DState)
{
B3DState ps = (B3DState)parent;
parent = ps.getParent();
}
return new B3DState(newAnimation, frame, frame, 0, parent);
}
}));
}
public BakedWrapper(Node<?> node, ModelState state, boolean smooth, boolean gui3d, boolean isSideLit, ImmutableSet<String> meshes, ImmutableMap<String, TextureAtlasSprite> textures, LoadingCache<Integer, B3DState> cache)
{
this.node = node;
this.state = state;
this.smooth = smooth;
this.gui3d = gui3d;
this.isSideLit = isSideLit;
this.meshes = meshes;
this.textures = textures;
this.cache = cache;
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData data)
{
if(side != null) return ImmutableList.of();
ModelState modelState = this.state;
ModelState newState = data.getData(Properties.AnimationProperty);
if(newState != null)
{
// FIXME: should animation state handle the parent state, or should it remain here?
ModelState parent = this.state;
if(parent instanceof B3DState)
{
B3DState ps = (B3DState)parent;
parent = ps.getParent();
}
if (parent == null)
{
modelState = newState;
}
else
{
modelState = new CompositeModelState(parent, newState);
}
}
if(quads == null)
{
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
generateQuads(builder, node, this.state, ImmutableList.of());
quads = builder.build();
}
// TODO: caching?
if(this.state != modelState)
{
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
generateQuads(builder, node, modelState, ImmutableList.of());
return builder.build();
}
return quads;
}
private void generateQuads(ImmutableList.Builder<BakedQuad> builder, Node<?> node, final ModelState state, ImmutableList<String> path)
{
ImmutableList.Builder<String> pathBuilder = ImmutableList.builder();
pathBuilder.addAll(path);
pathBuilder.add(node.getName());
ImmutableList<String> newPath = pathBuilder.build();
for(Node<?> child : node.getNodes().values())
{
generateQuads(builder, child, state, newPath);
}
if(node.getKind() instanceof Mesh && meshes.contains(node.getName()) && state.getPartTransformation(new HiddenModelPart(newPath)).isIdentity())
{
Mesh mesh = (Mesh)node.getKind();
Collection<Face> faces = mesh.bake(new Function<Node<?>, Matrix4f>()
{
private final Transformation global = state.getRotation();
private final LoadingCache<Node<?>, Transformation> localCache = CacheBuilder.newBuilder()
.maximumSize(32)
.build(new CacheLoader<Node<?>, Transformation>()
{
@Override
public Transformation load(Node<?> node) throws Exception
{
return state.getPartTransformation(new NodeJoint(node));
}
});
@Override
public Matrix4f apply(Node<?> node)
{
return global.compose(localCache.getUnchecked(node)).getMatrix();
}
});
for(Face f : faces)
{
List<Texture> textures = null;
if(f.getBrush() != null) textures = f.getBrush().getTextures();
TextureAtlasSprite sprite;
if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno");
else if(textures.get(0) == B3DModel.Texture.White) sprite = ForgeModelBakery.White.instance();
else sprite = this.textures.get(textures.get(0).getPath());
BakedQuadBuilder quadBuilder = new BakedQuadBuilder(sprite);
quadBuilder.setContractUVs(true);
quadBuilder.setQuadOrientation(Direction.getNearest(f.getNormal().x(), f.getNormal().y(), f.getNormal().z()));
putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite);
putVertexData(quadBuilder, f.getV2(), f.getNormal(), sprite);
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);
builder.add(quadBuilder.build());
}
}
}
private final void putVertexData(IVertexConsumer consumer, Vertex v, Vector3f faceNormal, TextureAtlasSprite sprite)
{
// TODO handle everything not handled (texture transformations, bones, transformations, normals, e.t.c)
ImmutableList<VertexFormatElement> vertexFormatElements = consumer.getVertexFormat().getElements();
for(int e = 0; e < vertexFormatElements.size(); e++)
{
switch(vertexFormatElements.get(e).getUsage())
{
case POSITION:
consumer.put(e, v.getPos().x(), v.getPos().y(), v.getPos().z(), 1);
break;
case COLOR:
if(v.getColor() != null)
{
consumer.put(e, v.getColor().x(), v.getColor().y(), v.getColor().z(), v.getColor().w());
}
else
{
consumer.put(e, 1, 1, 1, 1);
}
break;
case UV:
// TODO handle more brushes
if(vertexFormatElements.get(e).getIndex() < v.getTexCoords().length)
{
consumer.put(e,
sprite.getU(v.getTexCoords()[0].x() * 16),
sprite.getV(v.getTexCoords()[0].y() * 16),
0,
1
);
}
else
{
consumer.put(e, 0, 0, 0, 1);
}
break;
case NORMAL:
if(v.getNormal() != null)
{
consumer.put(e, v.getNormal().x(), v.getNormal().y(), v.getNormal().z(), 0);
}
else
{
consumer.put(e, faceNormal.x(), faceNormal.y(), faceNormal.z(), 0);
}
break;
default:
consumer.put(e);
}
}
}
@Override
public boolean useAmbientOcclusion()
{
return smooth;
}
@Override
public boolean isGui3d()
{
return gui3d;
}
@Override
public boolean usesBlockLight()
{
return isSideLit;
}
@Override
public boolean isCustomRenderer()
{
return false;
}
@Override
public TextureAtlasSprite getParticleIcon()
{
// FIXME somehow specify particle texture in the model
return textures.values().asList().get(0);
}
@Override
public boolean doesHandlePerspectives()
{
return true;
}
@Override
public BakedModel handlePerspective(TransformType cameraTransformType, PoseStack poseStack)
{
return PerspectiveMapWrapper.handlePerspective(this, state, cameraTransformType, poseStack);
}
@Override
public ItemOverrides getOverrides()
{
// TODO handle items
return ItemOverrides.EMPTY;
}
}
}
File diff suppressed because it is too large. Load diff
@@ -6,29 +6,28 @@
package net.minecraftforge.client.model.data;
import java.util.List;
import java.util.Random;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Convenience interface with default implementation of {@link BakedModel#getQuads(BlockState, Direction, Random, IModelData)}.
* Convenience interface with default implementation of {@link BakedModel#getQuads(BlockState, Direction, RandomSource, IModelData)}.
*/
public interface IDynamicBakedModel extends BakedModel
{
@Override
default @Nonnull List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand)
default @NotNull List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand)
{
return getQuads(state, side, rand, EmptyModelData.INSTANCE);
}
// Force this to be overriden otherwise this introduces a default cycle between the two overloads.
@Override
@Nonnull
List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData);
@NotNull
List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData);
}
@@ -5,7 +5,7 @@
package net.minecraftforge.client.model.data;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
public interface IModelData
{
@@ -16,7 +16,7 @@ public interface IModelData
* <p>
* IMPORTANT: {@link #getData(ModelProperty)} <em>can</em> return {@code null}
* even if this method returns {@code true}.
*
*
* @param prop The property to check for inclusion in this model data
* @return {@code true} if this data has the given property, even if no value is present
*/
@@ -24,7 +24,7 @@ public interface IModelData
@Nullable
<T> T getData(ModelProperty<T> prop);
@Nullable
<T> T setData(ModelProperty<T> prop, T data);
}
@@ -10,8 +10,8 @@ import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -5,10 +5,9 @@
package net.minecraftforge.client.model.generators;
import javax.annotation.Nonnull;
import net.minecraft.data.DataGenerator;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.NotNull;
/**
* Stub class to extend for block model data providers, eliminates some
@@ -20,7 +19,7 @@ public abstract class BlockModelProvider extends ModelProvider<BlockModelBuilder
super(generator, modid, BLOCK_FOLDER, BlockModelBuilder::new, existingFileHelper);
}
@Nonnull
@NotNull
@Override
public String getName() {
return "Block Models: " + modid;
@@ -13,12 +13,12 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nonnull;
import net.minecraft.data.CachedOutput;
import net.minecraft.world.level.block.ButtonBlock;
import net.minecraft.world.level.block.PressurePlateBlock;
import net.minecraft.world.level.block.StandingSignBlock;
import net.minecraft.world.level.block.WallSignBlock;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -47,7 +47,6 @@ import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.level.block.state.properties.WallSide;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.HashCache;
import net.minecraft.data.DataProvider;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.properties.AttachFace;
@@ -61,6 +60,7 @@ import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
/**
* Data provider for blockstate files. Extends {@link BlockModelProvider} so that
@@ -83,15 +83,19 @@ public abstract class BlockStateProvider implements DataProvider {
this.generator = gen;
this.modid = modid;
this.blockModels = new BlockModelProvider(gen, modid, exFileHelper) {
@Override public void run(CachedOutput p_236071_) throws IOException {}
@Override protected void registerModels() {}
};
this.itemModels = new ItemModelProvider(gen, modid, this.blockModels.existingFileHelper) {
@Override protected void registerModels() {}
@Override public void run(CachedOutput p_236071_) throws IOException {}
};
}
@Override
public void run(HashCache cache) throws IOException {
public void run(CachedOutput cache) throws IOException {
models().clear();
itemModels().clear();
registeredBlocks.clear();
@@ -145,12 +149,16 @@ public abstract class BlockStateProvider implements DataProvider {
return new ResourceLocation(name);
}
private ResourceLocation key(Block block) {
return ForgeRegistries.BLOCKS.getKey(block);
}
private String name(Block block) {
return block.getRegistryName().getPath();
return key(block).getPath();
}
public ResourceLocation blockTexture(Block block) {
ResourceLocation name = block.getRegistryName();
ResourceLocation name = key(block);
return new ResourceLocation(name.getNamespace(), ModelProvider.BLOCK_FOLDER + "/" + name.getPath());
}
@@ -175,7 +183,7 @@ public abstract class BlockStateProvider implements DataProvider {
}
public void simpleBlockItem(Block block, ModelFile model) {
itemModels().getBuilder(block.getRegistryName().getPath()).parent(model);
itemModels().getBuilder(key(block).getPath()).parent(model);
}
public void simpleBlock(Block block, ConfiguredModel... models) {
@@ -291,7 +299,7 @@ public abstract class BlockStateProvider implements DataProvider {
}
public void stairsBlock(StairBlock block, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
stairsBlockInternal(block, block.getRegistryName().toString(), side, bottom, top);
stairsBlockInternal(block, key(block).toString(), side, bottom, top);
}
public void stairsBlock(StairBlock block, String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
@@ -404,7 +412,7 @@ public abstract class BlockStateProvider implements DataProvider {
}
public void fenceBlock(FenceBlock block, ResourceLocation texture) {
String baseName = block.getRegistryName().toString();
String baseName = key(block).toString();
fourWayBlock(block, models().fencePost(baseName + "_post", texture), models().fenceSide(baseName + "_side", texture));
}
@@ -413,7 +421,7 @@ public abstract class BlockStateProvider implements DataProvider {
}
public void fenceGateBlock(FenceGateBlock block, ResourceLocation texture) {
fenceGateBlockInternal(block, block.getRegistryName().toString(), texture);
fenceGateBlockInternal(block, key(block).toString(), texture);
}
public void fenceGateBlock(FenceGateBlock block, String name, ResourceLocation texture) {
@@ -446,7 +454,7 @@ public abstract class BlockStateProvider implements DataProvider {
}
public void wallBlock(WallBlock block, ResourceLocation texture) {
wallBlockInternal(block, block.getRegistryName().toString(), texture);
wallBlockInternal(block, key(block).toString(), texture);
}
public void wallBlock(WallBlock block, String name, ResourceLocation texture) {
@@ -456,7 +464,7 @@ public abstract class BlockStateProvider implements DataProvider {
private void wallBlockInternal(WallBlock block, String baseName, ResourceLocation texture) {
wallBlock(block, models().wallPost(baseName + "_post", texture), models().wallSide(baseName + "_side", texture), models().wallSideTall(baseName + "_side_tall", texture));
}
public static final ImmutableMap<Direction, Property<WallSide>> WALL_PROPS = ImmutableMap.<Direction, Property<WallSide>>builder()
.put(Direction.EAST, BlockStateProperties.EAST_WALL)
.put(Direction.NORTH, BlockStateProperties.NORTH_WALL)
@@ -475,7 +483,7 @@ public abstract class BlockStateProvider implements DataProvider {
wallSidePart(builder, sideTall, e, WallSide.TALL);
});
}
private void wallSidePart(MultiPartBlockStateBuilder builder, ModelFile model, Map.Entry<Direction, Property<WallSide>> entry, WallSide height) {
builder.part()
.modelFile(model)
@@ -486,7 +494,7 @@ public abstract class BlockStateProvider implements DataProvider {
}
public void paneBlock(IronBarsBlock block, ResourceLocation pane, ResourceLocation edge) {
paneBlockInternal(block, block.getRegistryName().toString(), pane, edge);
paneBlockInternal(block, key(block).toString(), pane, edge);
}
public void paneBlock(IronBarsBlock block, String name, ResourceLocation pane, ResourceLocation edge) {
@@ -518,7 +526,7 @@ public abstract class BlockStateProvider implements DataProvider {
}
public void doorBlock(DoorBlock block, ResourceLocation bottom, ResourceLocation top) {
doorBlockInternal(block, block.getRegistryName().toString(), bottom, top);
doorBlockInternal(block, key(block).toString(), bottom, top);
}
public void doorBlock(DoorBlock block, String name, ResourceLocation bottom, ResourceLocation top) {
@@ -553,7 +561,7 @@ public abstract class BlockStateProvider implements DataProvider {
}
public void trapdoorBlock(TrapDoorBlock block, ResourceLocation texture, boolean orientable) {
trapdoorBlockInternal(block, block.getRegistryName().toString(), texture, orientable);
trapdoorBlockInternal(block, key(block).toString(), texture, orientable);
}
public void trapdoorBlock(TrapDoorBlock block, String name, ResourceLocation texture, boolean orientable) {
@@ -587,19 +595,19 @@ public abstract class BlockStateProvider implements DataProvider {
}, TrapDoorBlock.POWERED, TrapDoorBlock.WATERLOGGED);
}
private void saveBlockState(HashCache cache, JsonObject stateJson, Block owner) {
ResourceLocation blockName = Preconditions.checkNotNull(owner.getRegistryName());
private void saveBlockState(CachedOutput cache, JsonObject stateJson, Block owner) {
ResourceLocation blockName = Preconditions.checkNotNull(key(owner));
Path mainOutput = generator.getOutputFolder();
String pathSuffix = "assets/" + blockName.getNamespace() + "/blockstates/" + blockName.getPath() + ".json";
Path outputPath = mainOutput.resolve(pathSuffix);
try {
DataProvider.save(GSON, cache, stateJson, outputPath);
DataProvider.saveStable(cache, stateJson, outputPath);
} catch (IOException e) {
LOGGER.error("Couldn't save blockstate to {}", outputPath, e);
}
}
@Nonnull
@NotNull
@Override
public String getName() {
return "Block States: " + modid;
@@ -10,7 +10,6 @@ import java.util.List;
import java.util.function.Function;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@@ -20,6 +19,7 @@ import com.google.gson.JsonObject;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraftforge.client.model.generators.MultiPartBlockStateBuilder.PartBuilder;
import net.minecraftforge.client.model.generators.VariantBlockStateBuilder.PartialBlockstate;
import org.jetbrains.annotations.Nullable;
/**
* Represents a model with blockstate configurations, e.g. rotation, uvlock, and
@@ -70,13 +70,13 @@ public final class ConfiguredModel {
/**
* Construct a new {@link ConfiguredModel}.
*
*
* @param model the underlying model
* @param rotationX x-rotation to apply to the model
* @param rotationY y-rotation to apply to the model
* @param uvLock if uvlock should be enabled
* @param weight the random weight of the model
*
*
* @throws NullPointerException if {@code model} is {@code null}
* @throws IllegalArgumentException if x and/or y rotation are not valid (see
* {@link BlockModelRotation})
@@ -96,12 +96,12 @@ public final class ConfiguredModel {
/**
* Construct a new {@link ConfiguredModel} with the {@link #DEFAULT_WEIGHT
* default random weight}.
*
*
* @param model the underlying model
* @param rotationX x-rotation to apply to the model
* @param rotationY y-rotation to apply to the model
* @param uvLock if uvlock should be enabled
*
*
* @throws NullPointerException if {@code model} is {@code null}
* @throws IllegalArgumentException if x and/or y rotation are not valid (see
* {@link BlockModelRotation})
@@ -113,7 +113,7 @@ public final class ConfiguredModel {
/**
* Construct a new {@link ConfiguredModel} with the default rotation (0, 0),
* uvlock (false), and {@link #DEFAULT_WEIGHT default random weight}.
*
*
* @throws NullPointerException if {@code model} is {@code null}
*/
public ConfiguredModel(ModelFile model) {
@@ -144,7 +144,7 @@ public final class ConfiguredModel {
/**
* Create a new unowned {@link Builder}.
*
*
* @return the builder
* @see Builder
*/
@@ -197,7 +197,7 @@ public final class ConfiguredModel {
/**
* Set the underlying model object for this configured model.
*
*
* @param model the model
* @return this builder
* @throws NullPointerException if {@code model} is {@code null}
@@ -210,7 +210,7 @@ public final class ConfiguredModel {
/**
* Set the x-rotation for this model.
*
*
* @param value the x-rotation value
* @return this builder
* @throws IllegalArgumentException if {@code value} is not a valid x-rotation
@@ -224,7 +224,7 @@ public final class ConfiguredModel {
/**
* Set the y-rotation for this model.
*
*
* @param value the y-rotation value
* @return this builder
* @throws IllegalArgumentException if {@code value} is not a valid y-rotation
@@ -243,7 +243,7 @@ public final class ConfiguredModel {
/**
* Set the random weight for this model.
*
*
* @param value the weight value
* @return this builder
* @throws IllegalArgumentException if {@code value} is less than or equal to
@@ -258,7 +258,7 @@ public final class ConfiguredModel {
/**
* Build the most recent model, as if {@link #nextModel()} was never called.
* Useful for single-model builders.
*
*
* @return the most recently configured model
*/
public ConfiguredModel buildLast() {
@@ -267,7 +267,7 @@ public final class ConfiguredModel {
/**
* Build all configured models and return them as an array.
*
*
* @return the array of built models.
*/
public ConfiguredModel[] build() {
@@ -284,7 +284,7 @@ public final class ConfiguredModel {
* <li>{@link PartialBlockstate#modelForState()}</li>
* <li>{@link MultiPartBlockStateBuilder#part()}</li>
* </ul>
*
*
* @return the owning builder object
* @throws NullPointerException if there is no owning builder (and thus no callback)
*/
@@ -296,7 +296,7 @@ public final class ConfiguredModel {
/**
* Complete the current model and return a new builder instance with the same
* callback, and storing all previously built models.
*
*
* @return a new builder for configuring the next model
*/
public Builder<T> nextModel() {
@@ -5,12 +5,14 @@
package net.minecraftforge.client.model.generators;
import javax.annotation.Nonnull;
import net.minecraft.data.DataGenerator;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/**
* Stub class to extend for item model data providers, eliminates some
@@ -24,7 +26,7 @@ public abstract class ItemModelProvider extends ModelProvider<ItemModelBuilder>
public ItemModelBuilder basicItem(Item item)
{
return basicItem(item.getRegistryName());
return basicItem(Objects.requireNonNull(ForgeRegistries.ITEMS.getKey(item)));
}
public ItemModelBuilder basicItem(ResourceLocation item)
@@ -34,7 +36,7 @@ public abstract class ItemModelProvider extends ModelProvider<ItemModelBuilder>
.texture("layer0", new ResourceLocation(item.getNamespace(), "item/" + item.getPath()));
}
@Nonnull
@NotNull
@Override
public String getName() {
return "Item Models: " + modid;
@@ -15,8 +15,6 @@ import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.gson.Gson;
@@ -28,7 +26,6 @@ import net.minecraft.client.renderer.block.model.BlockModel.GuiLight;
import net.minecraft.client.renderer.block.model.BlockElement;
import net.minecraft.client.renderer.block.model.BlockElementFace;
import net.minecraft.client.renderer.block.model.BlockElementRotation;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemTransform;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
@@ -37,6 +34,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import com.mojang.math.Vector3f;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.Nullable;
/**
* General purpose model builder, contains all the commonalities between item
@@ -17,6 +17,7 @@ import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.HashCache;
import net.minecraft.data.DataProvider;
@@ -373,17 +374,17 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
}
@Override
public void run(HashCache cache) throws IOException {
public void run(CachedOutput cache) throws IOException {
clear();
registerModels();
generateAll(cache);
}
protected void generateAll(HashCache cache) {
protected void generateAll(CachedOutput cache) {
for (T model : generatedModels.values()) {
Path target = getPath(model);
try {
DataProvider.save(GSON, cache, model.toJson(), target);
DataProvider.saveStable(cache, model.toJson(), target);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -20,8 +20,6 @@ import java.util.TreeSet;
import java.util.function.Function;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
@@ -32,6 +30,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraftforge.client.model.generators.BlockStateProvider.ConfiguredModelList;
import org.jetbrains.annotations.Nullable;
/**
* Builder for variant-type blockstates, i.e. non-multipart blockstates. Should
@@ -49,7 +48,7 @@ import net.minecraftforge.client.model.generators.BlockStateProvider.ConfiguredM
* {@link #forAllStatesExcept(Function, Property...)} for cases where the model
* for each variant can be decided dynamically based on the state's property
* values.
*
*
* @see BlockStateProvider
*/
public class VariantBlockStateBuilder implements IGeneratedBlockstate {
@@ -86,7 +85,7 @@ public class VariantBlockStateBuilder implements IGeneratedBlockstate {
/**
* Assign some models to a given {@link PartialBlockstate partial state}.
*
*
* @param state The {@link PartialBlockstate partial state} for which to add
* the models
* @param models A set of models to add to this state
@@ -120,7 +119,7 @@ public class VariantBlockStateBuilder implements IGeneratedBlockstate {
* Assign some models to a given {@link PartialBlockstate partial state},
* throwing an exception if the state has already been configured. Otherwise,
* simply calls {@link #addModels(PartialBlockstate, ConfiguredModel...)}.
*
*
* @param state The {@link PartialBlockstate partial state} for which to set
* the models
* @param model A set of models to assign to this state
@@ -199,7 +198,7 @@ public class VariantBlockStateBuilder implements IGeneratedBlockstate {
* Creates a builder for models to assign to this state, which when completed
* via {@link ConfiguredModel.Builder#addModel()} will assign the resultant set
* of models to this state.
*
*
* @return the model builder
* @see ConfiguredModel.Builder
*/
@@ -212,7 +211,7 @@ public class VariantBlockStateBuilder implements IGeneratedBlockstate {
* Add models to the current state's variant. For use when it is more convenient
* to add multiple sets of models, as a replacement for
* {@link #setModels(ConfiguredModel...)}.
*
*
* @param models The models to add.
* @return {@code this}
* @throws NullPointerException If the parent builder is {@code null}
@@ -225,7 +224,7 @@ public class VariantBlockStateBuilder implements IGeneratedBlockstate {
/**
* Set this variant's models, and return the parent builder.
*
*
* @param models The models to set
* @return The parent builder instance
* @throws NullPointerException If the parent builder is {@code null}
@@ -239,7 +238,7 @@ public class VariantBlockStateBuilder implements IGeneratedBlockstate {
* Complete this state without adding any new models, and return a new partial
* state via the parent builder. For use after calling
* {@link #addModels(ConfiguredModel...)}.
*
*
* @return A fresh partial state as specified by
* {@link VariantBlockStateBuilder#partialState()}.
* @throws NullPointerException If the parent builder is {@code null}
@@ -12,6 +12,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.client.model.generators.CustomLoaderBuilder;
import net.minecraftforge.client.model.generators.ModelBuilder;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.ForgeRegistries;
public class DynamicBucketModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
{
@@ -34,7 +35,7 @@ public class DynamicBucketModelBuilder<T extends ModelBuilder<T>> extends Custom
public DynamicBucketModelBuilder<T> fluid(Fluid fluid)
{
Preconditions.checkNotNull(fluid, "fluid must not be null");
this.fluid = fluid.getRegistryName();
this.fluid = ForgeRegistries.FLUIDS.getKey(fluid);
return this;
}
@@ -8,8 +8,8 @@ package net.minecraftforge.client.model.obj;
import com.google.common.base.Charsets;
import joptsimple.internal.Strings;
import net.minecraft.server.packs.resources.Resource;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -22,9 +22,8 @@ public class LineReader implements AutoCloseable
InputStreamReader lineStream;
BufferedReader lineReader;
public LineReader(Resource resource)
{
this.lineStream = new InputStreamReader(resource.getInputStream(), Charsets.UTF_8);
public LineReader(Resource resource) throws IOException {
this.lineStream = new InputStreamReader(resource.open(), Charsets.UTF_8);
this.lineReader = new BufferedReader(lineStream);
}
@@ -14,8 +14,8 @@ import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.GsonHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.client.model.IModelLoader;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.io.FileNotFoundException;
import java.util.*;
@@ -57,9 +57,8 @@ public class OBJLoader implements IModelLoader<OBJModel>
public OBJModel loadModel(OBJModel.ModelSettings settings)
{
return modelCache.computeIfAbsent(settings, (data) -> {
try(Resource resource = manager.getResource(settings.modelLocation());
LineReader rdr = new LineReader(resource))
Resource resource = manager.getResource(settings.modelLocation()).orElseThrow();
try(LineReader rdr = new LineReader(resource))
{
return new OBJModel(rdr, settings);
}
@@ -77,8 +76,8 @@ public class OBJLoader implements IModelLoader<OBJModel>
public MaterialLibrary loadMaterialLibrary(ResourceLocation materialLocation)
{
return materialCache.computeIfAbsent(materialLocation, (location) -> {
try(Resource resource = manager.getResource(location);
LineReader rdr = new LineReader(resource))
Resource resource = manager.getResource(location).orElseThrow();
try(LineReader rdr = new LineReader(resource))
{
return new MaterialLibrary(rdr);
}
@@ -28,8 +28,6 @@ import net.minecraftforge.client.model.renderable.SimpleRenderable;
import net.minecraftforge.client.textures.UnitSprite;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
@@ -41,6 +39,8 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class OBJModel implements IMultipartModelGeometry<OBJModel>
{
@@ -660,7 +660,7 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
}
}
public record ModelSettings(@Nonnull ResourceLocation modelLocation,
public record ModelSettings(@NotNull ResourceLocation modelLocation,
boolean detectCullableFaces, boolean diffuseLighting, boolean flipV,
boolean ambientToFullbright, @Nullable String materialLibraryOverrideLocation)
{}
@@ -10,6 +10,7 @@ import java.util.Random;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.renderer.block.ModelBlockRenderer;
@@ -37,7 +38,7 @@ public class ForgeBlockModelRenderer extends ModelBlockRenderer
}
@Override
public boolean tesselateWithoutAO(BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer buffer, boolean checkSides, Random rand, long seed, int packedOverlay, IModelData modelData)
public void tesselateWithoutAO(BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer buffer, boolean checkSides, RandomSource rand, long seed, int packedOverlay, IModelData modelData)
{
if(ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
{
@@ -48,16 +49,16 @@ public class ForgeBlockModelRenderer extends ModelBlockRenderer
lighter.setParent(consumer);
lighter.setTransform(poseStack.last());
return render(lighter, level, model, state, pos, poseStack, checkSides, rand, seed, modelData);
render(lighter, level, model, state, pos, poseStack, checkSides, rand, seed, modelData);
}
else
{
return super.tesselateWithoutAO(level, model, state, pos, poseStack, buffer, checkSides, rand, seed, packedOverlay, modelData);
super.tesselateWithoutAO(level, model, state, pos, poseStack, buffer, checkSides, rand, seed, packedOverlay, modelData);
}
}
@Override
public boolean tesselateWithAO(BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer buffer, boolean checkSides, Random rand, long seed, int packedOverlay, IModelData modelData)
public void tesselateWithAO(BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer buffer, boolean checkSides, RandomSource rand, long seed, int packedOverlay, IModelData modelData)
{
if(ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
{
@@ -68,15 +69,15 @@ public class ForgeBlockModelRenderer extends ModelBlockRenderer
lighter.setParent(consumer);
lighter.setTransform(poseStack.last());
return render(lighter, level, model, state, pos, poseStack, checkSides, rand, seed, modelData);
render(lighter, level, model, state, pos, poseStack, checkSides, rand, seed, modelData);
}
else
{
return super.tesselateWithAO(level, model, state, pos, poseStack, buffer, checkSides, rand, seed, packedOverlay, modelData);
super.tesselateWithAO(level, model, state, pos, poseStack, buffer, checkSides, rand, seed, packedOverlay, modelData);
}
}
public static boolean render(VertexLighterFlat lighter, BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, boolean checkSides, Random rand, long seed, IModelData modelData)
public static boolean render(VertexLighterFlat lighter, BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, boolean checkSides, RandomSource rand, long seed, IModelData modelData)
{
lighter.setWorld(level);
lighter.setState(state);
@@ -14,6 +14,7 @@ import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraftforge.client.model.data.IModelData;
@@ -47,7 +48,7 @@ public class BakedRenderable implements IRenderable<IModelData>
return new BakedRenderable(model);
}
private final Random rand = new Random();
private final RandomSource rand = RandomSource.create();
private final BakedModel model;
private BakedRenderable(BakedModel model)
@@ -5,7 +5,7 @@
package net.minecraftforge.client.model.renderable;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
/**
* A standard interface for renderable context values that support providing different values for parts of the model.
@@ -7,8 +7,7 @@ package net.minecraftforge.client.model.renderable;
import com.google.common.collect.ImmutableMap;
import com.mojang.math.Matrix4f;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
/**
* A context value that provides {@link Matrix4f} transforms for certain parts of the model.