Cleanup of model system, taking advantage of java 8;

replaced guava Optional and Function with java 8 versions.
This commit is contained in:
RainWarrior 2017-06-25 04:08:20 +03:00
parent 1c24600bbb
commit dc043ac79f
93 changed files with 664 additions and 1271 deletions

View File

@ -8,12 +8,12 @@
+ this(p_i45663_1_, p_i45663_2_, null);
+ }
+
+ protected StateImplementation createState(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<net.minecraftforge.common.property.IUnlistedProperty<?>, com.google.common.base.Optional<?>> unlistedProperties)
+ protected StateImplementation createState(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<net.minecraftforge.common.property.IUnlistedProperty<?>, java.util.Optional<?>> unlistedProperties)
+ {
+ return new StateImplementation(block, properties);
+ }
+
+ protected BlockStateContainer(Block blockIn, IProperty<?>[] properties, ImmutableMap<net.minecraftforge.common.property.IUnlistedProperty<?>, com.google.common.base.Optional<?>> unlistedProperties)
+ protected BlockStateContainer(Block blockIn, IProperty<?>[] properties, ImmutableMap<net.minecraftforge.common.property.IUnlistedProperty<?>, java.util.Optional<?>> unlistedProperties)
+ {
+ this.field_177627_c = blockIn;
Map < String, IProperty<? >> map = Maps. < String, IProperty<? >> newHashMap();

View File

@ -1,10 +1,20 @@
--- ../src-base/minecraft/net/minecraft/client/renderer/block/model/IBakedModel.java
+++ ../src-work/minecraft/net/minecraft/client/renderer/block/model/IBakedModel.java
@@ -21,6 +21,7 @@
@@ -21,7 +21,16 @@
TextureAtlasSprite func_177554_e();
- ItemCameraTransforms func_177552_f();
+ @Deprecated
ItemCameraTransforms func_177552_f();
+ default ItemCameraTransforms func_177552_f() { return ItemCameraTransforms.field_178357_a; }
ItemOverrideList func_188617_f();
+
+ /*
+ * Returns the pair of the model for the given perspective, and the matrix
+ * that should be applied to the GL state before rendering it (matrix may be null).
+ */
+ default org.apache.commons.lang3.tuple.Pair<? extends IBakedModel, javax.vecmath.Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
+ return net.minecraftforge.client.ForgeHooksClient.handlePerspective(this, cameraTransformType);
+ }
}

View File

@ -12,7 +12,7 @@
+@Deprecated
+public class ItemTransformVec3f implements net.minecraftforge.common.model.IModelState
{
+ public com.google.common.base.Optional<net.minecraftforge.common.model.TRSRTransformation> apply(com.google.common.base.Optional<? extends net.minecraftforge.common.model.IModelPart> part) { return net.minecraftforge.client.ForgeHooksClient.applyTransform(this, part); }
+ public java.util.Optional<net.minecraftforge.common.model.TRSRTransformation> apply(java.util.Optional<? extends net.minecraftforge.common.model.IModelPart> part) { return net.minecraftforge.client.ForgeHooksClient.applyTransform(this, part); }
public static final ItemTransformVec3f field_178366_a = new ItemTransformVec3f(new Vector3f(), new Vector3f(), new Vector3f(1.0F, 1.0F, 1.0F));
public final Vector3f field_178364_b;
public final Vector3f field_178365_c;

View File

@ -63,6 +63,15 @@
}
}
}
@@ -228,7 +239,7 @@
try
{
inputstream = p_188636_2_.func_110527_b();
- lvt_4_1_ = ModelBlockDefinition.func_178331_a(new InputStreamReader(inputstream, StandardCharsets.UTF_8));
+ lvt_4_1_ = ModelBlockDefinition.parseFromReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8), p_188636_1_);
}
catch (Exception exception)
{
@@ -394,6 +405,7 @@
protected void func_177592_e()

View File

@ -1,11 +1,20 @@
--- ../src-base/minecraft/net/minecraft/client/renderer/block/model/ModelBlockDefinition.java
+++ ../src-work/minecraft/net/minecraft/client/renderer/block/model/ModelBlockDefinition.java
@@ -34,7 +34,7 @@
@@ -32,11 +32,16 @@
private final Map<String, VariantList> field_178332_b = Maps.<String, VariantList>newHashMap();
private Multipart field_188005_c;
+ @Deprecated
public static ModelBlockDefinition func_178331_a(Reader p_178331_0_)
{
- return (ModelBlockDefinition)JsonUtils.func_193839_a(field_178333_a, p_178331_0_, ModelBlockDefinition.class);
+ return net.minecraftforge.client.model.BlockStateLoader.load(p_178331_0_, field_178333_a);
+ return parseFromReader(p_178331_0_, null);
}
+ public static ModelBlockDefinition parseFromReader(Reader reader, net.minecraft.util.ResourceLocation location) {
+ return net.minecraftforge.client.model.BlockStateLoader.load(reader, location, field_178333_a);
+ }
+
public ModelBlockDefinition(Map<String, VariantList> p_i46572_1_, Multipart p_i46572_2_)
{
this.field_188005_c = p_i46572_2_;

View File

@ -14,7 +14,7 @@
}
}
+
+ public com.google.common.base.Optional<net.minecraftforge.common.model.TRSRTransformation> apply(com.google.common.base.Optional<? extends net.minecraftforge.common.model.IModelPart> part) { return net.minecraftforge.client.ForgeHooksClient.applyTransform(getMatrix(), part); }
+ public java.util.Optional<net.minecraftforge.common.model.TRSRTransformation> apply(java.util.Optional<? extends net.minecraftforge.common.model.IModelPart> part) { return net.minecraftforge.client.ForgeHooksClient.applyTransform(getMatrix(), part); }
+ public javax.vecmath.Matrix4f getMatrix() { return net.minecraftforge.client.ForgeHooksClient.getMatrix(this); }
+ public EnumFacing rotate(EnumFacing facing) { return func_177523_a(facing); }
+ public int rotate(EnumFacing facing, int vertexIndex) { return func_177520_a(facing, vertexIndex); }

View File

@ -34,6 +34,6 @@
+
+ public net.minecraftforge.client.model.IModel process(net.minecraftforge.client.model.IModel base)
+ {
+ return net.minecraftforge.client.model.ModelProcessingHelper.uvlock(base, func_188049_c());
+ return base.uvlock(func_188049_c());
+ }
}

View File

@ -103,7 +103,6 @@ import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.ScreenshotEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.client.model.IPerspectiveAwareModel;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.animation.Animation;
import net.minecraftforge.common.ForgeModContainer;
@ -120,7 +119,7 @@ import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.BufferUtils;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.Maps;
public class ForgeHooksClient
@ -399,32 +398,21 @@ public class ForgeHooksClient
flipX.m00 = -1;
}
@SuppressWarnings("deprecation")
public static IBakedModel handleCameraTransforms(IBakedModel model, ItemCameraTransforms.TransformType cameraTransformType, boolean leftHandHackery)
{
if(model instanceof IPerspectiveAwareModel)
{
Pair<? extends IBakedModel, Matrix4f> pair = ((IPerspectiveAwareModel)model).handlePerspective(cameraTransformType);
Pair<? extends IBakedModel, Matrix4f> pair = model.handlePerspective(cameraTransformType);
if(pair.getRight() != null)
{
Matrix4f matrix = new Matrix4f(pair.getRight());
if(leftHandHackery)
{
matrix.mul(flipX, matrix);
matrix.mul(matrix, flipX);
}
multiplyCurrentGlMatrix(matrix);
}
return pair.getLeft();
}
else
if (pair.getRight() != null)
{
//if(leftHandHackery) GlStateManager.scale(-1, 1, 1);
ItemCameraTransforms.applyTransformSide(model.getItemCameraTransforms().getTransform(cameraTransformType), leftHandHackery);
//if(leftHandHackery) GlStateManager.scale(-1, 1, 1);
Matrix4f matrix = new Matrix4f(pair.getRight());
if (leftHandHackery)
{
matrix.mul(flipX, matrix);
matrix.mul(matrix, flipX);
}
multiplyCurrentGlMatrix(matrix);
}
return model;
return pair.getLeft();
}
private static final FloatBuffer matrixBuf = BufferUtils.createFloatBuffer(16);
@ -608,13 +596,13 @@ public class ForgeHooksClient
@SuppressWarnings("deprecation")
public static Optional<TRSRTransformation> applyTransform(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform, Optional<? extends IModelPart> part)
{
if(part.isPresent()) return Optional.absent();
if(part.isPresent()) return Optional.empty();
return Optional.of(TRSRTransformation.blockCenterToCorner(new TRSRTransformation(transform)));
}
public static Optional<TRSRTransformation> applyTransform(Matrix4f matrix, Optional<? extends IModelPart> part)
{
if(part.isPresent()) return Optional.absent();
if(part.isPresent()) return Optional.empty();
return Optional.of(new TRSRTransformation(matrix));
}
@ -718,4 +706,12 @@ public class ForgeHooksClient
return event;
}
@SuppressWarnings("deprecation")
public static Pair<? extends IBakedModel,Matrix4f> handlePerspective(IBakedModel model, ItemCameraTransforms.TransformType type)
{
TRSRTransformation tr = new TRSRTransformation(model.getItemCameraTransforms().getTransform(type));
Matrix4f mat = null;
if(!tr.equals(TRSRTransformation.identity())) mat = tr.getMatrix();
return Pair.of(model, mat);
}
}

View File

@ -19,8 +19,6 @@
package net.minecraftforge.client.model;
import java.util.List;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumType;

View File

