Port capability patches to 1.13 and refactor to new system (#5134)

* resource package and misc leftover rendering stuff

* Port Item and ItemStack patches

* Extract most item patches to interface

* Refactor Item#setNoRepair to be part of Item.Builder

* Adapt AnimationItemOverrideList to new cap system

* Improve null contract of OptionalCapabilityInstance

* Remove Capability.cast

* Update CapabilityAnimation to new cap system

* Remove OptionalCapabilityInstance#flatMap and add NonNullConsumer

* Add capability patch to Entity, not everything yet

* Fix Entity patch and add missing methods to IForgeEntity

* Fix null contract of CapabilityDispatcher

* Add TileEntity caps

* Adapt FluidUtil to new cap system

* Add world caps

* Add chunk caps

* Clean up cap patches

* Replace all tabs with spaces

* Move builder methods on Item to Item.Builder

Whitepsace fix

* Sided stuff take 2

* Prevent OptionalCapabilityInstance creating additional empty instances

* Cache getCapability result in AnimationTESR

* Fix imports in TileEntity patch

* Pull out cap code to base class, add village caps
This commit is contained in:
tterrag authored and GitHub committed 2018-09-09 17:27:15 -04:00
1 parent f851b37aa0
commit 334d925972
45 files changed
+1967 -266

No files matched your search

@@ -41,6 +41,7 @@ import net.minecraft.client.renderer.vertex.VertexBuffer;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.entity.Entity;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
@@ -35,7 +35,8 @@ public class ForgeClientHandler
// register model for the universal bucket, if it exists
if (FluidRegistry.isUniversalBucketEnabled())
{
ModelLoader.setBucketModelDefinition(ForgeMod.getInstance().universalBucket);
// TODO no more mesh definitions, this should be implemented with overrides
// ModelLoader.setBucketModelDefinition(ForgeMod.getInstance().universalBucket);
}
}
@@ -44,7 +45,7 @@ public class ForgeClientHandler
{
if (FluidRegistry.isUniversalBucketEnabled())
{
event.getItemColors().registerItemColorHandler(new FluidContainerColorer(), ForgeMod.getInstance().universalBucket);
event.getItemColors().func_199877_a(new FluidContainerColorer(), ForgeMod.getInstance().universalBucket);
}
}
}
@@ -67,22 +67,23 @@ public final class AnimationItemOverrideList extends ItemOverrideList
@Override
public IBakedModel func_209581_a(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
IAnimationStateMachine asm = stack.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (asm != null)
{
// TODO: caching?
if(world == null && entity != null)
return stack.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)
.map(asm ->
{
world = entity.world;
}
if(world == null)
{
world = Minecraft.getMinecraft().world;
}
IModelState state = asm.apply(Animation.getWorldTime(world, Animation.getPartialTickTime())).getLeft();
World w = world;
// TODO caching?
if(w == null && entity != null)
{
w = entity.world;
}
if(world == null)
{
w = Minecraft.getMinecraft().world;
}
return asm.apply(Animation.getWorldTime(world, Animation.getPartialTickTime())).getLeft();
})
// TODO where should uvlock data come from?
return model.bake(ModelLoader.defaultModelGetter(), bakedTextureGetter, new ModelStateComposition(state, this.state), false, format);
}
return super.func_209581_a(originalModel, stack, world, entity);
.map(state -> model.bake(ModelLoader.defaultModelGetter(), bakedTextureGetter, new ModelStateComposition(state, this.state), false, format))
.orElseGet(() -> super.func_209581_a(originalModel, stack, world, entity));
}
}
@@ -42,11 +42,8 @@ import net.minecraftforge.client.model.pipeline.VertexLighterFlat;
import net.minecraftforge.client.model.pipeline.VertexBufferConsumer;
import net.minecraftforge.common.animation.Event;
import net.minecraftforge.common.animation.IEventHandler;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.animation.CapabilityAnimation;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.opengl.GL11;
/**
@@ -69,17 +66,18 @@ public class AnimationModelBase<T extends Entity> extends ModelBase implements I
@Override
public void render(Entity entity, float limbSwing, float limbSwingSpeed, float timeAlive, float yawHead, float rotationPitch, float scale)
{
IAnimationStateMachine capability = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability == null)
{
return;
}
Pair<IModelState, Iterable<Event>> pair = capability.apply(timeAlive / 20);
handleEvents((T)entity, timeAlive / 20, pair.getRight());
IUnbakedModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
// TODO where should uvlock data come from?
IBakedModel bakedModel = model.bake(ModelLoader.defaultModelGetter(), ModelLoader.defaultTextureGetter(), pair.getLeft(), false, DefaultVertexFormats.ITEM);
entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)
.map(cap -> cap.apply(timeAlive / 20))
.map(pair -> {
handleEvents((T) entity, timeAlive / 20, pair.getRight());
IUnbakedModel unbaked = ModelLoaderRegistry.getModelOrMissing(modelLocation);
// TODO where should uvlock data come from?
return unbaked.bake(ModelLoader.defaultModelGetter(), ModelLoader.defaultTextureGetter(), pair.getLeft(), false, DefaultVertexFormats.ITEM);
}).ifPresent(model -> drawModel(model, entity));
}
private void drawModel(IBakedModel bakedModel, Entity entity)
{
BlockPos pos = new BlockPos(entity.posX, entity.posY + entity.height, entity.posZ);
RenderHelper.disableStandardItemLighting();
@@ -109,7 +107,7 @@ public class AnimationModelBase<T extends Entity> extends ModelBase implements I
}
for(EnumFacing side : EnumFacing.values())
{
random.setSeed(42);
random.setSeed(42);
quads = bakedModel.func_200117_a(null, side, random);
if(!quads.isEmpty())
{
@@ -30,6 +30,7 @@ import net.minecraft.world.IWorldReader;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.animation.Event;
import net.minecraftforge.common.animation.IEventHandler;
import net.minecraftforge.common.capabilities.OptionalCapabilityInstance;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.animation.CapabilityAnimation;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
@@ -50,7 +51,8 @@ public class AnimationTESR<T extends TileEntity> extends FastTESR<T> implements
@Override
public void renderTileEntityFast(T te, double x, double y, double z, float partialTick, int breakStage, BufferBuilder renderer)
{
if(!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null))
OptionalCapabilityInstance<IAnimationStateMachine> cap = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY);
if(!cap.isPresent())
{
return;
}
@@ -60,7 +62,7 @@ public class AnimationTESR<T extends TileEntity> extends FastTESR<T> implements
IBlockState state = world.getBlockState(pos);
if(state.getBlock().getBlockState().getProperties().contains(Properties.StaticProperty))
{
state = state.withProperty(Properties.StaticProperty, false);
state = state.func_206870_a(Properties.StaticProperty, false);
}
if(state instanceof IExtendedBlockState)
{
@@ -68,20 +70,19 @@ public class AnimationTESR<T extends TileEntity> extends FastTESR<T> implements
if(exState.getUnlistedNames().contains(Properties.AnimationProperty))
{
float time = Animation.getWorldTime(getWorld(), partialTick);
IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability != null)
{
Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
handleEvents(te, time, pair.getRight());
cap
.map(asm -> asm.apply(time))
.ifPresent(pair -> {
handleEvents(te, time, pair.getRight());
// TODO: caching?
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
// TODO: caching?
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
IExtendedBlockState animState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
blockRenderer.getBlockModelRenderer().func_199324_a(world, model, exState, pos, renderer, false, new Random(), 42);
}
blockRenderer.getBlockModelRenderer().func_199324_a(world, model, animState, pos, renderer, false, new Random(), 42);
});
}
}
}
@@ -19,13 +19,13 @@
package net.minecraftforge.client.resource;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
/**
* Represents a generic type of reloadable resource. Used for resource reload filtering.
*/
@SideOnly(Side.CLIENT)
@OnlyIn(Dist.CLIENT)
public interface IResourceType
{
}
@@ -22,15 +22,15 @@ package net.minecraftforge.client.resource;
import java.util.Set;
import java.util.function.Predicate;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.google.common.collect.Sets;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
/**
* Holds methods to create standard predicates to select {@link IResourceType}s that should be reloaded.
*/
@SideOnly(Side.CLIENT)
@OnlyIn(Dist.CLIENT)
public final class ReloadRequirements
{
/**