Update to 1.15

Due to the massive rendering changes, certain features, such as emissive item rendering and the forge block rendering/lighting pipeline are currently disabled.

Co-authored-by: David Quintana <[email protected]>
Co-authored-by: tterrag <[email protected]>
Co-authored-by: Unnoen <[email protected]>
This commit is contained in:
authored and David Quintana committed 2019-12-17 03:38:12 +01:00
1 parent 9e5ecaaf75
commit 1933d05e36
565 files changed
+11114 -13142

No files matched your search

@@ -52,10 +52,11 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.MutableRegistry;
import net.minecraft.world.World;
import net.minecraft.world.biome.IBiomeMagnifier;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.listener.IChunkStatusListener;
import net.minecraft.world.server.ServerMultiWorld;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.ServerMultiWorld;
import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.event.world.RegisterDimensionsEvent;
import net.minecraftforge.event.world.WorldEvent;
@@ -96,6 +97,7 @@ public class DimensionManager
* @param type ModDimension type data
* @param data Extra data for the ModDimension
* @param hasSkyLight does this dimension have a skylight?
* @param magnifier The biome generation processor
* @return the DimensionType for the dimension.
*/
public static DimensionType registerOrGetDimension(ResourceLocation name, ModDimension type, PacketBuffer data, boolean hasSkyLight) {
@@ -111,6 +113,7 @@ public class DimensionManager
* @param type Dimension Type.
* @param data Configuration data for this dimension, passed into
* @param hasSkyLight skylight for this dimension
* @param magnifier The biome generation processor
* @return the DimensionType for the dimension.
*/
public static DimensionType registerDimension(ResourceLocation name, ModDimension type, PacketBuffer data, boolean hasSkyLight)
@@ -129,7 +132,7 @@ public class DimensionManager
savedEntries.remove(name);
}
@SuppressWarnings("deprecation")
DimensionType instance = new DimensionType(id, "", name.getNamespace() + "/" + name.getPath(), type.getFactory(), hasSkyLight, type, data);
DimensionType instance = new DimensionType(id, "", name.getNamespace() + "/" + name.getPath(), type.getFactory(), hasSkyLight, type.getMagnifier(), type, data);
REGISTRY.register(id, name, instance);
LOGGER.info(DIMMGR, "Registered dimension {} of type {} and id {}", name.toString(), type.getRegistryName().toString(), id);
return instance;
@@ -214,7 +217,7 @@ public class DimensionManager
Validate.isTrue(REGISTRY.getByValue(id) == null, "Dimension with id " + id + " already registered as name " + REGISTRY.getKey(REGISTRY.getByValue(id)));
@SuppressWarnings("deprecation")
DimensionType instance = new DimensionType(id, "", name.getNamespace() + "/" + name.getPath(), type.getFactory(), hasSkyLight, type, data);
DimensionType instance = new DimensionType(id, "", name.getNamespace() + "/" + name.getPath(), type.getFactory(), hasSkyLight, type.getMagnifier(), type, data);
REGISTRY.register(id, name, instance);
LOGGER.info(DIMMGR, "Registered dimension {} of type {} and id {}", name.toString(), type.getRegistryName().toString(), id);
return instance;
@@ -46,6 +46,8 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.advancements.Advancement;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.model.Material;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.fluid.*;
import net.minecraft.util.CachedBlockInfo;
import net.minecraft.block.BlockState;
@@ -744,7 +746,7 @@ public class ForgeHooks
public static ActionResultType onInteractEntityAt(PlayerEntity player, Entity entity, RayTraceResult ray, Hand hand)
{
Vec3d vec3d = new Vec3d(ray.getHitVec().x - entity.posX, ray.getHitVec().y - entity.posY, ray.getHitVec().z - entity.posZ);
Vec3d vec3d = ray.getHitVec().subtract(entity.getPositionVec());
return onInteractEntityAt(player, entity, vec3d, hand);
}
@@ -844,15 +846,15 @@ public class ForgeHooks
.color(0).density(0).temperature(0).luminosity(0).viscosity(0).build(fluid);
if (fluid instanceof WaterFluid)
return net.minecraftforge.fluids.FluidAttributes.Water.builder(
new net.minecraft.util.ResourceLocation("block/water_still"),
new net.minecraft.util.ResourceLocation("block/water_flow"))
.overlay(new net.minecraft.util.ResourceLocation("block/water_overlay"))
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_still")),
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_flow")))
.overlay(new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_overlay")))
.translationKey("block.minecraft.water")
.color(0xFF3F76E4).build(fluid);
if (fluid instanceof LavaFluid)
return net.minecraftforge.fluids.FluidAttributes.builder(
new net.minecraft.util.ResourceLocation("block/lava_still"),
new net.minecraft.util.ResourceLocation("block/lava_flow"))
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/lava_still")),
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/lava_flow")))
.translationKey("block.minecraft.lava")
.luminosity(15).density(3000).viscosity(6000).temperature(1300).build(fluid);
throw new RuntimeException("Mod fluids must override createAttributes.");
@@ -25,7 +25,6 @@ import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.client.CloudRenderer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
@@ -79,8 +78,8 @@ public class ForgeInternalHandler
@SubscribeEvent
public void checkSettings(ClientTickEvent event)
{
if (event.phase == Phase.END)
CloudRenderer.updateCloudSettings();
//if (event.phase == Phase.END)
// CloudRenderer.updateCloudSettings();
}
@SubscribeEvent
@@ -23,6 +23,8 @@ import java.util.function.BiFunction;
import net.minecraft.network.PacketBuffer;
import net.minecraft.world.World;
import net.minecraft.world.biome.ColumnFuzzedBiomeMagnifier;
import net.minecraft.world.biome.IBiomeMagnifier;
import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.registries.ForgeRegistryEntry;
@@ -55,6 +57,10 @@ public abstract class ModDimension extends ForgeRegistryEntry<ModDimension>
*/
public void read(PacketBuffer buffer, boolean network){}
public IBiomeMagnifier getMagnifier() {
return ColumnFuzzedBiomeMagnifier.INSTANCE;
}
/**
* Convenience method for generating a ModDimension with a specific factory but no extra
* data handling behaviour. Extend ModDimension to override other methods.
@@ -57,7 +57,7 @@ public class ForgeBlockTagsProvider extends BlockTagsProvider
getBuilder(CHESTS_TRAPPED).add(Blocks.TRAPPED_CHEST);
getBuilder(CHESTS_WOODEN).add(Blocks.CHEST, Blocks.TRAPPED_CHEST);
getBuilder(COBBLESTONE).add(Blocks.COBBLESTONE, Blocks.INFESTED_COBBLESTONE, Blocks.MOSSY_COBBLESTONE);
getBuilder(DIRT).add(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL);
getBuilder(DIRT).add(Blocks.DIRT, Blocks.GRASS_BLOCK, Blocks.COARSE_DIRT, Blocks.PODZOL, Blocks.MYCELIUM);
getBuilder(END_STONES).add(Blocks.END_STONE);
getBuilder(FENCE_GATES).add(FENCE_GATES_WOODEN);
getBuilder(FENCE_GATES_WOODEN).add(Blocks.OAK_FENCE_GATE, Blocks.SPRUCE_FENCE_GATE, Blocks.BIRCH_FENCE_GATE, Blocks.JUNGLE_FENCE_GATE, Blocks.ACACIA_FENCE_GATE, Blocks.DARK_OAK_FENCE_GATE);
@@ -16,6 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.data;
import java.io.BufferedWriter;
@@ -61,7 +61,6 @@ import net.minecraft.state.IProperty;
import net.minecraft.state.properties.BedPart;
import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
@@ -71,7 +70,7 @@ import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IEnviromentBlockReader;
import net.minecraft.world.ILightReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.IWorldWriter;
@@ -118,7 +117,7 @@ public interface IForgeBlock
* @param pos
* @return The light value
*/
default int getLightValue(BlockState state, IEnviromentBlockReader world, BlockPos pos)
default int getLightValue(BlockState state, ILightReader world, BlockPos pos)
{
return state.getLightValue();
}
@@ -152,7 +151,7 @@ public interface IForgeBlock
* @deprecated This is no longer used for rendering logic.
*/
@Deprecated
default boolean doesSideBlockRendering(BlockState state, IEnviromentBlockReader world, BlockPos pos, Direction face)
default boolean doesSideBlockRendering(BlockState state, ILightReader world, BlockPos pos, Direction face)
{
return state.isOpaqueCube(world, pos);
}
@@ -383,7 +382,7 @@ public interface IForgeBlock
*/
default boolean canBeReplacedByLogs(BlockState state, IWorldReader world, BlockPos pos)
{
return (isAir(state, world, pos) || state.isIn(BlockTags.LEAVES)) || this == Blocks.GRASS_BLOCK || Block.isDirt(getBlock())
return (isAir(state, world, pos) || state.isIn(BlockTags.LEAVES)) || this == Blocks.GRASS_BLOCK || state.isIn(net.minecraftforge.common.Tags.Blocks.DIRT)
|| getBlock().isIn(BlockTags.LOGS) || getBlock().isIn(BlockTags.SAPLINGS) || this == Blocks.VINE;
}
@@ -559,7 +558,7 @@ public interface IForgeBlock
*/
default void onPlantGrow(BlockState state, IWorld world, BlockPos pos, BlockPos source)
{
if (Block.isDirt(getBlock()))
if (state.isIn(net.minecraftforge.common.Tags.Blocks.DIRT))
world.setBlockState(pos, Blocks.DIRT.getDefaultState(), 2);
}
@@ -751,15 +750,6 @@ public interface IForgeBlock
return state;
}
/**
* Queries if this block should render in a given layer.
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()} to alter the model based on layer.
*/
default boolean canRenderInLayer(BlockState state, BlockRenderLayer layer)
{
return this.getBlock().getRenderLayer() == layer;
}
/**
* Sensitive version of getSoundType
* @param state The state
@@ -881,7 +871,16 @@ public interface IForgeBlock
@Nullable
default PathNodeType getAiPathNodeType(BlockState state, IBlockReader world, BlockPos pos, @Nullable MobEntity entity)
{
return state.isBurning(world, pos) ? PathNodeType.DAMAGE_FIRE : null;
return state.isBurning(world, pos) ? PathNodeType.DANGER_FIRE : null;
}
/**
* @param state The state
* @return true if the block is sticky block which used for pull or push adjacent blocks (use by piston)
*/
default boolean isSlimeBlock(BlockState state)
{
return state.getBlock() == Blocks.SLIME_BLOCK;
}
/**
@@ -890,7 +889,20 @@ public interface IForgeBlock
*/
default boolean isStickyBlock(BlockState state)
{
return state.getBlock() == Blocks.SLIME_BLOCK;
return state.getBlock() == Blocks.SLIME_BLOCK || state.getBlock() == Blocks.field_226907_mc_;
}
/**
* Determines if this block can stick to another block when pushed by a piston.
* @param state My state
* @param other Other block
* @return True to link blocks
*/
default boolean canStickTo(BlockState state, BlockState other)
{
if (state.getBlock() == Blocks.field_226907_mc_ && other.getBlock() == Blocks.SLIME_BLOCK) return false;
if (state.getBlock() == Blocks.SLIME_BLOCK && other.getBlock() == Blocks.field_226907_mc_) return false;
return state.isStickyBlock() || other.isStickyBlock();
}
/**
@@ -45,7 +45,7 @@ import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IEnviromentBlockReader;
import net.minecraft.world.ILightReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
@@ -84,7 +84,7 @@ public interface IForgeBlockState
/**
* Get a light value for this block, taking into account the given state and coordinates, normal ranges are between 0 and 15
*/
default int getLightValue(IEnviromentBlockReader world, BlockPos pos)
default int getLightValue(ILightReader world, BlockPos pos)
{
return getBlockState().getBlock().getLightValue(getBlockState(), world, pos);
}
@@ -116,7 +116,7 @@ public interface IForgeBlockState
* @deprecated This is no longer used for rendering logic.
*/
@Deprecated
default boolean doesSideBlockRendering(IEnviromentBlockReader world, BlockPos pos, Direction face)
default boolean doesSideBlockRendering(ILightReader world, BlockPos pos, Direction face)
{
return getBlockState().getBlock().doesSideBlockRendering(getBlockState(), world, pos, face);
}
@@ -632,23 +632,6 @@ public interface IForgeBlockState
return getBlockState().getBlock().isToolEffective(getBlockState(), tool);
}
/**
* Can return IExtendedBlockState
*/
default BlockState getExtendedState(IBlockReader world, BlockPos pos)
{
return getBlockState().getBlock().getExtendedState(getBlockState(), world, pos);
}
/**
* Queries if this blockstate should render in a given layer.
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()} to alter the model based on layer.
*/
default boolean canRenderInLayer(BlockRenderLayer layer)
{
return getBlockState().getBlock().canRenderInLayer(getBlockState(), layer);
}
/**
* Sensitive version of getSoundType
* @param world The world
@@ -735,6 +718,15 @@ public interface IForgeBlockState
return getBlockState().getBlock().canBeConnectedTo(getBlockState(), world, pos, facing);
}
/**
* @param state The state
* @return true if the block is sticky block which used for pull or push adjacent blocks (use by piston)
*/
default boolean isSlimeBlock()
{
return getBlockState().getBlock().isSlimeBlock(getBlockState());
}
/**
* @param state The state
* @return true if the block is sticky block which used for pull or push adjacent blocks (use by piston)
@@ -744,6 +736,16 @@ public interface IForgeBlockState
return getBlockState().getBlock().isStickyBlock(getBlockState());
}
/**
* Determines if this block can stick to another block when pushed by a piston.
* @param other Other block
* @return True to link blocks
*/
default boolean canStickTo(BlockState other)
{
return getBlockState().getBlock().canStickTo(getBlockState(), other);
}
/**
* Chance that fire will spread and consume this block.
* 300 being a 100% chance, 0, being a 0% chance.
@@ -851,6 +853,17 @@ public interface IForgeBlockState
return getBlockState().getBlock().isBurning(getBlockState(), world, pos);
}
/**
* Get the {@code PathNodeType} for this block. Return {@code null} for vanilla behavior.
*
* @return the PathNodeType
*/
@Nullable
default PathNodeType getAiPathNodeType(IBlockReader world, BlockPos pos)
{
return getAiPathNodeType(world, pos, null);
}
/**
* Get the {@code PathNodeType} for this block. Return {@code null} for vanilla behavior.
*
@@ -22,12 +22,14 @@ package net.minecraftforge.common.extensions;
import javax.annotation.Nullable;
import net.minecraft.client.audio.MusicTicker;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.dimension.DimensionType;
@@ -114,7 +116,7 @@ public interface IForgeDimension
*
* @see net.minecraft.client.renderer.GameRenderer#updateLightmap(float)
*/
default void getLightmapColors(float partialTicks, float sunBrightness, float skyLight, float blockLight, float[] colors) {}
default void getLightmapColors(float partialTicks, float sunBrightness, float skyLight, float blockLight, Vector3f colors) {}
void resetRainAndThunder();
@@ -149,7 +151,7 @@ public interface IForgeDimension
*/
default SleepResult canSleepAt(net.minecraft.entity.player.PlayerEntity player, BlockPos pos)
{
return (getDimension().canRespawnHere() && getWorld().getBiome(pos) != net.minecraft.world.biome.Biomes.NETHER) ? SleepResult.ALLOW : SleepResult.BED_EXPLODES;
return (getDimension().canRespawnHere() && getWorld().func_226691_t_(pos) != Biomes.NETHER) ? SleepResult.ALLOW : SleepResult.BED_EXPLODES;
}
enum SleepResult
@@ -159,39 +161,9 @@ public interface IForgeDimension
BED_EXPLODES;
}
default Biome getBiome(BlockPos pos)
{
return getWorld().getBiomeBody(pos);
}
default boolean isDaytime()
{
return getWorld().getSkylightSubtracted() < 4;
}
/**
* The current sun brightness factor for this dimension.
* 0.0f means no light at all, and 1.0f means maximum sunlight.
* This will be used for the "calculateSkylightSubtracted"
* which is for Sky light value calculation.
*
* @return The current brightness factor
**/
default float getSunBrightness(float partialTicks)
{
return getWorld().getSunBrightnessBody(partialTicks);
}
@OnlyIn(Dist.CLIENT)
default Vec3d getSkyColor(BlockPos cameraPos, float partialTicks)
{
return getWorld().getSkyColorBody(cameraPos, partialTicks);
}
@OnlyIn(Dist.CLIENT)
default Vec3d getCloudColor(float partialTicks)
{
return getWorld().getCloudColorBody(partialTicks);
return getDimension().getType() == DimensionType.OVERWORLD && getWorld().getSkylightSubtracted() < 4;
}
/**
@@ -204,15 +176,6 @@ public interface IForgeDimension
return Dimension.MOON_PHASE_FACTORS[this.getDimension().getMoonPhase(time)];
}
/**
* Gets the Star Brightness for rendering sky.
* */
@OnlyIn(Dist.CLIENT)
default float getStarBrightness(float partialTicks)
{
return getWorld().getStarBrightnessBody(partialTicks);
}
default void setAllowedSpawnTypes(boolean allowHostile, boolean allowPeaceful) { }
default void calculateInitialWeather()
@@ -258,7 +221,7 @@ public interface IForgeDimension
default boolean isHighHumidity(BlockPos pos)
{
return getWorld().getBiome(pos).isHighHumidity();
return getWorld().func_226691_t_(pos).isHighHumidity();
}
default int getHeight()
@@ -271,11 +234,6 @@ public interface IForgeDimension
return getDimension().isNether() ? 128 : 256;
}
default double getHorizon()
{
return getWorld().getWorldInfo().getGenerator().getHorizon(getWorld());
}
default int getSeaLevel()
{
return 63;
@@ -21,11 +21,15 @@ package net.minecraftforge.common.extensions;
import java.util.List;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.DisplayEffectsScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Potion;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public interface IForgeEffectInstance {
@@ -33,6 +37,59 @@ public interface IForgeEffectInstance {
return (EffectInstance)this;
}
/**
* If the Potion effect should be displayed in the players inventory
* @return true to display it (default), false to hide it.
*/
default boolean shouldRender() {
return getEffectInstance().getPotion().shouldRender(getEffectInstance());
}
/**
* If the standard PotionEffect text (name and duration) should be drawn when this potion is active.
* @return true to draw the standard text
*/
default boolean shouldRenderInvText() {
return getEffectInstance().getPotion().shouldRenderInvText(getEffectInstance());
}
/**
* If the Potion effect should be displayed in the player's ingame HUD
* @return true to display it (default), false to hide it.
*/
default boolean shouldRenderHUD() {
return getEffectInstance().getPotion().shouldRenderHUD(getEffectInstance());
}
/**
* Called to draw the this Potion onto the player's inventory when it's active.
* This can be used to e.g. render Potion icons from your own texture.
*
* @param gui the gui instance
* @param x the x coordinate
* @param y the y coordinate
* @param z the z level
*/
@OnlyIn(Dist.CLIENT)
default void renderInventoryEffect(DisplayEffectsScreen<?> gui, int x, int y, float z) {
getEffectInstance().getPotion().renderInventoryEffect(getEffectInstance(), gui, x, y, z);
}
/**
* Called to draw the this Potion onto the player's ingame HUD when it's active.
* This can be used to e.g. render Potion icons from your own texture.
*
* @param gui the gui instance
* @param x the x coordinate
* @param y the y coordinate
* @param z the z level
* @param alpha the alpha value, blinks when the potion is about to run out
*/
@OnlyIn(Dist.CLIENT)
default void renderHUDEffect(AbstractGui gui, int x, int y, float z, float alpha) {
getEffectInstance().getPotion().renderHUDEffect(getEffectInstance(), gui, x, y, z, alpha);
}
/***
* Returns a list of curative items for the potion effect
* By default, this list is initialized using {@link Potion#getCurativeItems}
@@ -19,14 +19,12 @@
package net.minecraftforge.common.extensions;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
import net.minecraft.item.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.IMinecartCollisionHandler;
public interface IForgeEntityMinecart
@@ -54,9 +52,9 @@ public interface IForgeEntityMinecart
*/
default BlockPos getCurrentRailPosition()
{
int x = MathHelper.floor(getMinecart().posX);
int y = MathHelper.floor(getMinecart().posY);
int z = MathHelper.floor(getMinecart().posZ);
int x = MathHelper.floor(getMinecart().func_226277_ct_());
int y = MathHelper.floor(getMinecart().func_226278_cu_());
int z = MathHelper.floor(getMinecart().func_226281_cx_());
BlockPos pos = new BlockPos(x, y - 1, z);
if (getMinecart().world.getBlockState(pos).isIn(BlockTags.RAILS)) pos = pos.down();
return pos;
@@ -27,10 +27,8 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.entity.Entity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.tags.Tag;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
@@ -109,10 +107,11 @@ public interface IForgeFluid
* Queries if this fluid should render in a given layer.
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()} to alter the model based on layer.
*/
/* TODO: reimplement
default boolean canRenderInLayer(IFluidState state, BlockRenderLayer layer)
{
return this.getFluid().getRenderLayer() == layer;
}
}*/
/**
* Retrieves a list of tags names this is known to be associated with.
@@ -26,7 +26,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.IFluidState;
import net.minecraft.tags.Tag;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.IWorldReader;
@@ -75,8 +74,9 @@ public interface IForgeFluidState
* Queries if this fluidstate should render in a given layer.
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()} to alter the model based on layer.
*/
/* TODO: reimplement
default boolean canRenderInLayer(BlockRenderLayer layer)
{
return getFluidState().getFluid().canRenderInLayer(getFluidState(), layer);
}
}*/
}
@@ -660,7 +660,7 @@ public interface IForgeItem
*/
default boolean canContinueUsing(ItemStack oldStack, ItemStack newStack)
{
return oldStack.equals(newStack);
return ItemStack.areItemsEqualIgnoreDurability(oldStack, newStack);
}
/**
@@ -350,6 +350,19 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundNBT>
return getStack().getItem().onDroppedByPlayer(getStack(), player);
}
/**
* Allow the item one last chance to modify its name used for the tool highlight
* useful for adding something extra that can't be removed by a user in the
* displayed name, such as a mode of operation.
*
* @param displayName the name that will be displayed unless it is changed in
* this method.
*/
default String getHighlightTip(String displayName)
{
return getStack().getItem().getHighlightTip(getStack(), displayName);
}
/**
* Get the NBT data to be sent to the client. The Item can control what data is kept in the tag.
*
@@ -119,7 +119,7 @@ public interface IForgeWorldType
default <T extends IArea, C extends IExtendedNoiseRandom<T>> IAreaFactory<T> getBiomeLayer(IAreaFactory<T> parentLayer,
OverworldGenSettings chunkSettings, LongFunction<C> contextFactory)
{
parentLayer = (new BiomeLayer(getWorldType(), chunkSettings)).apply(contextFactory.apply(200L), parentLayer);
parentLayer = (new BiomeLayer(getWorldType(), chunkSettings.getBiomeId())).apply(contextFactory.apply(200L), parentLayer);
parentLayer = AddBambooForestLayer.INSTANCE.apply(contextFactory.apply(1001L), parentLayer);
parentLayer = LayerUtil.repeat(1000L, ZoomLayer.NORMAL, parentLayer, 2, contextFactory);
parentLayer = EdgeBiomeLayer.INSTANCE.apply(contextFactory.apply(1000L), parentLayer);
@@ -21,7 +21,7 @@ package net.minecraftforge.common.model;
import com.google.common.collect.ImmutableList;
final class HiddenModelPart implements IModelPart
final class HiddenModelPart
{
private final ImmutableList<String> path;
@@ -1,27 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.model;
/**
* Represents some part of a model you can refer to, for example: mesh,
* skeleton, bone or some separately animated submodel.
* @see IModelState
*/
public interface IModelPart {}
@@ -1,37 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.model;
import java.util.Optional;
/**
* An {@code IModelState} is a function from model part to a transformation that should be applied
* when that part is baked, thus representing the current "state" of the model and its parts.
*/
public interface IModelState
{
/**
* @param part Part of the model we are wanting to transform. An empty optional means
* we want a transform for the entire model.
* @return A transformation to apply to the part, if any. The coordinate system of the transform
* is determined by the part type.
*/
Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part);
}
@@ -1,37 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.model;
import javax.vecmath.Matrix4f;
import net.minecraft.util.Direction;
/*
* Replacement interface for ModelRotation to allow custom transformations of vanilla models.
* You should probably use TRSRTransformation directly.
*/
public interface ITransformation
{
Matrix4f getMatrixVec();
Direction rotateTransform(Direction facing);
int rotate(Direction facing, int vertexIndex);
}
@@ -28,12 +28,12 @@ public enum Models
{
;
public static IModelPart getHiddenModelPart(ImmutableList<String> path)
public static Object getHiddenModelPart(ImmutableList<String> path)
{
return new HiddenModelPart(path);
}
public static UnmodifiableIterator<String> getParts(IModelPart part)
public static UnmodifiableIterator<String> getParts(Object part)
{
if(part instanceof HiddenModelPart)
{
@@ -1,865 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.model;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
import javax.vecmath.SingularMatrixException;
import javax.vecmath.Tuple3f;
import javax.vecmath.Tuple4f;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
import net.minecraft.client.renderer.model.ItemTransformVec3f;
import net.minecraft.client.renderer.model.ModelRotation;
import net.minecraft.util.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.ForgeHooksClient;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
/*
* Interpolation-friendly affine transformation.
* If created with matrix, should successfully decompose it to a composition
* of easily interpolatable transformations (translation, first rotation, scale
* (with generally speaking different factors for each axis) and second rotation.
* If the input matrix is a composition of translation, rotation and scale (in
* any order), then the interpolation of the derived primitive transformations
* should result in the same transformation as the interpolation of the originals.
* Decomposition happens lazily (and is hopefully fast enough), so performance
* should be comparable to using Matrix4f directly.
* Immutable.
*/
public final class TRSRTransformation implements IModelState, ITransformation
{
private final Matrix4f matrix;
private boolean full;
private Vector3f translation;
private Quat4f leftRot;
private Vector3f scale;
private Quat4f rightRot;
private Matrix3f normalTransform;
public TRSRTransformation(@Nullable Matrix4f matrix)
{
if(matrix == null)
{
this.matrix = identity.matrix;
}
else
{
this.matrix = matrix;
}
}
public TRSRTransformation(@Nullable Vector3f translation, @Nullable Quat4f leftRot, @Nullable Vector3f scale, @Nullable Quat4f rightRot)
{
this.matrix = mul(translation, leftRot, scale, rightRot);
this.translation = translation != null ? translation : new Vector3f();
this.leftRot = leftRot != null ? leftRot : new Quat4f(0, 0, 0, 1);
this.scale = scale != null ? scale : new Vector3f(1, 1, 1);
this.rightRot = rightRot!= null ? rightRot : new Quat4f(0, 0, 0, 1);
full = true;
}
@Deprecated
@OnlyIn(Dist.CLIENT)
public static TRSRTransformation from(ItemTransformVec3f transform)
{
return transform.equals(ItemTransformVec3f.DEFAULT) ? identity : new TRSRTransformation(toVecmath(transform.translation), quatFromXYZDegrees(toVecmath(transform.rotation)), toVecmath(transform.scale), null);
}
@OnlyIn(Dist.CLIENT)
public static TRSRTransformation from(ModelRotation rotation)
{
return Cache.get(rotation);
}
@OnlyIn(Dist.CLIENT)
public static TRSRTransformation from(Direction facing)
{
return Cache.get(getRotation(facing));
}
@OnlyIn(Dist.CLIENT)
public static Matrix4f getMatrix(Direction facing)
{
return getRotation(facing).getMatrixVec();
}
@OnlyIn(Dist.CLIENT)
public static ModelRotation getRotation(Direction facing)
{
switch (facing)
{
case DOWN: return ModelRotation.X90_Y0;
case UP: return ModelRotation.X270_Y0;
case NORTH: return ModelRotation.X0_Y0;
case SOUTH: return ModelRotation.X0_Y180;
case WEST: return ModelRotation.X0_Y270;
case EAST: return ModelRotation.X0_Y90;
}
throw new IllegalArgumentException(String.valueOf(facing));
}
private static final TRSRTransformation identity;
static
{
Matrix4f m = new Matrix4f();
m.setIdentity();
identity = new TRSRTransformation(m);
identity.getLeftRot();
}
public static TRSRTransformation identity()
{
return identity;
}
public TRSRTransformation compose(TRSRTransformation b)
{
if (this.isIdentity()) return b;
if (b.isIdentity()) return this;
Matrix4f m = getMatrixVec();
m.mul(b.getMatrixVec());
return new TRSRTransformation(m);
}
public TRSRTransformation inverse()
{
if (this.isIdentity()) return this;
Matrix4f m = getMatrixVec();
m.invert();
return new TRSRTransformation(m);
}
private void genCheck()
{
if(!full)
{
Pair<Matrix3f, Vector3f> pair = toAffine(matrix);
Triple<Quat4f, Vector3f, Quat4f> triple = svdDecompose(pair.getLeft());
this.translation = pair.getRight();
this.leftRot = triple.getLeft();
this.scale = triple.getMiddle();
this.rightRot = triple.getRight();
full = true;
}
}
public static Quat4f quatFromYXZ(float y, float x, float z)
{
Quat4f ret = new Quat4f(0, 0, 0, 1), t = new Quat4f();
t.set(0, (float)Math.sin(y/2), 0, (float)Math.cos(y/2));
ret.mul(t);
t.set((float)Math.sin(x/2), 0, 0, (float)Math.cos(x/2));
ret.mul(t);
t.set(0, 0, (float)Math.sin(z/2), (float)Math.cos(z/2));
ret.mul(t);
return ret;
}
public static Quat4f quatFromXYZDegrees(Vector3f xyz)
{
return quatFromXYZ((float)Math.toRadians(xyz.x), (float)Math.toRadians(xyz.y), (float)Math.toRadians(xyz.z));
}
public static Quat4f quatFromXYZ(Vector3f xyz)
{
return quatFromXYZ(xyz.x, xyz.y, xyz.z);
}
public static Quat4f quatFromXYZ(float x, float y, float z)
{
Quat4f ret = new Quat4f(0, 0, 0, 1), t = new Quat4f();
t.set((float)Math.sin(x/2), 0, 0, (float)Math.cos(x/2));
ret.mul(t);
t.set(0, (float)Math.sin(y/2), 0, (float)Math.cos(y/2));
ret.mul(t);
t.set(0, 0, (float)Math.sin(z/2), (float)Math.cos(z/2));
ret.mul(t);
return ret;
}
public static Vector3f toYXZDegrees(Quat4f q)
{
Vector3f yxz = toYXZ(q);
return new Vector3f((float)Math.toDegrees(yxz.x), (float)Math.toDegrees(yxz.y), (float)Math.toDegrees(yxz.z));
}
public static Vector3f toYXZ(Quat4f q)
{
float w2 = q.w * q.w;
float x2 = q.x * q.x;
float y2 = q.y * q.y;
float z2 = q.z * q.z;
float l = w2 + x2 + y2 + z2;
float sx = 2 * q.w * q.x - 2 * q.y * q.z;
float x = (float)Math.asin(sx / l);
if(Math.abs(sx) > .999f * l)
{
return new Vector3f(
x,
2 * (float)Math.atan2(q.y, q.w),
0
);
}
return new Vector3f(
x,
(float)Math.atan2(2 * q.x * q.z + 2 * q.y * q.w, w2 - x2 - y2 + z2),
(float)Math.atan2(2 * q.x * q.y + 2 * q.w * q.z, w2 - x2 + y2 - z2)
);
}
public static Vector3f toXYZDegrees(Quat4f q)
{
Vector3f xyz = toXYZ(q);
return new Vector3f((float)Math.toDegrees(xyz.x), (float)Math.toDegrees(xyz.y), (float)Math.toDegrees(xyz.z));
}
public static Vector3f toXYZ(Quat4f q)
{
float w2 = q.w * q.w;
float x2 = q.x * q.x;
float y2 = q.y * q.y;
float z2 = q.z * q.z;
float l = w2 + x2 + y2 + z2;
float sy = 2 * q.w * q.x - 2 * q.y * q.z;
float y = (float)Math.asin(sy / l);
if(Math.abs(sy) > .999f * l)
{
return new Vector3f(
2 * (float)Math.atan2(q.x, q.w),
y,
0
);
}
return new Vector3f(
(float)Math.atan2(2 * q.y * q.z + 2 * q.x * q.w, w2 - x2 - y2 + z2),
y,
(float)Math.atan2(2 * q.x * q.y + 2 * q.w * q.z, w2 + x2 - y2 - z2)
);
}
public static Matrix4f mul(@Nullable Vector3f translation, @Nullable Quat4f leftRot, @Nullable Vector3f scale, @Nullable Quat4f rightRot)
{
Matrix4f res = new Matrix4f(), t = new Matrix4f();
res.setIdentity();
if(leftRot != null)
{
t.set(leftRot);
res.mul(t);
}
if(scale != null)
{
t.setIdentity();
t.m00 = scale.x;
t.m11 = scale.y;
t.m22 = scale.z;
res.mul(t);
}
if(rightRot != null)
{
t.set(rightRot);
res.mul(t);
}
if(translation != null) res.setTranslation(translation);
return res;
}
/*
* Performs SVD decomposition of m, accumulating reflection in the scale (U and V are pure rotations).
*/
public static Triple<Quat4f, Vector3f, Quat4f> svdDecompose(Matrix3f m)
{
// determine V by doing 5 steps of Jacobi iteration on MT * M
Quat4f u = new Quat4f(0, 0, 0, 1), v = new Quat4f(0, 0, 0, 1), qt = new Quat4f();
Matrix3f b = new Matrix3f(m), t = new Matrix3f();
t.transpose(m);
b.mul(t, b);
for(int i = 0; i < 5; i++) v.mul(stepJacobi(b));
v.normalize();
t.set(v);
b.set(m);
b.mul(t);
// FIXME: this doesn't work correctly for some reason; not crucial, so disabling for now; investigate in the future.
//sortSingularValues(b, v);
Pair<Float, Float> p;
float ul = 1f;
p = qrGivensQuat(b.m00, b.m10);
qt.set(0, 0, p.getLeft(), p.getRight());
u.mul(qt);
t.setIdentity();
t.m00 = qt.w * qt.w - qt.z * qt.z;
t.m11 = t.m00;
t.m10 = -2 * qt.z * qt.w;
t.m01 = -t.m10;
t.m22 = qt.w * qt.w + qt.z * qt.z;
ul *= t.m22;
b.mul(t, b);
p = qrGivensQuat(b.m00, b.m20);
qt.set(0, -p.getLeft(), 0, p.getRight());
u.mul(qt);
t.setIdentity();
t.m00 = qt.w * qt.w - qt.y * qt.y;
t.m22 = t.m00;
t.m20 = 2 * qt.y * qt.w;
t.m02 = -t.m20;
t.m11 = qt.w * qt.w + qt.y * qt.y;
ul *= t.m11;
b.mul(t, b);
p = qrGivensQuat(b.m11, b.m21);
qt.set(p.getLeft(), 0, 0, p.getRight());
u.mul(qt);
t.setIdentity();
t.m11 = qt.w * qt.w - qt.x * qt.x;
t.m22 = t.m11;
t.m21 = -2 * qt.x * qt.w;
t.m12 = -t.m21;
t.m00 = qt.w * qt.w + qt.x * qt.x;
ul *= t.m00;
b.mul(t, b);
ul = 1f / ul;
u.scale((float)Math.sqrt(ul));
Vector3f s = new Vector3f(b.m00 * ul, b.m11 * ul, b.m22 * ul);
return Triple.of(u, s, v);
}
private static float rsqrt(float f)
{
float f2 = .5f * f;
int i = Float.floatToIntBits(f);
i = 0x5f3759df - (i >> 1);
f = Float.intBitsToFloat(i);
f *= 1.5f - f2 * f * f;
return f;
}
private static final float eps = 1e-6f;
private static final float g = 3f + 2f * (float)Math.sqrt(2);
private static final float cs = (float)Math.cos(Math.PI / 8);
private static final float ss = (float)Math.sin(Math.PI / 8);
private static final float sq2 = 1f / (float)Math.sqrt(2);
private static Pair<Float, Float> approxGivensQuat(float a11, float a12, float a22)
{
float ch = 2f * (a11 - a22);
float sh = a12;
boolean b = g * sh * sh < ch * ch;
float w = rsqrt(sh * sh + ch * ch);
ch = b ? w * ch : cs;
sh = b ? w * sh : ss;
return Pair.of(sh, ch);
}
private static final void swapNeg(Matrix3f m, int i, int j)
{
float[] t = new float[3];
m.getColumn(j, t);
for(int k = 0; k < 3; k++)
{
m.setElement(k, j, -m.getElement(k, i));
}
m.setColumn(i, t);
}
@SuppressWarnings("unused")
private static void sortSingularValues(Matrix3f b, Quat4f v)
{
float p0 = b.m00 * b.m00 + b.m10 * b.m10 + b.m20 * b.m20;
float p1 = b.m01 * b.m01 + b.m11 * b.m11 + b.m21 * b.m21;
float p2 = b.m02 * b.m02 + b.m12 * b.m12 + b.m22 * b.m22;
Quat4f t = new Quat4f();
if(p0 < p1)
{
swapNeg(b, 0, 1);
t.set(0, 0, sq2, sq2);
v.mul(t);
float f = p0;
p0 = p1;
p1 = f;
}
if(p0 < p2)
{
swapNeg(b, 0, 2);
t.set(0, sq2, 0, sq2);
v.mul(t);
float f = p0;
p0 = p2;
p2 = f;
}
if(p1 < p2)
{
swapNeg(b, 1, 2);
t.set(sq2, 0, 0, sq2);
v.mul(t);
}
}
private static Pair<Float, Float> qrGivensQuat(float a1, float a2)
{
float p = (float)Math.sqrt(a1 * a1 + a2 * a2);
float sh = p > eps ? a2 : 0;
float ch = Math.abs(a1) + Math.max(p, eps);
if(a1 < 0)
{
float f = sh;
sh = ch;
ch = f;
}
//float w = 1.f / (float)Math.sqrt(ch * ch + sh * sh);
float w = rsqrt(ch * ch + sh * sh);
ch *= w;
sh *= w;
return Pair.of(sh, ch);
}
private static Quat4f stepJacobi(Matrix3f m)
{
Matrix3f t = new Matrix3f();
Quat4f qt = new Quat4f(), ret = new Quat4f(0, 0, 0, 1);
Pair<Float, Float> p;
// 01
if(m.m01 * m.m01 + m.m10 * m.m10 > eps)
{
p = approxGivensQuat(m.m00, .5f * (m.m01 + m.m10), m.m11);
qt.set(0, 0, p.getLeft(), p.getRight());
//qt.normalize();
ret.mul(qt);
//t.set(qt);
t.setIdentity();
t.m00 = qt.w * qt.w - qt.z * qt.z;
t.m11 = t.m00;
t.m10 = 2 * qt.z * qt.w;
t.m01 = -t.m10;
t.m22 = qt.w * qt.w + qt.z * qt.z;
m.mul(m, t);
t.transpose();
m.mul(t, m);
}
// 02
if(m.m02 * m.m02 + m.m20 * m.m20 > eps)
{
p = approxGivensQuat(m.m00, .5f * (m.m02 + m.m20), m.m22);
qt.set(0, -p.getLeft(), 0, p.getRight());
//qt.normalize();
ret.mul(qt);
//t.set(qt);
t.setIdentity();
t.m00 = qt.w * qt.w - qt.y * qt.y;
t.m22 = t.m00;
t.m20 = -2 * qt.y * qt.w;
t.m02 = -t.m20;
t.m11 = qt.w * qt.w + qt.y * qt.y;
m.mul(m, t);
t.transpose();
m.mul(t, m);
}
// 12
if(m.m12 * m.m12 + m.m21 * m.m21 > eps)
{
p = approxGivensQuat(m.m11, .5f * (m.m12 + m.m21), m.m22);
qt.set(p.getLeft(), 0, 0, p.getRight());
//qt.normalize();
ret.mul(qt);
//t.set(qt);
t.setIdentity();
t.m11 = qt.w * qt.w - qt.x * qt.x;
t.m22 = t.m11;
t.m21 = 2 * qt.x * qt.w;
t.m12 = -t.m21;
t.m00 = qt.w * qt.w + qt.x * qt.x;
m.mul(m, t);
t.transpose();
m.mul(t, m);
}
return ret;
}
/*
* Divides m by m33, sets last row to (0, 0, 0, 1), extracts linear and translation parts
*/
public static Pair<Matrix3f, Vector3f> toAffine(Matrix4f m)
{
m.mul(1.f / m.m33);
Vector3f trans = new Vector3f(m.m03, m.m13, m.m23);
Matrix3f linear = new Matrix3f(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, m.m21, m.m22);
return Pair.of(linear, trans);
}
/*
* Don't use this if you don't need to, conversion is lossy (second rotation component is lost).
*/
@Deprecated
@OnlyIn(Dist.CLIENT)
public net.minecraft.client.renderer.model.ItemTransformVec3f toItemTransform()
{
return new ItemTransformVec3f(toMojang(toXYZDegrees(getLeftRot())), toMojang(getTranslation()), toMojang(getScale()));
}
public boolean isIdentity()
{
return this.equals(identity);
}
@Override
public Matrix4f getMatrixVec()
{
return (Matrix4f)matrix.clone();
}
public Vector3f getTranslation()
{
genCheck();
return (Vector3f)translation.clone();
}
public Quat4f getLeftRot()
{
genCheck();
return (Quat4f)leftRot.clone();
}
public Vector3f getScale()
{
genCheck();
return (Vector3f)scale.clone();
}
public Quat4f getRightRot()
{
genCheck();
return (Quat4f)rightRot.clone();
}
@Override
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
{
if(part.isPresent())
{
return Optional.empty();
}
return Optional.of(this);
}
@Override
public Direction rotateTransform(Direction facing)
{
return rotate(matrix, facing);
}
public static Direction rotate(Matrix4f matrix, Direction facing)
{
Vec3i dir = facing.getDirectionVec();
Vector4f vec = new Vector4f(dir.getX(), dir.getY(), dir.getZ(), 0);
matrix.transform(vec);
return Direction.getFacingFromVector(vec.x, vec.y, vec.z);
}
public static boolean isInteger(Matrix4f matrix)
{
Matrix4f m = new Matrix4f();
m.setIdentity();
m.m30 = m.m31 = m.m32 = 1;
m.m33 = 0;
m.mul(matrix, m);
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
float v = m.getElement(i, j) / m.getElement(3, j);
if(Math.abs(v - Math.round(v)) > 1e-5) return false;
}
}
return true;
}
@Override
public int rotate(Direction facing, int vertexIndex)
{
// FIXME check if this is good enough
return vertexIndex;
}
public void transformPosition(Vector4f position)
{
matrix.transform(position);
}
public void transformNormal(Vector3f normal)
{
checkNormalTransform();
normalTransform.transform(normal);
normal.normalize();
}
private void checkNormalTransform()
{
if (normalTransform == null)
{
normalTransform = new Matrix3f();
matrix.getRotationScale(normalTransform);
normalTransform.invert();
normalTransform.transpose();
}
}
@Override
public String toString()
{
genCheck();
return MoreObjects.toStringHelper(this.getClass())
.add("matrix", matrix)
.add("translation", translation)
.add("leftRot", leftRot)
.add("scale", scale)
.add("rightRot", rightRot)
.toString();
}
/**
* convert transformation from assuming center-block system to corner-block system
*/
public static TRSRTransformation blockCenterToCorner(TRSRTransformation transform)
{
if (transform.isIdentity()) return transform;
Matrix4f ret = new Matrix4f(transform.getMatrixVec()), tmp = new Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
ret.mul(tmp, ret);
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
ret.mul(tmp);
return new TRSRTransformation(ret);
}
/**
* convert transformation from assuming corner-block system to center-block system
*/
public static TRSRTransformation blockCornerToCenter(TRSRTransformation transform)
{
if (transform.isIdentity()) return transform;
Matrix4f ret = new Matrix4f(transform.getMatrixVec()), tmp = new Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
ret.mul(tmp, ret);
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
ret.mul(tmp);
return new TRSRTransformation(ret);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + Objects.hashCode(matrix);
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
TRSRTransformation other = (TRSRTransformation) obj;
return Objects.equals(matrix, other.matrix);
}
@OnlyIn(Dist.CLIENT)
public static Vector3f toVecmath(net.minecraft.client.renderer.Vector3f vec)
{
return new Vector3f(vec.getX(), vec.getY(), vec.getZ());
}
@OnlyIn(Dist.CLIENT)
public static Vector4f toVecmath(net.minecraft.client.renderer.Vector4f vec)
{
return new Vector4f(vec.getX(), vec.getY(), vec.getZ(), vec.getW());
}
@OnlyIn(Dist.CLIENT)
public static Matrix4f toVecmath(net.minecraft.client.renderer.Matrix4f m)
{
return new Matrix4f(
m.get(0, 0), m.get(1, 0), m.get(2, 0), m.get(3, 0),
m.get(0, 1), m.get(1, 1), m.get(2, 1), m.get(3, 1),
m.get(0, 2), m.get(1, 2), m.get(2, 2), m.get(3, 2),
m.get(0, 3), m.get(1, 3), m.get(2, 3), m.get(3, 3));
}
public static Quat4f toVecmath(net.minecraft.client.renderer.Quaternion q)
{
return new Quat4f(q.getX(), q.getY(), q.getZ(), q.getW());
}
@OnlyIn(Dist.CLIENT)
public static net.minecraft.client.renderer.Vector3f toMojang(Vector3f vec)
{
return new net.minecraft.client.renderer.Vector3f(vec.x, vec.y, vec.z);
}
@OnlyIn(Dist.CLIENT)
public static net.minecraft.client.renderer.Vector4f toMojang(Vector4f vec)
{
return new net.minecraft.client.renderer.Vector4f(vec.x, vec.y, vec.z, vec.w);
}
@OnlyIn(Dist.CLIENT)
public static net.minecraft.client.renderer.Matrix4f toMojang(Matrix4f m)
{
net.minecraft.client.renderer.Matrix4f r = new net.minecraft.client.renderer.Matrix4f();
float[] row = new float[4];
for (int x = 0; x < 4; x++)
{
m.getRow(x, row);
for (int y = 0; y < 4; y++)
{
r.set(x, y, row[y]);
}
}
return r;
}
public static Vector3f lerp(Tuple3f from, Tuple3f to, float progress)
{
Vector3f res = new Vector3f(from);
res.interpolate(from, to, progress);
return res;
}
public static Vector4f lerp(Tuple4f from, Tuple4f to, float progress)
{
Vector4f res = new Vector4f(from);
res.interpolate(from, to, progress);
return res;
}
public static Quat4f slerp(Quat4f from, Quat4f to, float progress)
{
Quat4f res = new Quat4f();
res.interpolate(from, to, progress);
return res;
}
public TRSRTransformation slerp(TRSRTransformation that, float progress)
{
return new TRSRTransformation(
lerp(this.getTranslation(), that.getTranslation(), progress),
slerp(this.getLeftRot(), that.getLeftRot(), progress),
lerp(this.getScale(), that.getScale(), progress),
slerp(this.getRightRot(), that.getRightRot(), progress)
);
}
private static final EnumMap<Direction, TRSRTransformation> vanillaUvTransformLocalToGlobal = Maps.newEnumMap(Direction.class);
private static final EnumMap<Direction, TRSRTransformation> vanillaUvTransformGlobalToLocal = Maps.newEnumMap(Direction.class);
static
{
vanillaUvTransformLocalToGlobal.put(Direction.SOUTH, identity);
Quat4f tmp = new Quat4f();
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(90)));
vanillaUvTransformLocalToGlobal.put(Direction.EAST, new TRSRTransformation(null, new Quat4f(tmp), null, null));
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(-90)));
vanillaUvTransformLocalToGlobal.put(Direction.WEST, new TRSRTransformation(null, new Quat4f(tmp), null, null));
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(180)));
vanillaUvTransformLocalToGlobal.put(Direction.NORTH, new TRSRTransformation(null, new Quat4f(tmp), null, null));
tmp.set(new AxisAngle4f(1, 0, 0, (float)Math.toRadians(-90)));
vanillaUvTransformLocalToGlobal.put(Direction.UP, new TRSRTransformation(null, new Quat4f(tmp), null, null));
tmp.set(new AxisAngle4f(1, 0, 0, (float)Math.toRadians(90)));
vanillaUvTransformLocalToGlobal.put(Direction.DOWN, new TRSRTransformation(null, new Quat4f(tmp), null, null));
for(Direction side : Direction.values())
{
vanillaUvTransformGlobalToLocal.put(side, vanillaUvTransformLocalToGlobal.get(side).inverse());
}
}
public static TRSRTransformation getVanillaUvTransformLocalToGlobal(Direction side)
{
return vanillaUvTransformLocalToGlobal.get(side);
}
public static TRSRTransformation getVanillaUvTransformGlobalToLocal(Direction side)
{
return vanillaUvTransformGlobalToLocal.get(side);
}
public TRSRTransformation getUVLockTransform(Direction originalSide)
{
Direction newSide = rotateTransform(originalSide);
try
{
return blockCenterToCorner(vanillaUvTransformGlobalToLocal.get(originalSide).compose(blockCornerToCenter(this.inverse())).compose(vanillaUvTransformLocalToGlobal.get(newSide)));
}
catch(SingularMatrixException e)
{
return new TRSRTransformation(null, null, new Vector3f(0, 0, 0), null);
}
}
@OnlyIn(Dist.CLIENT)
private static final class Cache
{
private static final Map<ModelRotation, TRSRTransformation> rotations = new EnumMap<>(ModelRotation.class);
static
{
rotations.put(ModelRotation.X0_Y0, identity());
}
static TRSRTransformation get(ModelRotation rotation)
{
return rotations.computeIfAbsent(rotation, r -> new TRSRTransformation(ForgeHooksClient.getMatrix(r)));
}
}
}
@@ -0,0 +1,436 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.model;
import java.lang.reflect.Type;
import java.util.EnumMap;
import java.util.Map;
import javax.annotation.Nullable;
import com.google.gson.*;
import net.minecraft.client.renderer.*;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import com.google.common.collect.Maps;
import net.minecraft.client.renderer.model.ItemTransformVec3f;
import net.minecraft.client.renderer.model.ModelRotation;
import net.minecraft.util.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.ForgeHooksClient;
public final class TransformationHelper
{
@Deprecated
@OnlyIn(Dist.CLIENT)
public static TransformationMatrix toTransformation(ItemTransformVec3f transform)
{
if (transform.equals(ItemTransformVec3f.DEFAULT)) return TransformationMatrix.func_227983_a_();
return new TransformationMatrix(transform.translation, quatFromXYZ(transform.rotation, true), transform.scale, null);
}
public static void transform(Matrix4f matrix, Vector4f vector)
{
javax.vecmath.Vector4f copy = toVecmath(vector);
toVecmath(matrix).transform(copy);
vector.set(copy.x, copy.y, copy.z, copy.w);
}
public static Quaternion quatFromXYZ(Vector3f xyz, boolean degrees)
{
return new Quaternion(xyz.getX(), xyz.getY(), xyz.getZ(), degrees);
}
public static Direction rotate(Matrix4f matrix, Direction facing)
{
Vec3i dir = facing.getDirectionVec();
javax.vecmath.Vector4f vec = new javax.vecmath.Vector4f(dir.getX(), dir.getY(), dir.getZ(), 0);
toVecmath(matrix).transform(vec);
return Direction.getFacingFromVector(vec.x, vec.y, vec.z);
}
/**
* convert transformation from assuming center-block system to corner-block system
*/
public static TransformationMatrix blockCenterToCorner(TransformationMatrix transform)
{
if (transform.isIdentity()) return TransformationMatrix.func_227983_a_();
javax.vecmath.Matrix4f ret = toVecmath(transform.func_227988_c_()), tmp = new javax.vecmath.Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
ret.mul(tmp, ret);
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
ret.mul(tmp);
return new TransformationMatrix(toMojang(ret));
}
/**
* convert transformation from assuming corner-block system to center-block system
*/
public static TransformationMatrix blockCornerToCenter(TransformationMatrix transform)
{
if (transform.isIdentity()) return TransformationMatrix.func_227983_a_();
javax.vecmath.Matrix4f ret = toVecmath(transform.func_227988_c_()), tmp = new javax.vecmath.Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
ret.mul(tmp, ret);
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
ret.mul(tmp);
return new TransformationMatrix(toMojang(ret));
}
@OnlyIn(Dist.CLIENT)
public static javax.vecmath.Vector3f toVecmath(Vector3f vec)
{
return new javax.vecmath.Vector3f(vec.getX(), vec.getY(), vec.getZ());
}
@OnlyIn(Dist.CLIENT)
public static javax.vecmath.Vector4f toVecmath(Vector4f vec)
{
return new javax.vecmath.Vector4f(vec.getX(), vec.getY(), vec.getZ(), vec.getW());
}
@OnlyIn(Dist.CLIENT)
public static javax.vecmath.Matrix4f toVecmath(Matrix4f m)
{
float[] all = new float[16];
m.write(all);
return new javax.vecmath.Matrix4f(all);
}
public static javax.vecmath.Quat4f toVecmath(Quaternion q)
{
return new javax.vecmath.Quat4f(q.getX(), q.getY(), q.getZ(), q.getW());
}
public static Quaternion toMojang(javax.vecmath.Quat4f q)
{
return new Quaternion(q.getX(), q.getY(), q.getZ(), q.getW());
}
@OnlyIn(Dist.CLIENT)
public static Vector3f toMojang(javax.vecmath.Vector3f vec)
{
return new Vector3f(vec.x, vec.y, vec.z);
}
@OnlyIn(Dist.CLIENT)
public static Vector4f toMojang(javax.vecmath.Vector4f vec)
{
return new Vector4f(vec.x, vec.y, vec.z, vec.w);
}
@OnlyIn(Dist.CLIENT)
public static Matrix4f toMojang(javax.vecmath.Matrix4f m)
{
Matrix4f r = new Matrix4f();
float[] row = new float[4];
float[] all = new float[16];
for (int x = 0; x < 4; x++)
{
m.getRow(x, row);
for (int y = 0; y < 4; y++)
{
all[y*4+x] = row[y];
}
}
r.set(all);
return r;
}
public static javax.vecmath.Vector3f lerp(javax.vecmath.Tuple3f from, javax.vecmath.Tuple3f to, float progress)
{
javax.vecmath.Vector3f res = new javax.vecmath.Vector3f(from);
res.interpolate(from, to, progress);
return res;
}
public static javax.vecmath.Vector4f lerp(javax.vecmath.Tuple4f from, javax.vecmath.Tuple4f to, float progress)
{
javax.vecmath.Vector4f res = new javax.vecmath.Vector4f(from);
res.interpolate(from, to, progress);
return res;
}
public static Vector3f lerp(Vector3f from, Vector3f to, float progress)
{
Vector3f res = from.func_229195_e_();
res.func_229190_a_(to, progress);
return res;
}
public static Quaternion slerp(Quaternion from, Quaternion to, float progress)
{
javax.vecmath.Quat4f res = new javax.vecmath.Quat4f();
res.interpolate(toVecmath(from), toVecmath(to), progress);
return toMojang(res);
}
public static TransformationMatrix slerp(TransformationMatrix one, TransformationMatrix that, float progress)
{
return new TransformationMatrix(
lerp(one.getTranslation(), that.getTranslation(), progress),
slerp(one.func_227989_d_(), that.func_227989_d_(), progress),
lerp(one.getScale(), that.getScale(), progress),
slerp(one.getRightRot(), that.getRightRot(), progress)
);
}
private static final EnumMap<Direction, TransformationMatrix> vanillaUvTransformLocalToGlobal = Maps.newEnumMap(Direction.class);
private static final EnumMap<Direction, TransformationMatrix> vanillaUvTransformGlobalToLocal = Maps.newEnumMap(Direction.class);
static
{
vanillaUvTransformLocalToGlobal.put(Direction.SOUTH, TransformationMatrix.func_227983_a_());
javax.vecmath.Quat4f tmp = new javax.vecmath.Quat4f();
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(90)));
vanillaUvTransformLocalToGlobal.put(Direction.EAST, new TransformationMatrix(null, toMojang(tmp), null, null));
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(-90)));
vanillaUvTransformLocalToGlobal.put(Direction.WEST, new TransformationMatrix(null, toMojang(tmp), null, null));
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(180)));
vanillaUvTransformLocalToGlobal.put(Direction.NORTH, new TransformationMatrix(null, toMojang(tmp), null, null));
tmp.set(new javax.vecmath.AxisAngle4f(1, 0, 0, (float)Math.toRadians(-90)));
vanillaUvTransformLocalToGlobal.put(Direction.UP, new TransformationMatrix(null, toMojang(tmp), null, null));
tmp.set(new javax.vecmath.AxisAngle4f(1, 0, 0, (float)Math.toRadians(90)));
vanillaUvTransformLocalToGlobal.put(Direction.DOWN, new TransformationMatrix(null, toMojang(tmp), null, null));
for(Direction side : Direction.values())
{
vanillaUvTransformGlobalToLocal.put(side, vanillaUvTransformLocalToGlobal.get(side).inverse());
}
}
public static TransformationMatrix getVanillaUvTransformLocalToGlobal(Direction side)
{
return vanillaUvTransformLocalToGlobal.get(side);
}
public static TransformationMatrix getVanillaUvTransformGlobalToLocal(Direction side)
{
return vanillaUvTransformGlobalToLocal.get(side);
}
public static TransformationMatrix getUVLockTransform(TransformationMatrix matrix, Direction originalSide)
{
Direction newSide = matrix.rotateTransform(originalSide);
try
{
return blockCenterToCorner(vanillaUvTransformGlobalToLocal.get(originalSide).compose(blockCornerToCenter(matrix.inverse())).compose(vanillaUvTransformLocalToGlobal.get(newSide)));
}
catch(javax.vecmath.SingularMatrixException e)
{
return new TransformationMatrix(null, null, new Vector3f(0, 0, 0), null);
}
}
public static class Deserializer implements JsonDeserializer<TransformationMatrix>
{
@Override
public TransformationMatrix deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString())
{
String transform = json.getAsString();
if(transform.equals("identity"))
{
return TransformationMatrix.func_227983_a_();
}
else
{
throw new JsonParseException("TRSR: unknown default string: " + transform);
}
}
if (json.isJsonArray())
{
// direct matrix array
return new TransformationMatrix(parseMatrix(json));
}
if (!json.isJsonObject()) throw new JsonParseException("TRSR: expected array or object, got: " + json);
JsonObject obj = json.getAsJsonObject();
TransformationMatrix ret;
if (obj.has("matrix"))
{
// matrix as a sole key
ret = new TransformationMatrix(parseMatrix(obj.get("matrix")));
obj.remove("matrix");
if (obj.entrySet().size() != 0)
{
throw new JsonParseException("TRSR: can't combine matrix and other keys");
}
return ret;
}
Vector3f translation = null;
Quaternion leftRot = null;
Vector3f scale = null;
Quaternion rightRot = null;
if (obj.has("translation"))
{
translation = new Vector3f(parseFloatArray(obj.get("translation"), 3, "Translation"));
obj.remove("translation");
}
if (obj.has("rotation"))
{
leftRot = parseRotation(obj.get("rotation"));
obj.remove("rotation");
}
if (obj.has("scale"))
{
if(!obj.get("scale").isJsonArray())
{
try
{
float s = obj.get("scale").getAsNumber().floatValue();
scale = new Vector3f(s, s, s);
}
catch (ClassCastException ex)
{
throw new JsonParseException("TRSR scale: expected number or array, got: " + obj.get("scale"));
}
}
else
{
scale = new Vector3f(parseFloatArray(obj.get("scale"), 3, "Scale"));
}
obj.remove("scale");
}
if (obj.has("post-rotation"))
{
rightRot = parseRotation(obj.get("post-rotation"));
obj.remove("post-rotation");
}
if (!obj.entrySet().isEmpty()) throw new JsonParseException("TRSR: can either have single 'matrix' key, or a combination of 'translation', 'rotation', 'scale', 'post-rotation'");
return new TransformationMatrix(translation, leftRot, scale, rightRot);
}
public static Matrix4f parseMatrix(JsonElement e)
{
if (!e.isJsonArray()) throw new JsonParseException("Matrix: expected an array, got: " + e);
JsonArray m = e.getAsJsonArray();
if (m.size() != 3) throw new JsonParseException("Matrix: expected an array of length 3, got: " + m.size());
javax.vecmath.Matrix4f ret = new javax.vecmath.Matrix4f();
for (int i = 0; i < 3; i++)
{
if (!m.get(i).isJsonArray()) throw new JsonParseException("Matrix row: expected an array, got: " + m.get(i));
JsonArray r = m.get(i).getAsJsonArray();
if (r.size() != 4) throw new JsonParseException("Matrix row: expected an array of length 4, got: " + r.size());
for (int j = 0; j < 4; j++)
{
try
{
ret.setElement(i, j, r.get(j).getAsNumber().floatValue());
}
catch (ClassCastException ex)
{
throw new JsonParseException("Matrix element: expected number, got: " + r.get(j));
}
}
}
return toMojang(ret);
}
public static float[] parseFloatArray(JsonElement e, int length, String prefix)
{
if (!e.isJsonArray()) throw new JsonParseException(prefix + ": expected an array, got: " + e);
JsonArray t = e.getAsJsonArray();
if (t.size() != length) throw new JsonParseException(prefix + ": expected an array of length " + length + ", got: " + t.size());
float[] ret = new float[length];
for (int i = 0; i < length; i++)
{
try
{
ret[i] = t.get(i).getAsNumber().floatValue();
}
catch (ClassCastException ex)
{
throw new JsonParseException(prefix + " element: expected number, got: " + t.get(i));
}
}
return ret;
}
public static Quaternion parseAxisRotation(JsonElement e)
{
if (!e.isJsonObject()) throw new JsonParseException("Axis rotation: object expected, got: " + e);
JsonObject obj = e.getAsJsonObject();
if (obj.entrySet().size() != 1) throw new JsonParseException("Axis rotation: expected single axis object, got: " + e);
Map.Entry<String, JsonElement> entry = obj.entrySet().iterator().next();
Quaternion ret;
try
{
if (entry.getKey().equals("x"))
{
ret = new Quaternion(new Vector3f(1, 0, 0), entry.getValue().getAsNumber().floatValue(), true);
}
else if (entry.getKey().equals("y"))
{
ret = new Quaternion(new Vector3f(0, 1, 0), entry.getValue().getAsNumber().floatValue(), true);
}
else if (entry.getKey().equals("z"))
{
ret = new Quaternion(new Vector3f(0, 0, 1), entry.getValue().getAsNumber().floatValue(), true);
}
else throw new JsonParseException("Axis rotation: expected single axis key, got: " + entry.getKey());
}
catch(ClassCastException ex)
{
throw new JsonParseException("Axis rotation value: expected number, got: " + entry.getValue());
}
return ret;
}
public static Quaternion parseRotation(JsonElement e)
{
if (e.isJsonArray())
{
if (e.getAsJsonArray().get(0).isJsonObject())
{
Quaternion ret = new Quaternion(0, 0, 0, 1);
for (JsonElement a : e.getAsJsonArray())
{
ret.multiply(parseAxisRotation(a));
}
return ret;
}
else if (e.isJsonArray())
{
JsonArray array = e.getAsJsonArray();
if (array.size() == 3) //Vanilla rotation
return quatFromXYZ(new Vector3f(parseFloatArray(e, 3, "Rotation")), true);
else // quaternion
return new Quaternion(parseFloatArray(e, 4, "Rotation"));
}
else throw new JsonParseException("Rotation: expected array or object, got: " + e);
}
else if (e.isJsonObject())
{
return parseAxisRotation(e);
}
else throw new JsonParseException("Rotation: expected array or object, got: " + e);
}
}
}
@@ -26,11 +26,7 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
@@ -40,6 +36,7 @@ import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import net.minecraft.client.renderer.model.IModelTransform;
import net.minecraft.resources.IResource;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
@@ -48,7 +45,6 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.animation.Event;
import net.minecraftforge.common.animation.ITimeValue;
import net.minecraftforge.common.animation.TimeValues;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.util.JsonUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
@@ -81,13 +77,13 @@ public final class AnimationStateMachine implements IAnimationStateMachine
private transient IClip currentState;
private transient float lastPollTime;
private static final LoadingCache<Triple<? extends IClip, Float, Float>, Pair<IModelState, Iterable<Event>>> clipCache = CacheBuilder.newBuilder()
private static final LoadingCache<Triple<? extends IClip, Float, Float>, Pair<IModelTransform, Iterable<Event>>> clipCache = CacheBuilder.newBuilder()
.maximumSize(100)
.expireAfterWrite(100, TimeUnit.MILLISECONDS)
.build(new CacheLoader<Triple<? extends IClip, Float, Float>, Pair<IModelState, Iterable<Event>>>()
.build(new CacheLoader<Triple<? extends IClip, Float, Float>, Pair<IModelTransform, Iterable<Event>>>()
{
@Override
public Pair<IModelState, Iterable<Event>> load(Triple<? extends IClip, Float, Float> key) throws Exception
public Pair<IModelTransform, Iterable<Event>> load(Triple<? extends IClip, Float, Float> key) throws Exception
{
return Clips.apply(key.getLeft(), key.getMiddle(), key.getRight());
}
@@ -136,13 +132,13 @@ public final class AnimationStateMachine implements IAnimationStateMachine
}
@Override
public Pair<IModelState, Iterable<Event>> apply(float time)
public Pair<IModelTransform, Iterable<Event>> apply(float time)
{
if(lastPollTime == Float.NEGATIVE_INFINITY)
{
lastPollTime = time;
}
Pair<IModelState, Iterable<Event>> pair = clipCache.getUnchecked(Triple.of(currentState, lastPollTime, time));
Pair<IModelTransform, Iterable<Event>> pair = clipCache.getUnchecked(Triple.of(currentState, lastPollTime, time));
lastPollTime = time;
boolean shouldFilter = false;
if(shouldHandleSpecialEvents)
@@ -21,21 +21,20 @@ package net.minecraftforge.common.model.animation;
import java.io.IOException;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.model.IModelTransform;
import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.animation.Event;
import net.minecraftforge.common.animation.ITimeValue;
import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.model.TransformationHelper;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
@@ -95,7 +94,7 @@ public final class Clips
@OnlyIn(Dist.CLIENT)
public static IClip getModelClipNode(ResourceLocation modelLocation, String clipName)
{
IUnbakedModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
IUnbakedModel model = ModelLoader.defaultModelGetter().apply(modelLocation);
Optional<? extends IClip> clip = model.getClip(clipName);
if (clip.isPresent())
{
@@ -175,7 +174,7 @@ public final class Clips
{
private final IJointClip parent = childClip.apply(joint);
@Override
public TRSRTransformation apply(float time)
public TransformationMatrix apply(float time)
{
return parent.apply(TimeClip.this.time.apply(time));
}
@@ -292,10 +291,10 @@ public final class Clips
return new IJointClip()
{
@Override
public TRSRTransformation apply(float time)
public TransformationMatrix apply(float time)
{
float clipTime = input.apply(time);
return fromClip.apply(clipTime).slerp(toClip.apply(clipTime), MathHelper.clamp(progress.apply(time), 0, 1));
return TransformationHelper.slerp(fromClip.apply(clipTime), toClip.apply(clipTime), MathHelper.clamp(progress.apply(time), 0, 1));
}
};
}
@@ -303,28 +302,34 @@ public final class Clips
/**
* IModelState wrapper for a Clip, sampled at specified time.
*/
public static Pair<IModelState, Iterable<Event>> apply(final IClip clip, final float lastPollTime, final float time)
public static Pair<IModelTransform, Iterable<Event>> apply(final IClip clip, final float lastPollTime, final float time)
{
return Pair.<IModelState, Iterable<Event>>of(new IModelState()
return Pair.of(new IModelTransform()
{
@Override
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
public TransformationMatrix func_225615_b_()
{
if(!part.isPresent() || !(part.get() instanceof IJoint))
return TransformationMatrix.func_227983_a_();
}
@Override
public TransformationMatrix getPartTransformation(Object part)
{
if(!(part instanceof IJoint))
{
return Optional.empty();
return TransformationMatrix.func_227983_a_();
}
IJoint joint = (IJoint)part.get();
IJoint joint = (IJoint)part;
// TODO: Cache clip application?
TRSRTransformation jointTransform = clip.apply(joint).apply(time).compose(joint.getInvBindPose());
TransformationMatrix jointTransform = clip.apply(joint).apply(time).compose(joint.getInvBindPose());
Optional<? extends IJoint> parent = joint.getParent();
while(parent.isPresent())
{
TRSRTransformation parentTransform = clip.apply(parent.get()).apply(time);
TransformationMatrix parentTransform = clip.apply(parent.get()).apply(time);
jointTransform = parentTransform.compose(jointTransform);
parent = parent.get().getParent();
}
return Optional.of(jointTransform);
return jointTransform;
}
}, clip.pastEvents(lastPollTime, time));
}
@@ -19,8 +19,8 @@
package net.minecraftforge.common.model.animation;
import net.minecraft.client.renderer.model.IModelTransform;
import net.minecraftforge.common.animation.Event;
import net.minecraftforge.common.model.IModelState;
import org.apache.commons.lang3.tuple.Pair;
@@ -34,7 +34,7 @@ public interface IAnimationStateMachine
* Event iterable will contain all events that happened from the last invocation of this method, from most to least recent.
* Event offset is relative to the previous event, and for the first event it's relative to the current time.
*/
Pair<IModelState, Iterable<Event>> apply(float time);
Pair<IModelTransform, Iterable<Event>> apply(float time);
/**
* Transition to a new state.
@@ -21,15 +21,14 @@ package net.minecraftforge.common.model.animation;
import java.util.Optional;
import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraft.client.renderer.TransformationMatrix;
/**
* Model part that's a part of the hierarchical skeleton.
*/
public interface IJoint extends IModelPart
public interface IJoint
{
TRSRTransformation getInvBindPose();
TransformationMatrix getInvBindPose();
Optional<? extends IJoint> getParent();
}
@@ -19,12 +19,12 @@
package net.minecraftforge.common.model.animation;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraft.client.renderer.TransformationMatrix;
/**
* Returns Local joint pose; animation clip for specific model part.
*/
public interface IJointClip
{
TRSRTransformation apply(float time);
TransformationMatrix apply(float time);
}
@@ -19,7 +19,7 @@
package net.minecraftforge.common.model.animation;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraft.client.renderer.TransformationMatrix;
/**
* Various implementations of IJointClip.
@@ -31,9 +31,9 @@ public final class JointClips
INSTANCE;
@Override
public TRSRTransformation apply(float time)
public TransformationMatrix apply(float time)
{
return TRSRTransformation.identity();
return TransformationMatrix.func_227983_a_();
}
}
@@ -49,7 +49,7 @@ public final class JointClips
}
@Override
public TRSRTransformation apply(float time)
public TransformationMatrix apply(float time)
{
return clip.apply(child).apply(time);
}
@@ -19,9 +19,9 @@
package net.minecraftforge.common.property;
import net.minecraft.client.renderer.model.IModelTransform;
import net.minecraft.state.BooleanProperty;
import net.minecraftforge.client.model.data.ModelProperty;
import net.minecraftforge.common.model.IModelState;
public class Properties
{
@@ -33,5 +33,5 @@ public class Properties
/**
* Property holding the IModelState used for animating the model in the TESR.
*/
public static final ModelProperty<IModelState> AnimationProperty = new ModelProperty<IModelState>();
public static final ModelProperty<IModelTransform> AnimationProperty = new ModelProperty<IModelTransform>();
}
@@ -30,8 +30,8 @@ public class ChunkCoordComparator implements java.util.Comparator<ChunkPos>
public ChunkCoordComparator(ServerPlayerEntity entityplayer)
{
x = (int) entityplayer.posX >> 4;
z = (int) entityplayer.posZ >> 4;
x = (int) entityplayer.func_226277_ct_() >> 4;
z = (int) entityplayer.func_226281_cx_() >> 4;
}
@Override
@@ -0,0 +1,108 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.util;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Supplier;
/**
* Proxy object for a value that is calculated on first access
* @param <T> The type of the value
*/
public interface Lazy<T> extends Supplier<T>
{
/**
* Constructs a lazy-initialized object
* @param supplier The supplier for the value, to be called the first time the value is needed.
*/
static <T> Lazy<T> of(@Nonnull Supplier<T> supplier)
{
return new Lazy.Fast<>(supplier);
}
/**
* Constructs a thread-safe lazy-initialized object
* @param supplier The supplier for the value, to be called the first time the value is needed.
*/
static <T> Lazy<T> concurrentOf(@Nonnull Supplier<T> supplier)
{
return new Lazy.Concurrent<>(supplier);
}
/**
* Non-thread-safe implementation.
*/
final class Fast<T> implements Lazy<T>
{
private Supplier<T> supplier;
private T instance;
private Fast(Supplier<T> supplier)
{
this.supplier = supplier;
}
@Nullable
@Override
public final T get()
{
if (supplier != null)
{
instance = supplier.get();
supplier = null;
}
return instance;
}
}
/**
* Thread-safe implementation.
*/
final class Concurrent<T> implements Lazy<T>
{
private static final Object lock = new Object();
private volatile Supplier<T> supplier;
private volatile T instance;
private Concurrent(Supplier<T> supplier)
{
this.supplier = supplier;
}
@Nullable
@Override
public final T get()
{
if (supplier != null)
{
synchronized (lock)
{
if (supplier != null)
{
instance = supplier.get();
supplier = null;
}
}
}
return instance;
}
}
}
@@ -0,0 +1,109 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.util;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Supplier;
/**
* Proxy object for a value that is calculated on first access.
* Same as {@link Lazy}, but with a nonnull contract.
* @param <T> The type of the value
*/
public interface NonNullLazy<T> extends NonNullSupplier<T>
{
/**
* Constructs a lazy-initialized object
* @param supplier The supplier for the value, to be called the first time the value is needed.
*/
static <T> NonNullLazy<T> of(@Nonnull NonNullSupplier<T> supplier)
{
return new NonNullLazy.Fast<>(supplier);
}
/**
* Constructs a thread-safe lazy-initialized object
* @param supplier The supplier for the value, to be called the first time the value is needed.
*/
static <T> NonNullLazy<T> concurrentOf(@Nonnull NonNullSupplier<T> supplier)
{
return new NonNullLazy.Concurrent<>(supplier);
}
/**
* Non-thread-safe implementation.
*/
final class Fast<T> implements NonNullLazy<T>
{
private NonNullSupplier<T> supplier;
private T instance;
private Fast(NonNullSupplier<T> supplier)
{
this.supplier = supplier;
}
@Nonnull
@Override
public final T get()
{
if (supplier != null)
{
instance = supplier.get();
supplier = null;
}
return instance;
}
}
/**
* Thread-safe implementation.
*/
final class Concurrent<T> implements NonNullLazy<T>
{
private static final Object lock = new Object();
private volatile NonNullSupplier<T> supplier;
private volatile T instance;
private Concurrent(NonNullSupplier<T> supplier)
{
this.supplier = supplier;
}
@Nonnull
@Override
public final T get()
{
if (supplier != null)
{
synchronized (lock)
{
if (supplier != null)
{
instance = supplier.get();
supplier = null;
}
}
}
return instance;
}
}
}