@ -36,6 +36,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.Pair;
@ -47,6 +48,8 @@ import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javax.annotation.Nullable;
public class BlockStateLoader
{
private static final Gson GSON = (new GsonBuilder())
@ -62,11 +65,12 @@ public class BlockStateLoader
* Note: This method is NOT thread safe
*
* @param reader json read
* @param location blockstate location
* @param vanillaGSON ModelBlockDefinition's GSON reader.
*
* @return Model definition including variants for all known combinations.
*/
public static ModelBlockDefinition load(Reader reader, final Gson vanillaGSON)
public static ModelBlockDefinition load(Reader reader, ResourceLocation location, final Gson vanillaGSON)
{
try
{
@ -86,15 +90,15 @@ public class BlockStateLoader
List<Variant> mcVars = Lists.newArrayList();
for (ForgeBlockStateV1.Variant var : entry.getValue())
{
boolean uvLock = var.getUvLock().or(false);
boolean smooth = var.getSmooth().or(true);
boolean gui3d = var.getGui3d().or(true);
int weight = var.getWeight().or(1);
boolean uvLock = var.getUvLock().orElse(false);
boolean smooth = var.getSmooth().orElse(true);
boolean gui3d = var.getGui3d().orElse(true);
int weight = var.getWeight().orElse(1);
if (var.getModel() != null && var.getSubmodels().size() == 0 && var.getTextures().size() == 0 && var.getCustomData().size() == 0 && var.getState().orNull() instanceof ModelRotation)
if (var.getModel() != null && var.getSubmodels().size() == 0 && var.getTextures().size() == 0 && var.getCustomData().size() == 0 && var.getState().orElse(null) instanceof ModelRotation)
mcVars.add(new Variant(var.getModel(), (ModelRotation)var.getState().get(), uvLock, weight));
else
mcVars.add(new ForgeVariant(var.getModel(), var.getState().or(TRSRTransformation.identity()), uvLock, smooth, gui3d, weight, var.getTextures(), var.getOnlyPartsVariant(), var.getCustomData()));
mcVars.add(new ForgeVariant(location, var.getModel(), var.getState().orElse(TRSRTransformation.identity()), uvLock, smooth, gui3d, weight, var.getTextures(), var.getOnlyPartsVariant(), var.getCustomData()));
}
variants.put(entry.getKey(), new VariantList(mcVars));
}
@ -125,10 +129,11 @@ public class BlockStateLoader
private final boolean smooth;
private final boolean gui3d;
private final ImmutableMap<String, String> textures;
@Nullable
private final ResourceLocation model;
private final ImmutableMap<String, String> customData;
public SubModel(IModelState state, boolean uvLock, boolean smooth, boolean gui3d, ImmutableMap<String, String> textures, ResourceLocation model, ImmutableMap<String, String> customData)
public SubModel(IModelState state, boolean uvLock, boolean smooth, boolean gui3d, ImmutableMap<String, String> textures, @Nullable ResourceLocation model, ImmutableMap<String, String> customData)
{
this.state = state;
this.uvLock = uvLock;
@ -142,12 +147,14 @@ public class BlockStateLoader
public IModelState getState() { return state; }
public boolean isUVLock() { return uvLock; }
public ImmutableMap<String, String> getTextures() { return textures; }
@Nullable
public ResourceLocation getModelLocation() { return model; }
public ImmutableMap<String, String> getCustomData() { return customData; }
}
private static class ForgeVariant extends Variant implements ISmartVariant
{
private final ResourceLocation blockstateLocation;
private final ImmutableMap<String, String> textures;
private final ImmutableMap<String, SubModel> parts;
private final ImmutableMap<String, String> customData;
@ -155,9 +162,10 @@ public class BlockStateLoader
private final boolean gui3d;
private final IModelState state;
public ForgeVariant(ResourceLocation model, IModelState state, boolean uvLock, boolean smooth, boolean gui3d, int weight, ImmutableMap<String, String> textures, ImmutableMap<String, SubModel> parts, ImmutableMap<String, String> customData)
public ForgeVariant(ResourceLocation blockstateLocation, @Nullable ResourceLocation model, IModelState state, boolean uvLock, boolean smooth, boolean gui3d, int weight, ImmutableMap<String, String> textures, ImmutableMap<String, SubModel> parts, ImmutableMap<String, String> customData)
{
super(model == null ? new ResourceLocation("builtin/missing") : model, state instanceof ModelRotation ? (ModelRotation)state : ModelRotation.X0_Y0, uvLock, weight);
this.blockstateLocation = blockstateLocation;
this.textures = textures;
this.parts = parts;
this.customData = customData;
@ -168,11 +176,11 @@ public class BlockStateLoader
private IModel runModelHooks(IModel base, boolean smooth, boolean gui3d, boolean uvlock, ImmutableMap<String, String> textureMap, ImmutableMap<String, String> customData)
{
base = ModelProcessingHelper.customData(base, customData);
base = ModelProcessingHelper.retexture(base, textureMap);
base = ModelProcessingHelper.smoothLighting(base, smooth);
base = ModelProcessingHelper.gui3d(base, gui3d);
base = ModelProcessingHelper.uvlock(base, uvlock);
base = base.process(customData);
base = base.retexture(textureMap);
base = base.smoothLighting(smooth);
base = base.gui3d(gui3d);
base = base.uvlock(uvlock);
return base;
}
@ -203,9 +211,19 @@ public class BlockStateLoader
{
SubModel part = entry.getValue();
IModel model = ModelLoaderRegistry.getModelOrLogError(part.getModelLocation(), "Unable to load block sub-model: \'" + part.getModelLocation());
final ResourceLocation modelLocation = part.getModelLocation();
final IModel model;
if (modelLocation == null)
{
FMLLog.getLogger().error("model not found for variant " + entry.getKey() + "for blockstate " + blockstateLocation);
model = ModelLoaderRegistry.getMissingModel(blockstateLocation, new Throwable());
}
else
{
model = ModelLoaderRegistry.getModelOrLogError(modelLocation, "Unable to load block sub-model: \'" + modelLocation);
}
models.put(entry.getKey(), Pair.<IModel, IModelState>of(runModelHooks(model, part.smooth, part.gui3d, part.uvLock, part.getTextures(), part.getCustomData()), part.getState()));
models.put(entry.getKey(), Pair.of(runModelHooks(model, part.smooth, part.gui3d, part.uvLock, part.getTextures(), part.getCustomData()), part.getState()));
}
return new MultiModel(getModelLocation(), hasBase ? base : null, baseTr, models.build());

View File

@ -1,7 +1,7 @@
package net.minecraftforge.client.model;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import java.util.function.Function;
import java.util.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
@ -70,12 +70,6 @@ final class FancyMissingModel implements IModel
this.message = message;
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return ImmutableList.of();
}
@Override
public Collection<ResourceLocation> getTextures()
{
@ -91,13 +85,7 @@ final class FancyMissingModel implements IModel
return new BakedModel(bigMissing, smallMissing, fontCache.getUnchecked(format), message, bakedTextureGetter.apply(font2));
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
}
private static final class BakedModel implements IPerspectiveAwareModel
private static final class BakedModel implements IBakedModel
{
private final SimpleModelFontRenderer fontRenderer;
private final String message;
@ -168,9 +156,6 @@ final class FancyMissingModel implements IModel
@Override
public TextureAtlasSprite getParticleTexture() { return fontTexture; }
@Override
public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
@Override
public ItemOverrideList getOverrides() { return ItemOverrideList.NONE; }

View File

@ -46,7 +46,7 @@ import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fml.common.FMLLog;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
@ -93,7 +93,7 @@ public class ForgeBlockStateV1 extends Marker
for (JsonElement a : e.getValue().getAsJsonArray())
{
Variant.Deserializer.INSTANCE.simpleSubmodelKey = e.getKey();
specified.put(e.getKey(), (ForgeBlockStateV1.Variant)context.deserialize(a, ForgeBlockStateV1.Variant.class));
specified.put(e.getKey(), context.deserialize(a, Variant.class));
}
}
else
@ -107,14 +107,14 @@ public class ForgeBlockStateV1 extends Marker
for (Entry<String, JsonElement> se : e.getValue().getAsJsonObject().entrySet())
{
Variant.Deserializer.INSTANCE.simpleSubmodelKey = e.getKey() + "=" + se.getKey();
subs.put(se.getKey(), (ForgeBlockStateV1.Variant)context.deserialize(se.getValue(), ForgeBlockStateV1.Variant.class));
subs.put(se.getKey(), context.deserialize(se.getValue(), Variant.class));
}
}
else
{
// fully-defined variant
Variant.Deserializer.INSTANCE.simpleSubmodelKey = e.getKey();
specified.put(e.getKey(), (ForgeBlockStateV1.Variant)context.deserialize(e.getValue(), ForgeBlockStateV1.Variant.class));
specified.put(e.getKey(), context.deserialize(e.getValue(), Variant.class));
}
}
}
@ -243,7 +243,7 @@ public class ForgeBlockStateV1 extends Marker
{
List<String> sorted = Lists.newArrayList(base.keySet());
Collections.sort(sorted); // Sort to get consistent results.
return getPermutations(sorted, base, 0, "", HashMultimap.<String, ForgeBlockStateV1.Variant>create(), null);
return getPermutations(sorted, base, 0, "", HashMultimap.create(), null);
}
private List<ForgeBlockStateV1.Variant> getSubmodelPermutations(ForgeBlockStateV1.Variant baseVar, List<String> sorted, Map<String, List<ForgeBlockStateV1.Variant>> map, int depth, Map<String, ForgeBlockStateV1.Variant> parts, List<ForgeBlockStateV1.Variant> ret)
@ -284,7 +284,7 @@ public class ForgeBlockStateV1 extends Marker
{
List<String> sorted = Lists.newArrayList(variants.keySet());
Collections.sort(sorted); // Sort to get consistent results.
return getSubmodelPermutations(baseVar, sorted, variants, 0, new HashMap<String, ForgeBlockStateV1.Variant>(), new ArrayList<ForgeBlockStateV1.Variant>());
return getSubmodelPermutations(baseVar, sorted, variants, 0, new HashMap<>(), new ArrayList<>());
}
}
@ -292,13 +292,14 @@ public class ForgeBlockStateV1 extends Marker
{
public static final Object SET_VALUE = new Object();
@Nullable
private ResourceLocation model = null;
private boolean modelSet = false;
private Optional<IModelState> state = Optional.absent();
private Optional<Boolean> uvLock = Optional.absent();
private Optional<Boolean> smooth = Optional.absent();
private Optional<Boolean> gui3d = Optional.absent();
private Optional<Integer> weight = Optional.absent();
private Optional<IModelState> state = Optional.empty();
private Optional<Boolean> uvLock = Optional.empty();
private Optional<Boolean> smooth = Optional.empty();
private Optional<Boolean> gui3d = Optional.empty();
private Optional<Integer> weight = Optional.empty();
private Map<String, String> textures = Maps.newHashMap();
private Map<String, List<ForgeBlockStateV1.Variant>> submodels = Maps.newHashMap();
private Map<String, Object> simpleSubmodels = Maps.newHashMap(); // Makeshift Set to allow us to "remove" (replace value with null) singleParts when needed.
@ -393,7 +394,7 @@ public class ForgeBlockStateV1 extends Marker
protected SubModel asGenericSubModel()
{
return new SubModel(state.or(TRSRTransformation.identity()), uvLock.or(false), smooth.or(true), gui3d.or(true), getTextures(), model, getCustomData());
return new SubModel(state.orElse(TRSRTransformation.identity()), uvLock.orElse(false), smooth.orElse(true), gui3d.orElse(true), getTextures(), model, getCustomData());
}
/**
@ -503,7 +504,7 @@ public class ForgeBlockStateV1 extends Marker
{ // Load rotation values.
int x = JsonUtils.getInt(json, "x", 0);
int y = JsonUtils.getInt(json, "y", 0);
ret.state = Optional.<IModelState>of(new TRSRTransformation(ModelRotation.getModelRotation(x, y)));
ret.state = Optional.of(new TRSRTransformation(ModelRotation.getModelRotation(x, y)));
if (!ret.state.isPresent())
throw new JsonParseException("Invalid BlockModelRotation x: " + x + " y: " + y);
}
@ -517,7 +518,7 @@ public class ForgeBlockStateV1 extends Marker
// TODO: vanilla now includes from parent, deprecate?
if (transform.equals("identity"))
{
ret.state = Optional.<IModelState>of(TRSRTransformation.identity());
ret.state = Optional.of(TRSRTransformation.identity());
}
// block/block
else if (transform.equals("forge:default-block"))
@ -531,7 +532,7 @@ public class ForgeBlockStateV1 extends Marker
builder.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(thirdperson));
builder.put(TransformType.FIRST_PERSON_RIGHT_HAND, get(0, 0, 0, 0, 45, 0, 0.4f));
builder.put(TransformType.FIRST_PERSON_LEFT_HAND, get(0, 0, 0, 0, 225, 0, 0.4f));
ret.state = Optional.<IModelState>of(new SimpleModelState(builder.build()));
ret.state = Optional.of(new SimpleModelState(builder.build()));
}
// item/generated
else if (transform.equals("forge:default-item"))
@ -546,12 +547,12 @@ public class ForgeBlockStateV1 extends Marker
builder.put(TransformType.FIRST_PERSON_RIGHT_HAND, firstperson);
builder.put(TransformType.FIRST_PERSON_LEFT_HAND, leftify(firstperson));
builder.put(TransformType.FIXED, get(0, 0, 0, 0, 180, 0, 1));
ret.state = Optional.<IModelState>of(new SimpleModelState(builder.build()));
ret.state = Optional.of(new SimpleModelState(builder.build()));
}
// item/handheld
else if (transform.equals("forge:default-tool"))
{
ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(
ret.state = Optional.of(new SimpleModelState(ImmutableMap.of(
TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 4, 0.5f, 0, -90, 55, 0.85f),
TransformType.THIRD_PERSON_LEFT_HAND, get(0, 4, 0.5f, 0, 90, -55, 0.85f),
TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f),
@ -567,7 +568,7 @@ public class ForgeBlockStateV1 extends Marker
try
{
TRSRTransformation base = context.deserialize(json.get("transform"), TRSRTransformation.class);
ret.state = Optional.<IModelState>of(TRSRTransformation.blockCenterToCorner(base));
ret.state = Optional.of(TRSRTransformation.blockCenterToCorner(base));
}
catch (JsonParseException e)
{
@ -719,7 +720,7 @@ public class ForgeBlockStateV1 extends Marker
{ // Multiple variants of the submodel.
submodelVariants = Lists.newArrayList();
for (JsonElement e : varEl.getAsJsonArray())
submodelVariants.add((ForgeBlockStateV1.Variant)context.deserialize(e, ForgeBlockStateV1.Variant.class));
submodelVariants.add(context.deserialize(e, Variant.class));
}
else if (varEl.isJsonNull())
{
@ -727,7 +728,7 @@ public class ForgeBlockStateV1 extends Marker
}
else
{
submodelVariants = Collections.singletonList((ForgeBlockStateV1.Variant)context.deserialize(varEl, ForgeBlockStateV1.Variant.class));
submodelVariants = Collections.singletonList(context.deserialize(varEl, Variant.class));
}
if (submodelVariants != null) // Throw an error if there are submodels inside a submodel.
@ -758,6 +759,7 @@ public class ForgeBlockStateV1 extends Marker
}
}
@Nullable
public ResourceLocation getModel() { return model; }
public boolean isModelSet() { return modelSet; }
public Optional<IModelState> getState() { return state; }

View File

@ -21,13 +21,18 @@ package net.minecraftforge.client.model;
import java.util.Collection;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.model.IModelState;
import com.google.common.base.Function;
import java.util.function.Function;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.common.model.animation.IClip;
/*
* Interface for models that can be baked
@ -40,13 +45,17 @@ public interface IModel
* Assume that returned collection is immutable.
* See ModelLoaderRegistry.getModel for dependency loading.
*/
Collection<ResourceLocation> getDependencies();
default Collection<ResourceLocation> getDependencies() {
return ImmutableList.of();
}
/*
* Returns all texture locations that this model depends on.
* Assume that returned collection is immutable.
*/
Collection<ResourceLocation> getTextures();
default Collection<ResourceLocation> getTextures() {
return ImmutableList.of();
}
/*
* All model texture coordinates should be resolved at this method.
@ -63,5 +72,53 @@ public interface IModel
* Default state this model will be baked with.
* See IModelState.
*/
IModelState getDefaultState();
default IModelState getDefaultState() {
return TRSRTransformation.identity();
}
default Optional<? extends IClip> getClip(String name) {
return Optional.empty();
}
/**
* Allows the model to process custom data from the variant definition.
* If unknown data is encountered it should be skipped.
* @return a new model, with data applied.
*/
default IModel process(ImmutableMap<String, String> customData) {
return this;
}
default IModel smoothLighting(boolean value) {
return this;
}
default IModel gui3d(boolean value) {
return this;
}
default IModel uvlock(boolean value) {
return this;
}
/**
* Applies new textures to the model.
* The returned model should be independent of the accessed one,
* as a model should be able to be retextured multiple times producing
* a separate model each time.
*
* The input map MAY map to an empty string "" which should be used
* to indicate the texture was removed. Handling of that is up to
* the model itself. Such as using default, missing texture, or
* removing vertices.
*
* The input should be considered a DIFF of the old textures, not a
* replacement as it may not contain everything.
*
* @param textures New
* @return Model with textures applied.
*/
default IModel retexture(ImmutableMap<String, String> textures) {
return this;
}
}

View File

@ -1,32 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.client.model;
import com.google.common.collect.ImmutableMap;
public interface IModelCustomData extends IModel
{
/**
* Allows the model to process custom data from the variant definition.
* If unknown data is encountered it should be skipped.
* @return a new model, with data applied.
*/
IModel process(ImmutableMap<String, String> customData);
}

View File

@ -1,29 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.client.model;
/**
* Implement this if the model can process "smooth_lighting" or "gui3d" attributes from the json.
*/
public interface IModelSimpleProperties extends IModel
{
IModel smoothLighting(boolean value);
IModel gui3d(boolean value);
}

View File

@ -1,25 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.client.model;
public interface IModelUVLock extends IModel
{
public IModel uvlock(boolean value);
}

View File

@ -1,128 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.client.model;
import java.util.List;
import javax.vecmath.Matrix4f;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
/*
* Model that changes based on the rendering perspective
* (first-person, GUI, e.t.c - see TransformType)
*/
public interface IPerspectiveAwareModel extends IBakedModel
{
/*
* Returns the pair of the model for the given perspective, and the matrix
* that should be applied to the GL state before rendering it (matrix may be null).
*/
Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType);
public static class MapWrapper implements IPerspectiveAwareModel
{
private final IBakedModel parent;
private final ImmutableMap<TransformType, TRSRTransformation> transforms;
public MapWrapper(IBakedModel parent, ImmutableMap<TransformType, TRSRTransformation> transforms)
{
this.parent = parent;
this.transforms = transforms;
}
public MapWrapper(IBakedModel parent, IModelState state)
{
this(parent, getTransforms(state));
}
public static ImmutableMap<TransformType, TRSRTransformation> getTransforms(IModelState state)
{
ImmutableMap.Builder<TransformType, TRSRTransformation> builder = ImmutableMap.builder();
for(TransformType type : TransformType.values())
{
Optional<TRSRTransformation> tr = state.apply(Optional.of(type));
if(tr.isPresent())
{
builder.put(type, tr.get());
}
}
return builder.build();
}
@SuppressWarnings("deprecation")
public static ImmutableMap<TransformType, TRSRTransformation> getTransforms(ItemCameraTransforms transforms)
{
ImmutableMap.Builder<TransformType, TRSRTransformation> builder = ImmutableMap.builder();
for(TransformType type : TransformType.values())
{
builder.put(type, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(transforms.getTransform(type))));
}
return builder.build();
}
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, ImmutableMap<TransformType, TRSRTransformation> transforms, TransformType cameraTransformType)
{
TRSRTransformation tr = transforms.get(cameraTransformType);
Matrix4f mat = null;
if(tr != null && !tr.equals(TRSRTransformation.identity())) mat = TRSRTransformation.blockCornerToCenter(tr).getMatrix();
return Pair.of(model, mat);
}
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, IModelState state, TransformType cameraTransformType)
{
TRSRTransformation tr = state.apply(Optional.of(cameraTransformType)).or(TRSRTransformation.identity());
if(tr != TRSRTransformation.identity())
{
return Pair.of(model, TRSRTransformation.blockCornerToCenter(tr).getMatrix());
}
return Pair.of(model, null);
}
@Override public boolean isAmbientOcclusion() { return parent.isAmbientOcclusion(); }
@Override public boolean isGui3d() { return parent.isGui3d(); }
@Override public boolean isBuiltInRenderer() { return parent.isBuiltInRenderer(); }
@Override public TextureAtlasSprite getParticleTexture() { return parent.getParticleTexture(); }
@SuppressWarnings("deprecation")
@Override public ItemCameraTransforms getItemCameraTransforms() { return parent.getItemCameraTransforms(); }
@Override public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) { return parent.getQuads(state, side, rand); }
@Override public ItemOverrideList getOverrides() { return parent.getOverrides(); }
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
{
return handlePerspective(this, transforms, cameraTransformType);
}
}
}

View File

@ -1,44 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.client.model;
import com.google.common.collect.ImmutableMap;
public interface IRetexturableModel extends IModel
{
/**
* Applies new textures to the model.
* The returned model should be independent of the accessed one,
* as a model should be able to be retextured multiple times producing
* a separate model each time.
*
* The input map MAY map to an empty string "" which should be used
* to indicate the texture was removed. Handling of that is up to
* the model itself. Such as using default, missing texture, or
* removing vertices.
*
* The input should be considered a DIFF of the old textures, not a
* replacement as it may not contain everything.
*
* @param textures New
* @return Model with textures applied.
*/
IModel retexture(ImmutableMap<String, String> textures);
}

View File

@ -34,7 +34,6 @@ import org.apache.commons.lang3.tuple.Pair;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ModelBlock;
@ -44,18 +43,17 @@ import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import java.util.function.Function;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
public final class ItemLayerModel implements IRetexturableModel
public final class ItemLayerModel implements IModel
{
public static final ItemLayerModel INSTANCE = new ItemLayerModel(ImmutableList.<ResourceLocation>of());
public static final ItemLayerModel INSTANCE = new ItemLayerModel(ImmutableList.of());
private final ImmutableList<ResourceLocation> textures;
private final ItemOverrideList overrides;
@ -86,25 +84,11 @@ public final class ItemLayerModel implements IRetexturableModel
return builder.build();
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return ImmutableList.of();
}
@Override
public Collection<ResourceLocation> getTextures()
{
return textures;
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
}
@Override
public ItemLayerModel retexture(ImmutableMap<String, String> textures)
{
ImmutableList.Builder<ResourceLocation> builder = ImmutableList.builder();
@ -126,18 +110,18 @@ public final class ItemLayerModel implements IRetexturableModel
public IBakedModel bake(IModelState state, final VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
{
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
Optional<TRSRTransformation> transform = state.apply(Optional.<IModelPart>absent());
Optional<TRSRTransformation> transform = state.apply(Optional.empty());
for(int i = 0; i < textures.size(); i++)
{
TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
builder.addAll(getQuadsForSprite(i, sprite, format, transform));
}
TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? new ResourceLocation("missingno") : textures.get(0));
ImmutableMap<TransformType, TRSRTransformation> map = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
ImmutableMap<TransformType, TRSRTransformation> map = PerspectiveMapWrapper.getTransforms(state);
return new BakedItemModel(builder.build(), particle, map, overrides, null);
}
private static final class BakedItemModel implements IPerspectiveAwareModel
private static final class BakedItemModel implements IBakedModel
{
private final ImmutableList<BakedQuad> quads;
private final TextureAtlasSprite particle;
@ -172,14 +156,12 @@ public final class ItemLayerModel implements IRetexturableModel
}
}
@Override public boolean isAmbientOcclusion() { return true; }
@Override public boolean isGui3d() { return false; }
@Override public boolean isBuiltInRenderer() { return false; }
@Override public TextureAtlasSprite getParticleTexture() { return particle; }
@Override public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
@Override public ItemOverrideList getOverrides() { return overrides; }
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
public boolean isAmbientOcclusion() { return true; }
public boolean isGui3d() { return false; }
public boolean isBuiltInRenderer() { return false; }
public TextureAtlasSprite getParticleTexture() { return particle; }
public ItemOverrideList getOverrides() { return overrides; }
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
if(side == null) return quads;
return ImmutableList.of();
@ -188,7 +170,7 @@ public final class ItemLayerModel implements IRetexturableModel
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
{
Pair<? extends IBakedModel, Matrix4f> pair = IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, type);
Pair<? extends IBakedModel, Matrix4f> pair = PerspectiveMapWrapper.handlePerspective(this, transforms, type);
if(type == TransformType.GUI && !isCulled && pair.getRight() == null)
{
return Pair.of(otherModel, null);

View File

@ -26,7 +26,7 @@ import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.ImmutableMap;
/*
@ -58,7 +58,7 @@ public class MapModelState implements IModelState
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
{
if(!part.isPresent() || !map.containsKey(part.get())) return def.apply(part);
return map.get(part.get()).apply(Optional.<IModelPart>absent());
return map.get(part.get()).apply(Optional.empty());
}
public IModelState getState(Object obj)

View File

@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
@ -56,14 +55,14 @@ import net.minecraftforge.fluids.FluidUtil;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import java.util.function.Function;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
public final class ModelDynBucket implements IModel, IModelCustomData, IRetexturableModel
public final class ModelDynBucket implements IModel
{
public static final ModelResourceLocation LOCATION = new ModelResourceLocation(new ResourceLocation(ForgeVersion.MOD_ID, "dynbucket"), "inventory");
@ -99,12 +98,6 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
this.flipGas = flipGas;
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return ImmutableList.of();
}
@Override
public Collection<ResourceLocation> getTextures()
{
@ -124,7 +117,7 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
{
ImmutableMap<TransformType, TRSRTransformation> transformMap = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
ImmutableMap<TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state);
// if the fluid is a gas wi manipulate the initial state to be rotated 180° to turn it upside down
if (flipGas && fluid != null && fluid.isGaseous())
@ -132,7 +125,7 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
state = new ModelStateComposition(state, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(null, new Quat4f(0, 0, 1, 0), null, null)));
}
TRSRTransformation transform = state.apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity());
TRSRTransformation transform = state.apply(Optional.empty()).orElse(TRSRTransformation.identity());
TextureAtlasSprite fluidSprite = null;
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
@ -162,13 +155,7 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
}
return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.newHashMap());
}
/**
@ -255,12 +242,11 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
public static final BakedDynBucketOverrideHandler INSTANCE = new BakedDynBucketOverrideHandler();
private BakedDynBucketOverrideHandler()
{
super(ImmutableList.<ItemOverride>of());
super(ImmutableList.of());
}
@Override
@Nonnull
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
FluidStack fluidStack = FluidUtil.getFluidContained(stack);
@ -280,14 +266,7 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
{
IModel parent = model.parent.process(ImmutableMap.of("fluid", name));
Function<ResourceLocation, TextureAtlasSprite> textureGetter;
textureGetter = new Function<ResourceLocation, TextureAtlasSprite>()
{
@Override
public TextureAtlasSprite apply(ResourceLocation location)
{
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
}
};
textureGetter = location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter);
model.cache.put(name, bakedModel);
@ -299,7 +278,7 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
}
// the dynamic bucket is based on the empty bucket
private static final class BakedDynBucket implements IPerspectiveAwareModel
private static final class BakedDynBucket implements IBakedModel
{
private final ModelDynBucket parent;
@ -331,20 +310,19 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
{
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, cameraTransformType);
return PerspectiveMapWrapper.handlePerspective(this, transforms, cameraTransformType);
}
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
if(side == null) return quads;
return ImmutableList.of();
}
@Override public boolean isAmbientOcclusion() { return true; }
@Override public boolean isGui3d() { return false; }
@Override public boolean isBuiltInRenderer() { return false; }
@Override public TextureAtlasSprite getParticleTexture() { return particle; }
@Override public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
public boolean isAmbientOcclusion() { return true; }
public boolean isGui3d() { return false; }
public boolean isBuiltInRenderer() { return false; }
public TextureAtlasSprite getParticleTexture() { return particle; }
}
}

View File

@ -20,17 +20,16 @@
package net.minecraftforge.client.model;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector4f;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ModelRotation;
@ -42,7 +41,6 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.common.property.IExtendedBlockState;
@ -53,8 +51,8 @@ import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import java.util.function.Function;
import java.util.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
@ -65,7 +63,7 @@ import com.google.common.collect.Maps;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
public final class ModelFluid implements IModelCustomData
public final class ModelFluid implements IModel
{
public static final ModelFluid WATER = new ModelFluid(FluidRegistry.WATER);
public static final ModelFluid LAVA = new ModelFluid(FluidRegistry.LAVA);
@ -76,13 +74,6 @@ public final class ModelFluid implements IModelCustomData
this.fluid = fluid;
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return Collections.emptySet();
}
@Override
public Collection<ResourceLocation> getTextures()
{
return ImmutableSet.of(fluid.getStill(), fluid.getFlowing());
@ -91,8 +82,8 @@ public final class ModelFluid implements IModelCustomData
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
{
ImmutableMap<TransformType, TRSRTransformation> map = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
return new BakedFluid(state.apply(Optional.<IModelPart>absent()), map, format, fluid.getColor(), bakedTextureGetter.apply(fluid.getStill()), bakedTextureGetter.apply(fluid.getFlowing()), fluid.isGaseous(), Optional.<IExtendedBlockState>absent());
ImmutableMap<TransformType, TRSRTransformation> map = PerspectiveMapWrapper.getTransforms(state);
return new BakedFluid(state.apply(Optional.empty()), map, format, fluid.getColor(), bakedTextureGetter.apply(fluid.getStill()), bakedTextureGetter.apply(fluid.getFlowing()), fluid.isGaseous(), Optional.empty());
}
@Override
@ -124,7 +115,7 @@ public final class ModelFluid implements IModelCustomData
}
}
private static final class BakedFluid implements IPerspectiveAwareModel
private static final class BakedFluid implements IBakedModel
{
private static final int x[] = { 0, 0, 1, 1 };
private static final int z[] = { 0, 1, 1, 0 };
@ -202,7 +193,7 @@ public final class ModelFluid implements IModelCustomData
faceQuads = Maps.newEnumMap(EnumFacing.class);
for(EnumFacing side : EnumFacing.values())
{
faceQuads.put(side, ImmutableList.<BakedQuad>of());
faceQuads.put(side, ImmutableList.of());
}
if(statePresent)
@ -271,7 +262,7 @@ public final class ModelFluid implements IModelCustomData
still.getInterpolatedU(z[i] * 16),
still.getInterpolatedV(x[i] * 16));
}
faceQuads.put(side, ImmutableList.<BakedQuad>of(builder.build()));
faceQuads.put(side, ImmutableList.of(builder.build()));
// sides
@ -315,7 +306,7 @@ public final class ModelFluid implements IModelCustomData
still.getInterpolatedU(z[i] * 16),
still.getInterpolatedV(x[i] * 16));
}
faceQuads.put(EnumFacing.SOUTH, ImmutableList.<BakedQuad>of(builder.build()));
faceQuads.put(EnumFacing.SOUTH, ImmutableList.of(builder.build()));
}
}
@ -382,13 +373,7 @@ public final class ModelFluid implements IModelCustomData
}
@Override
public ItemCameraTransforms getItemCameraTransforms()
{
return ItemCameraTransforms.DEFAULT;
}
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
BakedFluid model = this;
if(state instanceof IExtendedBlockState)
@ -419,7 +404,7 @@ public final class ModelFluid implements IModelCustomData
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
{
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, type);
return PerspectiveMapWrapper.handlePerspective(this, transforms, type);
}
}

View File

@ -54,7 +54,6 @@ import net.minecraft.client.renderer.block.model.ModelBlock;
import net.minecraft.client.renderer.block.model.ModelBlockDefinition;
import net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.model.ModelRotation;
import net.minecraft.client.renderer.block.model.MultipartBakedModel;
import net.minecraft.client.renderer.block.model.SimpleBakedModel;
import net.minecraft.client.renderer.block.model.Variant;
@ -78,7 +77,6 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import net.minecraftforge.client.model.animation.AnimationItemOverrideList;
import net.minecraftforge.client.model.animation.IAnimatedModel;
import net.minecraftforge.client.model.animation.ModelBlockAnimation;
import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.common.ForgeVersion;
@ -104,10 +102,10 @@ import net.minecraftforge.registries.IRegistryDelegate;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
@ -124,6 +122,7 @@ import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class ModelLoader extends ModelBakery
{
@ -166,13 +165,7 @@ public final class ModelLoader extends ModelBakery
textures.remove(TextureMap.LOCATION_MISSING_TEXTURE);
textures.addAll(LOCATIONS_BUILTIN_TEXTURES);
textureMap.loadSprites(resourceManager, map ->
{
for (ResourceLocation t : textures)
{
map.registerSprite(t);
}
});
textureMap.loadSprites(resourceManager, map -> textures.forEach(map::registerSprite));
IBakedModel missingBaked = missingModel.bake(missingModel.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE);
Map<IModel, IBakedModel> bakedModels = Maps.newHashMap();
@ -242,7 +235,7 @@ public final class ModelLoader extends ModelBakery
}
@Override
protected void registerVariant(ModelBlockDefinition definition, ModelResourceLocation location)
protected void registerVariant(@Nullable ModelBlockDefinition definition, ModelResourceLocation location)
{
IModel model;
try
@ -282,7 +275,7 @@ public final class ModelLoader extends ModelBakery
{
storeException(location, new Exception("Could not load model definition for variant " + location, exception));
}
return new ModelBlockDefinition(new ArrayList<ModelBlockDefinition>());
return new ModelBlockDefinition(new ArrayList<>());
}
@Override
@ -296,22 +289,8 @@ public final class ModelLoader extends ModelBakery
registerVariantNames();
List<Item> items = Lists.newArrayList(Iterables.filter(Item.REGISTRY, new Predicate<Item>()
{
@Override
public boolean apply(Item item)
{
return item.getRegistryName() != null;
}
}));
Collections.sort(items, new Comparator<Item>()
{
@Override
public int compare(Item i1, Item i2)
{
return i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString());
}
});
List<Item> items = Lists.newArrayList(Iterables.filter(Item.REGISTRY, item -> item.getRegistryName() != null));
Collections.sort(items, (i1, i2) -> i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString()));
ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size());
for(Item item : items)
@ -442,7 +421,7 @@ public final class ModelLoader extends ModelBakery
return new ResourceLocation(model.getResourceDomain(), model.getResourcePath() + ".json");
}
private final class VanillaModelWrapper implements IRetexturableModel, IModelSimpleProperties, IModelUVLock, IAnimatedModel
private final class VanillaModelWrapper implements IModel
{
private final ResourceLocation location;
private final ModelBlock model;
@ -549,8 +528,8 @@ public final class ModelLoader extends ModelBakery
ItemCameraTransforms transforms = model.getAllTransforms();
Map<TransformType, TRSRTransformation> tMap = Maps.newHashMap();
tMap.putAll(IPerspectiveAwareModel.MapWrapper.getTransforms(transforms));
tMap.putAll(IPerspectiveAwareModel.MapWrapper.getTransforms(state));
tMap.putAll(PerspectiveMapWrapper.getTransforms(transforms));
tMap.putAll(PerspectiveMapWrapper.getTransforms(state));
IModelState perState = new SimpleModelState(ImmutableMap.copyOf(tMap));
if(hasItemModel(model))
@ -563,7 +542,7 @@ public final class ModelLoader extends ModelBakery
private IBakedModel bakeNormal(ModelBlock model, IModelState perState, final IModelState modelState, List<TRSRTransformation> newTransforms, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, boolean uvLocked)
{
final TRSRTransformation baseState = modelState.apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity());
final TRSRTransformation baseState = modelState.apply(Optional.empty()).orElse(TRSRTransformation.identity());
TextureAtlasSprite particle = bakedTextureGetter.apply(new ResourceLocation(model.resolveTextureName("particle")));
SimpleBakedModel.Builder builder = (new SimpleBakedModel.Builder(model, model.createOverrides())).setTexture(particle);
for(int i = 0; i < model.getElements().size(); i++)
@ -596,12 +575,12 @@ public final class ModelLoader extends ModelBakery
}
}
return new IPerspectiveAwareModel.MapWrapper(builder.makeBakedModel(), perState)
return new PerspectiveMapWrapper(builder.makeBakedModel(), perState)
{
private final ItemOverrideList overrides = new AnimationItemOverrideList(VanillaModelWrapper.this, modelState, format, bakedTextureGetter, super.getOverrides());
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
if(state instanceof IExtendedBlockState)
{
@ -693,15 +672,9 @@ public final class ModelLoader extends ModelBakery
{
if(animation.getClips().containsKey(name))
{
return Optional.<IClip>fromNullable(animation.getClips().get(name));
return Optional.ofNullable(animation.getClips().get(name));
}
return Optional.absent();
}
@Override
public IModelState getDefaultState()
{
return ModelRotation.X0_Y0;
return Optional.empty();
}
@Override
@ -744,9 +717,9 @@ public final class ModelLoader extends ModelBakery
private static final class WeightedRandomModel implements IModel
{
private final List<Variant> variants;
private final List<ResourceLocation> locations = new ArrayList<ResourceLocation>();
private final List<ResourceLocation> locations = new ArrayList<>();
private final Set<ResourceLocation> textures = Sets.newHashSet();
private final List<IModel> models = new ArrayList<IModel>();
private final List<IModel> models = new ArrayList<>();
private final IModelState defaultState;
public WeightedRandomModel(ResourceLocation parent, VariantList variants) throws Exception
@ -791,7 +764,7 @@ public final class ModelLoader extends ModelBakery
// FIXME: log this?
IModel missing = ModelLoaderRegistry.getMissingModel();
models.add(missing);
builder.add(Pair.<IModel, IModelState>of(missing, TRSRTransformation.identity()));
builder.add(Pair.of(missing, TRSRTransformation.identity()));
}
defaultState = new MultiModelState(builder.build());
@ -894,6 +867,7 @@ public final class ModelLoader extends ModelBakery
{
INSTANCE;
@Nullable
private ModelLoader loader;
private LoadingCache<BakedModelCacheKey, IBakedModel> modelCache = CacheBuilder.newBuilder().maximumSize(50).expireAfterWrite(100, TimeUnit.MILLISECONDS).build(new CacheLoader<BakedModelCacheKey, IBakedModel>() {
@Override
@ -908,6 +882,7 @@ public final class ModelLoader extends ModelBakery
this.loader = loader;
}
@Nullable
ModelLoader getLoader()
{
return loader;
@ -1292,18 +1267,6 @@ public final class ModelLoader extends ModelBakery
}
// FIXME: represent selectors as dependencies?
@Override
public Collection<ResourceLocation> getDependencies()
{
return ImmutableSet.of();
}
@Override
public Collection<ResourceLocation> getTextures()
{
return ImmutableSet.of();
}
// FIXME
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
@ -1318,11 +1281,5 @@ public final class ModelLoader extends ModelBakery
IBakedModel bakedModel = builder.makeMultipartModel();
return bakedModel;
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
}
}
}

View File

@ -211,11 +211,12 @@ public class ModelLoaderRegistry
public static IModel getMissingModel()
{
if(ModelLoader.VanillaLoader.INSTANCE.getLoader() == null)
final ModelLoader loader = VanillaLoader.INSTANCE.getLoader();
if(loader == null)
{
throw new IllegalStateException("Using ModelLoaderRegistry too early.");
}
return ModelLoader.VanillaLoader.INSTANCE.getLoader().getMissingModel();
return loader.getMissingModel();
}
static IModel getMissingModel(ResourceLocation location, Throwable cause)

View File

@ -1,70 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.client.model;
import com.google.common.collect.ImmutableMap;
public class ModelProcessingHelper
{
public static IModel retexture(IModel model, ImmutableMap<String, String> textures)
{
if(model instanceof IRetexturableModel)
{
model = ((IRetexturableModel)model).retexture(textures);
}
return model;
}
public static IModel customData(IModel model, ImmutableMap<String, String> customData)
{
if(model instanceof IModelCustomData)
{
model = ((IModelCustomData)model).process(customData);
}
return model;
}
public static IModel smoothLighting(IModel model, boolean smooth)
{
if(model instanceof IModelSimpleProperties)
{
model = ((IModelSimpleProperties)model).smoothLighting(smooth);
}
return model;
}
public static IModel gui3d(IModel model, boolean gui3d)
{
if(model instanceof IModelSimpleProperties)
{
model = ((IModelSimpleProperties)model).gui3d(gui3d);
}
return model;
}
public static IModel uvlock(IModel model, boolean uvlock)
{
if(model instanceof IModelUVLock)
{
model = ((IModelUVLock)model).uvlock(uvlock);
}
return model;
}
}

View File

@ -24,7 +24,7 @@ import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import com.google.common.base.Optional;
import java.util.Optional;
public class ModelStateComposition implements IModelState
{
@ -45,7 +45,10 @@ public class ModelStateComposition implements IModelState
{
return Optional.of(f.get().compose(s.get()));
}
return f.or(s);
if (f.isPresent()) {
return f;
}
return s;
}
@Override

View File

@ -22,13 +22,12 @@ package net.minecraftforge.client.model;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
@ -46,16 +45,16 @@ import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import java.util.function.Function;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
public final class MultiLayerModel implements IModelCustomData
public final class MultiLayerModel implements IModel
{
public static final MultiLayerModel INSTANCE = new MultiLayerModel(ImmutableMap.<Optional<BlockRenderLayer>, ModelResourceLocation>of());
public static final MultiLayerModel INSTANCE = new MultiLayerModel(ImmutableMap.of());
private final ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models;
@ -67,13 +66,7 @@ public final class MultiLayerModel implements IModelCustomData
@Override
public Collection<ResourceLocation> getDependencies()
{
return ImmutableList.<ResourceLocation>copyOf(models.values());
}
@Override
public Collection<ResourceLocation> getTextures()
{
return ImmutableList.of();
return ImmutableList.copyOf(models.values());
}
private static ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> buildModels(ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
@ -94,16 +87,10 @@ public final class MultiLayerModel implements IModelCustomData
return new MultiLayerBakedModel(
buildModels(models, state, format, bakedTextureGetter),
missing.bake(missing.getDefaultState(), format, bakedTextureGetter),
IPerspectiveAwareModel.MapWrapper.getTransforms(state)
PerspectiveMapWrapper.getTransforms(state)
);
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
}
@Override
public MultiLayerModel process(ImmutableMap<String, String> customData)
{
@ -112,7 +99,7 @@ public final class MultiLayerModel implements IModelCustomData
{
if("base".equals(key))
{
builder.put(Optional.<BlockRenderLayer>absent(), getLocation(customData.get(key)));
builder.put(Optional.empty(), getLocation(customData.get(key)));
}
for(BlockRenderLayer layer : BlockRenderLayer.values())
{
@ -138,10 +125,10 @@ public final class MultiLayerModel implements IModelCustomData
return new ModelResourceLocation("builtin/missing", "missing");
}
private static final class MultiLayerBakedModel implements IPerspectiveAwareModel
private static final class MultiLayerBakedModel implements IBakedModel
{
private final ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models;
private final ImmutableMap<TransformType, TRSRTransformation> cameraTransforms;;
private final ImmutableMap<TransformType, TRSRTransformation> cameraTransforms;
private final IBakedModel base;
private final IBakedModel missing;
private final ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>> quads;
@ -151,16 +138,16 @@ public final class MultiLayerModel implements IModelCustomData
this.models = models;
this.cameraTransforms = cameraTransforms;
this.missing = missing;
if(models.containsKey(Optional.absent()))
if(models.containsKey(Optional.empty()))
{
base = models.get(Optional.absent());
base = models.get(Optional.empty());
}
else
{
base = missing;
}
ImmutableMap.Builder<Optional<EnumFacing>, ImmutableList<BakedQuad>> quadBuilder = ImmutableMap.builder();
quadBuilder.put(Optional.<EnumFacing>absent(), buildQuads(models, Optional.<EnumFacing>absent()));
quadBuilder.put(Optional.empty(), buildQuads(models, Optional.empty()));
for(EnumFacing side: EnumFacing.values())
{
quadBuilder.put(Optional.of(side), buildQuads(models, Optional.of(side)));
@ -173,20 +160,19 @@ public final class MultiLayerModel implements IModelCustomData
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
for(IBakedModel model : models.values())
{
builder.addAll(model.getQuads(null, side.orNull(), 0));
builder.addAll(model.getQuads(null, side.orElse(null), 0));
}
return builder.build();
}
@Nonnull
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
IBakedModel model;
BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
if(layer == null)
{
return quads.get(Optional.fromNullable(side));
return quads.get(Optional.ofNullable(side));
}
else if(!models.containsKey(Optional.of(layer)))
{
@ -224,16 +210,10 @@ public final class MultiLayerModel implements IModelCustomData
return base.getParticleTexture();
}
@Override
public ItemCameraTransforms getItemCameraTransforms()
{
return ItemCameraTransforms.DEFAULT;
}
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
{
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, cameraTransforms, cameraTransformType);
return PerspectiveMapWrapper.handlePerspective(this, cameraTransforms, cameraTransformType);
}
@Override

View File

@ -26,7 +26,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
@ -35,7 +34,6 @@ import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemOverride;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
@ -51,8 +49,8 @@ import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.Level;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import java.util.function.Function;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
@ -62,20 +60,20 @@ import com.google.common.collect.Sets;
@Deprecated
public final class MultiModel implements IModel
{
private static final class Baked implements IPerspectiveAwareModel
private static final class Baked implements IBakedModel
{
private final ResourceLocation location;
@Nullable
private final IBakedModel base;
private final ImmutableMap<String, IBakedModel> parts;
private final IBakedModel internalBase;
private ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>> quads;
private final ImmutableMap<TransformType, Pair<Baked, TRSRTransformation>> transforms;
private final ItemOverrideList overrides = new ItemOverrideList(Lists.<ItemOverride>newArrayList())
private final ItemOverrideList overrides = new ItemOverrideList(Lists.newArrayList())
{
@Override
@Nonnull
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
if(originalModel != Baked.this)
{
@ -105,13 +103,13 @@ public final class MultiModel implements IModel
if(dirty)
{
// TODO: caching?
return new Baked(location, newBase instanceof IPerspectiveAwareModel, newBase, builder.build());
return new Baked(location, true, newBase, builder.build());
}
return Baked.this;
}
};
public Baked(ResourceLocation location, boolean perspective, IBakedModel base, ImmutableMap<String, IBakedModel> parts)
public Baked(ResourceLocation location, boolean perspective, @Nullable IBakedModel base, ImmutableMap<String, IBakedModel> parts)
{
this.location = location;
this.base = base;
@ -129,13 +127,12 @@ public final class MultiModel implements IModel
}
// Only changes the base model based on perspective, may recurse for parts in the future.
if(perspective && base instanceof IPerspectiveAwareModel)
if(base != null && perspective)
{
IPerspectiveAwareModel perBase = (IPerspectiveAwareModel)base;
ImmutableMap.Builder<TransformType, Pair<Baked, TRSRTransformation>> builder = ImmutableMap.builder();
for(TransformType type : TransformType.values())
{
Pair<? extends IBakedModel, Matrix4f> p = perBase.handlePerspective(type);
Pair<? extends IBakedModel, Matrix4f> p = base.handlePerspective(type);
IBakedModel newBase = p.getLeft();
builder.put(type, Pair.of(new Baked(location, false, newBase, parts), new TRSRTransformation(p.getRight())));
}
@ -178,7 +175,7 @@ public final class MultiModel implements IModel
}
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
if(quads == null)
{
@ -206,10 +203,10 @@ public final class MultiModel implements IModel
{
quads.addAll(bakedPart.getQuads(state, null, 0));
}
builder.put(Optional.<EnumFacing>absent(), quads.build());
builder.put(Optional.empty(), quads.build());
this.quads = builder.build();
}
return quads.get(Optional.fromNullable(side));
return quads.get(Optional.ofNullable(side));
}
@Override
@ -228,11 +225,12 @@ public final class MultiModel implements IModel
}
private final ResourceLocation location;
@Nullable
private final IModel base;
private final IModelState baseState;
private final Map<String, Pair<IModel, IModelState>> parts;
public MultiModel(ResourceLocation location, IModel base, IModelState baseState, ImmutableMap<String, Pair<IModel, IModelState>> parts)
public MultiModel(ResourceLocation location, @Nullable IModel base, IModelState baseState, ImmutableMap<String, Pair<IModel, IModelState>> parts)
{
this.location = location;
this.base = base;

View File

@ -26,7 +26,7 @@ import net.minecraftforge.common.model.TRSRTransformation;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@ -64,7 +64,7 @@ public final class MultiModelState implements IModelState
MultiModelPart key = (MultiModelPart)part.get();
if(states.containsKey(key))
{
return Optional.of(states.get(key).apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity()));
return Optional.of(states.get(key).apply(Optional.empty()).orElse(TRSRTransformation.identity()));
}
}
else if(part.get() instanceof PartPart)
@ -77,7 +77,7 @@ public final class MultiModelState implements IModelState
}
}
}
return Optional.absent();
return Optional.empty();
}
private static class PartState implements IModelState
@ -102,7 +102,10 @@ public final class MultiModelState implements IModelState
{
return Optional.of(normal.get().compose(multi.get()));
}
return normal.or(multi);
if (normal.isPresent()) {
return normal;
}
return multi;
}
}

View File

@ -0,0 +1,93 @@
package net.minecraftforge.client.model;
import java.util.Optional;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import java.util.List;
public class PerspectiveMapWrapper implements IBakedModel
{
private final IBakedModel parent;
private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
public PerspectiveMapWrapper(IBakedModel parent, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms)
{
this.parent = parent;
this.transforms = transforms;
}
public PerspectiveMapWrapper(IBakedModel parent, IModelState state)
{
this(parent, getTransforms(state));
}
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(IModelState state)
{
ImmutableMap.Builder<ItemCameraTransforms.TransformType, TRSRTransformation> builder = ImmutableMap.builder();
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
{
Optional<TRSRTransformation> tr = state.apply(Optional.of(type));
if(tr.isPresent())
{
builder.put(type, tr.get());
}
}
return builder.build();
}
@SuppressWarnings("deprecation")
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(ItemCameraTransforms transforms)
{
ImmutableMap.Builder<ItemCameraTransforms.TransformType, TRSRTransformation> builder = ImmutableMap.builder();
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
{
builder.put(type, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(transforms.getTransform(type))));
}
return builder.build();
}
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, ItemCameraTransforms.TransformType cameraTransformType)
{
TRSRTransformation tr = transforms.get(cameraTransformType);
Matrix4f mat = null;
if(tr != null && !tr.equals(TRSRTransformation.identity())) mat = TRSRTransformation.blockCornerToCenter(tr).getMatrix();
return Pair.of(model, mat);
}
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, IModelState state, ItemCameraTransforms.TransformType cameraTransformType)
{
TRSRTransformation tr = state.apply(Optional.of(cameraTransformType)).orElse(TRSRTransformation.identity());
if(tr != TRSRTransformation.identity())
{
return Pair.of(model, TRSRTransformation.blockCornerToCenter(tr).getMatrix());
}
return Pair.of(model, null);
}
public boolean isAmbientOcclusion() { return parent.isAmbientOcclusion(); }
public boolean isGui3d() { return parent.isGui3d(); }
public boolean isBuiltInRenderer() { return parent.isBuiltInRenderer(); }
public TextureAtlasSprite getParticleTexture() { return parent.getParticleTexture(); }
@SuppressWarnings("deprecation")
public ItemCameraTransforms getItemCameraTransforms() { return parent.getItemCameraTransforms(); }
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) { return parent.getQuads(state, side, rand); }
public ItemOverrideList getOverrides() { return parent.getOverrides(); }
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType)
{
return handlePerspective(this, transforms, cameraTransformType);
}
}

View File

@ -23,7 +23,7 @@ import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.ImmutableMap;
/*
@ -36,7 +36,7 @@ public final class SimpleModelState implements IModelState
public SimpleModelState(ImmutableMap<? extends IModelPart, TRSRTransformation> map)
{
this(map, Optional.<TRSRTransformation>absent());
this(map, Optional.empty());
}
public SimpleModelState(ImmutableMap<? extends IModelPart, TRSRTransformation> map, Optional<TRSRTransformation> def)
@ -54,8 +54,8 @@ public final class SimpleModelState implements IModelState
}
if(!map.containsKey(part.get()))
{
return Optional.absent();
return Optional.empty();
}
return Optional.fromNullable(map.get(part.get()));
return Optional.ofNullable(map.get(part.get()));
}
}

View File

@ -37,9 +37,8 @@ import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.animation.CapabilityAnimation;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import com.google.common.base.Function;
import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class AnimationItemOverrideList extends ItemOverrideList
@ -63,9 +62,8 @@ public final class AnimationItemOverrideList extends ItemOverrideList
this.bakedTextureGetter = bakedTextureGetter;
}
@Nonnull
@Override
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
IAnimationStateMachine asm = stack.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (asm != null)

View File

@ -38,8 +38,6 @@ import net.minecraftforge.common.property.Properties;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
/**
* Generic TileEntitySpecialRenderer that works with the Forge model system and animations.
*/
@ -48,8 +46,8 @@ public class AnimationTESR<T extends TileEntity> extends FastTESR<T> implements
protected static BlockRendererDispatcher blockRenderer;
@Override
public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, float partial, @Nonnull BufferBuilder renderer)
{
public void renderTileEntityFast(T te, double x, double y, double z, float partialTick, int breakStage, float partial, BufferBuilder renderer)
{
if(!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null))
{
return;

View File

@ -31,12 +31,10 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.tileentity.TileEntity;
import javax.annotation.Nonnull;
public abstract class FastTESR<T extends TileEntity> extends TileEntitySpecialRenderer<T>
{
@Override
public final void render(@Nonnull T te, double x, double y, double z, float partialTicks, int destroyStage, float partial)
public final void render(T te, double x, double y, double z, float partialTicks, int destroyStage, float partial)
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
@ -66,5 +64,5 @@ public abstract class FastTESR<T extends TileEntity> extends TileEntitySpecialRe
}
@Override
public abstract void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTicks, int destroyStage, float partial, @Nonnull BufferBuilder buffer);
public abstract void renderTileEntityFast(T te, double x, double y, double z, float partialTicks, int destroyStage, float partial, BufferBuilder buffer);
}

View File

@ -1,33 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.client.model.animation;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.common.model.animation.IClip;
import com.google.common.base.Optional;
/**
* IModel that has animation data.
*/
public interface IAnimatedModel extends IModel
{
Optional<? extends IClip> getClip(String name);
}

View File

@ -55,7 +55,7 @@ import net.minecraftforge.common.model.animation.JointClips;
import net.minecraftforge.common.util.JsonUtils;
import net.minecraftforge.fml.common.FMLLog;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@ -447,7 +447,7 @@ public class ModelBlockAnimation
@Override
public Optional<? extends IJoint> getParent()
{
return Optional.absent();
return Optional.empty();
}
public String getName()

View File

@ -0,0 +1,6 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraftforge.client.model.animation;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -49,7 +49,7 @@ public enum B3DClip implements IClip
@Override
public Iterable<Event> pastEvents(float lastPollTime, float time)
{
return ImmutableSet.<Event>of();
return ImmutableSet.of();
}
protected static class NodeClip implements IJointClip

View File

@ -22,7 +22,6 @@ package net.minecraftforge.client.model.b3d;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -37,7 +36,6 @@ import javax.vecmath.Vector3f;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@ -49,14 +47,10 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.model.ICustomModelLoader;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.IModelCustomData;
import net.minecraftforge.client.model.IModelSimpleProperties;
import net.minecraftforge.client.model.IPerspectiveAwareModel;
import net.minecraftforge.client.model.IRetexturableModel;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.ModelStateComposition;
import net.minecraftforge.client.model.animation.IAnimatedModel;
import net.minecraftforge.client.model.PerspectiveMapWrapper;
import net.minecraftforge.client.model.b3d.B3DModel.Animation;
import net.minecraftforge.client.model.b3d.B3DModel.Face;
import net.minecraftforge.client.model.b3d.B3DModel.Key;
@ -79,9 +73,9 @@ import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
@ -104,8 +98,8 @@ public enum B3DLoader implements ICustomModelLoader
private IResourceManager manager;
private final Set<String> enabledDomains = new HashSet<String>();
private final Map<ResourceLocation, B3DModel> cache = new HashMap<ResourceLocation, B3DModel>();
private final Set<String> enabledDomains = new HashSet<>();
private final Map<ResourceLocation, B3DModel> cache = new HashMap<>();
public void addDomain(String domain)
{
@ -134,7 +128,7 @@ public enum B3DLoader implements ICustomModelLoader
{
try
{
IResource resource = null;
IResource resource;
try
{
resource = manager.getResource(file);
@ -161,13 +155,14 @@ public enum B3DLoader implements ICustomModelLoader
if(model == null) throw new ModelLoaderRegistry.LoaderException("Error loading model previously: " + file);
if(!(model.getRoot().getKind() instanceof Mesh))
{
return new ModelWrapper(modelLocation, model, ImmutableSet.<String>of(), true, true, 1);
return new ModelWrapper(modelLocation, model, ImmutableSet.of(), true, true, 1);
}
return new ModelWrapper(modelLocation, model, ImmutableSet.of(model.getRoot().getName()), true, true, 1);
}
public static final class B3DState implements IModelState
{
@Nullable
private final Animation animation;
private final int frame;
private final int nextFrame;
@ -175,22 +170,22 @@ public enum B3DLoader implements ICustomModelLoader
@Nullable
private final IModelState parent;
public B3DState(Animation animation, int frame)
public B3DState(@Nullable Animation animation, int frame)
{
this(animation, frame, frame, 0);
}
public B3DState(Animation animation, int frame, IModelState parent)
public B3DState(@Nullable Animation animation, int frame, IModelState parent)
{
this(animation, frame, frame, 0, parent);
}
public B3DState(Animation animation, int frame, int nextFrame, float progress)
public B3DState(@Nullable Animation animation, int frame, int nextFrame, float progress)
{
this(animation, frame, nextFrame, progress, null);
}
public B3DState(Animation animation, int frame, int nextFrame, float progress, @Nullable IModelState parent)
public B3DState(@Nullable Animation animation, int frame, int nextFrame, float progress, @Nullable IModelState parent)
{
this.animation = animation;
this.frame = frame;
@ -207,6 +202,7 @@ public enum B3DLoader implements ICustomModelLoader
return parent;
}
@Nullable
public Animation getAnimation()
{
return animation;
@ -243,11 +239,11 @@ public enum B3DLoader implements ICustomModelLoader
{
return parent.apply(part);
}
return Optional.absent();
return Optional.empty();
}
if(!(part.get() instanceof NodeJoint))
{
return Optional.absent();
return Optional.empty();
}
Node<?> node = ((NodeJoint)part.get()).getNode();
TRSRTransformation nodeTransform;
@ -266,7 +262,7 @@ public enum B3DLoader implements ICustomModelLoader
}
if(parent != null && node.getParent() == null)
{
return Optional.of(parent.apply(part).or(TRSRTransformation.identity()).compose(nodeTransform));
return Optional.of(parent.apply(part).orElse(TRSRTransformation.identity()).compose(nodeTransform));
}
return Optional.of(nodeTransform);
}
@ -290,22 +286,22 @@ public enum B3DLoader implements ICustomModelLoader
public TRSRTransformation getNodeMatrix(Node<?> node, int frame)
{
return cache.getUnchecked(Triple.<Animation, Node<?>, Integer>of(animation, node, frame));
return cache.getUnchecked(Triple.of(animation, node, frame));
}
public static TRSRTransformation getNodeMatrix(Animation animation, Node<?> node, int frame)
public static TRSRTransformation getNodeMatrix(@Nullable Animation animation, Node<?> node, int frame)
{
TRSRTransformation ret = TRSRTransformation.identity();
Key key = null;
if(animation != null) key = animation.getKeys().get(frame, node);
else if(node.getAnimation() != null && node.getAnimation() != animation) key = node.getAnimation().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
TRSRTransformation pm = cache.getUnchecked(Triple.<Animation, Node<?>, Integer>of(animation, node.getParent(), frame));
TRSRTransformation pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
ret = ret.compose(pm);
// joint offset in the parent coords
ret = ret.compose(new TRSRTransformation(parent.getPos(), parent.getRot(), parent.getScale(), null));
@ -334,7 +330,7 @@ public enum B3DLoader implements ICustomModelLoader
if(parent != null)
{
// parent model-global current pose
TRSRTransformation pm = cache.getUnchecked(Triple.<Animation, Node<?>, Integer>of(animation, node.getParent(), frame));
TRSRTransformation pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
ret = ret.compose(pm);
// joint offset in the parent coords
ret = ret.compose(new TRSRTransformation(parent.getPos(), parent.getRot(), parent.getScale(), null));
@ -376,7 +372,7 @@ public enum B3DLoader implements ICustomModelLoader
public Optional<NodeJoint> getParent()
{
// FIXME cache?
if(node.getParent() == null) return Optional.absent();
if(node.getParent() == null) return Optional.empty();
return Optional.of(new NodeJoint(node.getParent()));
}
@ -402,39 +398,7 @@ public enum B3DLoader implements ICustomModelLoader
}
}
/**
* @deprecated use AnimationProperty.
*/
@Deprecated
public static enum B3DFrameProperty implements IUnlistedProperty<B3DState>
{
INSTANCE;
@Override
public String getName()
{
return "B3DFrame";
}
@Override
public boolean isValid(B3DState value)
{
return value instanceof B3DState;
}
@Override
public Class<B3DState> getType()
{
return B3DState.class;
}
@Override
public String valueToString(B3DState value)
{
return value.toString();
}
}
private static final class ModelWrapper implements IRetexturableModel, IModelCustomData, IModelSimpleProperties, IAnimatedModel
private static final class ModelWrapper implements IModel
{
private final ResourceLocation modelLocation;
private final B3DModel model;
@ -480,23 +444,10 @@ public enum B3DLoader implements ICustomModelLoader
return path;
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return Collections.emptyList();
}
@Override
public Collection<ResourceLocation> getTextures()
{
return Collections2.filter(textures.values(), new Predicate<ResourceLocation>()
{
@Override
public boolean apply(ResourceLocation loc)
{
return !loc.getResourcePath().startsWith("#");
}
});
return Collections2.filter(textures.values(), loc -> !loc.getResourcePath().startsWith("#"));
}
@Override
@ -596,9 +547,9 @@ public enum B3DLoader implements ICustomModelLoader
{
if(name.equals("main"))
{
return Optional.<IClip>of(B3DClip.INSTANCE);
return Optional.of(B3DClip.INSTANCE);
}
return Optional.absent();
return Optional.empty();
}
@Override
@ -628,7 +579,7 @@ public enum B3DLoader implements ICustomModelLoader
}
}
private static final class BakedWrapper implements IPerspectiveAwareModel
private static final class BakedWrapper implements IBakedModel
{
private final Node<?> node;
private final IModelState state;
@ -676,41 +627,14 @@ public enum B3DLoader implements ICustomModelLoader
}
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
if(side != null) return ImmutableList.of();
IModelState modelState = this.state;
if(state instanceof IExtendedBlockState)
{
IExtendedBlockState exState = (IExtendedBlockState)state;
if(exState.getUnlistedNames().contains(B3DFrameProperty.INSTANCE))
{
B3DState s = exState.getValue(B3DFrameProperty.INSTANCE);
if(s != null)
{
//return getCachedModel(s.getFrame());
IModelState parent = this.state;
Animation newAnimation = s.getAnimation();
if(parent instanceof B3DState)
{
B3DState ps = (B3DState)parent;
parent = ps.getParent();
}
if(newAnimation == null)
{
newAnimation = node.getAnimation();
}
if(s.getFrame() == s.getNextFrame())
{
modelState = cache.getUnchecked(s.getFrame());
}
else
{
modelState = new B3DState(newAnimation, s.getFrame(), s.getNextFrame(), s.getProgress(), parent);
}
}
}
else if(exState.getUnlistedNames().contains(Properties.AnimationProperty))
if(exState.getUnlistedNames().contains(Properties.AnimationProperty))
{
// FIXME: should animation state handle the parent state, or should it remain here?
IModelState parent = this.state;
@ -722,21 +646,28 @@ public enum B3DLoader implements ICustomModelLoader
IModelState newState = exState.getValue(Properties.AnimationProperty);
if(newState != null)
{
modelState = new ModelStateComposition(parent, newState);
if (parent == null)
{
modelState = newState;
}
else
{
modelState = new ModelStateComposition(parent, newState);
}
}
}
}
if(quads == null)
{
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
generateQuads(builder, node, this.state, ImmutableList.<String>of());
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.<String>of());
generateQuads(builder, node, modelState, ImmutableList.of());
return builder.build();
}
return quads;
@ -757,7 +688,7 @@ public enum B3DLoader implements ICustomModelLoader
Mesh mesh = (Mesh)node.getKind();
Collection<Face> faces = mesh.bake(new Function<Node<?>, Matrix4f>()
{
private final TRSRTransformation global = state.apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity());
private final TRSRTransformation global = state.apply(Optional.empty()).orElse(TRSRTransformation.identity());
private final LoadingCache<Node<?>, TRSRTransformation> localCache = CacheBuilder.newBuilder()
.maximumSize(32)
.build(new CacheLoader<Node<?>, TRSRTransformation>()
@ -765,7 +696,7 @@ public enum B3DLoader implements ICustomModelLoader
@Override
public TRSRTransformation load(Node<?> node) throws Exception
{
return state.apply(Optional.of(new NodeJoint(node))).or(TRSRTransformation.identity());
return state.apply(Optional.of(new NodeJoint(node))).orElse(TRSRTransformation.identity());
}
});
@ -873,16 +804,10 @@ public enum B3DLoader implements ICustomModelLoader
return textures.values().asList().get(0);
}
@Override
public ItemCameraTransforms getItemCameraTransforms()
{
return ItemCameraTransforms.DEFAULT;
}
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
{
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType);
return PerspectiveMapWrapper.handlePerspective(this, state, cameraTransformType);
}
@Override

View File

@ -36,6 +36,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
@ -49,9 +50,9 @@ import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@ -133,7 +134,7 @@ public class B3DModel
return res;
}
private final List<Texture> textures = new ArrayList<Texture>();
private final List<Texture> textures = new ArrayList<>();
private Texture getTexture(int texture)
{
@ -146,27 +147,25 @@ public class B3DModel
return textures.get(texture);
}
private final List<Brush> brushes = new ArrayList<Brush>();
private final List<Brush> brushes = new ArrayList<>();
private Brush getBrush(int brush)
private @Nullable Brush getBrush(int brush) throws IOException
{
if(brush > brushes.size())
{
logger.error("brush {} is out of range", brush);
return null;
throw new IOException(String.format("brush %s is out of range", brush));
}
else if(brush == -1) return null;
return brushes.get(brush);
}
private final List<Vertex> vertices = new ArrayList<Vertex>();
private final List<Vertex> vertices = new ArrayList<>();
private Vertex getVertex(int vertex)
private Vertex getVertex(int vertex) throws IOException
{
if(vertex > vertices.size())
{
logger.error("vertex {} is out of range", vertex);
return null;
throw new IOException(String.format("vertex %s is out of range", vertex));
}
return vertices.get(vertex);
}
@ -199,11 +198,10 @@ public class B3DModel
buf.position(start);
buf.get(tmp);
buf.get();
String ret = new String(tmp, "UTF8");
return ret;
return new String(tmp, "UTF8");
}
private Deque<Integer> limitStack = new ArrayDeque<Integer>();
private Deque<Integer> limitStack = new ArrayDeque<>();
private void pushLimit()
{
@ -223,7 +221,7 @@ public class B3DModel
if(version / 100 > Parser.version / 100)
throw new IOException("Unsupported major model version: " + ((float)version / 100));
if(version % 100 > Parser.version % 100)
logger.warn(String.format("Minor version difference in model: ", ((float)version / 100)));
logger.warn(String.format("Minor version difference in model: %s", ((float)version / 100)));
List<Texture> textures = Collections.emptyList();
List<Brush> brushes = Collections.emptyList();
Node<?> root = null;
@ -238,13 +236,16 @@ public class B3DModel
}
dump("}");
popLimit();
if (root == null) {
throw new IOException("not found the root node in the model");
}
return new B3DModel(textures, brushes, root, meshes.build());
}
private List<Texture> texs() throws IOException
{
chunk("TEXS");
List<Texture> ret = new ArrayList<Texture>();
List<Texture> ret = new ArrayList<>();
while(buf.hasRemaining())
{
String path = readString();
@ -264,7 +265,7 @@ public class B3DModel
private List<Brush> brus() throws IOException
{
chunk("BRUS");
List<Brush> ret = new ArrayList<Brush>();
List<Brush> ret = new ArrayList<>();
int n_texs = buf.getInt();
while(buf.hasRemaining())
{
@ -273,7 +274,7 @@ public class B3DModel
float shininess = buf.getFloat();
int blend = buf.getInt();
int fx = buf.getInt();
List<Texture> textures = new ArrayList<Texture>();
List<Texture> textures = new ArrayList<>();
for(int i = 0; i < n_texs; i++) textures.add(getTexture(buf.getInt()));
ret.add(new Brush(name, color, shininess, blend, fx, textures));
}
@ -286,7 +287,7 @@ public class B3DModel
private List<Vertex> vrts() throws IOException
{
chunk("VRTS");
List<Vertex> ret = new ArrayList<Vertex>();
List<Vertex> ret = new ArrayList<>();
int flags = buf.getInt();
int tex_coord_sets = buf.getInt();
int tex_coord_set_size = buf.getInt();
@ -320,7 +321,7 @@ public class B3DModel
tex_coords[i] = new Vector4f(buf.getFloat(), buf.getFloat(), buf.getFloat(), buf.getFloat());
break;
default:
logger.error(String.format("Unsupported number of texture coords: ", tex_coord_set_size));
logger.error(String.format("Unsupported number of texture coords: %s", tex_coord_set_size));
tex_coords[i] = new Vector4f(0, 0, 0, 1);
}
}
@ -336,7 +337,7 @@ public class B3DModel
private List<Face> tris() throws IOException
{
chunk("TRIS");
List<Face> ret = new ArrayList<Face>();
List<Face> ret = new ArrayList<>();
int brush_id = buf.getInt();
while(buf.hasRemaining())
{
@ -354,7 +355,7 @@ public class B3DModel
readHeader();
dump("MESH(brush = " + brush_id + ") {");
vrts();
List<Face> ret = new ArrayList<Face>();
List<Face> ret = new ArrayList<>();
while(buf.hasRemaining())
{
readHeader();
@ -368,7 +369,7 @@ public class B3DModel
private List<Pair<Vertex, Float>> bone() throws IOException
{
chunk("BONE");
List<Pair<Vertex, Float>> ret = new ArrayList<Pair<Vertex, Float>>();
List<Pair<Vertex, Float>> ret = new ArrayList<>();
while(buf.hasRemaining())
{
ret.add(Pair.of(getVertex(buf.getInt()), buf.getFloat()));
@ -378,12 +379,12 @@ public class B3DModel
return ret;
}
private final Deque<Table<Integer, Optional<Node<?>>, Key>> animations = new ArrayDeque<Table<Integer, Optional<Node<?>>, Key>>();
private final Deque<Table<Integer, Optional<Node<?>>, Key>> animations = new ArrayDeque<>();
private Map<Integer, Key> keys() throws IOException
{
chunk("KEYS");
Map<Integer, Key> ret = new HashMap<Integer, Key>();
Map<Integer, Key> ret = new HashMap<>();
int flags = buf.getInt();
Vector3f pos = null, scale = null;
Quat4f rot = null;
@ -422,7 +423,7 @@ public class B3DModel
else key = new Key(key.getPos(), key.getScale(), oldKey.getRot());
}
}
animations.peek().put(frame, Optional.<Node<?>>absent(), key);
animations.peek().put(frame, Optional.empty(), key);
ret.put(frame, key);
}
dump("KEYS([(" + Joiner.on("), (").withKeyValueSeparator(" -> ").join(ret) + ")])");
@ -444,12 +445,12 @@ public class B3DModel
private Node<?> node() throws IOException
{
chunk("NODE");
animations.push(HashBasedTable.<Integer, Optional<Node<?>>, Key>create());
animations.push(HashBasedTable.create());
Triple<Integer, Integer, Float> animData = null;
Pair<Brush, List<Face>> mesh = null;
List<Pair<Vertex, Float>> bone = null;
Map<Integer, Key> keys = new HashMap<Integer, Key>();
List<Node<?>> nodes = new ArrayList<Node<?>>();
Map<Integer, Key> keys = new HashMap<>();
List<Node<?>> nodes = new ArrayList<>();
String name = readString();
Vector3f pos = new Vector3f(buf.getFloat(), buf.getFloat(), buf.getFloat());
Vector3f scale = new Vector3f(buf.getFloat(), buf.getFloat(), buf.getFloat());
@ -481,7 +482,7 @@ public class B3DModel
{
for(Table.Cell<Integer, Optional<Node<?>>, Key> key : keyData.cellSet())
{
animations.peek().put(key.getRowKey(), key.getColumnKey().or(Optional.of(node)), key.getValue());
animations.peek().put(key.getRowKey(), Optional.of(key.getColumnKey().orElse(node)), key.getValue());
}
}
else
@ -644,10 +645,12 @@ public class B3DModel
public static class Vertex
{
private final Vector3f pos;
@Nullable
private final Vector3f normal;
@Nullable
private final Vector4f color;
private final Vector4f[] texCoords;
public Vertex(Vector3f pos, Vector3f normal, Vector4f color, Vector4f[] texCoords)
public Vertex(Vector3f pos, @Nullable Vector3f normal, @Nullable Vector4f color, Vector4f[] texCoords)
{
this.pos = pos;
this.normal = normal;
@ -707,11 +710,13 @@ public class B3DModel
return pos;
}
@Nullable
public Vector3f getNormal()
{
return normal;
}
@Nullable
public Vector4f getColor()
{
return color;
@ -732,15 +737,16 @@ public class B3DModel
public static class Face
{
private final Vertex v1, v2, v3;
@Nullable
private final Brush brush;
private final Vector3f normal;
public Face(Vertex v1, Vertex v2, Vertex v3, Brush brush)
public Face(Vertex v1, Vertex v2, Vertex v3, @Nullable Brush brush)
{
this(v1, v2, v3, brush, getNormal(v1, v2, v3));
}
public Face(Vertex v1, Vertex v2, Vertex v3, Brush brush, Vector3f normal)
public Face(Vertex v1, Vertex v2, Vertex v3, @Nullable Brush brush, Vector3f normal)
{
this.v1 = v1;
this.v2 = v2;
@ -764,6 +770,7 @@ public class B3DModel
return v3;
}
@Nullable
public Brush getBrush()
{
return brush;
@ -795,27 +802,33 @@ public class B3DModel
public static class Key
{
@Nullable
private final Vector3f pos;
@Nullable
private final Vector3f scale;
@Nullable
private final Quat4f rot;
public Key(Vector3f pos, Vector3f scale, Quat4f rot)
public Key(@Nullable Vector3f pos, @Nullable Vector3f scale, @Nullable Quat4f rot)
{
this.pos = pos;
this.scale = scale;
this.rot = rot;
}
@Nullable
public Vector3f getPos()
{
return pos;
}
@Nullable
public Vector3f getScale()
{
return scale;
}
@Nullable
public Quat4f getRot()
{
return rot;
@ -883,13 +896,15 @@ public class B3DModel
private final Vector3f scale;
private final Quat4f rot;
private final ImmutableMap<String, Node<?>> nodes;
@Nullable
private Animation animation;
private final K kind;
@Nullable
private Node<? extends IKind<?>> parent;
public static <K extends IKind<K>> Node<K> create(String name, Vector3f pos, Vector3f scale, Quat4f rot, List<Node<?>> nodes, K kind)
{
return new Node<K>(name, pos, scale, rot, nodes, kind);
return new Node<>(name, pos, scale, rot, nodes, kind);
}
public Node(String name, Vector3f pos, Vector3f scale, Quat4f rot, List<Node<?>> nodes, K kind)
@ -910,7 +925,7 @@ public class B3DModel
public void setAnimation(Animation animation)
{
this.animation = animation;
Deque<Node<?>> q = new ArrayDeque<Node<?>>(nodes.values());
Deque<Node<?>> q = new ArrayDeque<>(nodes.values());
while(!q.isEmpty())
{
@ -926,7 +941,7 @@ public class B3DModel
ImmutableTable.Builder<Integer, Node<?>, Key> builder = ImmutableTable.builder();
for(Table.Cell<Integer, Optional<Node<?>>, Key> key : keyData.cellSet())
{
builder.put(key.getRowKey(), key.getColumnKey().or(this), key.getValue());
builder.put(key.getRowKey(), key.getColumnKey().orElse(this), key.getValue());
}
setAnimation(new Animation(animData.getLeft(), animData.getMiddle(), animData.getRight(), builder.build()));
}
@ -971,11 +986,13 @@ public class B3DModel
return nodes;
}
@Nullable
public Animation getAnimation()
{
return animation;
}
@Nullable
public Node<? extends IKind<?>> getParent()
{
return parent;
@ -1017,7 +1034,7 @@ public class B3DModel
private final ImmutableList<Face> faces;
//private final ImmutableList<Bone> bones;
private Set<Node<Bone>> bones = new HashSet<Node<Bone>>();
private Set<Node<Bone>> bones = new HashSet<>();
private ImmutableMultimap<Vertex, Pair<Float, Node<Bone>>> weightMap = ImmutableMultimap.of();
@ -1071,7 +1088,7 @@ public class B3DModel
public void setParent(Node<Mesh> parent)
{
this.parent = parent;
Deque<Node<?>> queue = new ArrayDeque<Node<?>>(parent.getNodes().values());
Deque<Node<?>> queue = new ArrayDeque<>(parent.getNodes().values());
while(!queue.isEmpty())
{
Node<?> node = queue.pop();

View File

@ -0,0 +1,6 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraftforge.client.model.b3d;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -44,9 +44,9 @@ public enum OBJLoader implements ICustomModelLoader {
INSTANCE;
private IResourceManager manager;
private final Set<String> enabledDomains = new HashSet<String>();
private final Map<ResourceLocation, OBJModel> cache = new HashMap<ResourceLocation, OBJModel>();
private final Map<ResourceLocation, Exception> errors = new HashMap<ResourceLocation, Exception>();
private final Set<String> enabledDomains = new HashSet<>();
private final Map<ResourceLocation, OBJModel> cache = new HashMap<>();
private final Map<ResourceLocation, Exception> errors = new HashMap<>();
public void addDomain(String domain)
{
@ -74,7 +74,7 @@ public enum OBJLoader implements ICustomModelLoader {
ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath());
if (!cache.containsKey(file))
{
IResource resource = null;
IResource resource;
try
{
resource = manager.getResource(file);

View File

@ -66,9 +66,9 @@ import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.base.Strings;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
@ -78,7 +78,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
public class OBJModel implements IRetexturableModel, IModelCustomData
public class OBJModel implements IModel
{
//private Gson GSON = new GsonBuilder().create();
private MaterialLibrary matLib;
@ -97,12 +97,6 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
this.customData = customData;
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return Collections.emptyList();
}
@Override
public Collection<ResourceLocation> getTextures()
{
@ -1081,7 +1075,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
for (Face f : this.faces)
{
// if (minUVBounds != null && maxUVBounds != null) f.normalizeUVs(minUVBounds, maxUVBounds);
faceSet.add(f.bake(transform.or(TRSRTransformation.identity())));
faceSet.add(f.bake(transform.orElse(TRSRTransformation.identity())));
}
return faceSet;
}
@ -1142,7 +1136,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
{
if (parent != null) return parent.apply(part);
return Optional.absent();
return Optional.empty();
}
public Map<String, Boolean> getVisibilityMap()
@ -1282,7 +1276,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
}
}
public class OBJBakedModel implements IPerspectiveAwareModel
public class OBJBakedModel implements IBakedModel
{
private final OBJModel model;
private IModelState state;
@ -1335,7 +1329,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
List<BakedQuad> quads = Lists.newArrayList();
Collections.synchronizedSet(new LinkedHashSet<BakedQuad>());
Set<Face> faces = Collections.synchronizedSet(new LinkedHashSet<Face>());
Optional<TRSRTransformation> transform = Optional.absent();
Optional<TRSRTransformation> transform = Optional.empty();
for (Group g : this.model.getMatLib().getGroups().values())
{
// g.minUVBounds = this.model.getMatLib().minUVBounds;
@ -1351,7 +1345,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
OBJState state = (OBJState) modelState;
if (state.parent != null)
{
transform = state.parent.apply(Optional.<IModelPart>absent());
transform = state.parent.apply(Optional.empty());
}
//TODO: can this be replaced by updateStateVisibilityMap(OBJState)?
if (state.getGroupNamesFromMap().contains(Group.ALL))
@ -1388,7 +1382,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
}
else
{
transform = modelState.apply(Optional.<IModelPart>absent());
transform = modelState.apply(Optional.empty());
faces.addAll(g.applyTransform(transform));
}
}
@ -1487,12 +1481,6 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
return this.sprite;
}
@Override
public ItemCameraTransforms getItemCameraTransforms()
{
return ItemCameraTransforms.DEFAULT;
}
// FIXME: merge with getQuads
/* @Override
public OBJBakedModel handleBlockState(IBlockState state)
@ -1580,7 +1568,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
{
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType);
return PerspectiveMapWrapper.handlePerspective(this, state, cameraTransformType);
}
@Override
@ -1607,10 +1595,4 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
this.modelLocation = modelLocation;
}
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
}
}

View File

@ -0,0 +1,6 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraftforge.client.model.obj;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -0,0 +1,6 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraftforge.client.model;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -68,12 +68,6 @@ public class BlockInfo
shz = (float) offset.z;
}
@Deprecated
public void updateShift(boolean ignoreY)
{
updateShift();
}
public void setWorld(IBlockAccess world)
{
this.world = world;

View File

@ -52,10 +52,10 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
}
};
private final ThreadLocal<VertexBufferConsumer> wrFlat = new ThreadLocal<VertexBufferConsumer>();
private final ThreadLocal<VertexBufferConsumer> wrSmooth = new ThreadLocal<VertexBufferConsumer>();
private final ThreadLocal<BufferBuilder> lastRendererFlat = new ThreadLocal<BufferBuilder>();
private final ThreadLocal<BufferBuilder> lastRendererSmooth = new ThreadLocal<BufferBuilder>();
private final ThreadLocal<VertexBufferConsumer> wrFlat = new ThreadLocal<>();
private final ThreadLocal<VertexBufferConsumer> wrSmooth = new ThreadLocal<>();
private final ThreadLocal<BufferBuilder> lastRendererFlat = new ThreadLocal<>();
private final ThreadLocal<BufferBuilder> lastRendererSmooth = new ThreadLocal<>();
private final BlockColors colors;

View File

@ -0,0 +1,6 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraftforge.client.model.pipeline;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@ -53,7 +54,7 @@ import net.minecraftforge.fml.common.eventhandler.Event;
import org.apache.logging.log4j.Level;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ArrayListMultimap;
@ -129,14 +130,7 @@ public class ForgeChunkManager
final ImmutableSetMultimap<ChunkPos, Ticket> persistentChunksFor = getPersistentChunksFor(world);
final ImmutableSet.Builder<Chunk> builder = ImmutableSet.builder();
world.profiler.startSection("forcedChunkLoading");
builder.addAll(Iterators.transform(persistentChunksFor.keys().iterator(), new Function<ChunkPos, Chunk>() {
@Nullable
@Override
public Chunk apply(@Nullable ChunkPos input)
{
return input == null ? null : world.getChunkFromChunkCoords(input.x, input.z);
}
}));
builder.addAll(persistentChunksFor.keys().stream().filter(Objects::nonNull).map(input -> world.getChunkFromChunkCoords(input.x, input.z)).iterator());
world.profiler.endStartSection("regularChunkLoading");
builder.addAll(chunkIterator);
world.profiler.endSection();

View File

@ -24,7 +24,7 @@ import java.util.regex.Pattern;
import net.minecraft.util.IStringSerializable;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;

View File

@ -29,7 +29,7 @@ import java.util.concurrent.Callable;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.Type;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;

View File

@ -19,7 +19,7 @@
package net.minecraftforge.common.model;
import com.google.common.base.Optional;
import java.util.Optional;
/*
* Represents the dynamic information associated with the model.

View File

@ -42,7 +42,7 @@ import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.Maps;
/*
@ -563,7 +563,7 @@ public final class TRSRTransformation implements IModelState, ITransformation
{
if(part.isPresent())
{
return Optional.absent();
return Optional.empty();
}
return Optional.of(this);
}

View File

@ -19,18 +19,24 @@
package net.minecraftforge.common.model.animation;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Supplier;
import com.google.common.collect.*;
import com.google.gson.*;
import com.google.common.base.Predicate;
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.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;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
@ -45,19 +51,18 @@ import net.minecraftforge.common.util.JsonUtils;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.Level;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.gson.annotations.SerializedName;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
public final class AnimationStateMachine implements IAnimationStateMachine
{
@ -88,21 +93,7 @@ public final class AnimationStateMachine implements IAnimationStateMachine
@Deprecated
public AnimationStateMachine(ImmutableMap<String, ITimeValue> parameters, ImmutableMap<String, IClip> clips, ImmutableList<String> states, ImmutableMap<String, String> transitions, String startState)
{
this(parameters, clips, states, ImmutableMultimap.copyOf(Multimaps.newSetMultimap(Maps.transformValues(transitions, new Function<String, Collection<String>>()
{
@Override
public Collection<String> apply(String input)
{
return ImmutableSet.of(input);
}
}), new Supplier<Set<String>>()
{
@Override
public Set<String> get()
{
return Sets.newHashSet();
}
})), startState);
this(parameters, clips, states, ImmutableMultimap.copyOf(Multimaps.newSetMultimap(Maps.transformValues(transitions, ImmutableSet::of), Sets::newHashSet)), startState);
}
public AnimationStateMachine(ImmutableMap<String, ITimeValue> parameters, ImmutableMap<String, IClip> clips, ImmutableList<String> states, ImmutableMultimap<String, String> transitions, String startState)

View File

@ -27,7 +27,6 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.animation.IAnimatedModel;
import net.minecraftforge.common.animation.Event;
import net.minecraftforge.common.animation.ITimeValue;
import net.minecraftforge.common.model.IModelPart;
@ -40,9 +39,9 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
@ -93,15 +92,12 @@ public final class Clips
public static IClip getModelClipNode(ResourceLocation modelLocation, String clipName)
{
IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
if(model instanceof IAnimatedModel)
Optional<? extends IClip> clip = model.getClip(clipName);
if (clip.isPresent())
{
Optional<? extends IClip> clip = ((IAnimatedModel)model).getClip(clipName);
if(clip.isPresent())
{
return new ModelClip(clip.get(), modelLocation, clipName);
}
FMLLog.log.error("Unable to find clip {} in the model {}", clipName, modelLocation);
return new ModelClip(clip.get(), modelLocation, clipName);
}
FMLLog.log.error("Unable to find clip {} in the model {}", clipName, modelLocation);
// FIXME: missing clip?
return new ModelClip(IdentityClip.INSTANCE, modelLocation, clipName);
}
@ -312,7 +308,7 @@ public final class Clips
{
if(!part.isPresent() || !(part.get() instanceof IJoint))
{
return Optional.absent();
return Optional.empty();
}
IJoint joint = (IJoint)part.get();
// TODO: Cache clip application?

View File

@ -19,7 +19,7 @@
package net.minecraftforge.common.model.animation;
import com.google.common.base.Optional;
import java.util.Optional;
import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.TRSRTransformation;

View File

@ -29,7 +29,7 @@ import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@ -65,7 +65,7 @@ public class ExtendedBlockState extends BlockStateContainer
ImmutableMap.Builder<IUnlistedProperty<?>, Optional<?>> builder = ImmutableMap.builder();
for(IUnlistedProperty<?> p : unlistedProperties)
{
builder.put(p, Optional.absent());
builder.put(p, Optional.empty());
}
return builder.build();
}
@ -111,7 +111,7 @@ public class ExtendedBlockState extends BlockStateContainer
}
Map<IProperty<?>, Comparable<?>> map = Maps.newHashMap(getProperties());
map.put(property, value);
if (Iterables.all(unlistedProperties.values(), Predicates.<Optional<?>>equalTo(Optional.absent())))
if (Iterables.all(unlistedProperties.values(), Predicates.<Optional<?>>equalTo(Optional.empty())))
{ // no dynamic properties present, looking up in the normal table
return normalMap.get(map);
}
@ -134,8 +134,8 @@ public class ExtendedBlockState extends BlockStateContainer
throw new IllegalArgumentException("Cannot set unlisted property " + property + " to " + value + " on block " + Block.REGISTRY.getNameForObject(getBlock()) + ", it is not an allowed value");
}
Map<IUnlistedProperty<?>, Optional<?>> newMap = new HashMap<IUnlistedProperty<?>, Optional<?>>(unlistedProperties);
newMap.put(property, Optional.fromNullable(value));
if(Iterables.all(newMap.values(), Predicates.<Optional<?>>equalTo(Optional.absent())))
newMap.put(property, Optional.ofNullable(value));
if(Iterables.all(newMap.values(), Predicates.<Optional<?>>equalTo(Optional.empty())))
{ // no dynamic properties, lookup normal state
return (IExtendedBlockState) normalMap.get(getProperties());
}
@ -155,7 +155,7 @@ public class ExtendedBlockState extends BlockStateContainer
{
throw new IllegalArgumentException("Cannot get unlisted property " + property + " as it does not exist in " + getBlock().getBlockState());
}
return property.getType().cast(this.unlistedProperties.get(property).orNull());
return property.getType().cast(this.unlistedProperties.get(property).orElse(null));
}
@Override

View File

@ -23,7 +23,7 @@ import java.util.Collection;
import net.minecraft.block.state.IBlockState;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.ImmutableMap;
public interface IExtendedBlockState extends IBlockState

View File

@ -109,7 +109,6 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.registries.GameData;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.LWJGLUtil;

View File

@ -24,14 +24,12 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import javax.imageio.ImageIO;
import net.minecraft.client.resources.FileResourcePack;
import net.minecraftforge.fml.common.FMLContainerHolder;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.ModContainer;
import com.google.common.base.Charsets;

View File

@ -24,14 +24,12 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import javax.imageio.ImageIO;
import net.minecraft.client.resources.FolderResourcePack;
import net.minecraftforge.fml.common.FMLContainerHolder;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.ModContainer;
import com.google.common.base.Charsets;

View File

@ -24,7 +24,6 @@ import net.minecraft.client.gui.GuiErrorScreen;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.Loader;
import org.apache.logging.log4j.Level;
import java.awt.*;
import java.io.File;

View File

@ -61,7 +61,6 @@ import net.minecraftforge.fml.common.ModContainer.Disableable;
import net.minecraftforge.fml.common.versioning.ComparableVersion;
import static net.minecraft.util.text.TextFormatting.*;
import org.apache.logging.log4j.Level;
import org.lwjgl.input.Mouse;
import com.google.common.base.Strings;

View File

@ -23,17 +23,13 @@ import java.io.File;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.world.WorldSettings;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.StartupQuery;
import net.minecraftforge.fml.common.ZipperUtil;
import org.apache.logging.log4j.Level;
public class GuiOldSaveLoadConfirm extends GuiYesNo implements GuiYesNoCallback {
private String dirName;

View File

@ -19,7 +19,6 @@
package net.minecraftforge.fml.client;
import net.minecraft.client.gui.GuiErrorScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.Loader;

View File

@ -28,8 +28,6 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.Thread.UncaughtExceptionHandler;
import java.nio.IntBuffer;
import java.util.Iterator;
@ -67,7 +65,6 @@ import net.minecraftforge.fml.common.asm.FMLSanityChecker;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Level;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;

View File

@ -31,7 +31,6 @@ import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.client.config.GuiConfigEntries.ArrayEntry;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.logging.log4j.Level;
import org.lwjgl.input.Keyboard;
import static net.minecraftforge.fml.client.config.GuiUtils.INVALID;

View File

@ -63,7 +63,7 @@ import org.apache.logging.log4j.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.ArrayListMultimap;

View File

@ -22,9 +22,11 @@ package net.minecraftforge.fml.common;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import net.minecraftforge.fml.common.LoaderState.ModState;
import net.minecraftforge.fml.common.ProgressManager.ProgressBar;
@ -33,16 +35,13 @@ import net.minecraftforge.fml.common.event.FMLLoadEvent;
import net.minecraftforge.fml.common.event.FMLModDisabledEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLStateEvent;
import net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.ThreadContext;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
@ -236,7 +235,7 @@ public class LoadController
private void sendEventToModContainer(FMLEvent stateEvent, ModContainer mc)
{
String modId = mc.getModId();
Collection<String> requirements = Collections2.transform(mc.getRequirements(),new ArtifactVersionNameFunction());
Collection<String> requirements = mc.getRequirements().stream().map(ArtifactVersion::getLabel).collect(Collectors.toCollection(HashSet::new));
for (ArtifactVersion av : mc.getDependencies())
{
if (av.getLabel()!= null && requirements.contains(av.getLabel()) && modStates.containsEntry(av.getLabel(),ModState.ERRORED))

View File

@ -46,8 +46,6 @@ import net.minecraftforge.fml.common.discovery.ModDiscoverer;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import net.minecraftforge.fml.common.event.FMLLoadEvent;
import net.minecraftforge.fml.common.event.FMLModIdMappingEvent;
import net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction;
import net.minecraftforge.fml.common.functions.ModIdFunction;
import net.minecraftforge.fml.common.registry.*;
import net.minecraftforge.fml.common.toposort.ModSorter;
import net.minecraftforge.fml.common.toposort.ModSortingException;
@ -64,7 +62,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Level;
import com.google.common.base.CharMatcher;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ArrayListMultimap;
@ -248,7 +246,7 @@ public class Loader
wrongMinecraftExceptions.add(ret);
continue;
}
Map<String,ArtifactVersion> names = Maps.uniqueIndex(mod.getRequirements(), new ArtifactVersionNameFunction());
Map<String,ArtifactVersion> names = Maps.uniqueIndex(mod.getRequirements(), ArtifactVersion::getLabel);
Set<ArtifactVersion> versionMissingMods = Sets.newHashSet();
Set<String> missingMods = Sets.difference(names.keySet(), modVersions.keySet());
@ -404,7 +402,7 @@ public class Loader
mods.addAll(discoverer.identifyMods());
identifyDuplicates(mods);
namedMods = Maps.uniqueIndex(mods, new ModIdFunction());
namedMods = Maps.uniqueIndex(mods, ModContainer::getModId);
FMLLog.log.info("Forge Mod Loader has identified {} mod{} to load", mods.size(), mods.size() != 1 ? "s" : "");
return discoverer;
}
@ -521,7 +519,7 @@ public class Loader
{
modController = new LoadController(this);
mods = Lists.newArrayList(containers);
namedMods = Maps.uniqueIndex(mods, new ModIdFunction());
namedMods = Maps.uniqueIndex(mods, ModContainer::getModId);
modController.transition(LoaderState.LOADING, false);
modController.transition(LoaderState.CONSTRUCTING, false);
ObjectHolderRegistry.INSTANCE.findObjectHolders(new ASMDataTable());
@ -652,14 +650,7 @@ public class Loader
modStates.putAll(sysPropertyStateList);
FMLLog.log.debug("After merging, found state information for {} mods", modStates.size());
Map<String, Boolean> isEnabled = Maps.transformValues(modStates, new Function<String, Boolean>()
{
@Override
public Boolean apply(String input)
{
return Boolean.parseBoolean(input);
}
});
Map<String, Boolean> isEnabled = Maps.transformValues(modStates, Boolean::parseBoolean);
for (Map.Entry<String, Boolean> entry : isEnabled.entrySet())
{

View File

@ -20,16 +20,17 @@
package net.minecraftforge.fml.common;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import net.minecraftforge.fml.common.asm.transformers.ModAPITransformer;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import net.minecraftforge.fml.common.discovery.ModCandidate;
import net.minecraftforge.fml.common.discovery.ModDiscoverer;
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
import net.minecraftforge.fml.common.functions.ModIdFunction;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
import net.minecraftforge.fml.common.versioning.VersionParser;
@ -195,7 +196,7 @@ public class ModAPIManager {
Set<ModCandidate> candidates = dataTable.getCandidatesFor(pkg);
for (ModCandidate candidate : candidates)
{
List<String> candidateIds = Lists.transform(candidate.getContainedMods(), new ModIdFunction());
List<String> candidateIds = candidate.getContainedMods().stream().map(ModContainer::getModId).collect(Collectors.toCollection(ArrayList::new));
if (!candidateIds.contains(container.ownerMod.getLabel()) && !container.currentReferents.containsAll(candidateIds))
{
FMLLog.log.info("Found mod(s) {} containing declared API package {} (owned by {}) without associated API reference",candidateIds, pkg, container.ownerMod);

View File

@ -22,7 +22,6 @@ package net.minecraftforge.fml.common;
import java.util.List;
import java.util.Set;
import net.minecraftforge.fml.common.functions.ModNameFunction;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import com.google.common.base.Joiner;
@ -84,7 +83,7 @@ public class ModMetadata
public String getChildModList()
{
return Joiner.on(", ").join(Lists.transform(childMods, new ModNameFunction()));
return Joiner.on(", ").join(childMods.stream().map(ModContainer::getName).iterator());
}
public String printableSortingRules()

View File

@ -40,8 +40,6 @@ import static org.objectweb.asm.Type.VOID_TYPE;
import static org.objectweb.asm.Type.BOOLEAN_TYPE;
import static org.objectweb.asm.Type.getMethodDescriptor;
import java.util.List;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraftforge.fml.common.eventhandler.Event;

View File

@ -32,7 +32,6 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.patcher.ClassPatchManager;
import org.apache.logging.log4j.message.Message;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.tree.ClassNode;

View File

@ -19,8 +19,8 @@
package net.minecraftforge.fml.common.event;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import java.util.function.Function;
import java.util.Optional;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
@ -33,7 +33,6 @@ import net.minecraftforge.fml.common.Mod.Instance;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import org.apache.logging.log4j.Level;
import javax.annotation.Nonnull;
@ -186,14 +185,14 @@ public class FMLInterModComms {
@SuppressWarnings("unchecked")
public <T,V> Optional<Function<T,V>> getFunctionValue(Class<T> functionFrom, Class<V> functionTo) {
if (!isFunction) {
return Optional.absent();
return Optional.empty();
}
try {
Function<T,V> f = Class.forName((String) value).asSubclass(Function.class).newInstance();
return Optional.of(f);
} catch (Exception e) {
FMLLog.log.info("An error occurred instantiating the IMC function. key: {} value: {}, caller: {}", key,value,sender);
return Optional.absent();
return Optional.empty();
}
}

View File

@ -19,16 +19,14 @@
package net.minecraftforge.fml.common.event;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.LoaderState.ModState;
import org.apache.logging.log4j.Level;
import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
/**
@ -66,13 +64,7 @@ public class FMLPostInitializationEvent extends FMLStateEvent
{
if (Loader.isModLoaded(modId))
{
Class<?>[] args = Lists.transform(Lists.newArrayList(arguments),new Function<Object, Class<?>>() {
@Nullable
@Override
public Class<?> apply(@Nullable Object input) {
return input == null ? null : input.getClass();
}
}).toArray(new Class[0]);
Class<?>[] args = Arrays.stream(arguments).filter(Objects::nonNull).map(Object::getClass).toArray(Class<?>[]::new);
try
{
Class<?> clz = Class.forName(className,true,Loader.instance().getModClassLoader());
@ -82,9 +74,9 @@ public class FMLPostInitializationEvent extends FMLStateEvent
catch (Exception e)
{
FMLLog.log.info("An error occurred trying to build a soft depend proxy", e);
return Optional.absent();
return Optional.empty();
}
}
return Optional.absent();
return Optional.empty();
}
}

View File

@ -1,32 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.fml.common.functions;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import com.google.common.base.Function;
public class ArtifactVersionNameFunction implements Function<ArtifactVersion, String> {
@Override
public String apply(ArtifactVersion v)
{
return v.getLabel();
}
}

View File

@ -1,44 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.fml.common.functions;
import java.util.Iterator;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
public class GenericIterableFactory {
public static <T> Iterable<T> newCastingIterable(final Iterator<?> input, final Class<T> type)
{
return new Iterable<T>()
{
@Override
public Iterator<T> iterator()
{
return Iterators.transform(input, new TypeCastFunction<T>(type));
}
};
}
public static <T> Iterable<T> newCastingIterable(Iterable<?> input, Class<T> type)
{
return Iterables.transform(input, new TypeCastFunction<T>(type));
}
}

View File

@ -1,33 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.fml.common.functions;
import net.minecraftforge.fml.common.ModContainer;
import com.google.common.base.Function;
public final class ModIdFunction implements Function<ModContainer, String>
{
@Override
public String apply(ModContainer container)
{
return container.getModId();
}
}

View File

@ -1,34 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.fml.common.functions;
import net.minecraftforge.fml.common.ModContainer;
import com.google.common.base.Function;
public class ModNameFunction implements Function<ModContainer, String>
{
@Override
public String apply(ModContainer input)
{
return input.getName();
}
}

View File

@ -1,36 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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.fml.common.functions;
import com.google.common.base.Function;
public class TypeCastFunction<T> implements Function<Object, T> {
private Class<T> type;
public TypeCastFunction(Class<T> type)
{
this.type = type;
}
@Override
public T apply(Object input)
{
return type.cast(input);
}
}

View File

@ -40,8 +40,6 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.Level;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.collect.Lists;
import com.google.common.collect.Multiset;

View File

@ -23,8 +23,6 @@ import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
import net.minecraftforge.fml.common.network.internal.FMLMessage.CompleteHandshake;
import org.apache.logging.log4j.Level;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.ChannelHandler.Sharable;

View File

@ -33,8 +33,6 @@ import net.minecraftforge.fml.common.versioning.InvalidVersionSpecificationExcep
import net.minecraftforge.fml.common.versioning.VersionRange;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.Level;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;

View File

@ -19,8 +19,6 @@
package net.minecraftforge.fml.common.network.internal;
import org.apache.logging.log4j.Level;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.fml.client.FMLClientHandler;

View File

@ -36,7 +36,7 @@ import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.network.internal.FMLMessage.EntitySpawnMessage;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

View File

@ -44,7 +44,6 @@ import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.StartupQuery;
import net.minecraftforge.fml.common.eventhandler.EventBus;
import net.minecraftforge.fml.common.functions.GenericIterableFactory;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import net.minecraftforge.fml.relauncher.Side;
@ -190,7 +189,7 @@ public class FMLServerHandler implements IFMLSidedHandler
// rudimentary command processing, check for fml confirm/cancel and stop commands
synchronized (dedServer.pendingCommandList)
{
for (Iterator<PendingCommand> it = GenericIterableFactory.newCastingIterable(dedServer.pendingCommandList, PendingCommand.class).iterator(); it.hasNext(); )
for (Iterator<PendingCommand> it = dedServer.pendingCommandList.iterator(); it.hasNext(); )
{
String cmd = it.next().command.trim().toLowerCase();

View File

@ -24,7 +24,7 @@ import java.util.regex.Pattern;
import org.fusesource.jansi.Ansi;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.collect.ImmutableMap;
import net.minecraft.util.text.TextFormatting;

View File

@ -39,7 +39,7 @@ import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.fusesource.jansi.AnsiConsole;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Functions;
import jline.TerminalFactory;

View File

@ -24,7 +24,7 @@ import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.common.base.Function;
import java.util.function.Function;
import jline.console.ConsoleReader;
import net.minecraft.server.dedicated.DedicatedServer;

View File

@ -186,40 +186,38 @@ public class ModelAnimationDebug
public static void registerItems(RegistryEvent.Register<Item> event)
{
event.getRegistry().register(
new ItemBlock(TEST_BLOCK)
new ItemBlock(TEST_BLOCK)
{
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt)
{
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt)
{
return new ItemAnimationHolder();
}
}.setRegistryName(TEST_BLOCK.getRegistryName())
return new ItemAnimationHolder();
}
}.setRegistryName(TEST_BLOCK.getRegistryName())
);
}
}
@SubscribeEvent
public void registerModels(ModelRegistryEvent event)
{
B3DLoader.INSTANCE.addDomain(MODID);
ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation(TEST_ITEM.getRegistryName(), "inventory"));
ClientRegistry.bindTileEntitySpecialRenderer(Chest.class, new AnimationTESR<Chest>()
@SubscribeEvent
public static void registerModels(ModelRegistryEvent event)
{
@Override
public void handleEvents(Chest chest, float time, Iterable<Event> pastEvents)
B3DLoader.INSTANCE.addDomain(MODID);
ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation(TEST_ITEM.getRegistryName(), "inventory"));
ClientRegistry.bindTileEntitySpecialRenderer(Chest.class, new AnimationTESR<Chest>()
{
chest.handleEvents(time, pastEvents);
}
});
String entityName = MODID + ":entity_chest";
//EntityRegistry.registerGlobalEntityID(EntityChest.class, entityName, EntityRegistry.findGlobalUniqueEntityId());
EntityRegistry.registerModEntity(new ResourceLocation(entityName), EntityChest.class, entityName, 0, ModelAnimationDebug.instance, 64, 20, true, 0xFFAAAA00, 0xFFDDDD00);
RenderingRegistry.registerEntityRenderingHandler(EntityChest.class, new IRenderFactory<EntityChest>()
{
@SuppressWarnings("deprecation")
public Render<EntityChest> createRenderFor(RenderManager manager)
@Override
public void handleEvents(Chest chest, float time, Iterable<Event> pastEvents)
{
chest.handleEvents(time, pastEvents);
}
});
String entityName = MODID + ":entity_chest";
//EntityRegistry.registerGlobalEntityID(EntityChest.class, entityName, EntityRegistry.findGlobalUniqueEntityId());
EntityRegistry.registerModEntity(new ResourceLocation(entityName), EntityChest.class, entityName, 0, ModelAnimationDebug.instance, 64, 20, true, 0xFFAAAA00, 0xFFDDDD00);
RenderingRegistry.registerEntityRenderingHandler(EntityChest.class, new IRenderFactory<EntityChest>()
{
@SuppressWarnings("deprecation")
public Render<EntityChest> createRenderFor(RenderManager manager)
{
/*model = ModelLoaderRegistry.getModel(new ResourceLocation(ModelLoaderRegistryDebug.MODID, "block/chest.b3d"));
if(model instanceof IRetexturableModel)
{
@ -229,23 +227,24 @@ public class ModelAnimationDebug
{
model = ((IModelCustomData)model).process(ImmutableMap.of("mesh", "[\"Base\", \"Lid\"]"));
}*/
ResourceLocation location = new ModelResourceLocation(new ResourceLocation(MODID, blockName), "entity");
return new RenderLiving<EntityChest>(manager, new net.minecraftforge.client.model.animation.AnimationModelBase<EntityChest>(location, new VertexLighterSmoothAo(Minecraft.getMinecraft().getBlockColors()))
{
@Override
public void handleEvents(EntityChest chest, float time, Iterable<Event> pastEvents)
ResourceLocation location = new ModelResourceLocation(new ResourceLocation(MODID, blockName), "entity");
return new RenderLiving<EntityChest>(manager, new net.minecraftforge.client.model.animation.AnimationModelBase<EntityChest>(location, new VertexLighterSmoothAo(Minecraft.getMinecraft().getBlockColors()))
{
chest.handleEvents(time, pastEvents);
}
}, 0.5f)
{
protected ResourceLocation getEntityTexture(EntityChest entity)
@Override
public void handleEvents(EntityChest chest, float time, Iterable<Event> pastEvents)
{
chest.handleEvents(time, pastEvents);
}
}, 0.5f)
{
return TextureMap.LOCATION_BLOCKS_TEXTURE;
}
};
}
});
protected ResourceLocation getEntityTexture(EntityChest entity)
{
return TextureMap.LOCATION_BLOCKS_TEXTURE;
}
};
}
});
}
}
public static abstract class CommonProxy

View File

@ -327,12 +327,6 @@ public class ModelBakeEventDebug
return this.base;
}
@Override
public ItemCameraTransforms getItemCameraTransforms()
{
return ItemCameraTransforms.DEFAULT;
}
@Override
public ItemOverrideList getOverrides()
{

View File

@ -1,6 +1,6 @@
package net.minecraftforge.debug;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.UnmodifiableIterator;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
@ -380,7 +380,7 @@ public class ModelLoaderRegistryDebug
}
}
}
return Optional.absent();
return Optional.empty();
}
};