mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 02:55:17 +00:00
Merge branch '1.9'
This commit is contained in:
commit
f5781488d9
745 files changed
+18019
-14550
No files matched your search
@@ -9,12 +9,13 @@ import net.minecraft.command.CommandHandler;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import static net.minecraft.util.EnumChatFormatting.*;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import static net.minecraft.util.text.TextFormatting.*;
|
||||
|
||||
/**
|
||||
* The class that handles client-side chat commands. You should register any
|
||||
@@ -48,7 +49,7 @@ public class ClientCommandHandler extends CommandHandler
|
||||
String[] args = new String[temp.length - 1];
|
||||
String commandName = temp[0];
|
||||
System.arraycopy(temp, 1, args, 0, args.length);
|
||||
ICommand icommand = (ICommand) getCommands().get(commandName);
|
||||
ICommand icommand = getCommands().get(commandName);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -57,19 +58,19 @@ public class ClientCommandHandler extends CommandHandler
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (icommand.canCommandSenderUseCommand(sender))
|
||||
if (icommand.checkPermission(this.getServer(), sender))
|
||||
{
|
||||
CommandEvent event = new CommandEvent(icommand, sender, args);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
{
|
||||
if (event.exception != null)
|
||||
if (event.getException() != null)
|
||||
{
|
||||
throw event.exception;
|
||||
throw event.getException();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
icommand.processCommand(sender, args);
|
||||
this.tryExecute(sender, args, icommand, message);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -95,14 +96,14 @@ public class ClientCommandHandler extends CommandHandler
|
||||
}
|
||||
|
||||
//Couple of helpers because the mcp names are stupid and long...
|
||||
private ChatComponentTranslation format(EnumChatFormatting color, String str, Object... args)
|
||||
private TextComponentTranslation format(TextFormatting color, String str, Object... args)
|
||||
{
|
||||
ChatComponentTranslation ret = new ChatComponentTranslation(str, args);
|
||||
TextComponentTranslation ret = new TextComponentTranslation(str, args);
|
||||
ret.getChatStyle().setColor(color);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void autoComplete(String leftOfCursor, String full)
|
||||
public void autoComplete(String leftOfCursor)
|
||||
{
|
||||
latestAutoComplete = null;
|
||||
|
||||
@@ -136,4 +137,9 @@ public class ClientCommandHandler extends CommandHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MinecraftServer getServer() {
|
||||
return Minecraft.getMinecraft().getIntegratedServer();
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,7 @@ import net.minecraftforge.common.util.EnumHelper;
|
||||
|
||||
public class EnumHelperClient extends EnumHelper
|
||||
{
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static Class[][] clentTypes =
|
||||
private static Class<?>[][] clientTypes =
|
||||
{
|
||||
{GameType.class, int.class, String.class},
|
||||
{Options.class, String.class, boolean.class, boolean.class},
|
||||
@@ -32,6 +31,6 @@ public class EnumHelperClient extends EnumHelper
|
||||
|
||||
public static <T extends Enum<? >> T addEnum(Class<T> enumType, String enumName, Object... paramValues)
|
||||
{
|
||||
return addEnum(clentTypes, enumType, enumName, paramValues);
|
||||
return addEnum(clientTypes, enumType, enumName, paramValues);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import static net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.BOSSINFO;
|
||||
import static net.minecraftforge.common.ForgeVersion.Status.BETA;
|
||||
import static net.minecraftforge.common.ForgeVersion.Status.BETA_OUTDATED;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
@@ -7,8 +8,10 @@ import static org.lwjgl.opengl.GL20.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.vecmath.Matrix3f;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
@@ -17,20 +20,26 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.audio.SoundEventAccessorComposite;
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockFaceUV;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
|
||||
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.block.model.SimpleBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
@@ -39,19 +48,23 @@ import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.model.ModelRotation;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.BossInfoLerping;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
@@ -61,22 +74,28 @@ import net.minecraftforge.client.event.FOVUpdateEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.client.event.sound.PlaySoundEvent;
|
||||
import net.minecraftforge.client.model.IFlexibleBakedModel;
|
||||
import net.minecraftforge.client.model.IModelPart;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.TRSRTransformation;
|
||||
import net.minecraftforge.client.model.animation.Animation;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.common.ForgeVersion.Status;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.ITransformation;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.client.GuiJava8Error;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Java8VersionException;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.lwjgl.BufferUtils;
|
||||
@@ -84,7 +103,6 @@ import org.lwjgl.BufferUtils;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ForgeHooksClient
|
||||
{
|
||||
//private static final ResourceLocation ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
|
||||
@@ -94,28 +112,28 @@ public class ForgeHooksClient
|
||||
return FMLClientHandler.instance().getClient().renderEngine;
|
||||
}
|
||||
|
||||
public static String getArmorTexture(Entity entity, ItemStack armor, String _default, int slot, String type)
|
||||
public static String getArmorTexture(Entity entity, ItemStack armor, String _default, EntityEquipmentSlot slot, String type)
|
||||
{
|
||||
String result = armor.getItem().getArmorTexture(armor, entity, slot, type);
|
||||
return result != null ? result : _default;
|
||||
}
|
||||
|
||||
//Optifine Helper Functions u.u, these are here specifically for Optifine
|
||||
//Note: When using Optfine, these methods are invoked using reflection, which
|
||||
//Note: When using Optifine, these methods are invoked using reflection, which
|
||||
//incurs a major performance penalty.
|
||||
public static void orientBedCamera(IBlockAccess world, BlockPos pos, IBlockState state, Entity entity)
|
||||
{
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block != null && block.isBed(world, pos, entity))
|
||||
if (block != null && block.isBed(state, world, pos, entity))
|
||||
{
|
||||
glRotatef((float)(block.getBedDirection(world, pos).getHorizontalIndex() * 90), 0.0F, 1.0F, 0.0F);
|
||||
glRotatef((float)(block.getBedDirection(state, world, pos).getHorizontalIndex() * 90), 0.0F, 1.0F, 0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean onDrawBlockHighlight(RenderGlobal context, EntityPlayer player, MovingObjectPosition target, int subID, ItemStack currentItem, float partialTicks)
|
||||
public static boolean onDrawBlockHighlight(RenderGlobal context, EntityPlayer player, RayTraceResult target, int subID, float partialTicks)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(context, player, target, subID, currentItem, partialTicks));
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(context, player, target, subID, partialTicks));
|
||||
}
|
||||
|
||||
public static void dispatchRenderLast(RenderGlobal context, float partialTicks)
|
||||
@@ -131,7 +149,7 @@ public class ForgeHooksClient
|
||||
public static void onTextureStitchedPre(TextureMap map)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new TextureStitchEvent.Pre(map));
|
||||
ModelLoader.White.instance.register(map);
|
||||
ModelLoader.White.INSTANCE.register(map);
|
||||
}
|
||||
|
||||
public static void onTextureStitchedPost(TextureMap map)
|
||||
@@ -145,22 +163,16 @@ public class ForgeHooksClient
|
||||
renderPass = pass;
|
||||
}
|
||||
|
||||
static final ThreadLocal<EnumWorldBlockLayer> renderLayer = new ThreadLocal<EnumWorldBlockLayer>()
|
||||
{
|
||||
protected EnumWorldBlockLayer initialValue()
|
||||
{
|
||||
return EnumWorldBlockLayer.SOLID;
|
||||
}
|
||||
};
|
||||
static final ThreadLocal<BlockRenderLayer> renderLayer = new ThreadLocal<BlockRenderLayer>();
|
||||
|
||||
public static void setRenderLayer(EnumWorldBlockLayer layer)
|
||||
public static void setRenderLayer(BlockRenderLayer layer)
|
||||
{
|
||||
renderLayer.set(layer);
|
||||
}
|
||||
|
||||
public static ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, int slotID, ModelBiped _default)
|
||||
public static ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, EntityEquipmentSlot slot, ModelBiped _default)
|
||||
{
|
||||
ModelBiped model = itemStack.getItem().getArmorModel(entityLiving, itemStack, slotID, _default);
|
||||
ModelBiped model = itemStack.getItem().getArmorModel(entityLiving, itemStack, slot, _default);
|
||||
return model == null ? _default : model;
|
||||
}
|
||||
|
||||
@@ -194,11 +206,11 @@ public class ForgeHooksClient
|
||||
{
|
||||
FOVUpdateEvent fovUpdateEvent = new FOVUpdateEvent(entity, fov);
|
||||
MinecraftForge.EVENT_BUS.post(fovUpdateEvent);
|
||||
return fovUpdateEvent.newfov;
|
||||
return fovUpdateEvent.getNewfov();
|
||||
}
|
||||
|
||||
public static float getFOVModifier(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, float fov) {
|
||||
EntityViewRenderEvent.FOVModifier event = new EntityViewRenderEvent.FOVModifier(renderer, entity, block, renderPartialTicks, fov);
|
||||
|
||||
public static float getFOVModifier(EntityRenderer renderer, Entity entity, IBlockState state, double renderPartialTicks, float fov) {
|
||||
EntityViewRenderEvent.FOVModifier event = new EntityViewRenderEvent.FOVModifier(renderer, entity, state, renderPartialTicks, fov);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getFOV();
|
||||
}
|
||||
@@ -259,18 +271,30 @@ public class ForgeHooksClient
|
||||
//RenderingRegistry.registerBlockHandler(RenderBlockFluid.instance);
|
||||
}
|
||||
|
||||
public static void renderMainMenu(GuiMainMenu gui, FontRenderer font, int width, int height)
|
||||
private static int updatescrollcounter = 0;
|
||||
public static String renderMainMenu(GuiMainMenu gui, FontRenderer font, int width, int height, String splashText)
|
||||
{
|
||||
Status status = ForgeVersion.getStatus();
|
||||
if (status == BETA || status == BETA_OUTDATED)
|
||||
{
|
||||
// render a warning at the top of the screen,
|
||||
String line = I18n.format("forge.update.beta.1", EnumChatFormatting.RED, EnumChatFormatting.RESET);
|
||||
String line = I18n.format("forge.update.beta.1", TextFormatting.RED, TextFormatting.RESET);
|
||||
gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (0 * (font.FONT_HEIGHT + 1)), -1);
|
||||
line = I18n.format("forge.update.beta.2");
|
||||
gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (1 * (font.FONT_HEIGHT + 1)), -1);
|
||||
}
|
||||
|
||||
if (!Loader.instance().java8)
|
||||
{
|
||||
String line = I18n.format("fml.messages.java8warning.1", TextFormatting.RED, TextFormatting.RESET);
|
||||
gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (8 * (font.FONT_HEIGHT + 1)), -1);
|
||||
line = I18n.format("fml.messages.java8warning.2");
|
||||
gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (9 * (font.FONT_HEIGHT + 1)), -1);
|
||||
splashText = updatescrollcounter < 50 ? "UPDATE!" : "JAVA!";
|
||||
updatescrollcounter+=1;
|
||||
updatescrollcounter%=100;
|
||||
}
|
||||
|
||||
String line = null;
|
||||
switch(status)
|
||||
{
|
||||
@@ -287,17 +311,34 @@ public class ForgeHooksClient
|
||||
// if we have a line, render it in the bottom right, above Mojang's copyright line
|
||||
gui.drawString(font, line, width - font.getStringWidth(line) - 2, height - (2 * (font.FONT_HEIGHT + 1)), -1);
|
||||
}
|
||||
|
||||
return splashText;
|
||||
}
|
||||
|
||||
public static void mainMenuMouseClick(int mouseX, int mouseY, int mouseButton, FontRenderer font, int width)
|
||||
{
|
||||
if (!Loader.instance().java8)
|
||||
{
|
||||
if (mouseY >= (4 + (8 * 10)) && mouseY < (4 + (10 * 10)))
|
||||
{
|
||||
int w = font.getStringWidth(I18n.format("fml.messages.java8warning.1", TextFormatting.RED, TextFormatting.RESET));
|
||||
w = Math.max(w, font.getStringWidth(I18n.format("fml.messages.java8warning.2")));
|
||||
if (mouseX >= ((width - w) / 2) && mouseX <= ((width + w) / 2))
|
||||
{
|
||||
FMLClientHandler.instance().showGuiScreen(new GuiJava8Error(new Java8VersionException(Collections.<ModContainer>emptyList())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ISound playSound(SoundManager manager, ISound sound)
|
||||
{
|
||||
SoundEventAccessorComposite accessor = manager.sndHandler.getSound(sound.getSoundLocation());
|
||||
PlaySoundEvent e = new PlaySoundEvent(manager, sound, (accessor == null ? null : accessor.getSoundCategory()));
|
||||
PlaySoundEvent e = new PlaySoundEvent(manager, sound);
|
||||
MinecraftForge.EVENT_BUS.post(e);
|
||||
return e.result;
|
||||
return e.getResultSound();
|
||||
}
|
||||
|
||||
//static RenderBlocks worldRendererRB;
|
||||
//static RenderBlocks VertexBufferRB;
|
||||
static int worldRenderPass;
|
||||
|
||||
public static int getWorldRenderPass()
|
||||
@@ -312,51 +353,26 @@ public class ForgeHooksClient
|
||||
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.DrawScreenEvent.Post(screen, mouseX, mouseY, partialTicks));
|
||||
}
|
||||
|
||||
public static float getFogDensity(EntityRenderer renderer, Entity entity, Block block, float partial, float density)
|
||||
public static float getFogDensity(EntityRenderer renderer, Entity entity, IBlockState state, float partial, float density)
|
||||
{
|
||||
EntityViewRenderEvent.FogDensity event = new EntityViewRenderEvent.FogDensity(renderer, entity, block, partial, density);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return event.density;
|
||||
EntityViewRenderEvent.FogDensity event = new EntityViewRenderEvent.FogDensity(renderer, entity, state, partial, density);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return event.getDensity();
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void onFogRender(EntityRenderer renderer, Entity entity, Block block, float partial, int mode, float distance)
|
||||
public static void onFogRender(EntityRenderer renderer, Entity entity, IBlockState state, float partial, int mode, float distance)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EntityViewRenderEvent.RenderFogEvent(renderer, entity, block, partial, mode, distance));
|
||||
MinecraftForge.EVENT_BUS.post(new EntityViewRenderEvent.RenderFogEvent(renderer, entity, state, partial, mode, distance));
|
||||
}
|
||||
|
||||
/*
|
||||
public static void setWorldRendererRB(RenderBlocks renderBlocks)
|
||||
public static void onModelBake(ModelManager modelManager, IRegistry<ModelResourceLocation, IBakedModel> modelRegistry, ModelLoader modelLoader)
|
||||
{
|
||||
worldRendererRB = renderBlocks;
|
||||
MinecraftForge.EVENT_BUS.post(new ModelBakeEvent(modelManager, modelRegistry, modelLoader));
|
||||
modelLoader.onPostBakeEvent(modelRegistry);
|
||||
}
|
||||
|
||||
public static void onPreRenderWorld(WorldRenderer worldRenderer, int pass)
|
||||
{
|
||||
if(worldRendererRB != null)
|
||||
{
|
||||
worldRenderPass = pass;
|
||||
MinecraftForge.EVENT_BUS.post(new RenderWorldEvent.Pre(worldRenderer, (ChunkCache)worldRendererRB.blockAccess, worldRendererRB, pass));
|
||||
}
|
||||
}
|
||||
|
||||
public static void onPostRenderWorld(WorldRenderer worldRenderer, int pass)
|
||||
{
|
||||
if(worldRendererRB != null)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new RenderWorldEvent.Post(worldRenderer, (ChunkCache)worldRendererRB.blockAccess, worldRendererRB, pass));
|
||||
worldRenderPass = -1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public static void onModelBake(ModelManager modelManager, IRegistry<ModelResourceLocation, IBakedModel> modelRegistry, ModelBakery modelBakery)
|
||||
{
|
||||
ModelLoader loader = (ModelLoader)modelBakery;
|
||||
MinecraftForge.EVENT_BUS.post(new ModelBakeEvent(modelManager, modelRegistry, loader));
|
||||
loader.onPostBakeEvent(modelRegistry);
|
||||
}
|
||||
|
||||
public static Matrix4f getMatrix(ItemTransformVec3f transform)
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Matrix4f getMatrix(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform)
|
||||
{
|
||||
javax.vecmath.Matrix4f m = new javax.vecmath.Matrix4f(), t = new javax.vecmath.Matrix4f();
|
||||
m.setIdentity();
|
||||
@@ -378,18 +394,37 @@ public class ForgeHooksClient
|
||||
return m;
|
||||
}
|
||||
|
||||
public static IBakedModel handleCameraTransforms(IBakedModel model, ItemCameraTransforms.TransformType cameraTransformType)
|
||||
private static final Matrix4f flipX;
|
||||
static {
|
||||
flipX = new Matrix4f();
|
||||
flipX.setIdentity();
|
||||
flipX.m00 = -1;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static IBakedModel handleCameraTransforms(IBakedModel model, ItemCameraTransforms.TransformType cameraTransformType, boolean leftHandHackery)
|
||||
{
|
||||
if(model instanceof IPerspectiveAwareModel)
|
||||
{
|
||||
Pair<? extends IFlexibleBakedModel, Matrix4f> pair = ((IPerspectiveAwareModel)model).handlePerspective(cameraTransformType);
|
||||
Pair<? extends IBakedModel, Matrix4f> pair = ((IPerspectiveAwareModel)model).handlePerspective(cameraTransformType);
|
||||
|
||||
if(pair.getRight() != null) multiplyCurrentGlMatrix(pair.getRight());
|
||||
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
|
||||
{
|
||||
model.getItemCameraTransforms().applyTransform(cameraTransformType);
|
||||
//if(leftHandHackery) GlStateManager.scale(-1, 1, 1);
|
||||
ItemCameraTransforms.applyTransformSide(model.getItemCameraTransforms().getTransform(cameraTransformType), leftHandHackery);
|
||||
//if(leftHandHackery) GlStateManager.scale(-1, 1, 1);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
@@ -416,7 +451,7 @@ public class ForgeHooksClient
|
||||
VertexFormatElement attr = format.getElement(element);
|
||||
int count = attr.getElementCount();
|
||||
int constant = attr.getType().getGlConstant();
|
||||
buffer.position(format.func_181720_d(element));
|
||||
buffer.position(format.getOffset(element));
|
||||
switch(attrType)
|
||||
{
|
||||
case POSITION:
|
||||
@@ -501,15 +536,18 @@ public class ForgeHooksClient
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void putQuadColor(WorldRenderer renderer, BakedQuad quad, int color)
|
||||
public static void putQuadColor(VertexBuffer renderer, BakedQuad quad, int color)
|
||||
{
|
||||
float cr = color & 0xFF;
|
||||
float cb = color & 0xFF;
|
||||
float cg = (color >>> 8) & 0xFF;
|
||||
float cb = (color >>> 16) & 0xFF;
|
||||
float cr = (color >>> 16) & 0xFF;
|
||||
float ca = (color >>> 24) & 0xFF;
|
||||
VertexFormat format = quad.getFormat();
|
||||
int size = format.getIntegerSize();
|
||||
int offset = format.getColorOffset() / 4; // assumes that color is aligned
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
int vc = quad.getVertexData()[3 + 7 * i];
|
||||
int vc = quad.getVertexData()[offset + size * i];
|
||||
float vcr = vc & 0xFF;
|
||||
float vcg = (vc >>> 8) & 0xFF;
|
||||
float vcb = (vc >>> 16) & 0xFF;
|
||||
@@ -569,10 +607,11 @@ public class ForgeHooksClient
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<TRSRTransformation> applyTransform(ItemTransformVec3f transform, Optional<? extends IModelPart> part)
|
||||
@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();
|
||||
return Optional.of(new TRSRTransformation(transform));
|
||||
return Optional.of(TRSRTransformation.blockCenterToCorner(new TRSRTransformation(transform)));
|
||||
}
|
||||
|
||||
public static Optional<TRSRTransformation> applyTransform(Matrix4f matrix, Optional<? extends IModelPart> part)
|
||||
@@ -592,4 +631,78 @@ public class ForgeHooksClient
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IBakedModel getDamageModel(IBakedModel ibakedmodel, TextureAtlasSprite texture, IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
// TODO custom damage models
|
||||
// state = state.block.getExtendedState(state, world, pos);
|
||||
return (new SimpleBakedModel.Builder(state, ibakedmodel, texture, pos)).makeBakedModel();
|
||||
}
|
||||
|
||||
private static int slotMainHand = 0;
|
||||
// FIXME
|
||||
public static boolean shouldCauseReequipAnimation(ItemStack from, ItemStack to, int slot)
|
||||
{
|
||||
if (from == null && to != null) return true;
|
||||
if (from == null && to == null) return false;
|
||||
if (from != null && to == null) return true;
|
||||
boolean changed = false;
|
||||
if (slot != -1)
|
||||
{
|
||||
changed = slot != slotMainHand;
|
||||
slotMainHand = slot;
|
||||
}
|
||||
return from.getItem().shouldCauseReequipAnimation(from, to, changed);
|
||||
}
|
||||
|
||||
public static BlockFaceUV applyUVLock(BlockFaceUV blockFaceUV, EnumFacing originalSide, ITransformation rotation)
|
||||
{
|
||||
TRSRTransformation global = new TRSRTransformation(rotation.getMatrix());
|
||||
Matrix4f uv = global.getUVLockTransform(originalSide).getMatrix();
|
||||
Vector4f vec = new Vector4f(0, 0, 0, 1);
|
||||
vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(0)) / 16;
|
||||
vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(0)) / 16;
|
||||
uv.transform(vec);
|
||||
float uMin = 16 * vec.x; // / vec.w;
|
||||
float vMin = 16 * vec.y; // / vec.w;
|
||||
vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(2)) / 16;
|
||||
vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(2)) / 16;
|
||||
vec.z = 0;
|
||||
vec.w = 1;
|
||||
uv.transform(vec);
|
||||
float uMax = 16 * vec.x; // / vec.w;
|
||||
float vMax = 16 * vec.y; // / vec.w;
|
||||
if(uMin > uMax)
|
||||
{
|
||||
float t = uMin;
|
||||
uMin = uMax;
|
||||
uMax = t;
|
||||
}
|
||||
if(vMin > vMax)
|
||||
{
|
||||
float t = vMin;
|
||||
vMin = vMax;
|
||||
vMax = t;
|
||||
}
|
||||
float a = (float)Math.toRadians(blockFaceUV.rotation);
|
||||
Vector3f rv = new Vector3f(MathHelper.cos(a), MathHelper.sin(a), 0);
|
||||
Matrix3f rot = new Matrix3f();
|
||||
uv.getRotationScale(rot);
|
||||
rot.transform(rv);
|
||||
int angle = MathHelper.normalizeAngle(-(int)Math.round(Math.toDegrees(Math.atan2(rv.y, rv.x)) / 90) * 90, 360);
|
||||
return new BlockFaceUV(new float[]{ uMin, vMin, uMax, vMax }, angle);
|
||||
}
|
||||
|
||||
public static RenderGameOverlayEvent.BossInfo bossBarRenderPre(ScaledResolution res, BossInfoLerping bossInfo, int x, int y, int increment)
|
||||
{
|
||||
RenderGameOverlayEvent.BossInfo evt = new RenderGameOverlayEvent.BossInfo(new RenderGameOverlayEvent(Animation.getPartialTickTime(), res),
|
||||
BOSSINFO, bossInfo, x, y, increment);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt;
|
||||
}
|
||||
|
||||
public static void bossBarRenderPost(ScaledResolution res)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Post(new RenderGameOverlayEvent(Animation.getPartialTickTime(), res), BOSSINFO));
|
||||
}
|
||||
}
|
||||
@@ -23,17 +23,17 @@ import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.scoreboard.ScoreObjective;
|
||||
import net.minecraft.scoreboard.ScorePlayerTeam;
|
||||
import net.minecraft.scoreboard.Scoreboard;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.FoodStats;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StringUtils;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
@@ -88,8 +88,8 @@ public class GuiIngameForge extends GuiIngame
|
||||
eventParent = new RenderGameOverlayEvent(partialTicks, res);
|
||||
int width = res.getScaledWidth();
|
||||
int height = res.getScaledHeight();
|
||||
renderHealthMount = mc.thePlayer.ridingEntity instanceof EntityLivingBase;
|
||||
renderFood = mc.thePlayer.ridingEntity == null;
|
||||
renderHealthMount = mc.thePlayer.getRidingEntity() instanceof EntityLivingBase;
|
||||
renderFood = mc.thePlayer.getRidingEntity() == null;
|
||||
renderJumpBar = mc.thePlayer.isRidingHorse();
|
||||
|
||||
right_height = 39;
|
||||
@@ -107,25 +107,27 @@ public class GuiIngameForge extends GuiIngame
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
}
|
||||
|
||||
if (renderHelmet) renderHelmet(res, partialTicks);
|
||||
|
||||
if (renderPortal && !mc.thePlayer.isPotionActive(Potion.confusion))
|
||||
if (renderPortal && !mc.thePlayer.isPotionActive(MobEffects.confusion))
|
||||
{
|
||||
renderPortal(res, partialTicks);
|
||||
}
|
||||
|
||||
if (renderHotbar) renderTooltip(res, partialTicks);
|
||||
if (renderHotbar) renderHotbar(res, partialTicks);
|
||||
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
zLevel = -90.0F;
|
||||
rand.setSeed((long)(updateCounter * 312871));
|
||||
|
||||
if (renderCrosshairs) renderCrosshairs(width, height);
|
||||
if (renderCrosshairs) renderCrosshairs(partialTicks);
|
||||
if (renderBossHealth) renderBossHealth();
|
||||
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
if (this.mc.playerController.shouldDrawHUD() && this.mc.getRenderViewEntity() instanceof EntityPlayer)
|
||||
{
|
||||
if (renderHealth) renderHealth(width, height);
|
||||
@@ -134,6 +136,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
if (renderHealthMount) renderHealthMount(width, height);
|
||||
if (renderAir) renderAir(width, height);
|
||||
}
|
||||
|
||||
renderSleepFade(width, height);
|
||||
|
||||
if (renderJumpBar)
|
||||
@@ -145,9 +148,11 @@ public class GuiIngameForge extends GuiIngame
|
||||
renderExperience(width, height);
|
||||
}
|
||||
|
||||
renderToolHightlight(res);
|
||||
renderToolHighlight(res);
|
||||
renderHUDText(width, height);
|
||||
renderPotionIcons(res);
|
||||
renderRecordOverlay(width, height, partialTicks);
|
||||
renderSubtitles(res);
|
||||
renderTitle(width, height, partialTicks);
|
||||
|
||||
|
||||
@@ -185,31 +190,38 @@ public class GuiIngameForge extends GuiIngame
|
||||
return res;
|
||||
}
|
||||
|
||||
protected void renderCrosshairs(int width, int height)
|
||||
protected void renderCrosshairs(float partialTicks)
|
||||
{
|
||||
if (pre(CROSSHAIRS)) return;
|
||||
if (this.showCrosshair())
|
||||
{
|
||||
bind(Gui.icons);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR, 1, 0);
|
||||
GlStateManager.enableAlpha();
|
||||
drawTexturedModalRect(width / 2 - 7, height / 2 - 7, 0, 0, 16, 16);
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
bind(Gui.icons);
|
||||
GlStateManager.enableBlend();
|
||||
super.renderAttackIndicator(partialTicks, res);
|
||||
post(CROSSHAIRS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderPotionIcons(ScaledResolution resolution)
|
||||
{
|
||||
if (pre(POTION_ICONS)) return;
|
||||
super.renderPotionEffects(resolution);
|
||||
post(POTION_ICONS);
|
||||
}
|
||||
|
||||
protected void renderSubtitles(ScaledResolution resolution)
|
||||
{
|
||||
if (pre(SUBTITLES)) return;
|
||||
this.overlaySubtitle.renderSubtitles(res);
|
||||
post(SUBTITLES);
|
||||
}
|
||||
|
||||
//@Override
|
||||
protected void renderBossHealth()
|
||||
{
|
||||
if (pre(BOSSHEALTH)) return;
|
||||
bind(Gui.icons);
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
mc.mcProfiler.startSection("bossHealth");
|
||||
GlStateManager.enableBlend();
|
||||
super.renderBossHealth();
|
||||
this.overlayBoss.renderBossHealth();
|
||||
GlStateManager.disableBlend();
|
||||
mc.mcProfiler.endSection();
|
||||
post(BOSSHEALTH);
|
||||
@@ -284,7 +296,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderTooltip(ScaledResolution res, float partialTicks)
|
||||
protected void renderHotbar(ScaledResolution res, float partialTicks)
|
||||
{
|
||||
if (pre(HOTBAR)) return;
|
||||
|
||||
@@ -294,7 +306,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
}
|
||||
else
|
||||
{
|
||||
super.renderTooltip(res, partialTicks);
|
||||
super.renderHotbar(res, partialTicks);
|
||||
}
|
||||
|
||||
post(HOTBAR);
|
||||
@@ -359,9 +371,9 @@ public class GuiIngameForge extends GuiIngame
|
||||
this.playerHealth = health;
|
||||
int healthLast = this.lastPlayerHealth;
|
||||
|
||||
IAttributeInstance attrMaxHealth = player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
|
||||
IAttributeInstance attrMaxHealth = player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH);
|
||||
float healthMax = (float)attrMaxHealth.getAttributeValue();
|
||||
float absorb = player.getAbsorptionAmount();
|
||||
float absorb = MathHelper.ceiling_float_int(player.getAbsorptionAmount());
|
||||
|
||||
int healthRows = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F / 10.0F);
|
||||
int rowHeight = Math.max(10 - (healthRows - 2), 3);
|
||||
@@ -374,7 +386,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
if (rowHeight != 10) left_height += 10 - rowHeight;
|
||||
|
||||
int regen = -1;
|
||||
if (player.isPotionActive(Potion.regeneration))
|
||||
if (player.isPotionActive(MobEffects.regeneration))
|
||||
{
|
||||
regen = updateCounter % 25;
|
||||
}
|
||||
@@ -382,8 +394,8 @@ public class GuiIngameForge extends GuiIngame
|
||||
final int TOP = 9 * (mc.theWorld.getWorldInfo().isHardcoreModeEnabled() ? 5 : 0);
|
||||
final int BACKGROUND = (highlight ? 25 : 16);
|
||||
int MARGIN = 16;
|
||||
if (player.isPotionActive(Potion.poison)) MARGIN += 36;
|
||||
else if (player.isPotionActive(Potion.wither)) MARGIN += 72;
|
||||
if (player.isPotionActive(MobEffects.poison)) MARGIN += 36;
|
||||
else if (player.isPotionActive(MobEffects.wither)) MARGIN += 72;
|
||||
float absorbRemaining = absorb;
|
||||
|
||||
for (int i = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F) - 1; i >= 0; --i)
|
||||
@@ -409,10 +421,15 @@ public class GuiIngameForge extends GuiIngame
|
||||
if (absorbRemaining > 0.0F)
|
||||
{
|
||||
if (absorbRemaining == absorb && absorb % 2.0F == 1.0F)
|
||||
{
|
||||
drawTexturedModalRect(x, y, MARGIN + 153, TOP, 9, 9); //17
|
||||
absorbRemaining -= 1.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawTexturedModalRect(x, y, MARGIN + 144, TOP, 9, 9); //16
|
||||
absorbRemaining -= 2.0F;
|
||||
absorbRemaining -= 2.0F;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -450,21 +467,21 @@ public class GuiIngameForge extends GuiIngame
|
||||
int x = left - i * 8 - 9;
|
||||
int y = top;
|
||||
int icon = 16;
|
||||
byte backgound = 0;
|
||||
byte background = 0;
|
||||
|
||||
if (mc.thePlayer.isPotionActive(Potion.hunger))
|
||||
if (mc.thePlayer.isPotionActive(MobEffects.hunger))
|
||||
{
|
||||
icon += 36;
|
||||
backgound = 13;
|
||||
background = 13;
|
||||
}
|
||||
if (unused) backgound = 1; //Probably should be a += 1 but vanilla never uses this
|
||||
if (unused) background = 1; //Probably should be a += 1 but vanilla never uses this
|
||||
|
||||
if (player.getFoodStats().getSaturationLevel() <= 0.0F && updateCounter % (level * 3 + 1) == 0)
|
||||
{
|
||||
y = top + (rand.nextInt(3) - 1);
|
||||
}
|
||||
|
||||
drawTexturedModalRect(x, y, 16 + backgound * 9, 27, 9, 9);
|
||||
drawTexturedModalRect(x, y, 16 + background * 9, 27, 9, 9);
|
||||
|
||||
if (unused)
|
||||
{
|
||||
@@ -586,7 +603,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
post(JUMPBAR);
|
||||
}
|
||||
|
||||
protected void renderToolHightlight(ScaledResolution res)
|
||||
protected void renderToolHighlight(ScaledResolution res)
|
||||
{
|
||||
if (this.mc.gameSettings.heldItemTooltips && !this.mc.playerController.isSpectator())
|
||||
{
|
||||
@@ -596,7 +613,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
{
|
||||
String name = this.highlightingItemStack.getDisplayName();
|
||||
if (this.highlightingItemStack.hasDisplayName())
|
||||
name = EnumChatFormatting.ITALIC + name;
|
||||
name = TextFormatting.ITALIC + name;
|
||||
|
||||
name = this.highlightingItemStack.getItem().getHighlightTip(this.highlightingItemStack, name);
|
||||
|
||||
@@ -610,7 +627,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
FontRenderer font = highlightingItemStack.getItem().getFontRenderer(highlightingItemStack);
|
||||
if (font != null)
|
||||
{
|
||||
@@ -631,7 +648,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
}
|
||||
else if (this.mc.thePlayer.isSpectator())
|
||||
{
|
||||
this.spectatorGui.func_175263_a(res);
|
||||
this.spectatorGui.renderSelectedItem(res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -704,7 +721,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate((float)(width / 2), (float)(height - 68), 0.0F);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
int color = (recordIsPlaying ? Color.HSBtoRGB(hue / 50.0F, 0.7F, 0.6F) & WHITE : WHITE);
|
||||
fontrenderer.drawString(recordPlaying, -fontrenderer.getStringWidth(recordPlaying) / 2, -4, color | (opacity << 24));
|
||||
GlStateManager.disableBlend();
|
||||
@@ -717,18 +734,18 @@ public class GuiIngameForge extends GuiIngame
|
||||
|
||||
protected void renderTitle(int width, int height, float partialTicks)
|
||||
{
|
||||
if (field_175195_w > 0)
|
||||
if (titlesTimer > 0)
|
||||
{
|
||||
mc.mcProfiler.startSection("titleAndSubtitle");
|
||||
float age = (float)this.field_175195_w - partialTicks;
|
||||
float age = (float)this.titlesTimer - partialTicks;
|
||||
int opacity = 255;
|
||||
|
||||
if (field_175195_w > field_175193_B + field_175192_A)
|
||||
if (titlesTimer > titleFadeOut + titleDisplayTime)
|
||||
{
|
||||
float f3 = (float)(field_175199_z + field_175192_A + field_175193_B) - age;
|
||||
opacity = (int)(f3 * 255.0F / (float)field_175199_z);
|
||||
float f3 = (float)(titleFadeIn + titleDisplayTime + titleFadeOut) - age;
|
||||
opacity = (int)(f3 * 255.0F / (float)titleFadeIn);
|
||||
}
|
||||
if (field_175195_w <= field_175193_B) opacity = (int)(age * 255.0F / (float)this.field_175193_B);
|
||||
if (titlesTimer <= titleFadeOut) opacity = (int)(age * 255.0F / (float)this.titleFadeOut);
|
||||
|
||||
opacity = MathHelper.clamp_int(opacity, 0, 255);
|
||||
|
||||
@@ -737,15 +754,15 @@ public class GuiIngameForge extends GuiIngame
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate((float)(width / 2), (float)(height / 2), 0.0F);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(4.0F, 4.0F, 4.0F);
|
||||
int l = opacity << 24 & -16777216;
|
||||
this.getFontRenderer().drawString(this.field_175201_x, (float)(-this.getFontRenderer().getStringWidth(this.field_175201_x) / 2), -10.0F, 16777215 | l, true);
|
||||
this.getFontRenderer().drawString(this.displayedTitle, (float)(-this.getFontRenderer().getStringWidth(this.displayedTitle) / 2), -10.0F, 16777215 | l, true);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(2.0F, 2.0F, 2.0F);
|
||||
this.getFontRenderer().drawString(this.field_175200_y, (float)(-this.getFontRenderer().getStringWidth(this.field_175200_y) / 2), 5.0F, 16777215 | l, true);
|
||||
this.getFontRenderer().drawString(this.displayedSubTitle, (float)(-this.getFontRenderer().getStringWidth(this.displayedSubTitle) / 2), 5.0F, 16777215 | l, true);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.popMatrix();
|
||||
@@ -763,7 +780,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate((float)event.posX, (float)event.posY, 0.0F);
|
||||
GlStateManager.translate((float) event.getPosX(), (float) event.getPosY(), 0.0F);
|
||||
persistantChatGUI.drawChat(updateCounter);
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
@@ -793,7 +810,7 @@ public class GuiIngameForge extends GuiIngame
|
||||
protected void renderHealthMount(int width, int height)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer)mc.getRenderViewEntity();
|
||||
Entity tmp = player.ridingEntity;
|
||||
Entity tmp = player.getRidingEntity();
|
||||
if (!(tmp instanceof EntityLivingBase)) return;
|
||||
|
||||
bind(icons);
|
||||
|
||||
@@ -8,9 +8,9 @@ import com.google.common.collect.Maps;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
import gnu.trove.procedure.TIntObjectProcedure;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.util.BitSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.minecraft.client.renderer.RegionRenderCache;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumWorldBlockLayer;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -26,7 +26,7 @@ public class MinecraftForgeClient
|
||||
return ForgeHooksClient.renderPass;
|
||||
}
|
||||
|
||||
public static EnumWorldBlockLayer getRenderLayer()
|
||||
public static BlockRenderLayer getRenderLayer()
|
||||
{
|
||||
return ForgeHooksClient.renderLayer.get();
|
||||
}
|
||||
|
||||
@@ -1,23 +1,38 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@Cancelable
|
||||
public class ClientChatReceivedEvent extends Event
|
||||
{
|
||||
public IChatComponent message;
|
||||
private ITextComponent message;
|
||||
private final byte type;
|
||||
public ClientChatReceivedEvent(byte type, ITextComponent message)
|
||||
{
|
||||
this.type = type;
|
||||
this.setMessage(message);
|
||||
}
|
||||
|
||||
public ITextComponent getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(ITextComponent message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Introduced in 1.8:
|
||||
* 0 : Standard Text Message
|
||||
* 1 : 'System' message, displayed as standard text.
|
||||
* 2 : 'Status' message, displayed above action bar, where song notifications are.
|
||||
*/
|
||||
public final byte type;
|
||||
public ClientChatReceivedEvent(byte type, IChatComponent message)
|
||||
public byte getType()
|
||||
{
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -3,28 +3,30 @@ package net.minecraftforge.client.event;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
|
||||
@Cancelable
|
||||
public class DrawBlockHighlightEvent extends Event
|
||||
{
|
||||
public final RenderGlobal context;
|
||||
public final EntityPlayer player;
|
||||
public final MovingObjectPosition target;
|
||||
public final int subID;
|
||||
public final ItemStack currentItem;
|
||||
public final float partialTicks;
|
||||
|
||||
public DrawBlockHighlightEvent(RenderGlobal context, EntityPlayer player, MovingObjectPosition target, int subID, ItemStack currentItem, float partialTicks)
|
||||
private final RenderGlobal context;
|
||||
private final EntityPlayer player;
|
||||
private final RayTraceResult target;
|
||||
private final int subID;
|
||||
private final float partialTicks;
|
||||
|
||||
public DrawBlockHighlightEvent(RenderGlobal context, EntityPlayer player, RayTraceResult target, int subID, float partialTicks)
|
||||
{
|
||||
this.context = context;
|
||||
this.player = player;
|
||||
this.target = target;
|
||||
this.subID = subID;
|
||||
this.currentItem = currentItem;
|
||||
this.partialTicks= partialTicks;
|
||||
}
|
||||
|
||||
public RenderGlobal getContext() { return context; }
|
||||
public EntityPlayer getPlayer() { return player; }
|
||||
public RayTraceResult getTarget() { return target; }
|
||||
public int getSubID() { return subID; }
|
||||
public float getPartialTicks() { return partialTicks; }
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
@@ -12,31 +12,61 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
*/
|
||||
public abstract class EntityViewRenderEvent extends Event
|
||||
{
|
||||
public final EntityRenderer renderer;
|
||||
public final Entity entity;
|
||||
public final Block block;
|
||||
public final double renderPartialTicks;
|
||||
private final EntityRenderer renderer;
|
||||
private final Entity entity;
|
||||
private final IBlockState state;
|
||||
private final double renderPartialTicks;
|
||||
|
||||
public EntityViewRenderEvent(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks)
|
||||
public EntityViewRenderEvent(EntityRenderer renderer, Entity entity, IBlockState state, double renderPartialTicks)
|
||||
{
|
||||
this.renderer = renderer;
|
||||
this.entity = entity;
|
||||
this.block = block;
|
||||
this.state = state;
|
||||
this.renderPartialTicks = renderPartialTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
public EntityRenderer getRenderer()
|
||||
{
|
||||
return renderer;
|
||||
}
|
||||
|
||||
public Entity getEntity()
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
|
||||
public IBlockState getState()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
public double getRenderPartialTicks()
|
||||
{
|
||||
return renderPartialTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event that allows any feature to customize the fog density the player sees.
|
||||
* NOTE: In order to make this event have an effect, you must cancel the event
|
||||
*/
|
||||
@Cancelable
|
||||
public static class FogDensity extends EntityViewRenderEvent
|
||||
{
|
||||
public float density;
|
||||
private float density;
|
||||
|
||||
public FogDensity(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, float density)
|
||||
public FogDensity(EntityRenderer renderer, Entity entity, IBlockState state, double renderPartialTicks, float density)
|
||||
{
|
||||
super(renderer, entity, state, renderPartialTicks);
|
||||
this.setDensity(density);
|
||||
}
|
||||
|
||||
public float getDensity()
|
||||
{
|
||||
return density;
|
||||
}
|
||||
|
||||
public void setDensity(float density)
|
||||
{
|
||||
super(renderer, entity, block, renderPartialTicks);
|
||||
this.density = density;
|
||||
}
|
||||
}
|
||||
@@ -47,15 +77,25 @@ public abstract class EntityViewRenderEvent extends Event
|
||||
@HasResult
|
||||
public static class RenderFogEvent extends EntityViewRenderEvent
|
||||
{
|
||||
public final int fogMode;
|
||||
public final float farPlaneDistance;
|
||||
private final int fogMode;
|
||||
private final float farPlaneDistance;
|
||||
|
||||
public RenderFogEvent(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, int fogMode, float farPlaneDistance)
|
||||
public RenderFogEvent(EntityRenderer renderer, Entity entity, IBlockState state, double renderPartialTicks, int fogMode, float farPlaneDistance)
|
||||
{
|
||||
super(renderer, entity, block, renderPartialTicks);
|
||||
super(renderer, entity, state, renderPartialTicks);
|
||||
this.fogMode = fogMode;
|
||||
this.farPlaneDistance = farPlaneDistance;
|
||||
}
|
||||
|
||||
public int getFogMode()
|
||||
{
|
||||
return fogMode;
|
||||
}
|
||||
|
||||
public float getFarPlaneDistance()
|
||||
{
|
||||
return farPlaneDistance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,17 +104,24 @@ public abstract class EntityViewRenderEvent extends Event
|
||||
*/
|
||||
public static class FogColors extends EntityViewRenderEvent
|
||||
{
|
||||
public float red;
|
||||
public float green;
|
||||
public float blue;
|
||||
private float red;
|
||||
private float green;
|
||||
private float blue;
|
||||
|
||||
public FogColors(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, float red, float green, float blue)
|
||||
public FogColors(EntityRenderer renderer, Entity entity, IBlockState state, double renderPartialTicks, float red, float green, float blue)
|
||||
{
|
||||
super(renderer, entity, block, renderPartialTicks);
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
super(renderer, entity, state, renderPartialTicks);
|
||||
this.setRed(red);
|
||||
this.setGreen(green);
|
||||
this.setBlue(blue);
|
||||
}
|
||||
|
||||
public float getRed() { return red; }
|
||||
public void setRed(float red) { this.red = red; }
|
||||
public float getGreen() { return green; }
|
||||
public void setGreen(float green) { this.green = green; }
|
||||
public float getBlue() { return blue; }
|
||||
public void setBlue(float blue) { this.blue = blue; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,17 +129,24 @@ public abstract class EntityViewRenderEvent extends Event
|
||||
*/
|
||||
public static class CameraSetup extends EntityViewRenderEvent
|
||||
{
|
||||
public float yaw;
|
||||
public float pitch;
|
||||
public float roll;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private float roll;
|
||||
|
||||
public CameraSetup(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, float yaw, float pitch, float roll)
|
||||
public CameraSetup(EntityRenderer renderer, Entity entity, IBlockState state, double renderPartialTicks, float yaw, float pitch, float roll)
|
||||
{
|
||||
super(renderer, entity, block, renderPartialTicks);
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
this.roll = roll;
|
||||
super(renderer, entity, state, renderPartialTicks);
|
||||
this.setYaw(yaw);
|
||||
this.setPitch(pitch);
|
||||
this.setRoll(roll);
|
||||
}
|
||||
|
||||
public float getYaw() { return yaw; }
|
||||
public void setYaw(float yaw) { this.yaw = yaw; }
|
||||
public float getPitch() { return pitch; }
|
||||
public void setPitch(float pitch) { this.pitch = pitch; }
|
||||
public float getRoll() { return roll; }
|
||||
public void setRoll(float roll) { this.roll = roll; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,8 +157,8 @@ public abstract class EntityViewRenderEvent extends Event
|
||||
{
|
||||
private float fov;
|
||||
|
||||
public FOVModifier(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, float fov) {
|
||||
super(renderer, entity, block, renderPartialTicks);
|
||||
public FOVModifier(EntityRenderer renderer, Entity entity, IBlockState state, double renderPartialTicks, float fov) {
|
||||
super(renderer, entity, state, renderPartialTicks);
|
||||
this.setFOV(fov);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,34 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
*/
|
||||
public class FOVUpdateEvent extends Event
|
||||
{
|
||||
public final EntityPlayer entity;
|
||||
public final float fov;
|
||||
public float newfov;
|
||||
private final EntityPlayer entity;
|
||||
private final float fov;
|
||||
private float newfov;
|
||||
|
||||
public FOVUpdateEvent(EntityPlayer entity, float fov)
|
||||
{
|
||||
this.entity = entity;
|
||||
this.fov = fov;
|
||||
this.newfov = fov;
|
||||
this.setNewfov(fov);
|
||||
}
|
||||
|
||||
public EntityPlayer getEntity()
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
|
||||
public float getFov()
|
||||
{
|
||||
return fov;
|
||||
}
|
||||
|
||||
public float getNewfov()
|
||||
{
|
||||
return newfov;
|
||||
}
|
||||
|
||||
public void setNewfov(float newfov)
|
||||
{
|
||||
this.newfov = newfov;
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,18 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
@Cancelable
|
||||
public class GuiOpenEvent extends Event
|
||||
{
|
||||
public GuiScreen gui;
|
||||
private GuiScreen gui;
|
||||
public GuiOpenEvent(GuiScreen gui)
|
||||
{
|
||||
this.setGui(gui);
|
||||
}
|
||||
|
||||
public GuiScreen getGui()
|
||||
{
|
||||
return gui;
|
||||
}
|
||||
|
||||
public void setGui(GuiScreen gui)
|
||||
{
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@@ -22,29 +22,44 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiScreenEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The GuiScreen object generating this event.
|
||||
*/
|
||||
public final GuiScreen gui;
|
||||
private final GuiScreen gui;
|
||||
|
||||
public GuiScreenEvent(GuiScreen gui)
|
||||
{
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GuiScreen object generating this event.
|
||||
*/
|
||||
public GuiScreen getGui()
|
||||
{
|
||||
return gui;
|
||||
}
|
||||
|
||||
public static class InitGuiEvent extends GuiScreenEvent
|
||||
{
|
||||
/**
|
||||
* The {@code buttonList} field from the GuiScreen object referenced by {@code gui}.
|
||||
*/
|
||||
public List<GuiButton> buttonList;
|
||||
private List<GuiButton> buttonList;
|
||||
|
||||
public InitGuiEvent(GuiScreen gui, List<GuiButton> buttonList)
|
||||
{
|
||||
super(gui);
|
||||
this.setButtonList(buttonList);
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@code buttonList} field from the GuiScreen object referenced by {@code gui}.
|
||||
*/
|
||||
public List<GuiButton> getButtonList()
|
||||
{
|
||||
return buttonList;
|
||||
}
|
||||
|
||||
public void setButtonList(List<GuiButton> buttonList)
|
||||
{
|
||||
this.buttonList = buttonList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This event fires just after initializing {@code GuiScreen.mc}, {@code GuiScreen.fontRendererObj},
|
||||
* {@code GuiScreen.width}, and {@code GuiScreen.height}, and just before calling {@code GuiScreen.buttonList.clear()}
|
||||
@@ -78,18 +93,9 @@ public class GuiScreenEvent extends Event
|
||||
|
||||
public static class DrawScreenEvent extends GuiScreenEvent
|
||||
{
|
||||
/**
|
||||
* The x coordinate of the mouse pointer on the screen.
|
||||
*/
|
||||
public final int mouseX;
|
||||
/**
|
||||
* The y coordinate of the mouse pointer on the screen.
|
||||
*/
|
||||
public final int mouseY;
|
||||
/**
|
||||
* Partial render ticks elapsed.
|
||||
*/
|
||||
public final float renderPartialTicks;
|
||||
private final int mouseX;
|
||||
private final int mouseY;
|
||||
private final float renderPartialTicks;
|
||||
|
||||
public DrawScreenEvent(GuiScreen gui, int mouseX, int mouseY, float renderPartialTicks)
|
||||
{
|
||||
@@ -98,7 +104,31 @@ public class GuiScreenEvent extends Event
|
||||
this.mouseY = mouseY;
|
||||
this.renderPartialTicks = renderPartialTicks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The x coordinate of the mouse pointer on the screen.
|
||||
*/
|
||||
public int getMouseX()
|
||||
{
|
||||
return mouseX;
|
||||
}
|
||||
|
||||
/**
|
||||
* The y coordinate of the mouse pointer on the screen.
|
||||
*/
|
||||
public int getMouseY()
|
||||
{
|
||||
return mouseY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Partial render ticks elapsed.
|
||||
*/
|
||||
public float getRenderPartialTicks()
|
||||
{
|
||||
return renderPartialTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires just before {@code GuiScreen.drawScreen()} is called.
|
||||
* Cancel this event to skip {@code GuiScreen.drawScreen()}.
|
||||
@@ -159,25 +189,59 @@ public class GuiScreenEvent extends Event
|
||||
return mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires in {@code InventoryEffectRenderer.updateActivePotionEffects()}
|
||||
* when potion effects are active and the gui wants to move over.
|
||||
* Cancel this event to prevent the Gui from being moved.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class PotionShiftEvent extends GuiScreenEvent
|
||||
{
|
||||
public PotionShiftEvent(GuiScreen gui)
|
||||
{
|
||||
super(gui);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ActionPerformedEvent extends GuiScreenEvent
|
||||
{
|
||||
/**
|
||||
* The button that was clicked.
|
||||
*/
|
||||
public GuiButton button;
|
||||
/**
|
||||
* A COPY of the {@code buttonList} field from the GuiScreen referenced by {@code gui}.
|
||||
*/
|
||||
public List<GuiButton> buttonList;
|
||||
private GuiButton button;
|
||||
private List<GuiButton> buttonList;
|
||||
|
||||
public ActionPerformedEvent(GuiScreen gui, GuiButton button, List<GuiButton> buttonList)
|
||||
{
|
||||
super(gui);
|
||||
this.button = button;
|
||||
this.buttonList = new ArrayList<GuiButton>(buttonList);
|
||||
this.setButton(button);
|
||||
this.setButtonList(new ArrayList<GuiButton>(buttonList));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The button that was clicked.
|
||||
*/
|
||||
public GuiButton getButton()
|
||||
{
|
||||
return button;
|
||||
}
|
||||
|
||||
public void setButton(GuiButton button)
|
||||
{
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
/**
|
||||
* A COPY of the {@code buttonList} field from the GuiScreen referenced by {@code gui}.
|
||||
*/
|
||||
public List<GuiButton> getButtonList()
|
||||
{
|
||||
return buttonList;
|
||||
}
|
||||
|
||||
public void setButtonList(List<GuiButton> buttonList)
|
||||
{
|
||||
this.buttonList = buttonList;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires once it has been determined that a GuiButton object has been clicked.
|
||||
* Cancel this event to bypass {@code GuiScreen.actionPerformed()}.
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.util.IRegistry;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@@ -12,25 +11,32 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
* Fired when the ModelManager is notified of the resource manager reloading.
|
||||
* Called after model registry is setup, but before it's passed to BlockModelShapes.
|
||||
*/
|
||||
// TODO: try to merge with ICustomModelLoader
|
||||
public class ModelBakeEvent extends Event
|
||||
{
|
||||
public final ModelManager modelManager;
|
||||
public final IRegistry<ModelResourceLocation, IBakedModel> modelRegistry;
|
||||
@Deprecated
|
||||
public final ModelBakery modelBakery;
|
||||
public final ModelLoader modelLoader;
|
||||
|
||||
@Deprecated
|
||||
public ModelBakeEvent(ModelManager modelManager, IRegistry<ModelResourceLocation, IBakedModel> modelRegistry, ModelBakery modelBakery)
|
||||
{
|
||||
this(modelManager, modelRegistry, (ModelLoader)modelBakery);
|
||||
}
|
||||
private final ModelManager modelManager;
|
||||
private final IRegistry<ModelResourceLocation, IBakedModel> modelRegistry;
|
||||
private final ModelLoader modelLoader;
|
||||
|
||||
public ModelBakeEvent(ModelManager modelManager, IRegistry<ModelResourceLocation, IBakedModel> modelRegistry, ModelLoader modelLoader)
|
||||
{
|
||||
this.modelManager = modelManager;
|
||||
this.modelRegistry = modelRegistry;
|
||||
this.modelBakery = modelLoader;
|
||||
this.modelLoader = modelLoader;
|
||||
}
|
||||
|
||||
public ModelManager getModelManager()
|
||||
{
|
||||
return modelManager;
|
||||
}
|
||||
|
||||
public IRegistry<ModelResourceLocation, IBakedModel> getModelRegistry()
|
||||
{
|
||||
return modelRegistry;
|
||||
}
|
||||
|
||||
public ModelLoader getModelLoader()
|
||||
{
|
||||
return modelLoader;
|
||||
}
|
||||
}
|
||||
@@ -12,14 +12,14 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
@Cancelable
|
||||
public class MouseEvent extends Event
|
||||
{
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int dx;
|
||||
public final int dy;
|
||||
public final int dwheel;
|
||||
public final int button;
|
||||
public final boolean buttonstate;
|
||||
public final long nanoseconds;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int dx;
|
||||
private final int dy;
|
||||
private final int dwheel;
|
||||
private final int button;
|
||||
private final boolean buttonstate;
|
||||
private final long nanoseconds;
|
||||
|
||||
public MouseEvent()
|
||||
{
|
||||
@@ -32,4 +32,13 @@ public class MouseEvent extends Event
|
||||
this.buttonstate = Mouse.getEventButtonState();
|
||||
this.nanoseconds = Mouse.getEventNanoseconds();
|
||||
}
|
||||
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int getDx() { return dx; }
|
||||
public int getDy() { return dy; }
|
||||
public int getDwheel() { return dwheel; }
|
||||
public int getButton() { return button; }
|
||||
public boolean isButtonstate() { return buttonstate; }
|
||||
public long getNanoseconds() { return nanoseconds; }
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package net.minecraftforge.client.event;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@@ -12,25 +12,16 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
*/
|
||||
@Cancelable
|
||||
public class RenderBlockOverlayEvent extends Event {
|
||||
|
||||
|
||||
public static enum OverlayType {
|
||||
FIRE, BLOCK, WATER
|
||||
}
|
||||
|
||||
/**
|
||||
* The player which the overlay will apply to
|
||||
*/
|
||||
public final EntityPlayer player;
|
||||
public final float renderPartialTicks;
|
||||
/**
|
||||
* The type of overlay to occur
|
||||
*/
|
||||
public final OverlayType overlayType;
|
||||
/**
|
||||
* If the overlay type is BLOCK, then this is the block which the overlay is getting it's icon from
|
||||
*/
|
||||
public final IBlockState blockForOverlay;
|
||||
public final BlockPos blockPos;
|
||||
private final EntityPlayer player;
|
||||
private final float renderPartialTicks;
|
||||
private final OverlayType overlayType;
|
||||
private final IBlockState blockForOverlay;
|
||||
private final BlockPos blockPos;
|
||||
|
||||
@Deprecated
|
||||
public RenderBlockOverlayEvent(EntityPlayer player, float renderPartialTicks, OverlayType type, Block block, int x, int y, int z)
|
||||
@@ -48,4 +39,18 @@ public class RenderBlockOverlayEvent extends Event {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The player which the overlay will apply to
|
||||
*/
|
||||
public EntityPlayer getPlayer() { return player; }
|
||||
public float getRenderPartialTicks() { return renderPartialTicks; }
|
||||
/**
|
||||
* The type of overlay to occur
|
||||
*/
|
||||
public OverlayType getOverlayType() { return overlayType; }
|
||||
/**
|
||||
* If the overlay type is BLOCK, then this is the block which the overlay is getting it's icon from
|
||||
*/
|
||||
public IBlockState getBlockForOverlay() { return blockForOverlay; }
|
||||
public BlockPos getBlockPos() { return blockPos; }
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.world.BossInfoLerping;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@@ -10,13 +11,29 @@ import net.minecraft.client.gui.ScaledResolution;
|
||||
@Cancelable
|
||||
public class RenderGameOverlayEvent extends Event
|
||||
{
|
||||
public float getPartialTicks()
|
||||
{
|
||||
return partialTicks;
|
||||
}
|
||||
|
||||
public ScaledResolution getResolution()
|
||||
{
|
||||
return resolution;
|
||||
}
|
||||
|
||||
public ElementType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public static enum ElementType
|
||||
{
|
||||
ALL,
|
||||
HELMET,
|
||||
PORTAL,
|
||||
CROSSHAIRS,
|
||||
BOSSHEALTH,
|
||||
BOSSHEALTH, // All boss bars
|
||||
BOSSINFO, // Individual boss bar
|
||||
ARMOR,
|
||||
HEALTH,
|
||||
FOOD,
|
||||
@@ -28,12 +45,14 @@ public class RenderGameOverlayEvent extends Event
|
||||
JUMPBAR,
|
||||
CHAT,
|
||||
PLAYER_LIST,
|
||||
DEBUG
|
||||
DEBUG,
|
||||
POTION_ICONS,
|
||||
SUBTITLES
|
||||
}
|
||||
|
||||
public final float partialTicks;
|
||||
public final ScaledResolution resolution;
|
||||
public final ElementType type;
|
||||
private final float partialTicks;
|
||||
private final ScaledResolution resolution;
|
||||
private final ElementType type;
|
||||
|
||||
public RenderGameOverlayEvent(float partialTicks, ScaledResolution resolution)
|
||||
{
|
||||
@@ -44,8 +63,8 @@ public class RenderGameOverlayEvent extends Event
|
||||
|
||||
private RenderGameOverlayEvent(RenderGameOverlayEvent parent, ElementType type)
|
||||
{
|
||||
this.partialTicks = parent.partialTicks;
|
||||
this.resolution = parent.resolution;
|
||||
this.partialTicks = parent.getPartialTicks();
|
||||
this.resolution = parent.getResolution();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -66,27 +85,114 @@ public class RenderGameOverlayEvent extends Event
|
||||
@Override public boolean isCancelable(){ return false; }
|
||||
}
|
||||
|
||||
public static class BossInfo extends Pre
|
||||
{
|
||||
private final BossInfoLerping bossInfo;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private int increment;
|
||||
public BossInfo(RenderGameOverlayEvent parent, ElementType type, BossInfoLerping bossInfo, int x, int y, int increment)
|
||||
{
|
||||
super(parent, type);
|
||||
this.bossInfo = bossInfo;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.increment = increment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link BossInfoLerping} currently being rendered
|
||||
*/
|
||||
public BossInfoLerping getBossInfo()
|
||||
{
|
||||
return bossInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current x position we are rendering at
|
||||
*/
|
||||
public int getX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current y position we are rendering at
|
||||
*/
|
||||
public int getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return How much to move down before rendering the next bar
|
||||
*/
|
||||
public int getIncrement()
|
||||
{
|
||||
return increment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount to move down before rendering the next bar
|
||||
* @param increment The increment to set
|
||||
*/
|
||||
public void setIncrement(int increment)
|
||||
{
|
||||
this.increment = increment;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Text extends Pre
|
||||
{
|
||||
public final ArrayList<String> left;
|
||||
public final ArrayList<String> right;
|
||||
private final ArrayList<String> left;
|
||||
private final ArrayList<String> right;
|
||||
public Text(RenderGameOverlayEvent parent, ArrayList<String> left, ArrayList<String> right)
|
||||
{
|
||||
super(parent, ElementType.TEXT);
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public ArrayList<String> getLeft()
|
||||
{
|
||||
return left;
|
||||
}
|
||||
|
||||
public ArrayList<String> getRight()
|
||||
{
|
||||
return right;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Chat extends Pre
|
||||
{
|
||||
public int posX;
|
||||
public int posY;
|
||||
private int posX;
|
||||
private int posY;
|
||||
|
||||
public Chat(RenderGameOverlayEvent parent, int posX, int posY)
|
||||
{
|
||||
super(parent, ElementType.CHAT);
|
||||
this.setPosX(posX);
|
||||
this.setPosY(posY);
|
||||
}
|
||||
|
||||
public int getPosX()
|
||||
{
|
||||
return posX;
|
||||
}
|
||||
|
||||
public void setPosX(int posX)
|
||||
{
|
||||
this.posX = posX;
|
||||
}
|
||||
|
||||
public int getPosY()
|
||||
{
|
||||
return posY;
|
||||
}
|
||||
|
||||
public void setPosY(int posY)
|
||||
{
|
||||
this.posY = posY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,28 @@ import net.minecraft.client.renderer.RenderGlobal;
|
||||
@Cancelable
|
||||
public class RenderHandEvent extends Event
|
||||
{
|
||||
public final RenderGlobal context;
|
||||
public final float partialTicks;
|
||||
public final int renderPass;
|
||||
private final RenderGlobal context;
|
||||
private final float partialTicks;
|
||||
private final int renderPass;
|
||||
public RenderHandEvent(RenderGlobal context, float partialTicks, int renderPass)
|
||||
{
|
||||
this.context = context;
|
||||
this.partialTicks = partialTicks;
|
||||
this.renderPass = renderPass;
|
||||
}
|
||||
|
||||
public RenderGlobal getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
public float getPartialTicks()
|
||||
{
|
||||
return partialTicks;
|
||||
}
|
||||
|
||||
public int getRenderPass()
|
||||
{
|
||||
return renderPass;
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,9 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
@Cancelable
|
||||
public class RenderItemInFrameEvent extends Event
|
||||
{
|
||||
public final ItemStack item;
|
||||
public final EntityItemFrame entityItemFrame;
|
||||
public final RenderItemFrame renderer;
|
||||
private final ItemStack item;
|
||||
private final EntityItemFrame entityItemFrame;
|
||||
private final RenderItemFrame renderer;
|
||||
|
||||
public RenderItemInFrameEvent(EntityItemFrame itemFrame, RenderItemFrame renderItemFrame)
|
||||
{
|
||||
@@ -24,4 +24,19 @@ public class RenderItemInFrameEvent extends Event
|
||||
entityItemFrame = itemFrame;
|
||||
renderer = renderItemFrame;
|
||||
}
|
||||
|
||||
public ItemStack getItem()
|
||||
{
|
||||
return item;
|
||||
}
|
||||
|
||||
public EntityItemFrame getEntityItemFrame()
|
||||
{
|
||||
return entityItemFrame;
|
||||
}
|
||||
|
||||
public RenderItemFrame getRenderer()
|
||||
{
|
||||
return renderer;
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,18 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
||||
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
public abstract class RenderLivingEvent<T extends EntityLivingBase> extends Event
|
||||
{
|
||||
public final EntityLivingBase entity;
|
||||
public final RendererLivingEntity<T> renderer;
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double z;
|
||||
private final EntityLivingBase entity;
|
||||
private final RenderLivingBase<T> renderer;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
public RenderLivingEvent(EntityLivingBase entity, RendererLivingEntity<T> renderer, double x, double y, double z)
|
||||
public RenderLivingEvent(EntityLivingBase entity, RenderLivingBase<T> renderer, double x, double y, double z)
|
||||
{
|
||||
this.entity = entity;
|
||||
this.renderer = renderer;
|
||||
@@ -21,29 +21,35 @@ public abstract class RenderLivingEvent<T extends EntityLivingBase> extends Even
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
|
||||
public EntityLivingBase getEntity() { return entity; }
|
||||
public RenderLivingBase<T> getRenderer() { return renderer; }
|
||||
public double getX() { return x; }
|
||||
public double getY() { return y; }
|
||||
public double getZ() { return z; }
|
||||
|
||||
@Cancelable
|
||||
public static class Pre<T extends EntityLivingBase> extends RenderLivingEvent<T>
|
||||
{
|
||||
public Pre(EntityLivingBase entity, RendererLivingEntity<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
public Pre(EntityLivingBase entity, RenderLivingBase<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
}
|
||||
public static class Post<T extends EntityLivingBase> extends RenderLivingEvent<T>
|
||||
{
|
||||
public Post(EntityLivingBase entity, RendererLivingEntity<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
public Post(EntityLivingBase entity, RenderLivingBase<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
}
|
||||
|
||||
public abstract static class Specials<T extends EntityLivingBase> extends RenderLivingEvent<T>
|
||||
{
|
||||
public Specials(EntityLivingBase entity, RendererLivingEntity<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
public Specials(EntityLivingBase entity, RenderLivingBase<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
|
||||
@Cancelable
|
||||
public static class Pre<T extends EntityLivingBase> extends Specials<T>
|
||||
{
|
||||
public Pre(EntityLivingBase entity, RendererLivingEntity<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
public Pre(EntityLivingBase entity, RenderLivingBase<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
}
|
||||
public static class Post<T extends EntityLivingBase> extends Specials<T>
|
||||
{
|
||||
public Post(EntityLivingBase entity, RendererLivingEntity<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
public Post(EntityLivingBase entity, RenderLivingBase<T> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,11 @@ import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
||||
public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
{
|
||||
public final RenderPlayer renderer;
|
||||
public final float partialRenderTick;
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double z;
|
||||
private final RenderPlayer renderer;
|
||||
private final float partialRenderTick;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
public RenderPlayerEvent(EntityPlayer player, RenderPlayer renderer, float partialRenderTick, double x, double y, double z)
|
||||
{
|
||||
@@ -24,6 +24,12 @@ public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public RenderPlayer getRenderer() { return renderer; }
|
||||
public float getPartialRenderTick() { return partialRenderTick; }
|
||||
public double getX() { return x; }
|
||||
public double getY() { return y; }
|
||||
public double getZ() { return z; }
|
||||
|
||||
@Cancelable
|
||||
public static class Pre extends RenderPlayerEvent
|
||||
{
|
||||
@@ -50,10 +56,17 @@ public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
@Cancelable
|
||||
public static class Pre extends Specials
|
||||
{
|
||||
public boolean renderHelmet = true;
|
||||
public boolean renderCape = true;
|
||||
public boolean renderItem = true;
|
||||
private boolean renderHelmet = true;
|
||||
private boolean renderCape = true;
|
||||
private boolean renderItem = true;
|
||||
public Pre(EntityPlayer player, RenderPlayer renderer, float partialTicks){ super(player, renderer, partialTicks); }
|
||||
|
||||
public boolean shouldRenderHelmet() { return renderHelmet; }
|
||||
public void setRenderHelmet(boolean renderHelmet) { this.renderHelmet = renderHelmet; }
|
||||
public boolean shouldRenderCape() { return renderCape; }
|
||||
public void setRenderCape(boolean renderCape) { this.renderCape = renderCape; }
|
||||
public boolean shouldRenderItem() { return renderItem; }
|
||||
public void setRenderItem(boolean renderItem) { this.renderItem = renderItem; }
|
||||
}
|
||||
|
||||
public static class Post extends Specials
|
||||
@@ -65,18 +78,38 @@ public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
@Deprecated
|
||||
public static class SetArmorModel extends RenderPlayerEvent
|
||||
{
|
||||
/**
|
||||
* Setting this to any value besides -1 will result in the function being
|
||||
* Immediately exited with the return value specified.
|
||||
*/
|
||||
public int result = -1;
|
||||
public final int slot;
|
||||
public final ItemStack stack;
|
||||
private int result = -1;
|
||||
private final int slot;
|
||||
private final ItemStack stack;
|
||||
public SetArmorModel(EntityPlayer player, RenderPlayer renderer, int slot, float partialTick, ItemStack stack)
|
||||
{
|
||||
super(player, renderer, partialTick, 0D, 0D, 0D);
|
||||
this.slot = slot;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting this to any value besides -1 will result in the function being
|
||||
* Immediately exited with the return value specified.
|
||||
*/
|
||||
public int getResultValue()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(int result)
|
||||
{
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public int getSlot()
|
||||
{
|
||||
return slot;
|
||||
}
|
||||
|
||||
public ItemStack getStack()
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
//import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.world.ChunkCache;
|
||||
|
||||
public abstract class RenderWorldEvent extends Event
|
||||
{
|
||||
public final WorldRenderer renderer;
|
||||
public final ChunkCache chunkCache;
|
||||
//public final RenderBlocks renderBlocks;
|
||||
public final int pass;
|
||||
|
||||
public RenderWorldEvent(WorldRenderer renderer, ChunkCache chunkCache, /*RenderBlocks renderBlocks,*/ int pass)
|
||||
{
|
||||
this.renderer = renderer;
|
||||
this.chunkCache = chunkCache;
|
||||
//this.renderBlocks = renderBlocks;
|
||||
this.pass = pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when 16x16x16 chunk area is being redrawn.
|
||||
* Fired after GL state is setup, before tessellator is started.
|
||||
*/
|
||||
public static class Pre extends RenderWorldEvent
|
||||
{
|
||||
public Pre(WorldRenderer renderer, ChunkCache chunkCache, /*RenderBlocks renderBlocks,*/ int pass){ super(renderer, chunkCache, /*renderBlocks,*/ pass); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired after the tessellator is stopped, before the display list is ended.
|
||||
*/
|
||||
public static class Post extends RenderWorldEvent
|
||||
{
|
||||
public Post(WorldRenderer renderer, ChunkCache chunkCache, /*RenderBlocks renderBlocks,*/ int pass){ super(renderer, chunkCache, /*renderBlocks,*/ pass); }
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,21 @@ import net.minecraft.client.renderer.RenderGlobal;
|
||||
|
||||
public class RenderWorldLastEvent extends Event
|
||||
{
|
||||
public final RenderGlobal context;
|
||||
public final float partialTicks;
|
||||
private final RenderGlobal context;
|
||||
private final float partialTicks;
|
||||
public RenderWorldLastEvent(RenderGlobal context, float partialTicks)
|
||||
{
|
||||
this.context = context;
|
||||
this.partialTicks = partialTicks;
|
||||
}
|
||||
|
||||
public RenderGlobal getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
public float getPartialTicks()
|
||||
{
|
||||
return partialTicks;
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,18 @@ import net.minecraft.client.renderer.texture.TextureMap;
|
||||
|
||||
public class TextureStitchEvent extends Event
|
||||
{
|
||||
public final TextureMap map;
|
||||
private final TextureMap map;
|
||||
|
||||
public TextureStitchEvent(TextureMap map)
|
||||
{
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public TextureMap getMap()
|
||||
{
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the TextureMap is told to refresh it's stitched texture.
|
||||
* Called after the Stitched list is cleared, but before any blocks or items
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
import net.minecraft.client.audio.SoundPoolEntry;
|
||||
|
||||
/**
|
||||
* Raised when the SoundManager tries to play a Background Music file,
|
||||
* If you return null from this function it will prevent the sound from being played,
|
||||
* you can return a different entry if you want to change the sound being played.
|
||||
*/
|
||||
@Deprecated // Remove in 1.8
|
||||
public class PlayBackgroundMusicEvent extends SoundResultEvent
|
||||
{
|
||||
public PlayBackgroundMusicEvent(SoundManager manager, SoundPoolEntry entry)
|
||||
{ super(manager, entry, null, 0.0f, 0.0f); }
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
import net.minecraft.client.audio.SoundPoolEntry;
|
||||
|
||||
@Deprecated //Remove in 1.8
|
||||
public class PlaySoundEffectEvent extends SoundResultEvent
|
||||
{
|
||||
public PlaySoundEffectEvent(SoundManager manager, SoundPoolEntry source, String name, float volume, float pitch)
|
||||
{ super(manager, source, name, volume, pitch); }
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
|
||||
@Deprecated //Remove in 1.8
|
||||
public class PlaySoundEffectSourceEvent extends SoundEvent
|
||||
{
|
||||
public final SoundManager manager;
|
||||
public final String name;
|
||||
public PlaySoundEffectSourceEvent(SoundManager manager, String name)
|
||||
{
|
||||
super(manager);
|
||||
this.manager = manager;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.audio.SoundCategory;
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
|
||||
/***
|
||||
@@ -12,17 +11,35 @@ import net.minecraft.client.audio.SoundManager;
|
||||
*/
|
||||
public class PlaySoundEvent extends SoundEvent
|
||||
{
|
||||
public final String name;
|
||||
public final ISound sound;
|
||||
public final SoundCategory category;
|
||||
public ISound result;
|
||||
private final String name;
|
||||
private final ISound sound;
|
||||
private ISound result;
|
||||
|
||||
public PlaySoundEvent(SoundManager manager, ISound sound, SoundCategory category)
|
||||
public PlaySoundEvent(SoundManager manager, ISound sound)
|
||||
{
|
||||
super(manager);
|
||||
this.sound = sound;
|
||||
this.category = category;
|
||||
this.name = sound.getSoundLocation().getResourcePath();
|
||||
this.result = sound;
|
||||
this.setResultSound(sound);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public ISound getSound()
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
|
||||
public ISound getResultSound()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResultSound(ISound result)
|
||||
{
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
import net.minecraft.client.audio.SoundPoolEntry;
|
||||
|
||||
/**
|
||||
* Raised when the SoundManager tries to play a 'Streaming' file,
|
||||
* in vanilla it is only the Jukebox that uses this function.
|
||||
*
|
||||
* If you return null from this function it will prevent the sound from being played,
|
||||
* you can return a different entry if you want to change the sound being played.
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class PlayStreamingEvent extends SoundResultEvent
|
||||
{
|
||||
public final float x;
|
||||
public final float y;
|
||||
public final float z;
|
||||
public PlayStreamingEvent(SoundManager manager, SoundPoolEntry source, String name, float x, float y, float z)
|
||||
{
|
||||
super(manager, source, name, 0.0f, 0.0f);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,25 @@ package net.minecraftforge.client.event.sound;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
import net.minecraft.client.audio.SoundPoolEntry;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class SoundEvent extends Event
|
||||
{
|
||||
public final SoundManager manager;
|
||||
private final SoundManager manager;
|
||||
public SoundEvent(SoundManager manager)
|
||||
{
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static SoundPoolEntry getResult(SoundResultEvent event)
|
||||
public SoundManager getManager()
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.result;
|
||||
return manager;
|
||||
}
|
||||
|
||||
public static class SoundSourceEvent extends SoundEvent
|
||||
{
|
||||
public final ISound sound;
|
||||
public final String uuid;
|
||||
public final String name;
|
||||
private final ISound sound;
|
||||
private final String uuid;
|
||||
private final String name;
|
||||
|
||||
public SoundSourceEvent(SoundManager manager, ISound sound, String uuid)
|
||||
{
|
||||
@@ -34,5 +30,20 @@ public class SoundEvent extends Event
|
||||
this.sound = sound;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public ISound getSound()
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
|
||||
public String getUuid()
|
||||
{
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,13 @@ package net.minecraftforge.client.event.sound;
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
|
||||
/**
|
||||
* Raised by the SoundManager.loadSoundSettings, this would be a good place for
|
||||
* Raised by the SoundManager.loadSoundSettings, this would be a good place for
|
||||
* adding your custom sounds to the SoundPool.
|
||||
*/
|
||||
public class SoundLoadEvent extends SoundEvent
|
||||
{
|
||||
@Deprecated
|
||||
public final SoundManager manager;
|
||||
public SoundLoadEvent(SoundManager manager)
|
||||
{
|
||||
super(manager);
|
||||
this.manager = manager;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
import net.minecraft.client.audio.SoundPoolEntry;
|
||||
|
||||
@Deprecated //Remove in 1.8
|
||||
public abstract class SoundResultEvent extends SoundEvent
|
||||
{
|
||||
public final SoundManager manager;
|
||||
public final SoundPoolEntry source;
|
||||
public final String name;
|
||||
public final float volume;
|
||||
public final float pitch;
|
||||
public SoundPoolEntry result;
|
||||
|
||||
public SoundResultEvent(SoundManager manager, SoundPoolEntry source, String name, float volume, float pitch)
|
||||
{
|
||||
super(manager);
|
||||
this.manager = manager;
|
||||
this.source = source;
|
||||
this.name = name;
|
||||
this.volume = volume;
|
||||
this.pitch = pitch;
|
||||
this.result = source;
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,13 @@ package net.minecraftforge.client.event.sound;
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
|
||||
/**
|
||||
* This event is raised by the SoundManager when it does its first setup of the
|
||||
* This event is raised by the SoundManager when it does its first setup of the
|
||||
* SoundSystemConfig's codecs, use this function to add your own codecs.
|
||||
*/
|
||||
public class SoundSetupEvent extends SoundEvent
|
||||
{
|
||||
@Deprecated
|
||||
public final SoundManager manager;
|
||||
public SoundSetupEvent(SoundManager manager)
|
||||
{
|
||||
super(manager);
|
||||
this.manager = manager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package net.minecraftforge.client.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.common.ForgeVersion.Status;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class NotificationModUpdateScreen extends GuiScreen
|
||||
{
|
||||
|
||||
private static final ResourceLocation VERSION_CHECK_ICONS = new ResourceLocation("forge", "textures/gui/version_check_icons.png");
|
||||
|
||||
private final GuiButton modButton;
|
||||
private Status showNotification = null;
|
||||
private boolean hasCheckedForUpdates = false;
|
||||
|
||||
public NotificationModUpdateScreen(GuiButton modButton)
|
||||
{
|
||||
this.modButton = modButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
if (!hasCheckedForUpdates)
|
||||
{
|
||||
if (modButton != null)
|
||||
{
|
||||
for (ModContainer mod : Loader.instance().getModList())
|
||||
{
|
||||
Status status = ForgeVersion.getResult(mod).status;
|
||||
if (status == Status.OUTDATED || status == Status.BETA_OUTDATED)
|
||||
{
|
||||
// TODO: Needs better visualization, maybe stacked icons
|
||||
// drawn in a terrace-like pattern?
|
||||
showNotification = Status.OUTDATED;
|
||||
}
|
||||
}
|
||||
}
|
||||
hasCheckedForUpdates = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
if (showNotification == null || !showNotification.shouldDraw() || ForgeModContainer.disableVersionCheck)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(VERSION_CHECK_ICONS);
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
int x = modButton.xPosition;
|
||||
int y = modButton.yPosition;
|
||||
int w = modButton.width;
|
||||
int h = modButton.height;
|
||||
|
||||
drawModalRectWithCustomSizedTexture(x + w - (h / 2 + 4), y + (h / 2 - 4), showNotification.getSheetOffset() * 8, (showNotification.isAnimated() && ((System.currentTimeMillis() / 800 & 1) == 1)) ? 8 : 0, 8, 8, 64, 16);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
public static NotificationModUpdateScreen init(GuiMainMenu guiMainMenu, GuiButton modButton)
|
||||
{
|
||||
NotificationModUpdateScreen notificationModUpdateScreen = new NotificationModUpdateScreen(modButton);
|
||||
notificationModUpdateScreen.setGuiSize(guiMainMenu.width, guiMainMenu.height);
|
||||
notificationModUpdateScreen.initGui();
|
||||
return notificationModUpdateScreen;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class Attributes
|
||||
|
||||
int padding = 0;
|
||||
int j = 0;
|
||||
for(VertexFormatElement firstAttr : (List<VertexFormatElement>)first.getElements())
|
||||
for(VertexFormatElement firstAttr : first.getElements())
|
||||
{
|
||||
while(j < second.getElementCount() && second.getElement(j).getUsage() == EnumUsage.PADDING)
|
||||
{
|
||||
|
||||
@@ -6,12 +6,16 @@ import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelBlockDefinition;
|
||||
import net.minecraft.client.resources.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.block.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.block.model.Variant;
|
||||
import net.minecraft.client.renderer.block.model.VariantList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -20,6 +24,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
@@ -55,11 +60,11 @@ public class BlockStateLoader
|
||||
{
|
||||
case 1: // Version 1
|
||||
ForgeBlockStateV1 v1 = GSON.fromJson(reader, ForgeBlockStateV1.class);
|
||||
List<ModelBlockDefinition.Variants> variants = Lists.newArrayList();
|
||||
Map<String, VariantList> variants = Maps.newHashMap();
|
||||
|
||||
for (Entry<String, Collection<ForgeBlockStateV1.Variant>> entry : v1.variants.asMap().entrySet())
|
||||
{ // Convert Version1 variants into vanilla variants for the ModelBlockDefinition.
|
||||
List<ModelBlockDefinition.Variant> mcVars = Lists.newArrayList();
|
||||
List<Variant> mcVars = Lists.newArrayList();
|
||||
for (ForgeBlockStateV1.Variant var : entry.getValue())
|
||||
{
|
||||
boolean uvLock = var.getUvLock().or(false);
|
||||
@@ -68,14 +73,14 @@ public class BlockStateLoader
|
||||
int weight = var.getWeight().or(1);
|
||||
|
||||
if (var.getModel() != null && var.getSubmodels().size() == 0 && var.getTextures().size() == 0 && var.getCustomData().size() == 0 && var.getState().orNull() instanceof ModelRotation)
|
||||
mcVars.add(new ModelBlockDefinition.Variant(var.getModel(), (ModelRotation)var.getState().get(), uvLock, weight));
|
||||
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()));
|
||||
}
|
||||
variants.add(new ModelBlockDefinition.Variants(entry.getKey(), mcVars));
|
||||
variants.put(entry.getKey(), new VariantList(mcVars));
|
||||
}
|
||||
|
||||
return new ModelBlockDefinition(variants);
|
||||
return new ModelBlockDefinition(variants, null);
|
||||
|
||||
default: //Unknown version.. try loading it as normal.
|
||||
return vanillaGSON.fromJson(reader, ModelBlockDefinition.class);
|
||||
@@ -104,12 +109,6 @@ public class BlockStateLoader
|
||||
private final ResourceLocation model;
|
||||
private final ImmutableMap<String, String> customData;
|
||||
|
||||
@Deprecated // remove in 1.9
|
||||
public SubModel(IModelState state, boolean uvLock, ImmutableMap<String, String> textures, ResourceLocation model, ImmutableMap<String, String> customData)
|
||||
{
|
||||
this(state, uvLock, true, true, textures, model, customData);
|
||||
}
|
||||
|
||||
public SubModel(IModelState state, boolean uvLock, boolean smooth, boolean gui3d, ImmutableMap<String, String> textures, ResourceLocation model, ImmutableMap<String, String> customData)
|
||||
{
|
||||
this.state = state;
|
||||
@@ -128,7 +127,7 @@ public class BlockStateLoader
|
||||
public ImmutableMap<String, String> getCustomData() { return customData; }
|
||||
}
|
||||
|
||||
private static class ForgeVariant extends ModelBlockDefinition.Variant implements ISmartVariant
|
||||
private static class ForgeVariant extends Variant implements ISmartVariant
|
||||
{
|
||||
private final ImmutableMap<String, String> textures;
|
||||
private final ImmutableMap<String, SubModel> parts;
|
||||
@@ -148,67 +147,46 @@ public class BlockStateLoader
|
||||
this.gui3d = gui3d;
|
||||
}
|
||||
|
||||
private IModel runModelHooks(IModel base, boolean smooth, boolean gui3d, ImmutableMap<String, String> textureMap, ImmutableMap<String, String> customData)
|
||||
private IModel runModelHooks(IModel base, boolean smooth, boolean gui3d, boolean uvlock, ImmutableMap<String, String> textureMap, ImmutableMap<String, String> customData)
|
||||
{
|
||||
if (!customData.isEmpty() && base instanceof IModelCustomData)
|
||||
{
|
||||
base = ((IModelCustomData<?>)base).process(customData);
|
||||
}
|
||||
|
||||
if (!textureMap.isEmpty() && base instanceof IRetexturableModel)
|
||||
{
|
||||
base = ((IRetexturableModel<?>)base).retexture(textureMap);
|
||||
}
|
||||
|
||||
if (base instanceof IModelSimpleProperties<?>)
|
||||
{
|
||||
base = ((IModelSimpleProperties<?>) base).smoothLighting(smooth).gui3d(gui3d);
|
||||
}
|
||||
|
||||
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);
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to replace the base model with a retextured model containing submodels.
|
||||
* Used to replace the base model with a re-textured model containing sub-models.
|
||||
*/
|
||||
@Override
|
||||
public IModel process(IModel base, ModelLoader loader)
|
||||
public IModel process(IModel base)
|
||||
{
|
||||
int size = parts.size();
|
||||
boolean hasBase = base != loader.getMissingModel();
|
||||
// FIXME: should missing base be handled this way?
|
||||
boolean hasBase = base != ModelLoaderRegistry.getMissingModel();
|
||||
|
||||
if (hasBase)
|
||||
{
|
||||
base = runModelHooks(base, smooth, gui3d, textures, customData);
|
||||
base = runModelHooks(base, smooth, gui3d, this.isUvLock(), textures, customData);
|
||||
|
||||
if (size <= 0)
|
||||
return base;
|
||||
}
|
||||
|
||||
// Apply rotation of base model to submodels.
|
||||
// Apply rotation of base model to sub-models.
|
||||
// If baseRot is non-null, then that rotation will be applied instead of the base model's rotation.
|
||||
// This is used to allow replacing base model with a submodel when there is no base model for a variant.
|
||||
// This is used to allow replacing base model with a sub-model when there is no base model for a variant.
|
||||
IModelState baseTr = getState();
|
||||
ImmutableMap.Builder<String, Pair<IModel, IModelState>> models = ImmutableMap.builder();
|
||||
for (Entry<String, SubModel> entry : parts.entrySet())
|
||||
{
|
||||
SubModel part = entry.getValue();
|
||||
|
||||
IModel model = null;
|
||||
try
|
||||
{
|
||||
model = loader.getModel(part.getModelLocation());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
FMLLog.warning("Unable to load block sub-model: \'" + part.getModelLocation() /*+ "\' for variant: \'" + parent*/ + "\': " + e.toString());
|
||||
model = loader.getMissingModel(); // Will make it look weird, but that is good.
|
||||
}
|
||||
IModel model = ModelLoaderRegistry.getModelOrLogError(part.getModelLocation(), "Unable to load block sub-model: \'" + part.getModelLocation());
|
||||
|
||||
IModelState partState = new ModelStateComposition(baseTr, part.getState());
|
||||
if (part.isUVLock()) partState = new ModelLoader.UVLock(partState);
|
||||
|
||||
models.put(entry.getKey(), Pair.<IModel, IModelState>of(runModelHooks(model, part.smooth, part.gui3d, part.getTextures(), part.getCustomData()), partState));
|
||||
models.put(entry.getKey(), Pair.<IModel, IModelState>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());
|
||||
|
||||
@@ -17,11 +17,13 @@ import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.resources.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.block.model.ModelRotation;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.BlockStateLoader.Marker;
|
||||
import net.minecraftforge.client.model.BlockStateLoader.SubModel;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
@@ -37,7 +39,6 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ForgeBlockStateV1 extends Marker
|
||||
{
|
||||
ForgeBlockStateV1.Variant defaults;
|
||||
@@ -372,7 +373,7 @@ public class ForgeBlockStateV1 extends Marker
|
||||
|
||||
protected SubModel asGenericSubModel()
|
||||
{
|
||||
return new SubModel(state.or(TRSRTransformation.identity()), uvLock.or(false), getTextures(), model, getCustomData());
|
||||
return new SubModel(state.or(TRSRTransformation.identity()), uvLock.or(false), smooth.or(true), gui3d.or(true), getTextures(), model, getCustomData());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,6 +437,22 @@ public class ForgeBlockStateV1 extends Marker
|
||||
throw new UnsupportedOperationException("Forge BlockStateLoader V1 does not support nested submodels.");
|
||||
}
|
||||
|
||||
private static TRSRTransformation get(float tx, float ty, float tz, float ax, float ay, float az, float s)
|
||||
{
|
||||
return TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
|
||||
new Vector3f(tx / 16, ty / 16, tz / 16),
|
||||
TRSRTransformation.quatFromXYZDegrees(new Vector3f(ax, ay, az)),
|
||||
new Vector3f(s, s, s),
|
||||
null));
|
||||
}
|
||||
|
||||
private static final TRSRTransformation flipX = new TRSRTransformation(null, null, new Vector3f(-1, 1, 1), null);
|
||||
|
||||
private static TRSRTransformation leftify(TRSRTransformation transform)
|
||||
{
|
||||
return TRSRTransformation.blockCenterToCorner(flipX.compose(TRSRTransformation.blockCornerToCenter(transform)).compose(flipX));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeBlockStateV1.Variant deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
@@ -456,7 +473,7 @@ public class ForgeBlockStateV1 extends Marker
|
||||
for (Entry<String, JsonElement> e : json.get("textures").getAsJsonObject().entrySet())
|
||||
{
|
||||
if (e.getValue().isJsonNull())
|
||||
ret.textures.put(e.getKey(), ""); // We have to use "" because ImmutibleMaps don't allow nulls -.-
|
||||
ret.textures.put(e.getKey(), ""); // We have to use "" because ImmutableMaps don't allow nulls -.-
|
||||
else
|
||||
ret.textures.put(e.getKey(), e.getValue().getAsString());
|
||||
}
|
||||
@@ -477,46 +494,47 @@ public class ForgeBlockStateV1 extends Marker
|
||||
{
|
||||
String transform = json.get("transform").getAsString();
|
||||
// Note: these strings might change to a full-blown resource locations in the future, and move from here to some json somewhere
|
||||
// TODO: vanilla now includes from parent, deprecate?
|
||||
if (transform.equals("identity"))
|
||||
{
|
||||
ret.state = Optional.<IModelState>of(TRSRTransformation.identity());
|
||||
}
|
||||
// block/block
|
||||
else if (transform.equals("forge:default-block"))
|
||||
{
|
||||
TRSRTransformation thirdperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
|
||||
new Vector3f(0, 1.5f / 16, -2.75f / 16),
|
||||
TRSRTransformation.quatFromYXZDegrees(new Vector3f(10, -45, 170)),
|
||||
new Vector3f(0.375f, 0.375f, 0.375f),
|
||||
null));
|
||||
ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(TransformType.THIRD_PERSON, thirdperson)));
|
||||
TRSRTransformation thirdperson = get(0, 2.5f, 0, 75, 45, 0, 0.375f);
|
||||
ImmutableMap.Builder<TransformType, TRSRTransformation> builder = ImmutableMap.builder();
|
||||
builder.put(TransformType.GUI, get(0, 0, 0, 30, 225, 0, 0.625f));
|
||||
builder.put(TransformType.GROUND, get(0, 3, 0, 0, 0, 0, 0.25f));
|
||||
builder.put(TransformType.FIXED, get(0, 0, 0, 0, 0, 0, 0.5f));
|
||||
builder.put(TransformType.THIRD_PERSON_RIGHT_HAND, thirdperson);
|
||||
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()));
|
||||
}
|
||||
// item/generated
|
||||
else if (transform.equals("forge:default-item"))
|
||||
{
|
||||
TRSRTransformation thirdperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
|
||||
new Vector3f(0, 1f / 16, -3f / 16),
|
||||
TRSRTransformation.quatFromYXZDegrees(new Vector3f(-90, 0, 0)),
|
||||
new Vector3f(0.55f, 0.55f, 0.55f),
|
||||
null));
|
||||
TRSRTransformation firstperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
|
||||
new Vector3f(0, 4f / 16, 2f / 16),
|
||||
TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, -135, 25)),
|
||||
new Vector3f(1.7f, 1.7f, 1.7f),
|
||||
null));
|
||||
ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(TransformType.THIRD_PERSON, thirdperson, TransformType.FIRST_PERSON, firstperson)));
|
||||
TRSRTransformation thirdperson = get(0, 3, 1, 0, 0, 0, 0.55f);
|
||||
TRSRTransformation firstperson = get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f);
|
||||
ImmutableMap.Builder<TransformType, TRSRTransformation> builder = ImmutableMap.builder();
|
||||
builder.put(TransformType.GROUND, get(0, 2, 0, 0, 0, 0, 0.5f));
|
||||
builder.put(TransformType.HEAD, get(0, 13, 7, 0, 180, 0, 1));
|
||||
builder.put(TransformType.THIRD_PERSON_RIGHT_HAND, thirdperson);
|
||||
builder.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(thirdperson));
|
||||
builder.put(TransformType.FIRST_PERSON_RIGHT_HAND, firstperson);
|
||||
builder.put(TransformType.FIRST_PERSON_LEFT_HAND, leftify(firstperson));
|
||||
ret.state = Optional.<IModelState>of(new SimpleModelState(builder.build()));
|
||||
}
|
||||
// item/handheld
|
||||
else if (transform.equals("forge:default-tool"))
|
||||
{
|
||||
TRSRTransformation thirdperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
|
||||
new Vector3f(0, 1.25f / 16, -3.5f / 16),
|
||||
TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, 90, -35)),
|
||||
new Vector3f(0.85f, 0.85f, 0.85f),
|
||||
null));
|
||||
TRSRTransformation firstperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
|
||||
new Vector3f(0, 4f / 16, 2f / 16),
|
||||
TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, -135, 25)),
|
||||
new Vector3f(1.7f, 1.7f, 1.7f),
|
||||
null));
|
||||
ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(TransformType.THIRD_PERSON, thirdperson, TransformType.FIRST_PERSON, firstperson)));
|
||||
ret.state = Optional.<IModelState>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),
|
||||
TransformType.FIRST_PERSON_LEFT_HAND, get(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f))));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -543,13 +561,37 @@ public class ForgeBlockStateV1 extends Marker
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("thirdperson"), TRSRTransformation.class);
|
||||
transform.remove("thirdperson");
|
||||
transforms.put(TransformType.THIRD_PERSON, TRSRTransformation.blockCenterToCorner(t));
|
||||
transforms.put(TransformType.THIRD_PERSON_RIGHT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("thirdperson_righthand"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("thirdperson_righthand"), TRSRTransformation.class);
|
||||
transform.remove("thirdperson_righthand");
|
||||
transforms.put(TransformType.THIRD_PERSON_RIGHT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("thirdperson_lefthand"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("thirdperson_lefthand"), TRSRTransformation.class);
|
||||
transform.remove("thirdperson_lefthand");
|
||||
transforms.put(TransformType.THIRD_PERSON_LEFT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("firstperson"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("firstperson"), TRSRTransformation.class);
|
||||
transform.remove("firstperson");
|
||||
transforms.put(TransformType.FIRST_PERSON, TRSRTransformation.blockCenterToCorner(t));
|
||||
transforms.put(TransformType.FIRST_PERSON_RIGHT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("firstperson_righthand"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("firstperson_righthand"), TRSRTransformation.class);
|
||||
transform.remove("firstperson_righthand");
|
||||
transforms.put(TransformType.FIRST_PERSON_RIGHT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("firstperson_lefthand"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("firstperson_lefthand"), TRSRTransformation.class);
|
||||
transform.remove("firstperson_lefthand");
|
||||
transforms.put(TransformType.FIRST_PERSON_LEFT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("head"))
|
||||
{
|
||||
@@ -707,7 +749,7 @@ public class ForgeBlockStateV1 extends Marker
|
||||
|
||||
public static class TRSRDeserializer implements JsonDeserializer<TRSRTransformation>
|
||||
{
|
||||
public static TRSRDeserializer INSTANCE = new TRSRDeserializer();
|
||||
public static final TRSRDeserializer INSTANCE = new TRSRDeserializer();
|
||||
|
||||
public TRSRTransformation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IColoredBakedQuad {
|
||||
public static class ColoredBakedQuad extends BakedQuad implements IColoredBakedQuad
|
||||
{
|
||||
public ColoredBakedQuad(int[] data, int tintIndex, EnumFacing side)
|
||||
{
|
||||
super(data, tintIndex, side);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
@@ -16,5 +14,5 @@ public interface ICustomModelLoader extends IResourceManagerReloadListener
|
||||
/*
|
||||
* loads (or reloads) specified model
|
||||
*/
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws IOException;
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception;
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/*
|
||||
* Version of IBakedModel with less restriction on camera transformations and with explicit format of the baked array.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public interface IFlexibleBakedModel extends IBakedModel
|
||||
{
|
||||
/*
|
||||
* Specifies the format which BakedQuads' getVertexData will have.
|
||||
*/
|
||||
VertexFormat getFormat();
|
||||
|
||||
/*
|
||||
* Default implementation of IFlexibleBakedModel that should be useful in most cases
|
||||
*/
|
||||
public static class Wrapper implements IFlexibleBakedModel
|
||||
{
|
||||
private final IBakedModel parent;
|
||||
VertexFormat format;
|
||||
|
||||
public Wrapper(IBakedModel parent, VertexFormat format)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side)
|
||||
{
|
||||
return parent.getFaceQuads(side);
|
||||
}
|
||||
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
return parent.getGeneralQuads();
|
||||
}
|
||||
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return parent.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return parent.isGui3d();
|
||||
}
|
||||
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return parent.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return parent.getParticleTexture();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return parent.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return new VertexFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,11 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
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;
|
||||
|
||||
@@ -36,7 +38,7 @@ public interface IModel
|
||||
* format argument (some attributes can be replaced with padding),
|
||||
* if there's no such info in this model.
|
||||
*/
|
||||
IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter);
|
||||
IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter);
|
||||
|
||||
/*
|
||||
* Default state this model will be baked with.
|
||||
|
||||
@@ -2,13 +2,12 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public interface IModelCustomData<M extends IModelCustomData<M>> extends IModel
|
||||
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.
|
||||
*/
|
||||
// 1.9: change IModel to M
|
||||
IModel process(ImmutableMap<String, String> customData);
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package net.minecraftforge.client.model;
|
||||
/**
|
||||
* Implement this if the model can process "smooth_lighting" or "gui3d" attributes from the json.
|
||||
*/
|
||||
public interface IModelSimpleProperties<M extends IModelSimpleProperties<M>> extends IModel
|
||||
public interface IModelSimpleProperties extends IModel
|
||||
{
|
||||
M smoothLighting(boolean value);
|
||||
M gui3d(boolean value);
|
||||
IModel smoothLighting(boolean value);
|
||||
IModel gui3d(boolean value);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
public interface IModelUVLock extends IModel
|
||||
{
|
||||
public IModel uvlock(boolean value);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Created by rainwarrior on 2/2/16.
|
||||
*/
|
||||
public interface IModelWithSubmodels<M extends IModelWithSubmodels<M>> extends IModel
|
||||
{
|
||||
M setDefaultSubmodelEnabled (boolean value);
|
||||
M setSubmodelsEnabled(ImmutableSet<String> submodelNames, boolean show);
|
||||
}
|
||||
@@ -4,12 +4,16 @@ 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.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
@@ -20,26 +24,26 @@ 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 IFlexibleBakedModel
|
||||
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 IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType);
|
||||
Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType);
|
||||
|
||||
public static class MapWrapper implements IPerspectiveAwareModel
|
||||
{
|
||||
private final IFlexibleBakedModel parent;
|
||||
private final IBakedModel parent;
|
||||
private final ImmutableMap<TransformType, TRSRTransformation> transforms;
|
||||
|
||||
public MapWrapper(IFlexibleBakedModel parent, ImmutableMap<TransformType, TRSRTransformation> transforms)
|
||||
public MapWrapper(IBakedModel parent, ImmutableMap<TransformType, TRSRTransformation> transforms)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.transforms = transforms;
|
||||
}
|
||||
|
||||
public MapWrapper(IFlexibleBakedModel parent, IModelState state)
|
||||
public MapWrapper(IBakedModel parent, IModelState state)
|
||||
{
|
||||
this(parent, getTransforms(state));
|
||||
}
|
||||
@@ -58,17 +62,18 @@ public interface IPerspectiveAwareModel extends IFlexibleBakedModel
|
||||
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, new TRSRTransformation(transforms.getTransform(type)));
|
||||
builder.put(type, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(transforms.getTransform(type))));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(IFlexibleBakedModel model, ImmutableMap<TransformType, TRSRTransformation> transforms, TransformType cameraTransformType)
|
||||
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, ImmutableMap<TransformType, TRSRTransformation> transforms, TransformType cameraTransformType)
|
||||
{
|
||||
TRSRTransformation tr = transforms.get(cameraTransformType);
|
||||
Matrix4f mat = null;
|
||||
@@ -76,7 +81,7 @@ public interface IPerspectiveAwareModel extends IFlexibleBakedModel
|
||||
return Pair.of(model, mat);
|
||||
}
|
||||
|
||||
public static Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(IFlexibleBakedModel model, IModelState state, TransformType cameraTransformType)
|
||||
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())
|
||||
@@ -90,13 +95,13 @@ public interface IPerspectiveAwareModel extends IFlexibleBakedModel
|
||||
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> getFaceQuads(EnumFacing side) { return parent.getFaceQuads(side); }
|
||||
public List<BakedQuad> getGeneralQuads() { return parent.getGeneralQuads(); }
|
||||
public VertexFormat getFormat() { return parent.getFormat(); }
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) { return parent.getQuads(state, side, rand); }
|
||||
public ItemOverrideList getOverrides() { return parent.getOverrides(); }
|
||||
|
||||
@Override
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
return handlePerspective(this, transforms, cameraTransformType);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public interface IRetexturableModel<M extends IRetexturableModel<M>> extends IModel
|
||||
public interface IRetexturableModel extends IModel
|
||||
{
|
||||
/**
|
||||
* Applies new textures to the model.
|
||||
@@ -21,6 +21,5 @@ public interface IRetexturableModel<M extends IRetexturableModel<M>> extends IMo
|
||||
* @param textures New
|
||||
* @return Model with textures applied.
|
||||
*/
|
||||
// 1.9: change IModel to M
|
||||
IModel retexture(ImmutableMap<String, String> textures);
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
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.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public interface ISmartBlockModel extends IBakedModel
|
||||
{
|
||||
IBakedModel handleBlockState(IBlockState state);
|
||||
|
||||
public static abstract class Wrapper implements ISmartBlockModel, IFlexibleBakedModel
|
||||
{
|
||||
protected final IFlexibleBakedModel parent;
|
||||
|
||||
public Wrapper(IFlexibleBakedModel parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side)
|
||||
{
|
||||
return parent.getFaceQuads(side);
|
||||
}
|
||||
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
return parent.getGeneralQuads();
|
||||
}
|
||||
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return parent.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return parent.isGui3d();
|
||||
}
|
||||
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return parent.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return parent.getParticleTexture();
|
||||
}
|
||||
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return parent.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return parent.getFormat();
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class PerspectiveWrapper extends Wrapper implements IPerspectiveAwareModel
|
||||
{
|
||||
protected final IPerspectiveAwareModel parent;
|
||||
|
||||
public PerspectiveWrapper(IPerspectiveAwareModel parent)
|
||||
{
|
||||
super(parent);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType type)
|
||||
{
|
||||
Pair<? extends IFlexibleBakedModel, Matrix4f> pair = parent.handlePerspective(type);
|
||||
return Pair.of(new ISmartBlockModel.Wrapper(pair.getLeft())
|
||||
{
|
||||
public IBakedModel handleBlockState(IBlockState state)
|
||||
{
|
||||
return PerspectiveWrapper.this.handleBlockState(state);
|
||||
}
|
||||
}, pair.getRight());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
|
||||
public interface ISmartItemModel extends IBakedModel
|
||||
{
|
||||
IBakedModel handleItemState(ItemStack stack);
|
||||
}
|
||||
@@ -3,5 +3,5 @@ package net.minecraftforge.client.model;
|
||||
|
||||
public interface ISmartVariant
|
||||
{
|
||||
IModel process(IModel base, ModelLoader loader);
|
||||
IModel process(IModel base);
|
||||
}
|
||||
@@ -10,9 +10,12 @@ import javax.vecmath.Vector4f;
|
||||
|
||||
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;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
@@ -20,27 +23,36 @@ 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 com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
public final class ItemLayerModel implements IRetexturableModel
|
||||
{
|
||||
|
||||
public static final ItemLayerModel instance = new ItemLayerModel(ImmutableList.<ResourceLocation>of());
|
||||
public static final ItemLayerModel INSTANCE = new ItemLayerModel(ImmutableList.<ResourceLocation>of());
|
||||
|
||||
private final ImmutableList<ResourceLocation> textures;
|
||||
private final ItemOverrideList overrides;
|
||||
|
||||
public ItemLayerModel(ImmutableList<ResourceLocation> textures)
|
||||
{
|
||||
this(textures, ItemOverrideList.NONE);
|
||||
}
|
||||
|
||||
public ItemLayerModel(ImmutableList<ResourceLocation> textures, ItemOverrideList overrides)
|
||||
{
|
||||
this.textures = textures;
|
||||
this.overrides = overrides;
|
||||
}
|
||||
|
||||
public ItemLayerModel(ModelBlock model)
|
||||
{
|
||||
this(getTextures(model));
|
||||
this(getTextures(model), model.createOverrides());
|
||||
}
|
||||
|
||||
private static ImmutableList<ResourceLocation> getTextures(ModelBlock model)
|
||||
@@ -68,7 +80,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
|
||||
public IModel retexture(ImmutableMap<String, String> textures)
|
||||
public ItemLayerModel retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
ImmutableList.Builder<ResourceLocation> builder = ImmutableList.builder();
|
||||
for(int i = 0; i < textures.size() + this.textures.size(); i++)
|
||||
@@ -82,10 +94,10 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
builder.add(this.textures.get(i));
|
||||
}
|
||||
}
|
||||
return new ItemLayerModel(builder.build());
|
||||
return new ItemLayerModel(builder.build(), overrides);
|
||||
}
|
||||
|
||||
public IFlexibleBakedModel bake(IModelState state, final VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
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());
|
||||
@@ -96,48 +108,24 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
}
|
||||
TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? new ResourceLocation("missingno") : textures.get(0));
|
||||
ImmutableMap<TransformType, TRSRTransformation> map = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
|
||||
return new BakedItemModel(builder.build(), particle, format, map, null);
|
||||
return new BakedItemModel(builder.build(), particle, map, overrides, null);
|
||||
}
|
||||
|
||||
@Deprecated // remove 1.9
|
||||
public static class BakedModel implements IFlexibleBakedModel
|
||||
private static final class BakedItemModel implements IPerspectiveAwareModel
|
||||
{
|
||||
private final ImmutableList<BakedQuad> quads;
|
||||
private final TextureAtlasSprite particle;
|
||||
private final VertexFormat format;
|
||||
|
||||
public BakedModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, VertexFormat format)
|
||||
{
|
||||
this.quads = quads;
|
||||
this.particle = particle;
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public boolean isAmbientOcclusion() { return true; }
|
||||
public boolean isGui3d() { return false; }
|
||||
public boolean isBuiltInRenderer() { return false; }
|
||||
public TextureAtlasSprite getParticleTexture() { return particle; }
|
||||
public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side) { return ImmutableList.of(); }
|
||||
public List<BakedQuad> getGeneralQuads() { return quads; }
|
||||
public VertexFormat getFormat() { return format; }
|
||||
}
|
||||
|
||||
private static class BakedItemModel implements IFlexibleBakedModel, IPerspectiveAwareModel
|
||||
{
|
||||
private final ImmutableList<BakedQuad> quads;
|
||||
private final TextureAtlasSprite particle;
|
||||
private final VertexFormat format;
|
||||
private final ImmutableMap<TransformType, TRSRTransformation> transforms;
|
||||
private final IFlexibleBakedModel otherModel;
|
||||
private final IBakedModel otherModel;
|
||||
private final boolean isCulled;
|
||||
private final ItemOverrideList overrides;
|
||||
|
||||
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, VertexFormat format, ImmutableMap<TransformType, TRSRTransformation> transforms, IFlexibleBakedModel otherModel)
|
||||
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides, IBakedModel otherModel)
|
||||
{
|
||||
this.quads = quads;
|
||||
this.particle = particle;
|
||||
this.format = format;
|
||||
this.transforms = transforms;
|
||||
this.overrides = overrides;
|
||||
if(otherModel != null)
|
||||
{
|
||||
this.otherModel = otherModel;
|
||||
@@ -153,7 +141,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
builder.add(quad);
|
||||
}
|
||||
}
|
||||
this.otherModel = new BakedItemModel(builder.build(), particle, format, transforms, this);
|
||||
this.otherModel = new BakedItemModel(builder.build(), particle, transforms, overrides, this);
|
||||
isCulled = false;
|
||||
}
|
||||
}
|
||||
@@ -163,13 +151,16 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
public boolean isBuiltInRenderer() { return false; }
|
||||
public TextureAtlasSprite getParticleTexture() { return particle; }
|
||||
public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side) { return ImmutableList.of(); }
|
||||
public List<BakedQuad> getGeneralQuads() { return quads; }
|
||||
public VertexFormat getFormat() { return format; }
|
||||
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType type)
|
||||
public ItemOverrideList getOverrides() { return overrides; }
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
|
||||
{
|
||||
Pair<? extends IFlexibleBakedModel, Matrix4f> pair = IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, type);
|
||||
if(side == null) return quads;
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
|
||||
{
|
||||
Pair<? extends IBakedModel, Matrix4f> pair = IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, type);
|
||||
if(type == TransformType.GUI && !isCulled && pair.getRight() == null)
|
||||
{
|
||||
return Pair.of(otherModel, null);
|
||||
@@ -182,7 +173,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional<TRSRTransformation> transform)
|
||||
public static ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional<TRSRTransformation> transform)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
|
||||
@@ -236,14 +227,14 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
}
|
||||
}
|
||||
// front
|
||||
builder.add(buildQuad(format, transform, EnumFacing.NORTH, tint,
|
||||
builder.add(buildQuad(format, transform, EnumFacing.NORTH, sprite, tint,
|
||||
0, 0, 7.5f / 16f, sprite.getMinU(), sprite.getMaxV(),
|
||||
0, 1, 7.5f / 16f, sprite.getMinU(), sprite.getMinV(),
|
||||
1, 1, 7.5f / 16f, sprite.getMaxU(), sprite.getMinV(),
|
||||
1, 0, 7.5f / 16f, sprite.getMaxU(), sprite.getMaxV()
|
||||
));
|
||||
// back
|
||||
builder.add(buildQuad(format, transform, EnumFacing.SOUTH, tint,
|
||||
builder.add(buildQuad(format, transform, EnumFacing.SOUTH, sprite, tint,
|
||||
0, 0, 8.5f / 16f, sprite.getMinU(), sprite.getMaxV(),
|
||||
1, 0, 8.5f / 16f, sprite.getMaxU(), sprite.getMaxV(),
|
||||
1, 1, 8.5f / 16f, sprite.getMaxU(), sprite.getMinV(),
|
||||
@@ -252,7 +243,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected boolean isTransparent(int[] pixels, int uMax, int vMax, int u, int v)
|
||||
private static boolean isTransparent(int[] pixels, int uMax, int vMax, int u, int v)
|
||||
{
|
||||
return (pixels[u + (vMax - 1 - v) * uMax] >> 24 & 0xFF) == 0;
|
||||
}
|
||||
@@ -341,7 +332,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
throw new IllegalArgumentException("can't handle z-oriented side");
|
||||
}
|
||||
return buildQuad(
|
||||
format, transform, side.getOpposite(), tint, // getOpposite is related either to the swapping of V direction, or something else
|
||||
format, transform, side.getOpposite(), sprite, tint, // getOpposite is related either to the swapping of V direction, or something else
|
||||
x0, y0, z1, sprite.getInterpolatedU(u0), sprite.getInterpolatedV(v0),
|
||||
x1, y1, z1, sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v1),
|
||||
x1, y1, z2, sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v1),
|
||||
@@ -350,7 +341,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
}
|
||||
|
||||
private static final BakedQuad buildQuad(
|
||||
VertexFormat format, Optional<TRSRTransformation> transform, EnumFacing side, int tint,
|
||||
VertexFormat format, Optional<TRSRTransformation> transform, EnumFacing side, TextureAtlasSprite sprite, int tint,
|
||||
float x0, float y0, float z0, float u0, float v0,
|
||||
float x1, float y1, float z1, float u1, float v1,
|
||||
float x2, float y2, float z2, float u2, float v2,
|
||||
@@ -359,6 +350,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
|
||||
builder.setQuadTint(tint);
|
||||
builder.setQuadOrientation(side);
|
||||
builder.setTexture(sprite);
|
||||
putVertex(builder, format, transform, side, x0, y0, z0, u0, v0);
|
||||
putVertex(builder, format, transform, side, x1, y1, z1, u1, v1);
|
||||
putVertex(builder, format, transform, side, x2, y2, z2, u2, v2);
|
||||
@@ -408,7 +400,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
|
||||
public static enum Loader implements ICustomModelLoader
|
||||
{
|
||||
instance;
|
||||
INSTANCE;
|
||||
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@@ -422,7 +414,7 @@ public class ItemLayerModel implements IRetexturableModel<ItemLayerModel>
|
||||
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return ItemLayerModel.instance;
|
||||
return ItemLayerModel.INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class ItemTextureQuadConverter
|
||||
@@ -195,10 +198,10 @@ public final class ItemTextureQuadConverter
|
||||
y1 = 1f - y2;
|
||||
y2 = 1f - tmp;
|
||||
|
||||
return putQuad(format, transform, facing, color, x1, y1, x2, y2, z, u1, v1, u2, v2);
|
||||
return putQuad(format, transform, facing, sprite, color, x1, y1, x2, y2, z, u1, v1, u2, v2);
|
||||
}
|
||||
|
||||
private static UnpackedBakedQuad putQuad(VertexFormat format, TRSRTransformation transform, EnumFacing side, int color,
|
||||
private static UnpackedBakedQuad putQuad(VertexFormat format, TRSRTransformation transform, EnumFacing side, TextureAtlasSprite sprite, int color,
|
||||
float x1, float y1, float x2, float y2, float z,
|
||||
float u1, float v1, float u2, float v2)
|
||||
{
|
||||
@@ -206,7 +209,7 @@ public final class ItemTextureQuadConverter
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
|
||||
builder.setQuadTint(-1);
|
||||
builder.setQuadOrientation(side);
|
||||
builder.setQuadColored();
|
||||
builder.setTexture(sprite);
|
||||
|
||||
if (side == EnumFacing.NORTH)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,10 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
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 com.google.common.collect.ImmutableMap;
|
||||
@@ -27,7 +31,7 @@ public class MapModelState implements IModelState
|
||||
|
||||
public MapModelState(Map<Wrapper, IModelState> map, IModelState def)
|
||||
{
|
||||
this.map = ImmutableMap.<Wrapper, IModelState>copyOf(map);
|
||||
this.map = ImmutableMap.copyOf(map);
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,48 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.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;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.*;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>, IRetexturableModel<ModelDynBucket>
|
||||
public final class ModelDynBucket implements IModel, IModelCustomData, IRetexturableModel
|
||||
{
|
||||
public static final ModelResourceLocation LOCATION = new ModelResourceLocation(new ResourceLocation("forge", "dynbucket"), "inventory");
|
||||
|
||||
@@ -39,12 +54,12 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
|
||||
public static final IModel MODEL = new ModelDynBucket();
|
||||
|
||||
protected final ResourceLocation baseLocation;
|
||||
protected final ResourceLocation liquidLocation;
|
||||
protected final ResourceLocation coverLocation;
|
||||
private final ResourceLocation baseLocation;
|
||||
private final ResourceLocation liquidLocation;
|
||||
private final ResourceLocation coverLocation;
|
||||
|
||||
protected final Fluid fluid;
|
||||
protected final boolean flipGas;
|
||||
private final Fluid fluid;
|
||||
private final boolean flipGas;
|
||||
|
||||
public ModelDynBucket()
|
||||
{
|
||||
@@ -81,7 +96,7 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format,
|
||||
public IBakedModel bake(IModelState state, VertexFormat format,
|
||||
Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
|
||||
@@ -104,8 +119,8 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
if (baseLocation != null)
|
||||
{
|
||||
// build base (insidest)
|
||||
IFlexibleBakedModel model = (new ItemLayerModel(ImmutableList.of(baseLocation))).bake(state, format, bakedTextureGetter);
|
||||
builder.addAll(model.getGeneralQuads());
|
||||
IBakedModel model = (new ItemLayerModel(ImmutableList.of(baseLocation))).bake(state, format, bakedTextureGetter);
|
||||
builder.addAll(model.getQuads(null, null, 0));
|
||||
}
|
||||
if (liquidLocation != null && fluidSprite != null)
|
||||
{
|
||||
@@ -123,7 +138,7 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
}
|
||||
|
||||
|
||||
return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.<String, IFlexibleBakedModel>newHashMap());
|
||||
return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +155,7 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
* If the fluid can't be found, water is used
|
||||
*/
|
||||
@Override
|
||||
public IModel process(ImmutableMap<String, String> customData)
|
||||
public ModelDynBucket process(ImmutableMap<String, String> customData)
|
||||
{
|
||||
String fluidName = customData.get("fluid");
|
||||
Fluid fluid = FluidRegistry.getFluid(fluidName);
|
||||
@@ -171,7 +186,7 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
* If no liquid is given a hardcoded variant for the bucket is used.
|
||||
*/
|
||||
@Override
|
||||
public IModel retexture(ImmutableMap<String, String> textures)
|
||||
public ModelDynBucket retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
|
||||
ResourceLocation base = baseLocation;
|
||||
@@ -190,7 +205,7 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
|
||||
public enum LoaderDynBucket implements ICustomModelLoader
|
||||
{
|
||||
instance;
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
@@ -199,7 +214,7 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws IOException
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return MODEL;
|
||||
}
|
||||
@@ -211,26 +226,16 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
}
|
||||
}
|
||||
|
||||
// the dynamic bucket is based on the empty bucket
|
||||
protected static class BakedDynBucket extends ItemLayerModel.BakedModel implements ISmartItemModel, IPerspectiveAwareModel
|
||||
private static final class BakedDynBucketOverrideHandler extends ItemOverrideList
|
||||
{
|
||||
|
||||
private final ModelDynBucket parent;
|
||||
private final Map<String, IFlexibleBakedModel> cache; // contains all the baked models since they'll never change
|
||||
private final ImmutableMap<TransformType, TRSRTransformation> transforms;
|
||||
|
||||
public BakedDynBucket(ModelDynBucket parent,
|
||||
ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, VertexFormat format, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms,
|
||||
Map<String, IFlexibleBakedModel> cache)
|
||||
public static final BakedDynBucketOverrideHandler INSTANCE = new BakedDynBucketOverrideHandler();
|
||||
private BakedDynBucketOverrideHandler()
|
||||
{
|
||||
super(quads, particle, format);
|
||||
this.parent = parent;
|
||||
this.transforms = transforms;
|
||||
this.cache = cache;
|
||||
super(ImmutableList.<ItemOverride>of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState(ItemStack stack)
|
||||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
|
||||
{
|
||||
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
if (fluidStack == null)
|
||||
@@ -245,16 +250,17 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
if (fluidStack == null)
|
||||
{
|
||||
// empty bucket
|
||||
return this;
|
||||
return originalModel;
|
||||
}
|
||||
|
||||
BakedDynBucket model = (BakedDynBucket)originalModel;
|
||||
|
||||
Fluid fluid = fluidStack.getFluid();
|
||||
String name = fluid.getName();
|
||||
|
||||
if (!cache.containsKey(name))
|
||||
if (!model.cache.containsKey(name))
|
||||
{
|
||||
IModel model = parent.process(ImmutableMap.of("fluid", name));
|
||||
IModel parent = model.parent.process(ImmutableMap.of("fluid", name));
|
||||
Function<ResourceLocation, TextureAtlasSprite> textureGetter;
|
||||
textureGetter = new Function<ResourceLocation, TextureAtlasSprite>()
|
||||
{
|
||||
@@ -264,18 +270,62 @@ public class ModelDynBucket implements IModel, IModelCustomData<ModelDynBucket>,
|
||||
}
|
||||
};
|
||||
|
||||
IFlexibleBakedModel bakedModel = model.bake(new SimpleModelState(transforms), this.getFormat(), textureGetter);
|
||||
cache.put(name, bakedModel);
|
||||
IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter);
|
||||
model.cache.put(name, bakedModel);
|
||||
return bakedModel;
|
||||
}
|
||||
|
||||
return cache.get(name);
|
||||
return model.cache.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
// the dynamic bucket is based on the empty bucket
|
||||
private static final class BakedDynBucket implements IPerspectiveAwareModel
|
||||
{
|
||||
|
||||
private final ModelDynBucket parent;
|
||||
// FIXME: guava cache?
|
||||
private final Map<String, IBakedModel> cache; // contains all the baked models since they'll never change
|
||||
private final ImmutableMap<TransformType, TRSRTransformation> transforms;
|
||||
private final ImmutableList<BakedQuad> quads;
|
||||
private final TextureAtlasSprite particle;
|
||||
private final VertexFormat format;
|
||||
|
||||
public BakedDynBucket(ModelDynBucket parent,
|
||||
ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, VertexFormat format, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms,
|
||||
Map<String, IBakedModel> cache)
|
||||
{
|
||||
this.quads = quads;
|
||||
this.particle = particle;
|
||||
this.format = format;
|
||||
this.parent = parent;
|
||||
this.transforms = transforms;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return BakedDynBucketOverrideHandler.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, cameraTransformType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
|
||||
{
|
||||
if(side == null) return quads;
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
public boolean isAmbientOcclusion() { return true; }
|
||||
public boolean isGui3d() { return false; }
|
||||
public boolean isBuiltInRenderer() { return false; }
|
||||
public TextureAtlasSprite getParticleTexture() { return particle; }
|
||||
public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,21 @@ 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;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelRotation;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
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 net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.fluids.BlockFluidBase;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
@@ -42,11 +45,10 @@ import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
public final class ModelFluid implements IModelCustomData
|
||||
{
|
||||
public static final ModelFluid waterModel = new ModelFluid(FluidRegistry.WATER);
|
||||
public static final ModelFluid lavaModel = new ModelFluid(FluidRegistry.LAVA);
|
||||
public static final ModelFluid WATER = new ModelFluid(FluidRegistry.WATER);
|
||||
public static final ModelFluid LAVA = new ModelFluid(FluidRegistry.LAVA);
|
||||
private final Fluid fluid;
|
||||
|
||||
public ModelFluid(Fluid fluid)
|
||||
@@ -64,7 +66,7 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
return ImmutableSet.of(fluid.getStill(), fluid.getFlowing());
|
||||
}
|
||||
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
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());
|
||||
@@ -77,7 +79,7 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
|
||||
public static enum FluidLoader implements ICustomModelLoader
|
||||
{
|
||||
instance;
|
||||
INSTANCE;
|
||||
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@@ -91,11 +93,11 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return waterModel;
|
||||
return WATER;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BakedFluid implements IFlexibleBakedModel, ISmartBlockModel, IPerspectiveAwareModel
|
||||
private static final class BakedFluid implements IPerspectiveAwareModel
|
||||
{
|
||||
private static final int x[] = { 0, 0, 1, 1 };
|
||||
private static final int z[] = { 0, 1, 1, 0 };
|
||||
@@ -126,16 +128,6 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
private final boolean gas;
|
||||
private final EnumMap<EnumFacing, List<BakedQuad>> faceQuads;
|
||||
|
||||
public BakedFluid(Optional<TRSRTransformation> transformation, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas)
|
||||
{
|
||||
this(transformation, format, color, still, flowing, gas, Optional.<IExtendedBlockState>absent());
|
||||
}
|
||||
|
||||
public BakedFluid(Optional<TRSRTransformation> transformation, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas, Optional<IExtendedBlockState> stateOption)
|
||||
{
|
||||
this(transformation, ImmutableMap.<TransformType, TRSRTransformation>of(), format, color, still, flowing, gas, stateOption);
|
||||
}
|
||||
|
||||
public BakedFluid(Optional<TRSRTransformation> transformation, ImmutableMap<TransformType, TRSRTransformation> transforms, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas, Optional<IExtendedBlockState> stateOption)
|
||||
{
|
||||
this(transformation, transforms, format, color, still, flowing, gas, stateOption.isPresent(), getCorners(stateOption), getFlow(stateOption));
|
||||
@@ -217,25 +209,32 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
float s = MathHelper.sin(flow) * scale;
|
||||
|
||||
EnumFacing side = gas ? EnumFacing.DOWN : EnumFacing.UP;
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
|
||||
builder.setQuadOrientation(side);
|
||||
builder.setQuadColored();
|
||||
for(int i = gas ? 3 : 0; i != (gas ? -1 : 4); i+= (gas ? -1 : 1))
|
||||
UnpackedBakedQuad.Builder builder;
|
||||
ImmutableList.Builder<BakedQuad> topFaceBuilder = ImmutableList.builder();
|
||||
for(int k = 0; k < 2; k++)
|
||||
{
|
||||
putVertex(
|
||||
builder, side,
|
||||
x[i], y[i], z[i],
|
||||
topSprite.getInterpolatedU(8 + c * (x[i] * 2 - 1) + s * (z[i] * 2 - 1)),
|
||||
topSprite.getInterpolatedV(8 + c * (x[(i + 1) % 4] * 2 - 1) + s * (z[(i + 1) % 4] * 2 - 1)));
|
||||
builder = new UnpackedBakedQuad.Builder(format);
|
||||
builder.setQuadOrientation(side);
|
||||
builder.setTexture(topSprite);
|
||||
for (int i = gas ? 3 : 0; i != (gas ? -1 : 4); i += (gas ? -1 : 1))
|
||||
{
|
||||
int l = (k * 3) + (1 - 2 * k) * i;
|
||||
putVertex(
|
||||
builder, side,
|
||||
x[l], y[l], z[l],
|
||||
topSprite.getInterpolatedU(8 + c * (x[l] * 2 - 1) + s * (z[l] * 2 - 1)),
|
||||
topSprite.getInterpolatedV(8 + c * (x[(l + 1) % 4] * 2 - 1) + s * (z[(l + 1) % 4] * 2 - 1)));
|
||||
}
|
||||
topFaceBuilder.add(builder.build());
|
||||
}
|
||||
faceQuads.put(side, ImmutableList.<BakedQuad>of(builder.build()));
|
||||
faceQuads.put(side, topFaceBuilder.build());
|
||||
|
||||
// bottom
|
||||
|
||||
side = side.getOpposite();
|
||||
builder = new UnpackedBakedQuad.Builder(format);
|
||||
builder.setQuadOrientation(side);
|
||||
builder.setQuadColored();
|
||||
builder.setTexture(still);
|
||||
for(int i = gas ? 3 : 0; i != (gas ? -1 : 4); i+= (gas ? -1 : 1))
|
||||
{
|
||||
putVertex(
|
||||
@@ -257,7 +256,7 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
{
|
||||
builder = new UnpackedBakedQuad.Builder(format);
|
||||
builder.setQuadOrientation(side);
|
||||
builder.setQuadColored();
|
||||
builder.setTexture(flowing);
|
||||
for(int j = 0; j < 4; j++)
|
||||
{
|
||||
int l = (k * 3) + (1 - 2 * k) * j;
|
||||
@@ -279,7 +278,7 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
// 1 quad for inventory
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
|
||||
builder.setQuadOrientation(EnumFacing.UP);
|
||||
builder.setQuadColored();
|
||||
builder.setTexture(still);
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
putVertex(
|
||||
@@ -309,11 +308,10 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
builder.put(e, data);
|
||||
break;
|
||||
case COLOR:
|
||||
float d = LightUtil.diffuseLight(side);
|
||||
builder.put(e,
|
||||
d * ((color >> 16) & 0xFF) / 255f,
|
||||
d * ((color >> 8) & 0xFF) / 255f,
|
||||
d * (color & 0xFF) / 255f,
|
||||
((color >> 16) & 0xFF) / 255f,
|
||||
((color >> 8) & 0xFF) / 255f,
|
||||
(color & 0xFF) / 255f,
|
||||
((color >> 24) & 0xFF) / 255f);
|
||||
break;
|
||||
case UV: if(format.getElement(e).getIndex() == 0)
|
||||
@@ -333,7 +331,7 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isGui3d()
|
||||
@@ -356,23 +354,9 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side)
|
||||
{
|
||||
return faceQuads.get(side);
|
||||
}
|
||||
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
public IBakedModel handleBlockState(IBlockState state)
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
|
||||
{
|
||||
BakedFluid model = this;
|
||||
if(state instanceof IExtendedBlockState)
|
||||
{
|
||||
IExtendedBlockState exState = (IExtendedBlockState)state;
|
||||
@@ -386,20 +370,26 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
}
|
||||
key <<= 1;
|
||||
key |= 1;
|
||||
return modelCache.getUnchecked(key);
|
||||
model = modelCache.getUnchecked(key);
|
||||
}
|
||||
return this;
|
||||
if(side == null) return ImmutableList.of();
|
||||
return model.faceQuads.get(side);
|
||||
}
|
||||
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType type)
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
|
||||
{
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel process(ImmutableMap<String, String> customData)
|
||||
public ModelFluid process(ImmutableMap<String, String> customData)
|
||||
{
|
||||
if(!customData.containsKey("fluid")) return this;
|
||||
|
||||
@@ -409,7 +399,7 @@ public class ModelFluid implements IModelCustomData<ModelFluid>
|
||||
if(!FluidRegistry.isFluidRegistered(fluid))
|
||||
{
|
||||
FMLLog.severe("fluid '%s' not found", fluid);
|
||||
return waterModel;
|
||||
return WATER;
|
||||
}
|
||||
return new ModelFluid(FluidRegistry.getFluid(fluid));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,41 +1,49 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ModelLoader.VanillaLoader;
|
||||
import net.minecraftforge.client.model.ModelLoader.VariantLoader;
|
||||
import net.minecraftforge.client.model.b3d.B3DLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.common.animation.ITimeValue;
|
||||
import net.minecraftforge.common.model.animation.AnimationStateMachine;
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/*
|
||||
* Central hub for custom model loaders.
|
||||
*/
|
||||
public class ModelLoaderRegistry
|
||||
{
|
||||
private static final Set<ICustomModelLoader> loaders = new HashSet<ICustomModelLoader>();
|
||||
private static final Map<ResourceLocation, IModel> cache = new HashMap<ResourceLocation, IModel>();
|
||||
private static final Set<ICustomModelLoader> loaders = Sets.newHashSet();
|
||||
private static final Map<ResourceLocation, IModel> cache = Maps.newHashMap();
|
||||
private static final Deque<ResourceLocation> loadingModels = Queues.newArrayDeque();
|
||||
private static final Set<ResourceLocation> textures = Sets.newHashSet();
|
||||
private static IResourceManager manager;
|
||||
|
||||
// Forge built-in loaders
|
||||
static
|
||||
{
|
||||
registerLoader(B3DLoader.instance);
|
||||
registerLoader(OBJLoader.instance);
|
||||
registerLoader(ModelFluid.FluidLoader.instance);
|
||||
registerLoader(ItemLayerModel.Loader.instance);
|
||||
registerLoader(MultiLayerModel.Loader.instance);
|
||||
registerLoader(ModelDynBucket.LoaderDynBucket.instance);
|
||||
registerLoader(B3DLoader.INSTANCE);
|
||||
registerLoader(OBJLoader.INSTANCE);
|
||||
registerLoader(ModelFluid.FluidLoader.INSTANCE);
|
||||
registerLoader(ItemLayerModel.Loader.INSTANCE);
|
||||
registerLoader(MultiLayerModel.Loader.INSTANCE);
|
||||
registerLoader(ModelDynBucket.LoaderDynBucket.INSTANCE);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -55,6 +63,7 @@ public class ModelLoaderRegistry
|
||||
|
||||
public static ResourceLocation getActualLocation(ResourceLocation location)
|
||||
{
|
||||
if(location instanceof ModelResourceLocation) return location;
|
||||
if(location.getResourcePath().startsWith("builtin/")) return location;
|
||||
return new ResourceLocation(location.getResourceDomain(), "models/" + location.getResourcePath());
|
||||
}
|
||||
@@ -64,25 +73,20 @@ public class ModelLoaderRegistry
|
||||
* ResourceLocation argument will be passed directly to the custom model loaders,
|
||||
* ModelResourceLocation argument will be loaded through the blockstate system.
|
||||
*/
|
||||
public static IModel getModel(ResourceLocation location) throws IOException
|
||||
public static IModel getModel(ResourceLocation location) throws Exception
|
||||
{
|
||||
IModel model;
|
||||
if(location instanceof ModelResourceLocation)
|
||||
if(cache.containsKey(location)) return cache.get(location);
|
||||
for(ResourceLocation loading : loadingModels)
|
||||
{
|
||||
ModelLoader loader = ModelLoader.VanillaLoader.instance.getLoader();
|
||||
if(loader != null)
|
||||
if(location.getClass() == loading.getClass() && location.equals(loading))
|
||||
{
|
||||
model = loader.getVariantModel((ModelResourceLocation)location);
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.log(Level.ERROR, "Loading model too early, skipping: %s", location);
|
||||
model = getMissingModel();
|
||||
throw new LoaderException("circular model dependencies, stack: [" + Joiner.on(", ").join(loadingModels) + "]");
|
||||
}
|
||||
}
|
||||
else
|
||||
loadingModels.addLast(location);
|
||||
try
|
||||
{
|
||||
if(cache.containsKey(location)) return cache.get(location);
|
||||
ResourceLocation actual = getActualLocation(location);
|
||||
ICustomModelLoader accepted = null;
|
||||
for(ICustomModelLoader loader : loaders)
|
||||
@@ -93,61 +97,140 @@ public class ModelLoaderRegistry
|
||||
{
|
||||
if(accepted != null)
|
||||
{
|
||||
FMLLog.severe("2 loaders (%s and %s) want to load the same model %s", accepted, loader, location);
|
||||
throw new IllegalStateException("2 loaders want to load the same model");
|
||||
throw new LoaderException(String.format("2 loaders (%s and %s) want to load the same model %s", accepted, loader, location));
|
||||
}
|
||||
accepted = loader;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception checking if model %s can be loaded with loader %s, skipping", location, loader);
|
||||
throw new LoaderException(String.format("Exception checking if model %s can be loaded with loader %s, skipping", location, loader), e);
|
||||
}
|
||||
}
|
||||
|
||||
// no custom loaders found, try vanilla one
|
||||
// no custom loaders found, try vanilla ones
|
||||
if(accepted == null)
|
||||
{
|
||||
if(VanillaLoader.instance.accepts(actual)) accepted = VanillaLoader.instance;
|
||||
if(VariantLoader.INSTANCE.accepts(actual))
|
||||
{
|
||||
accepted = VariantLoader.INSTANCE;
|
||||
}
|
||||
else if(VanillaLoader.INSTANCE.accepts(actual))
|
||||
{
|
||||
accepted = VanillaLoader.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
if(accepted == null)
|
||||
{
|
||||
FMLLog.severe("no suitable loader found for the model %s, skipping", location);
|
||||
model = getMissingModel();
|
||||
throw new LoaderException("no suitable loader found for the model " + location + ", skipping");
|
||||
}
|
||||
else
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
model = accepted.loadModel(actual);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading model %s with loader %s, skipping", location, accepted);
|
||||
model = getMissingModel();
|
||||
}
|
||||
model = accepted.loadModel(actual);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new LoaderException(String.format("Exception loading model %s with loader %s, skipping", location, accepted), e);
|
||||
}
|
||||
if(model == getMissingModel())
|
||||
{
|
||||
throw new LoaderException(String.format("Loader %s returned missing model while loading model %s", accepted, location));
|
||||
}
|
||||
if(model == null)
|
||||
{
|
||||
throw new LoaderException(String.format("Loader %s returned null while loading model %s", accepted, location));
|
||||
}
|
||||
textures.addAll(model.getTextures());
|
||||
}
|
||||
finally
|
||||
{
|
||||
ResourceLocation popLoc = loadingModels.removeLast();
|
||||
if(popLoc != location)
|
||||
{
|
||||
throw new IllegalStateException("Corrupted loading model stack: " + popLoc + " != " + location);
|
||||
}
|
||||
}
|
||||
cache.put(location, model);
|
||||
for (ResourceLocation dep : model.getDependencies())
|
||||
{
|
||||
getModelOrMissing(dep);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this if you don't care about the exception and want some model anyway.
|
||||
*/
|
||||
public static IModel getModelOrMissing(ResourceLocation location)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getModel(location);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return getMissingModel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this if you want the model, but need to log the error.
|
||||
*/
|
||||
public static IModel getModelOrLogError(ResourceLocation location, String error)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getModel(location);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
FMLLog.getLogger().error(error, e);
|
||||
return getMissingModel();
|
||||
}
|
||||
}
|
||||
|
||||
public static IModel getMissingModel()
|
||||
{
|
||||
return ModelLoader.VanillaLoader.instance.getLoader().getMissingModel();
|
||||
if(ModelLoader.VanillaLoader.INSTANCE.getLoader() == null)
|
||||
{
|
||||
throw new IllegalStateException("Using ModelLoaderRegistry too early.");
|
||||
}
|
||||
return ModelLoader.VanillaLoader.INSTANCE.getLoader().getMissingModel();
|
||||
}
|
||||
|
||||
public static void clearModelCache()
|
||||
public static void clearModelCache(IResourceManager manager)
|
||||
{
|
||||
ModelLoaderRegistry.manager = manager;
|
||||
cache.clear();
|
||||
// putting the builtin models in
|
||||
cache.put(new ResourceLocation("minecraft:builtin/generated"), ModelLoader.VanillaLoader.instance.getLoader().getItemModel());
|
||||
cache.put(new ResourceLocation("minecraft:block/builtin/generated"), ModelLoader.VanillaLoader.instance.getLoader().getItemModel());
|
||||
cache.put(new ResourceLocation("minecraft:item/builtin/generated"), ModelLoader.VanillaLoader.instance.getLoader().getItemModel());
|
||||
cache.put(new ResourceLocation("minecraft:builtin/generated"), ItemLayerModel.INSTANCE);
|
||||
cache.put(new ResourceLocation("minecraft:block/builtin/generated"), ItemLayerModel.INSTANCE);
|
||||
cache.put(new ResourceLocation("minecraft:item/builtin/generated"), ItemLayerModel.INSTANCE);
|
||||
}
|
||||
|
||||
static Iterable<ResourceLocation> getTextures()
|
||||
{
|
||||
return textures;
|
||||
}
|
||||
|
||||
public static class LoaderException extends Exception
|
||||
{
|
||||
public LoaderException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public LoaderException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
public static IAnimationStateMachine loadASM(ResourceLocation location, ImmutableMap<String, ITimeValue> customParameters)
|
||||
{
|
||||
return AnimationStateMachine.load(manager, location, customParameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
public class ModelStateComposition implements IModelState
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumWorldBlockLayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
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;
|
||||
@@ -32,13 +32,13 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public class MultiLayerModel implements IModelCustomData<MultiLayerModel>
|
||||
public final class MultiLayerModel implements IModelCustomData
|
||||
{
|
||||
public static final MultiLayerModel instance = new MultiLayerModel(ImmutableMap.<Optional<EnumWorldBlockLayer>, ModelResourceLocation>of());
|
||||
public static final MultiLayerModel INSTANCE = new MultiLayerModel(ImmutableMap.<Optional<BlockRenderLayer>, ModelResourceLocation>of());
|
||||
|
||||
private final ImmutableMap<Optional<EnumWorldBlockLayer>, ModelResourceLocation> models;
|
||||
private final ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models;
|
||||
|
||||
public MultiLayerModel(ImmutableMap<Optional<EnumWorldBlockLayer>, ModelResourceLocation> models)
|
||||
public MultiLayerModel(ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models)
|
||||
{
|
||||
this.models = models;
|
||||
}
|
||||
@@ -55,34 +55,24 @@ public class MultiLayerModel implements IModelCustomData<MultiLayerModel>
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
private static ImmutableMap<Optional<EnumWorldBlockLayer>, IFlexibleBakedModel> buildModels(ImmutableMap<Optional<EnumWorldBlockLayer>, ModelResourceLocation> models, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
private static ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> buildModels(ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
ImmutableMap.Builder<Optional<EnumWorldBlockLayer>, IFlexibleBakedModel> builder = ImmutableMap.builder();
|
||||
for(Optional<EnumWorldBlockLayer> key : models.keySet())
|
||||
ImmutableMap.Builder<Optional<BlockRenderLayer>, IBakedModel> builder = ImmutableMap.builder();
|
||||
for(Optional<BlockRenderLayer> key : models.keySet())
|
||||
{
|
||||
IModel model;
|
||||
try
|
||||
{
|
||||
model = ModelLoaderRegistry.getModel(models.get(key));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Couldn't load MultiLayerModel dependency: %s", models.get(key));
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
}
|
||||
IModel model = ModelLoaderRegistry.getModelOrLogError(models.get(key), "Couldn't load MultiLayerModel dependency: " + models.get(key));
|
||||
builder.put(key, model.bake(new ModelStateComposition(state, model.getDefaultState()), format, bakedTextureGetter));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
IModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
return new MultiLayerBakedModel(
|
||||
buildModels(models, state, format, bakedTextureGetter),
|
||||
missing.bake(missing.getDefaultState(), format, bakedTextureGetter),
|
||||
format,
|
||||
IPerspectiveAwareModel.MapWrapper.getTransforms(state)
|
||||
);
|
||||
}
|
||||
@@ -94,16 +84,16 @@ public class MultiLayerModel implements IModelCustomData<MultiLayerModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel process(ImmutableMap<String, String> customData)
|
||||
public MultiLayerModel process(ImmutableMap<String, String> customData)
|
||||
{
|
||||
ImmutableMap.Builder<Optional<EnumWorldBlockLayer>, ModelResourceLocation> builder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<Optional<BlockRenderLayer>, ModelResourceLocation> builder = ImmutableMap.builder();
|
||||
for(String key : customData.keySet())
|
||||
{
|
||||
if("base".equals(key))
|
||||
{
|
||||
builder.put(Optional.<EnumWorldBlockLayer>absent(), getLocation(customData.get(key)));
|
||||
builder.put(Optional.<BlockRenderLayer>absent(), getLocation(customData.get(key)));
|
||||
}
|
||||
for(EnumWorldBlockLayer layer : EnumWorldBlockLayer.values())
|
||||
for(BlockRenderLayer layer : BlockRenderLayer.values())
|
||||
{
|
||||
if(layer.toString().equals(key))
|
||||
{
|
||||
@@ -111,8 +101,8 @@ public class MultiLayerModel implements IModelCustomData<MultiLayerModel>
|
||||
}
|
||||
}
|
||||
}
|
||||
ImmutableMap<Optional<EnumWorldBlockLayer>, ModelResourceLocation> models = builder.build();
|
||||
if(models.isEmpty()) return instance;
|
||||
ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models = builder.build();
|
||||
if(models.isEmpty()) return INSTANCE;
|
||||
return new MultiLayerModel(models);
|
||||
}
|
||||
|
||||
@@ -127,38 +117,17 @@ public class MultiLayerModel implements IModelCustomData<MultiLayerModel>
|
||||
return new ModelResourceLocation("builtin/missing", "missing");
|
||||
}
|
||||
|
||||
public static class MultiLayerBakedModel implements IFlexibleBakedModel, ISmartBlockModel, IPerspectiveAwareModel
|
||||
private static final class MultiLayerBakedModel implements IPerspectiveAwareModel
|
||||
{
|
||||
private final ImmutableMap<Optional<EnumWorldBlockLayer>, IFlexibleBakedModel> models;
|
||||
private final VertexFormat format;
|
||||
private final ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models;
|
||||
private final ImmutableMap<TransformType, TRSRTransformation> cameraTransforms;;
|
||||
private final IFlexibleBakedModel base;
|
||||
private final IFlexibleBakedModel missing;
|
||||
private final IBakedModel base;
|
||||
private final IBakedModel missing;
|
||||
private final ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>> quads;
|
||||
|
||||
private static final Function<ResourceLocation, TextureAtlasSprite> defaultTextureGetter = new Function<ResourceLocation, TextureAtlasSprite>()
|
||||
{
|
||||
public TextureAtlasSprite apply(ResourceLocation location)
|
||||
{
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
|
||||
}
|
||||
};
|
||||
|
||||
@Deprecated // remove 1.9
|
||||
public MultiLayerBakedModel(ImmutableMap<Optional<EnumWorldBlockLayer>, ModelResourceLocation> models, VertexFormat format, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms)
|
||||
{
|
||||
this(
|
||||
buildModels(models, TRSRTransformation.identity(), format, defaultTextureGetter),
|
||||
ModelLoaderRegistry.getMissingModel().bake(ModelLoaderRegistry.getMissingModel().getDefaultState(), format, defaultTextureGetter),
|
||||
format,
|
||||
cameraTransforms
|
||||
);
|
||||
}
|
||||
|
||||
public MultiLayerBakedModel(ImmutableMap<Optional<EnumWorldBlockLayer>, IFlexibleBakedModel> models, IFlexibleBakedModel missing, VertexFormat format, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms)
|
||||
public MultiLayerBakedModel(ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models, IBakedModel missing, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms)
|
||||
{
|
||||
this.models = models;
|
||||
this.format = format;
|
||||
this.cameraTransforms = cameraTransforms;
|
||||
this.missing = missing;
|
||||
if(models.containsKey(Optional.absent()))
|
||||
@@ -178,33 +147,35 @@ public class MultiLayerModel implements IModelCustomData<MultiLayerModel>
|
||||
quads = quadBuilder.build();
|
||||
}
|
||||
|
||||
private static ImmutableList<BakedQuad> buildQuads(ImmutableMap<Optional<EnumWorldBlockLayer>, IFlexibleBakedModel> models, Optional<EnumFacing> side)
|
||||
private static ImmutableList<BakedQuad> buildQuads(ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models, Optional<EnumFacing> side)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
for(IBakedModel model : models.values())
|
||||
{
|
||||
if(side.isPresent())
|
||||
{
|
||||
builder.addAll(model.getFaceQuads(side.get()));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addAll(model.getGeneralQuads());
|
||||
}
|
||||
builder.addAll(model.getQuads(null, side.orNull(), 0));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side)
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
|
||||
{
|
||||
return quads.get(Optional.of(side));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
return quads.get(Optional.absent());
|
||||
IBakedModel model;
|
||||
BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
|
||||
if(layer == null)
|
||||
{
|
||||
return quads.get(Optional.fromNullable(side));
|
||||
}
|
||||
else if(!models.containsKey(Optional.of(layer)))
|
||||
{
|
||||
model = missing;
|
||||
}
|
||||
else
|
||||
{
|
||||
model = models.get(Optional.of(layer));
|
||||
}
|
||||
// assumes that child model will handle this state properly. FIXME?
|
||||
return model.getQuads(state, side, rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -238,32 +209,21 @@ public class MultiLayerModel implements IModelCustomData<MultiLayerModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleBlockState(IBlockState state)
|
||||
{
|
||||
Optional<EnumWorldBlockLayer> layer = Optional.of(MinecraftForgeClient.getRenderLayer());
|
||||
if(!models.containsKey(layer))
|
||||
{
|
||||
return missing;
|
||||
}
|
||||
return models.get(layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, cameraTransforms, cameraTransformType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Loader implements ICustomModelLoader
|
||||
{
|
||||
instance;
|
||||
INSTANCE;
|
||||
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@@ -277,7 +237,7 @@ public class MultiLayerModel implements IModelCustomData<MultiLayerModel>
|
||||
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return MultiLayerModel.instance;
|
||||
return MultiLayerModel.INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -10,44 +9,89 @@ import java.util.Set;
|
||||
|
||||
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.ItemOverride;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
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 com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MultiModel implements IModel
|
||||
// TODO: Switch to vanilla class, or to something similar
|
||||
@Deprecated
|
||||
public final class MultiModel implements IModel
|
||||
{
|
||||
public static class Baked implements IFlexibleBakedModel, IPerspectiveAwareModel
|
||||
private static final class Baked implements IPerspectiveAwareModel
|
||||
{
|
||||
protected final IFlexibleBakedModel base;
|
||||
protected final ImmutableMap<String, IFlexibleBakedModel> parts;
|
||||
private final ResourceLocation location;
|
||||
private final IBakedModel base;
|
||||
private final ImmutableMap<String, IBakedModel> parts;
|
||||
|
||||
protected final IFlexibleBakedModel internalBase;
|
||||
protected ImmutableList<BakedQuad> general;
|
||||
protected ImmutableMap<EnumFacing, ImmutableList<BakedQuad>> faces;
|
||||
protected final ImmutableMap<TransformType, Pair<Baked, TRSRTransformation>> transforms;
|
||||
|
||||
public Baked(IFlexibleBakedModel base, ImmutableMap<String, IFlexibleBakedModel> 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())
|
||||
{
|
||||
this(null, false, base, parts);
|
||||
}
|
||||
@Override
|
||||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
|
||||
{
|
||||
if(originalModel != Baked.this)
|
||||
{
|
||||
return originalModel;
|
||||
}
|
||||
boolean dirty = false;
|
||||
IBakedModel newBase = null;
|
||||
|
||||
public Baked(ResourceLocation location, boolean perspective, IFlexibleBakedModel base, ImmutableMap<String, IFlexibleBakedModel> parts)
|
||||
if(base != null)
|
||||
{
|
||||
newBase = base.getOverrides().handleItemState(base, stack, world, entity);
|
||||
if(base != newBase)
|
||||
{
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
ImmutableMap.Builder<String, IBakedModel> builder = ImmutableMap.builder();
|
||||
for(Map.Entry<String, IBakedModel> entry : parts.entrySet())
|
||||
{
|
||||
IBakedModel newPart = entry.getValue().getOverrides().handleItemState(entry.getValue(), stack, world, entity);
|
||||
builder.put(entry.getKey(), newPart);
|
||||
if(entry.getValue() != newPart)
|
||||
{
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
if(dirty)
|
||||
{
|
||||
// TODO: caching?
|
||||
return new Baked(location, newBase instanceof IPerspectiveAwareModel, newBase, builder.build());
|
||||
}
|
||||
return Baked.this;
|
||||
}
|
||||
};
|
||||
|
||||
public Baked(ResourceLocation location, boolean perspective, IBakedModel base, ImmutableMap<String, IBakedModel> parts)
|
||||
{
|
||||
this.location = location;
|
||||
this.base = base;
|
||||
this.parts = parts;
|
||||
|
||||
@@ -55,7 +99,7 @@ public class MultiModel implements IModel
|
||||
internalBase = base;
|
||||
else
|
||||
{
|
||||
Iterator<IFlexibleBakedModel> iter = parts.values().iterator();
|
||||
Iterator<IBakedModel> iter = parts.values().iterator();
|
||||
if (iter.hasNext())
|
||||
internalBase = iter.next();
|
||||
else
|
||||
@@ -69,8 +113,8 @@ public class MultiModel implements IModel
|
||||
ImmutableMap.Builder<TransformType, Pair<Baked, TRSRTransformation>> builder = ImmutableMap.builder();
|
||||
for(TransformType type : TransformType.values())
|
||||
{
|
||||
Pair<? extends IFlexibleBakedModel, Matrix4f> p = perBase.handlePerspective(type);
|
||||
IFlexibleBakedModel newBase = p.getLeft();
|
||||
Pair<? extends IBakedModel, Matrix4f> p = perBase.handlePerspective(type);
|
||||
IBakedModel newBase = p.getLeft();
|
||||
builder.put(type, Pair.of(new Baked(location, false, newBase, parts), new TRSRTransformation(p.getRight())));
|
||||
}
|
||||
transforms = builder.build();
|
||||
@@ -112,72 +156,59 @@ public class MultiModel implements IModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side)
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
|
||||
{
|
||||
if(faces == null)
|
||||
if(quads == null)
|
||||
{
|
||||
// Create map of each face's quads.
|
||||
EnumMap<EnumFacing, ImmutableList<BakedQuad>> faces = Maps.newEnumMap(EnumFacing.class);
|
||||
ImmutableMap.Builder<Optional<EnumFacing>, ImmutableList<BakedQuad>> builder = ImmutableMap.builder();
|
||||
|
||||
for (EnumFacing face : EnumFacing.values())
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> faceQuads = ImmutableList.builder();
|
||||
ImmutableList.Builder<BakedQuad> quads = ImmutableList.builder();
|
||||
if (base != null)
|
||||
faceQuads.addAll(base.getFaceQuads(face));
|
||||
for (IFlexibleBakedModel bakedPart : parts.values())
|
||||
faceQuads.addAll(bakedPart.getFaceQuads(face));
|
||||
faces.put(face, faceQuads.build());
|
||||
{
|
||||
quads.addAll(base.getQuads(state, face, 0));
|
||||
}
|
||||
for (IBakedModel bakedPart : parts.values())
|
||||
{
|
||||
quads.addAll(bakedPart.getQuads(state, face, 0));
|
||||
}
|
||||
builder.put(Optional.of(face), quads.build());
|
||||
}
|
||||
this.faces = Maps.immutableEnumMap(faces);
|
||||
}
|
||||
return faces.get(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
if(general == null)
|
||||
{
|
||||
// Create list of general quads.
|
||||
ImmutableList.Builder<BakedQuad> genQuads = ImmutableList.builder();
|
||||
ImmutableList.Builder<BakedQuad> quads = ImmutableList.builder();
|
||||
if (base != null)
|
||||
genQuads.addAll(base.getGeneralQuads());
|
||||
for (IFlexibleBakedModel bakedPart : parts.values())
|
||||
genQuads.addAll(bakedPart.getGeneralQuads());
|
||||
general = genQuads.build();
|
||||
{
|
||||
quads.addAll(base.getQuads(state, null, 0));
|
||||
}
|
||||
for (IBakedModel bakedPart : parts.values())
|
||||
{
|
||||
quads.addAll(bakedPart.getQuads(state, null, 0));
|
||||
}
|
||||
builder.put(Optional.<EnumFacing>absent(), quads.build());
|
||||
this.quads = builder.build();
|
||||
}
|
||||
return general;
|
||||
return quads.get(Optional.fromNullable(side));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return internalBase.getFormat();
|
||||
}
|
||||
|
||||
public IFlexibleBakedModel getBaseModel()
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
public Map<String, IFlexibleBakedModel> getParts()
|
||||
{
|
||||
return parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
if(transforms.isEmpty()) return Pair.of(this, null);
|
||||
Pair<Baked, TRSRTransformation> p = transforms.get(cameraTransformType);
|
||||
return Pair.of(p.getLeft(), p.getRight().getMatrix());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return overrides;
|
||||
}
|
||||
}
|
||||
|
||||
protected final ResourceLocation location;
|
||||
protected final IModel base;
|
||||
protected final IModelState baseState;
|
||||
protected final Map<String, Pair<IModel, IModelState>> parts;
|
||||
private final ResourceLocation location;
|
||||
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)
|
||||
{
|
||||
@@ -187,16 +218,6 @@ public class MultiModel implements IModel
|
||||
this.parts = parts;
|
||||
}
|
||||
|
||||
public MultiModel(IModel base, IModelState baseState, ImmutableMap<String, Pair<IModel, IModelState>> parts)
|
||||
{
|
||||
this(null, base, baseState, parts);
|
||||
}
|
||||
|
||||
public MultiModel(IModel base, IModelState baseState, Map<String, Pair<IModel, IModelState>> parts)
|
||||
{
|
||||
this(null, base, baseState, ImmutableMap.copyOf(parts));
|
||||
}
|
||||
|
||||
public MultiModel(ResourceLocation location, IModel base, IModelState baseState, Map<String, Pair<IModel, IModelState>> parts)
|
||||
{
|
||||
this(location, base, baseState, ImmutableMap.copyOf(parts));
|
||||
@@ -231,19 +252,19 @@ public class MultiModel implements IModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
IFlexibleBakedModel bakedBase = null;
|
||||
IBakedModel bakedBase = null;
|
||||
|
||||
if (base != null)
|
||||
bakedBase = base.bake(state, format, bakedTextureGetter);
|
||||
|
||||
ImmutableMap.Builder<String, IFlexibleBakedModel> mapBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<String, IBakedModel> mapBuilder = ImmutableMap.builder();
|
||||
|
||||
for (Entry<String, Pair<IModel, IModelState>> entry : parts.entrySet())
|
||||
{
|
||||
Pair<IModel, IModelState> pair = entry.getValue();
|
||||
mapBuilder.put(entry.getKey(), pair.getLeft().bake(pair.getRight(), format, bakedTextureGetter));
|
||||
mapBuilder.put(entry.getKey(), pair.getLeft().bake(new ModelStateComposition(state, pair.getRight()), format, bakedTextureGetter));
|
||||
}
|
||||
|
||||
if(bakedBase == null && parts.isEmpty())
|
||||
@@ -255,22 +276,6 @@ public class MultiModel implements IModel
|
||||
return new Baked(location, true, bakedBase, mapBuilder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The base model of this MultiModel. May be null.
|
||||
*/
|
||||
public IModel getBaseModel()
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A map of the submodel name to its IModel and IModelState.
|
||||
*/
|
||||
public Map<String, Pair<IModel, IModelState>> getParts()
|
||||
{
|
||||
return parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
@@ -7,7 +11,7 @@ import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public class MultiModelState implements IModelState
|
||||
public final class MultiModelState implements IModelState
|
||||
{
|
||||
private final ImmutableMap<MultiModelPart, ? extends IModelState> states;
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
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 com.google.common.collect.ImmutableMap;
|
||||
|
||||
/*
|
||||
* Simple implementation of IModelState via a map and a default value.
|
||||
*/
|
||||
public class SimpleModelState implements IModelState
|
||||
public final class SimpleModelState implements IModelState
|
||||
{
|
||||
private final ImmutableMap<? extends IModelPart, TRSRTransformation> map;
|
||||
private final Optional<TRSRTransformation> def;
|
||||
|
||||
@@ -1,28 +1,8 @@
|
||||
package net.minecraftforge.client.model.animation;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
import net.minecraftforge.common.util.JsonUtils;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
public enum Animation implements IResourceManagerReloadListener
|
||||
public enum Animation
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
@@ -53,151 +33,9 @@ public enum Animation implements IResourceManagerReloadListener
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a new instance if AnimationStateMachine at specified location, with specified custom parameters.
|
||||
*/
|
||||
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> customParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
ClipResolver clipResolver = new ClipResolver();
|
||||
ParameterResolver parameterResolver = new ParameterResolver(customParameters);
|
||||
Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(clipResolver);
|
||||
TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(parameterResolver);
|
||||
IResource resource = manager.getResource(location);
|
||||
AnimationStateMachine asm = asmGson.fromJson(new InputStreamReader(resource.getInputStream(), "UTF-8"), AnimationStateMachine.class);
|
||||
clipResolver.asm = asm;
|
||||
parameterResolver.asm = asm;
|
||||
asm.initialize();
|
||||
//String json = asmGson.toJson(asm);
|
||||
//System.out.println(location + ": " + json);
|
||||
return asm;
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading Animation State Machine %s, skipping", location);
|
||||
return missing;
|
||||
}
|
||||
catch(JsonParseException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading Animation State Machine %s, skipping", location);
|
||||
return missing;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(null);
|
||||
TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load armature associated with a vanilla model.
|
||||
*/
|
||||
public ModelBlockAnimation loadVanillaAnimation(ResourceLocation armatureLocation)
|
||||
{
|
||||
try
|
||||
{
|
||||
IResource resource = null;
|
||||
try
|
||||
{
|
||||
resource = manager.getResource(armatureLocation);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
// this is normal. FIXME: error reporting?
|
||||
return defaultModelBlockAnimation;
|
||||
}
|
||||
ModelBlockAnimation mba = mbaGson.fromJson(new InputStreamReader(resource.getInputStream(), "UTF-8"), ModelBlockAnimation.class);
|
||||
String json = mbaGson.toJson(mba);
|
||||
return mba;
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading vanilla model aniamtion %s, skipping", armatureLocation);
|
||||
return defaultModelBlockAnimation;
|
||||
}
|
||||
catch(JsonParseException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading vanilla model aniamtion %s, skipping", armatureLocation);
|
||||
return defaultModelBlockAnimation;
|
||||
}
|
||||
}
|
||||
|
||||
private IResourceManager manager;
|
||||
|
||||
private final AnimationStateMachine missing = new AnimationStateMachine(
|
||||
ImmutableMap.<String, ITimeValue>of(),
|
||||
ImmutableMap.of("missingno", (IClip)Clips.IdentityClip.instance),
|
||||
ImmutableList.of("missingno"),
|
||||
ImmutableMap.<String, String>of(),
|
||||
"missingno");
|
||||
|
||||
{
|
||||
missing.initialize();
|
||||
}
|
||||
|
||||
private final Gson asmGson = new GsonBuilder()
|
||||
.registerTypeAdapter(ImmutableList.class, JsonUtils.ImmutableListTypeAdapter.INSTANCE)
|
||||
.registerTypeAdapter(ImmutableMap.class, JsonUtils.ImmutableMapTypeAdapter.INSTANCE)
|
||||
.registerTypeAdapterFactory(Clips.CommonClipTypeAdapterFactory.INSTANCE)
|
||||
//.registerTypeAdapterFactory(ClipProviders.CommonClipProviderTypeAdapterFactory.INSTANCE)
|
||||
.registerTypeAdapterFactory(TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE)
|
||||
.setPrettyPrinting()
|
||||
.enableComplexMapKeySerialization()
|
||||
.disableHtmlEscaping()
|
||||
.create();
|
||||
|
||||
private static final class ClipResolver implements Function<String, IClip>
|
||||
{
|
||||
private AnimationStateMachine asm;
|
||||
|
||||
public IClip apply(String name)
|
||||
{
|
||||
return asm.getClips().get(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ParameterResolver implements Function<String, ITimeValue>
|
||||
{
|
||||
private final ImmutableMap<String, ITimeValue> customParameters;
|
||||
private AnimationStateMachine asm;
|
||||
|
||||
public ParameterResolver(ImmutableMap<String, ITimeValue> customParameters)
|
||||
{
|
||||
this.customParameters = customParameters;
|
||||
}
|
||||
|
||||
public ITimeValue apply(String name)
|
||||
{
|
||||
if(asm.getParameters().containsKey(name))
|
||||
{
|
||||
return asm.getParameters().get(name);
|
||||
}
|
||||
return customParameters.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
private final Gson mbaGson = new GsonBuilder()
|
||||
.registerTypeAdapter(ImmutableList.class, JsonUtils.ImmutableListTypeAdapter.INSTANCE)
|
||||
.registerTypeAdapter(ImmutableMap.class, JsonUtils.ImmutableMapTypeAdapter.INSTANCE)
|
||||
.setPrettyPrinting()
|
||||
.enableComplexMapKeySerialization()
|
||||
.disableHtmlEscaping()
|
||||
.create();
|
||||
|
||||
private final ModelBlockAnimation defaultModelBlockAnimation = new ModelBlockAnimation(ImmutableMap.<String, ImmutableMap<String, float[]>>of(), ImmutableMap.<String, ModelBlockAnimation.MBClip>of());
|
||||
|
||||
/**
|
||||
* Iternal hook, do not use.
|
||||
* Internal hook, do not use.
|
||||
*/
|
||||
public static void setClientPartialTickTime(float clientPartialTickTime) {
|
||||
Animation.INSTANCE.clientPartialTickTime = clientPartialTickTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iternal hook, do not use.
|
||||
*/
|
||||
public void onResourceManagerReload(IResourceManager manager)
|
||||
{
|
||||
this.manager = manager;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package net.minecraftforge.client.model.animation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
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;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.ModelStateComposition;
|
||||
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;
|
||||
|
||||
public final class AnimationItemOverrideList extends ItemOverrideList
|
||||
{
|
||||
private final IModel model;
|
||||
private final IModelState state;
|
||||
private final VertexFormat format;
|
||||
private final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter;
|
||||
|
||||
public AnimationItemOverrideList(IModel model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, ItemOverrideList overrides)
|
||||
{
|
||||
this(model, state, format, bakedTextureGetter, overrides.getOverrides());
|
||||
}
|
||||
|
||||
public AnimationItemOverrideList(IModel model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, List<ItemOverride> overrides)
|
||||
{
|
||||
super(overrides);
|
||||
this.model = model;
|
||||
this.state = state;
|
||||
this.format = format;
|
||||
this.bakedTextureGetter = bakedTextureGetter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
|
||||
{
|
||||
if(stack.hasCapability(net.minecraftforge.common.model.animation.CapabilityAnimation.ANIMATION_CAPABILITY, null))
|
||||
{
|
||||
// TODO: caching?
|
||||
IAnimationStateMachine asm = stack.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
|
||||
if(world == null)
|
||||
{
|
||||
world = entity.worldObj;
|
||||
}
|
||||
if(world == null)
|
||||
{
|
||||
world = Minecraft.getMinecraft().theWorld;
|
||||
}
|
||||
IModelState state = asm.apply(Animation.getWorldTime(world, Animation.getPartialTickTime())).getLeft();
|
||||
return model.bake(new ModelStateComposition(state, this.state), format, bakedTextureGetter);
|
||||
}
|
||||
return originalModel;
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,24 @@ import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.pipeline.VertexLighterFlat;
|
||||
import net.minecraftforge.client.model.pipeline.WorldRendererConsumer;
|
||||
import net.minecraftforge.client.model.pipeline.VertexBufferConsumer;
|
||||
import net.minecraftforge.common.animation.Event;
|
||||
import net.minecraftforge.common.animation.IEventHandler;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.animation.CapabilityAnimation;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -28,14 +33,14 @@ import org.lwjgl.opengl.GL11;
|
||||
* Some quirks are still left, deprecated for the moment.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AnimationModelBase<T extends Entity & IAnimationProvider> extends ModelBase implements IEventHandler<T>
|
||||
public class AnimationModelBase<T extends Entity> extends ModelBase implements IEventHandler<T>
|
||||
{
|
||||
private final VertexLighterFlat lighter;
|
||||
private final IModel model;
|
||||
private final ResourceLocation modelLocation;
|
||||
|
||||
public AnimationModelBase(IModel model, VertexLighterFlat lighter)
|
||||
public AnimationModelBase(ResourceLocation modelLocation, VertexLighterFlat lighter)
|
||||
{
|
||||
this.model = model;
|
||||
this.modelLocation = modelLocation;
|
||||
this.lighter = lighter;
|
||||
}
|
||||
|
||||
@@ -43,13 +48,14 @@ public class AnimationModelBase<T extends Entity & IAnimationProvider> extends M
|
||||
@Override
|
||||
public void render(Entity entity, float limbSwing, float limbSwingSpeed, float timeAlive, float yawHead, float rotationPitch, float scale)
|
||||
{
|
||||
if(!(entity instanceof IAnimationProvider))
|
||||
if(!(entity.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)))
|
||||
{
|
||||
throw new ClassCastException("AnimationModelBase expects IAnimationProvider");
|
||||
return;
|
||||
}
|
||||
|
||||
Pair<IModelState, Iterable<Event>> pair = ((IAnimationProvider)entity).asm().apply(timeAlive / 20);
|
||||
Pair<IModelState, Iterable<Event>> pair = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null).apply(timeAlive / 20);
|
||||
handleEvents((T)entity, timeAlive / 20, pair.getRight());
|
||||
IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
|
||||
IBakedModel bakedModel = model.bake(pair.getLeft(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
|
||||
|
||||
BlockPos pos = new BlockPos(entity.posX, entity.posY + entity.height, entity.posZ);
|
||||
@@ -58,16 +64,16 @@ public class AnimationModelBase<T extends Entity & IAnimationProvider> extends M
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.rotate(180, 0, 0, 1);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldRenderer = tessellator.getWorldRenderer();
|
||||
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
|
||||
worldRenderer.setTranslation(-0.5, -1.5, -0.5);
|
||||
VertexBuffer VertexBuffer = tessellator.getBuffer();
|
||||
VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
|
||||
VertexBuffer.setTranslation(-0.5, -1.5, -0.5);
|
||||
|
||||
lighter.setParent(new WorldRendererConsumer(worldRenderer));
|
||||
lighter.setParent(new VertexBufferConsumer(VertexBuffer));
|
||||
lighter.setWorld(entity.worldObj);
|
||||
lighter.setBlock(Blocks.air);
|
||||
lighter.setState(Blocks.air.getDefaultState());
|
||||
lighter.setBlockPos(pos);
|
||||
boolean empty = true;
|
||||
List<BakedQuad> quads = bakedModel.getGeneralQuads();
|
||||
List<BakedQuad> quads = bakedModel.getQuads(null, null, 0);
|
||||
if(!quads.isEmpty())
|
||||
{
|
||||
lighter.updateBlockInfo();
|
||||
@@ -79,7 +85,7 @@ public class AnimationModelBase<T extends Entity & IAnimationProvider> extends M
|
||||
}
|
||||
for(EnumFacing side : EnumFacing.values())
|
||||
{
|
||||
quads = bakedModel.getFaceQuads(side);
|
||||
quads = bakedModel.getQuads(null, side, 0);
|
||||
if(!quads.isEmpty())
|
||||
{
|
||||
if(empty) lighter.updateBlockInfo();
|
||||
@@ -92,12 +98,12 @@ public class AnimationModelBase<T extends Entity & IAnimationProvider> extends M
|
||||
}
|
||||
|
||||
// debug quad
|
||||
/*worldRenderer.pos(0, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 0).lightmap(240, 0).endVertex();
|
||||
worldRenderer.pos(0, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 1).lightmap(240, 0).endVertex();
|
||||
worldRenderer.pos(1, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 1).lightmap(240, 0).endVertex();
|
||||
worldRenderer.pos(1, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 0).lightmap(240, 0).endVertex();*/
|
||||
/*VertexBuffer.pos(0, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 0).lightmap(240, 0).endVertex();
|
||||
VertexBuffer.pos(0, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 1).lightmap(240, 0).endVertex();
|
||||
VertexBuffer.pos(1, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 1).lightmap(240, 0).endVertex();
|
||||
VertexBuffer.pos(1, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 0).lightmap(240, 0).endVertex();*/
|
||||
|
||||
worldRenderer.setTranslation(0, 0, 0);
|
||||
VertexBuffer.setTranslation(0, 0, 0);
|
||||
|
||||
tessellator.draw();
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
@@ -1,54 +1,36 @@
|
||||
package net.minecraftforge.client.model.animation;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
import net.minecraftforge.client.model.ISmartBlockModel;
|
||||
import net.minecraftforge.common.animation.Event;
|
||||
import net.minecraftforge.common.animation.IEventHandler;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.animation.CapabilityAnimation;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
/**
|
||||
* Generic TileEntitySpecialRenderer that works with the Forge model system and animations.
|
||||
*/
|
||||
public class AnimationTESR<T extends TileEntity & IAnimationProvider> extends FastTESR<T> implements IEventHandler<T>
|
||||
public class AnimationTESR<T extends TileEntity> extends FastTESR<T> implements IEventHandler<T>
|
||||
{
|
||||
protected static BlockRendererDispatcher blockRenderer;
|
||||
|
||||
protected static final LoadingCache<Pair<IExtendedBlockState, IModelState>, IBakedModel> modelCache = CacheBuilder.newBuilder().maximumSize(10).expireAfterWrite(100, TimeUnit.MILLISECONDS).build(new CacheLoader<Pair<IExtendedBlockState, IModelState>, IBakedModel>()
|
||||
public void renderTileEntityFast(T te, double x, double y, double z, float partialTick, int breakStage, VertexBuffer renderer)
|
||||
{
|
||||
public IBakedModel load(Pair<IExtendedBlockState, IModelState> key) throws Exception
|
||||
if(!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null))
|
||||
{
|
||||
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(key.getLeft().getClean());
|
||||
if(model instanceof ISmartBlockModel)
|
||||
{
|
||||
model = ((ISmartBlockModel)model).handleBlockState(key.getLeft().withProperty(Properties.AnimationProperty, key.getRight()));
|
||||
}
|
||||
return model;
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
protected static IBakedModel getModel(IExtendedBlockState state, IModelState modelState)
|
||||
{
|
||||
return modelCache.getUnchecked(Pair.of(state, modelState));
|
||||
}
|
||||
|
||||
public void renderTileEntityFast(T te, double x, double y, double z, float partialTick, int breakStage, WorldRenderer renderer)
|
||||
{
|
||||
if(blockRenderer == null) blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
|
||||
BlockPos pos = te.getPos();
|
||||
IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
|
||||
@@ -63,14 +45,16 @@ public class AnimationTESR<T extends TileEntity & IAnimationProvider> extends Fa
|
||||
if(exState.getUnlistedNames().contains(Properties.AnimationProperty))
|
||||
{
|
||||
float time = Animation.getWorldTime(getWorld(), partialTick);
|
||||
Pair<IModelState, Iterable<Event>> pair = te.asm().apply(time);
|
||||
Pair<IModelState, Iterable<Event>> pair = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null).apply(time);
|
||||
handleEvents(te, time, pair.getRight());
|
||||
|
||||
IBakedModel model = getModel(exState, pair.getLeft());
|
||||
// TODO: caching?
|
||||
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
|
||||
exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
|
||||
|
||||
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
|
||||
|
||||
blockRenderer.getBlockModelRenderer().renderModel(world, model, state, pos, renderer, false);
|
||||
blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
@@ -18,7 +18,7 @@ public abstract class FastTESR<T extends TileEntity> extends TileEntitySpecialRe
|
||||
public final void renderTileEntityAt(T te, double x, double y, double z, float partialTicks, int destroyStage)
|
||||
{
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldRenderer = tessellator.getWorldRenderer();
|
||||
VertexBuffer VertexBuffer = tessellator.getBuffer();
|
||||
this.bindTexture(TextureMap.locationBlocksTexture);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -34,10 +34,10 @@ public abstract class FastTESR<T extends TileEntity> extends TileEntitySpecialRe
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
}
|
||||
|
||||
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
|
||||
VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
|
||||
|
||||
renderTileEntityFast(te, x, y, z, partialTicks, destroyStage, worldRenderer);
|
||||
worldRenderer.setTranslation(0, 0, 0);
|
||||
renderTileEntityFast(te, x, y, z, partialTicks, destroyStage, VertexBuffer);
|
||||
VertexBuffer.setTranslation(0, 0, 0);
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
@@ -45,5 +45,5 @@ public abstract class FastTESR<T extends TileEntity> extends TileEntitySpecialRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void renderTileEntityFast(T te, double x, double y, double z, float partialTicks, int destroyStage, WorldRenderer worldRenderer);
|
||||
public abstract void renderTileEntityFast(T te, double x, double y, double z, float partialTicks, int destroyStage, VertexBuffer VertexBuffer);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package net.minecraftforge.client.model.animation;
|
||||
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
|
||||
|
||||
/**
|
||||
* Something that can provide the Animation State Machine, for example and Entity or a Block
|
||||
*/
|
||||
public interface IAnimationProvider
|
||||
{
|
||||
public IAnimationStateMachine asm();
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package net.minecraftforge.client.model.animation;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
@@ -12,13 +15,25 @@ import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockPart;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
import net.minecraftforge.client.model.TRSRTransformation;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.client.model.animation.ModelBlockAnimation.Parameter.Interpolation;
|
||||
import net.minecraftforge.client.model.animation.ModelBlockAnimation.Parameter.Type;
|
||||
import net.minecraftforge.client.model.animation.ModelBlockAnimation.Parameter.Variable;
|
||||
import net.minecraftforge.common.animation.Event;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.animation.IClip;
|
||||
import net.minecraftforge.common.model.animation.IJoint;
|
||||
import net.minecraftforge.common.model.animation.IJointClip;
|
||||
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 com.google.common.collect.ImmutableCollection;
|
||||
@@ -28,6 +43,9 @@ import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.UnmodifiableIterator;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ModelBlockAnimation
|
||||
@@ -152,7 +170,7 @@ public class ModelBlockAnimation
|
||||
MBJointClip clip = jointClips.get(mbJoint.getName());
|
||||
if(clip != null) return clip;
|
||||
}
|
||||
return JointClips.IdentityJointClip.instance;
|
||||
return JointClips.IdentityJointClip.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -509,4 +527,47 @@ public class ModelBlockAnimation
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load armature associated with a vanilla model.
|
||||
*/
|
||||
public static ModelBlockAnimation loadVanillaAnimation(IResourceManager manager, ResourceLocation armatureLocation)
|
||||
{
|
||||
try
|
||||
{
|
||||
IResource resource = null;
|
||||
try
|
||||
{
|
||||
resource = manager.getResource(armatureLocation);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
// this is normal. FIXME: error reporting?
|
||||
return defaultModelBlockAnimation;
|
||||
}
|
||||
ModelBlockAnimation mba = mbaGson.fromJson(new InputStreamReader(resource.getInputStream(), "UTF-8"), ModelBlockAnimation.class);
|
||||
//String json = mbaGson.toJson(mba);
|
||||
return mba;
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading vanilla model animation %s, skipping", armatureLocation);
|
||||
return defaultModelBlockAnimation;
|
||||
}
|
||||
catch(JsonParseException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading vanilla model animation %s, skipping", armatureLocation);
|
||||
return defaultModelBlockAnimation;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Gson mbaGson = new GsonBuilder()
|
||||
.registerTypeAdapter(ImmutableList.class, JsonUtils.ImmutableListTypeAdapter.INSTANCE)
|
||||
.registerTypeAdapter(ImmutableMap.class, JsonUtils.ImmutableMapTypeAdapter.INSTANCE)
|
||||
.setPrettyPrinting()
|
||||
.enableComplexMapKeySerialization()
|
||||
.disableHtmlEscaping()
|
||||
.create();
|
||||
|
||||
private static final ModelBlockAnimation defaultModelBlockAnimation = new ModelBlockAnimation(ImmutableMap.<String, ImmutableMap<String, float[]>>of(), ImmutableMap.<String, ModelBlockAnimation.MBClip>of());
|
||||
}
|
||||
@@ -1,27 +1,27 @@
|
||||
package net.minecraftforge.client.model.b3d;
|
||||
|
||||
import net.minecraftforge.client.model.TRSRTransformation;
|
||||
import net.minecraftforge.client.model.animation.Event;
|
||||
import net.minecraftforge.client.model.animation.IClip;
|
||||
import net.minecraftforge.client.model.animation.IJoint;
|
||||
import net.minecraftforge.client.model.animation.IJointClip;
|
||||
import net.minecraftforge.client.model.animation.JointClips;
|
||||
import net.minecraftforge.client.model.b3d.B3DLoader.NodeJoint;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Key;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Node;
|
||||
import net.minecraftforge.common.animation.Event;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.animation.IClip;
|
||||
import net.minecraftforge.common.model.animation.IJoint;
|
||||
import net.minecraftforge.common.model.animation.IJointClip;
|
||||
import net.minecraftforge.common.model.animation.JointClips;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
// FIXME: is this fast enough?
|
||||
public enum B3DClip implements IClip
|
||||
{
|
||||
instance;
|
||||
INSTANCE;
|
||||
|
||||
public IJointClip apply(final IJoint joint)
|
||||
{
|
||||
if(!(joint instanceof NodeJoint))
|
||||
{
|
||||
return JointClips.IdentityJointClip.instance;
|
||||
return JointClips.IdentityJointClip.INSTANCE;
|
||||
}
|
||||
return new NodeClip(((NodeJoint)joint).getNode());
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public enum B3DClip implements IClip
|
||||
{
|
||||
ret = ret.compose(new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null));
|
||||
}
|
||||
// TODO animated TRSR for speed?
|
||||
// TODO animated TRSRTransformation for speed?
|
||||
else
|
||||
{
|
||||
ret = ret.compose(endTr);
|
||||
|
||||
@@ -16,30 +16,40 @@ 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;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.*;
|
||||
import net.minecraftforge.client.model.animation.IClip;
|
||||
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.animation.IJoint;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Animation;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Face;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.IKind;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Key;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Mesh;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Node;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Texture;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Vertex;
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
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 net.minecraftforge.common.model.animation.IClip;
|
||||
import net.minecraftforge.common.model.animation.IJoint;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
@@ -64,13 +74,12 @@ import com.google.gson.JsonParser;
|
||||
|
||||
/*
|
||||
* Loader for Blitz3D models.
|
||||
* To enable for your mod call instance.addDomain(modid).
|
||||
* To enable for your mod call instance.addDomain(modId).
|
||||
* If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class B3DLoader implements ICustomModelLoader
|
||||
public enum B3DLoader implements ICustomModelLoader
|
||||
{
|
||||
public static final B3DLoader instance = new B3DLoader();
|
||||
INSTANCE;
|
||||
|
||||
private IResourceManager manager;
|
||||
|
||||
@@ -94,7 +103,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws IOException
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath());
|
||||
if(!cache.containsKey(file))
|
||||
@@ -120,75 +129,20 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
//FMLLog.log(Level.ERROR, e, "Exception loading model %s with B3D loader, skipping", modelLocation);
|
||||
cache.put(file, null);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
B3DModel model = cache.get(file);
|
||||
if(model == null) return ModelLoaderRegistry.getMissingModel();
|
||||
if(modelLocation instanceof B3DMeshLocation)
|
||||
{
|
||||
String mesh = ((B3DMeshLocation)modelLocation).getMesh();
|
||||
if(!model.getMeshes().containsKey(mesh))
|
||||
{
|
||||
FMLLog.severe("No mesh named %s in model %s, skipping", mesh, modelLocation);
|
||||
return ModelLoaderRegistry.getMissingModel();
|
||||
}
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(mesh), 1);
|
||||
}
|
||||
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(), 1);
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.<String>of(), true, true, 1);
|
||||
}
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(((Node<Mesh>)model.getRoot()).getName()), 1);
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(model.getRoot().getName()), true, true, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use json or IModelCustomData.process
|
||||
*/
|
||||
@Deprecated
|
||||
public static class B3DMeshLocation extends ResourceLocation
|
||||
{
|
||||
public final String mesh;
|
||||
|
||||
public B3DMeshLocation(String domain, String path, String mesh)
|
||||
{
|
||||
super(domain, path);
|
||||
this.mesh = mesh;
|
||||
}
|
||||
|
||||
public String getMesh()
|
||||
{
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((mesh == null) ? 0 : mesh.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj) return true;
|
||||
if (!super.equals(obj)) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
B3DMeshLocation other = (B3DMeshLocation) obj;
|
||||
if (mesh == null)
|
||||
{
|
||||
if (other.mesh != null) return false;
|
||||
}
|
||||
else if (!mesh.equals(other.mesh)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class B3DState implements IModelState
|
||||
public static final class B3DState implements IModelState
|
||||
{
|
||||
private final Animation animation;
|
||||
private final int frame;
|
||||
@@ -254,7 +208,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
|
||||
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
|
||||
{
|
||||
// TODO optionify better
|
||||
// TODO make more use of Optional
|
||||
if(!part.isPresent()) return parent.apply(part);
|
||||
if(!(part.get() instanceof NodeJoint))
|
||||
{
|
||||
@@ -323,7 +277,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
// current node local pose
|
||||
ret = ret.compose(new TRSRTransformation(key.getPos(), key.getRot(), key.getScale(), null));
|
||||
// this part moved inside the model
|
||||
// inverse bind of the curent node
|
||||
// inverse bind of the current node
|
||||
/*Matrix4f rm = new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null).getMatrix();
|
||||
rm.invert();
|
||||
ret = ret.compose(new TRSRTransformation(rm));
|
||||
@@ -358,7 +312,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
}
|
||||
|
||||
public static class NodeJoint implements IJoint
|
||||
static final class NodeJoint implements IJoint
|
||||
{
|
||||
private final Node<?> node;
|
||||
|
||||
@@ -412,7 +366,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
|
||||
public static enum B3DFrameProperty implements IUnlistedProperty<B3DState>
|
||||
{
|
||||
instance;
|
||||
INSTANCE;
|
||||
public String getName()
|
||||
{
|
||||
return "B3DFrame";
|
||||
@@ -434,187 +388,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
}
|
||||
|
||||
public static class PartWrapper<K extends IKind<K>> implements IModelPart
|
||||
{
|
||||
private final Node<K> node;
|
||||
|
||||
public static <K extends IKind<K>> PartWrapper<K> create(Node<K> node)
|
||||
{
|
||||
return new PartWrapper<K>(node);
|
||||
}
|
||||
|
||||
public PartWrapper(Node<K> node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public Node<K> getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use ModelWrapper, this will be removed in 1.9
|
||||
*/
|
||||
@Deprecated
|
||||
public static class Wrapper extends PartWrapper<Mesh> implements IRetexturableModel<Wrapper>, IModelCustomData<Wrapper>
|
||||
{
|
||||
private final ResourceLocation location;
|
||||
private final ImmutableSet<String> meshes;
|
||||
private final ImmutableMap<String, ResourceLocation> textures;
|
||||
|
||||
public Wrapper(ResourceLocation location, List<Texture> textures, B3DModel.Node<Mesh> mesh)
|
||||
{
|
||||
this(location, ImmutableSet.<String>of(), buildTextures(textures), mesh);
|
||||
}
|
||||
|
||||
public Wrapper(ResourceLocation location, ImmutableMap<String, ResourceLocation> textures, B3DModel.Node<Mesh> mesh)
|
||||
{
|
||||
this(location, ImmutableSet.<String>of(), textures, mesh);
|
||||
}
|
||||
|
||||
public Wrapper(ResourceLocation location, ImmutableSet<String> meshes, List<Texture> textures, B3DModel.Node<Mesh> mesh)
|
||||
{
|
||||
this(location, meshes, buildTextures(textures), mesh);
|
||||
}
|
||||
|
||||
public Wrapper(ResourceLocation location, ImmutableSet<String> meshes, ImmutableMap<String, ResourceLocation> textures, B3DModel.Node<Mesh> mesh)
|
||||
{
|
||||
super(mesh);
|
||||
this.location = location;
|
||||
this.meshes = meshes;
|
||||
this.textures = textures;
|
||||
}
|
||||
|
||||
private static ImmutableMap<String, ResourceLocation> buildTextures(List<Texture> textures)
|
||||
{
|
||||
ImmutableMap.Builder<String, ResourceLocation> builder = ImmutableMap.builder();
|
||||
|
||||
for(Texture t : textures)
|
||||
{
|
||||
String path = t.getPath();
|
||||
String location = getLocation(path);
|
||||
if(!location.startsWith("#")) location = "#" + location;
|
||||
builder.put(path, new ResourceLocation(location));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String getLocation(String path)
|
||||
{
|
||||
if(path.endsWith(".png")) path = path.substring(0, path.length() - ".png".length());
|
||||
return path;
|
||||
}
|
||||
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
// no dependencies for in-file models
|
||||
// FIXME maybe add child meshes
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Collection<ResourceLocation> getTextures()
|
||||
{
|
||||
return Collections2.filter(textures.values(), new Predicate<ResourceLocation>()
|
||||
{
|
||||
public boolean apply(ResourceLocation loc)
|
||||
{
|
||||
return !loc.getResourcePath().startsWith("#");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
ImmutableMap.Builder<String, TextureAtlasSprite> builder = ImmutableMap.builder();
|
||||
TextureAtlasSprite missing = bakedTextureGetter.apply(new ResourceLocation("missingno"));
|
||||
for(Map.Entry<String, ResourceLocation> e : textures.entrySet())
|
||||
{
|
||||
if(e.getValue().getResourcePath().startsWith("#"))
|
||||
{
|
||||
FMLLog.severe("unresolved texture '%s' for b3d model '%s'", e.getValue().getResourcePath(), location);
|
||||
builder.put(e.getKey(), missing);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.put(e.getKey(), bakedTextureGetter.apply(e.getValue()));
|
||||
}
|
||||
}
|
||||
builder.put("missingno", missing);
|
||||
return new BakedWrapper(getNode(), state, format, meshes, builder.build());
|
||||
}
|
||||
|
||||
public ResourceLocation getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
public ImmutableMap<String, ResourceLocation> getTextureMap()
|
||||
{
|
||||
return textures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((location == null) ? 0 : location.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
Wrapper other = (Wrapper) obj;
|
||||
if (location == null)
|
||||
{
|
||||
if (other.location != null) return false;
|
||||
}
|
||||
else if (!location.equals(other.location)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
ImmutableMap.Builder<String, ResourceLocation> builder = ImmutableMap.builder();
|
||||
for(Map.Entry<String, ResourceLocation> e : this.textures.entrySet())
|
||||
{
|
||||
String path = e.getKey();
|
||||
String loc = getLocation(path);
|
||||
if(textures.containsKey(loc))
|
||||
{
|
||||
String newLoc = textures.get(loc);
|
||||
if(newLoc == null) newLoc = getLocation(path);
|
||||
builder.put(e.getKey(), new ResourceLocation(newLoc));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.put(e);
|
||||
}
|
||||
}
|
||||
return new Wrapper(location, builder.build(), getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel process(ImmutableMap<String, String> customData)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
return new B3DState(getNode().getAnimation(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ModelWrapper implements IRetexturableModel<ModelWrapper>, IModelCustomData<ModelWrapper>, IModelSimpleProperties<ModelWrapper>, IAnimatedModel
|
||||
private static final class ModelWrapper implements IRetexturableModel, IModelCustomData, IModelSimpleProperties, IAnimatedModel
|
||||
{
|
||||
private final ResourceLocation modelLocation;
|
||||
private final B3DModel model;
|
||||
@@ -624,23 +398,11 @@ public class B3DLoader implements ICustomModelLoader
|
||||
private final boolean gui3d;
|
||||
private final int defaultKey;
|
||||
|
||||
@Deprecated // remove in 1.9
|
||||
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, int defaultKey)
|
||||
{
|
||||
this(modelLocation, model, meshes, true, true, defaultKey);
|
||||
}
|
||||
|
||||
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, boolean smooth, boolean gui3d, int defaultKey)
|
||||
{
|
||||
this(modelLocation, model, meshes, smooth, gui3d, defaultKey, buildTextures(model.getTextures()));
|
||||
}
|
||||
|
||||
@Deprecated // remove in 1.9
|
||||
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, int defaultKey, ImmutableMap<String, ResourceLocation> textures)
|
||||
{
|
||||
this(modelLocation, model, meshes, true, true, defaultKey, textures);
|
||||
}
|
||||
|
||||
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, boolean smooth, boolean gui3d, int defaultKey, ImmutableMap<String, ResourceLocation> textures)
|
||||
{
|
||||
this.modelLocation = modelLocation;
|
||||
@@ -691,7 +453,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
ImmutableMap.Builder<String, TextureAtlasSprite> builder = ImmutableMap.builder();
|
||||
TextureAtlasSprite missing = bakedTextureGetter.apply(new ResourceLocation("missingno"));
|
||||
@@ -712,7 +474,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel retexture(ImmutableMap<String, String> textures)
|
||||
public ModelWrapper retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
ImmutableMap.Builder<String, ResourceLocation> builder = ImmutableMap.builder();
|
||||
for(Map.Entry<String, ResourceLocation> e : this.textures.entrySet())
|
||||
@@ -730,18 +492,18 @@ public class B3DLoader implements ICustomModelLoader
|
||||
builder.put(e);
|
||||
}
|
||||
}
|
||||
return new ModelWrapper(modelLocation, model, meshes, defaultKey, builder.build());
|
||||
return new ModelWrapper(modelLocation, model, meshes, smooth, gui3d, defaultKey, builder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel process(ImmutableMap<String, String> data)
|
||||
public ModelWrapper process(ImmutableMap<String, String> data)
|
||||
{
|
||||
if(data.containsKey("mesh"))
|
||||
{
|
||||
JsonElement e = new JsonParser().parse(data.get("mesh"));
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isString())
|
||||
{
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(e.getAsString()), defaultKey, textures);
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(e.getAsString()), smooth, gui3d, defaultKey, textures);
|
||||
}
|
||||
else if (e.isJsonArray())
|
||||
{
|
||||
@@ -758,7 +520,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
return this;
|
||||
}
|
||||
}
|
||||
return new ModelWrapper(modelLocation, model, builder.build(), defaultKey, textures);
|
||||
return new ModelWrapper(modelLocation, model, builder.build(), smooth, gui3d, defaultKey, textures);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -771,7 +533,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
JsonElement e = new JsonParser().parse(data.get("key"));
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isNumber())
|
||||
{
|
||||
return new ModelWrapper(modelLocation, model, meshes, e.getAsNumber().intValue(), textures);
|
||||
return new ModelWrapper(modelLocation, model, meshes, smooth, gui3d, e.getAsNumber().intValue(), textures);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -786,7 +548,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
{
|
||||
if(name.equals("main"))
|
||||
{
|
||||
return Optional.<IClip>of(B3DClip.instance);
|
||||
return Optional.<IClip>of(B3DClip.INSTANCE);
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
@@ -817,7 +579,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static class BakedWrapper implements IFlexibleBakedModel, ISmartBlockModel, ISmartItemModel, IPerspectiveAwareModel
|
||||
private static final class BakedWrapper implements IPerspectiveAwareModel
|
||||
{
|
||||
private final Node<?> node;
|
||||
private final IModelState state;
|
||||
@@ -826,24 +588,18 @@ public class B3DLoader implements ICustomModelLoader
|
||||
private final VertexFormat format;
|
||||
private final ImmutableSet<String> meshes;
|
||||
private final ImmutableMap<String, TextureAtlasSprite> textures;
|
||||
private final LoadingCache<Integer, BakedWrapper> cache;
|
||||
private final LoadingCache<Integer, B3DState> cache;
|
||||
|
||||
private ImmutableList<BakedQuad> quads;
|
||||
|
||||
@Deprecated // remove in 1.9
|
||||
public BakedWrapper(Node<?> node, IModelState state, VertexFormat format, ImmutableSet<String> meshes, ImmutableMap<String, TextureAtlasSprite> textures)
|
||||
{
|
||||
this(node, state, true, true, format, meshes, textures);
|
||||
}
|
||||
|
||||
public BakedWrapper(final Node<?> node, final IModelState state, final boolean smooth, final boolean gui3d, final VertexFormat format, final ImmutableSet<String> meshes, final ImmutableMap<String, TextureAtlasSprite> textures)
|
||||
{
|
||||
this(node, state, smooth, gui3d, format, meshes, textures, CacheBuilder.newBuilder()
|
||||
.maximumSize(128)
|
||||
.expireAfterAccess(2, TimeUnit.MINUTES)
|
||||
.<Integer, BakedWrapper>build(new CacheLoader<Integer, BakedWrapper>()
|
||||
.<Integer, B3DState>build(new CacheLoader<Integer, B3DState>()
|
||||
{
|
||||
public BakedWrapper load(Integer frame) throws Exception
|
||||
public B3DState load(Integer frame) throws Exception
|
||||
{
|
||||
IModelState parent = state;
|
||||
Animation newAnimation = node.getAnimation();
|
||||
@@ -852,18 +608,12 @@ public class B3DLoader implements ICustomModelLoader
|
||||
B3DState ps = (B3DState)parent;
|
||||
parent = ps.getParent();
|
||||
}
|
||||
return new BakedWrapper(node, new B3DState(newAnimation, frame, frame, 0, parent), smooth, gui3d, format, meshes, textures);
|
||||
return new B3DState(newAnimation, frame, frame, 0, parent);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Deprecated // remove in 1.9
|
||||
public BakedWrapper(Node<?> node, IModelState state, VertexFormat format, ImmutableSet<String> meshes, ImmutableMap<String, TextureAtlasSprite> textures, LoadingCache<Integer, BakedWrapper> cache)
|
||||
{
|
||||
this(node, state, true, true, format, meshes, textures, cache);
|
||||
}
|
||||
|
||||
public BakedWrapper(Node<?> node, IModelState state, boolean smooth, boolean gui3d, VertexFormat format, ImmutableSet<String> meshes, ImmutableMap<String, TextureAtlasSprite> textures, LoadingCache<Integer, BakedWrapper> cache)
|
||||
public BakedWrapper(Node<?> node, IModelState state, boolean smooth, boolean gui3d, VertexFormat format, ImmutableSet<String> meshes, ImmutableMap<String, TextureAtlasSprite> textures, LoadingCache<Integer, B3DState> cache)
|
||||
{
|
||||
this.node = node;
|
||||
this.state = state;
|
||||
@@ -875,64 +625,121 @@ public class B3DLoader implements ICustomModelLoader
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(IBlockState state, 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))
|
||||
{
|
||||
// FIXME: should animation state handle the parent state, or should it remain here?
|
||||
IModelState parent = this.state;
|
||||
if(parent instanceof B3DState)
|
||||
{
|
||||
B3DState ps = (B3DState)parent;
|
||||
parent = ps.getParent();
|
||||
}
|
||||
IModelState newState = exState.getValue(Properties.AnimationProperty);
|
||||
if(newState != null)
|
||||
{
|
||||
modelState = new ModelStateComposition(parent, newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(quads == null)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
for(Node<?> child : node.getNodes().values())
|
||||
{
|
||||
builder.addAll(new BakedWrapper(child, state, format, meshes, textures).getGeneralQuads());
|
||||
}
|
||||
if(node.getKind() instanceof Mesh && meshes.contains(node.getName()))
|
||||
{
|
||||
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 LoadingCache<Node<?>, TRSRTransformation> localCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(32)
|
||||
.build(new CacheLoader<Node<?>, TRSRTransformation>()
|
||||
{
|
||||
public TRSRTransformation load(Node<?> node) throws Exception
|
||||
{
|
||||
return state.apply(Optional.of(new NodeJoint(node))).or(TRSRTransformation.identity());
|
||||
}
|
||||
});
|
||||
|
||||
public Matrix4f apply(Node<?> node)
|
||||
{
|
||||
return global.compose(localCache.getUnchecked(node)).getMatrix();
|
||||
}
|
||||
});
|
||||
for(Face f : faces)
|
||||
{
|
||||
UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format);
|
||||
quadBuilder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
|
||||
quadBuilder.setQuadColored();
|
||||
List<Texture> textures = null;
|
||||
if(f.getBrush() != null) textures = f.getBrush().getTextures();
|
||||
TextureAtlasSprite sprite;
|
||||
if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno");
|
||||
else if(textures.get(0) == B3DModel.Texture.White) sprite = ModelLoader.White.instance;
|
||||
else sprite = this.textures.get(textures.get(0).getPath());
|
||||
putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV2(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);
|
||||
builder.add(quadBuilder.build());
|
||||
}
|
||||
}
|
||||
generateQuads(builder, node, this.state);
|
||||
quads = builder.build();
|
||||
}
|
||||
// TODO: caching?
|
||||
if(this.state != modelState)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
generateQuads(builder, node, modelState);
|
||||
return builder.build();
|
||||
}
|
||||
return quads;
|
||||
}
|
||||
|
||||
private void generateQuads(ImmutableList.Builder<BakedQuad> builder, Node<?> node, final IModelState state)
|
||||
{
|
||||
for(Node<?> child : node.getNodes().values())
|
||||
{
|
||||
generateQuads(builder, child, state);
|
||||
}
|
||||
if(node.getKind() instanceof Mesh && meshes.contains(node.getName()))
|
||||
{
|
||||
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 LoadingCache<Node<?>, TRSRTransformation> localCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(32)
|
||||
.build(new CacheLoader<Node<?>, TRSRTransformation>()
|
||||
{
|
||||
public TRSRTransformation load(Node<?> node) throws Exception
|
||||
{
|
||||
return state.apply(Optional.of(new NodeJoint(node))).or(TRSRTransformation.identity());
|
||||
}
|
||||
});
|
||||
|
||||
public Matrix4f apply(Node<?> node)
|
||||
{
|
||||
return global.compose(localCache.getUnchecked(node)).getMatrix();
|
||||
}
|
||||
});
|
||||
for(Face f : faces)
|
||||
{
|
||||
UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format);
|
||||
quadBuilder.setContractUVs(true);
|
||||
quadBuilder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
|
||||
List<Texture> textures = null;
|
||||
if(f.getBrush() != null) textures = f.getBrush().getTextures();
|
||||
TextureAtlasSprite sprite;
|
||||
if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno");
|
||||
else if(textures.get(0) == B3DModel.Texture.White) sprite = ModelLoader.White.INSTANCE;
|
||||
else sprite = this.textures.get(textures.get(0).getPath());
|
||||
quadBuilder.setTexture(sprite);
|
||||
putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV2(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);
|
||||
builder.add(quadBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final void putVertexData(UnpackedBakedQuad.Builder builder, Vertex v, Vector3f faceNormal, TextureAtlasSprite sprite)
|
||||
{
|
||||
// TODO handle everything not handled (texture transformations, bones, transformations, normals, e.t.c)
|
||||
@@ -944,14 +751,13 @@ public class B3DLoader implements ICustomModelLoader
|
||||
builder.put(e, v.getPos().x, v.getPos().y, v.getPos().z, 1);
|
||||
break;
|
||||
case COLOR:
|
||||
float d = LightUtil.diffuseLight(faceNormal.x, faceNormal.y, faceNormal.z);
|
||||
if(v.getColor() != null)
|
||||
{
|
||||
builder.put(e, d * v.getColor().x, d * v.getColor().y, d * v.getColor().z, v.getColor().w);
|
||||
builder.put(e, v.getColor().x, v.getColor().y, v.getColor().z, v.getColor().w);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.put(e, d, d, d, 1);
|
||||
builder.put(e, 1, 1, 1, 1);
|
||||
}
|
||||
break;
|
||||
case UV:
|
||||
@@ -1012,70 +818,15 @@ public class B3DLoader implements ICustomModelLoader
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedWrapper handleBlockState(IBlockState 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())
|
||||
{
|
||||
return cache.getUnchecked(s.getFrame());
|
||||
}
|
||||
B3DState newState = new B3DState(newAnimation, s.getFrame(), s.getNextFrame(), s.getProgress(), parent);
|
||||
return new BakedWrapper(node, newState, format, meshes, textures);
|
||||
}
|
||||
}
|
||||
else if(exState.getUnlistedNames().contains(Properties.AnimationProperty))
|
||||
{
|
||||
// FIXME: should animation state handle the parent state, or should it remain here?
|
||||
IModelState parent = this.state;
|
||||
if(parent instanceof B3DState)
|
||||
{
|
||||
B3DState ps = (B3DState)parent;
|
||||
parent = ps.getParent();
|
||||
}
|
||||
IModelState newState = exState.getValue(Properties.AnimationProperty);
|
||||
if(newState != null)
|
||||
{
|
||||
return new BakedWrapper(node, new ModelStateComposition(parent, newState), format, meshes, textures);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
public BakedWrapper handleItemState(ItemStack stack)
|
||||
{
|
||||
// TODO specify how to get B3DState from ItemStack
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType);
|
||||
}
|
||||
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
// TODO handle items
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class B3DModel
|
||||
|
||||
public static class Parser
|
||||
{
|
||||
private static final int version = 0001;
|
||||
private static final int version = 1;
|
||||
private final ByteBuffer buf;
|
||||
|
||||
private byte[] tag = new byte[4];
|
||||
@@ -204,7 +204,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 differnce in model: ", ((float)version / 100)));
|
||||
logger.warn(String.format("Minor version difference in model: ", ((float)version / 100)));
|
||||
List<Texture> textures = Collections.emptyList();
|
||||
List<Brush> brushes = Collections.emptyList();
|
||||
Node<?> root = null;
|
||||
@@ -511,7 +511,7 @@ public class B3DModel
|
||||
|
||||
public static class Texture
|
||||
{
|
||||
public static Texture White = new Texture("builtin/white", 0, 0, new Vector2f(0, 0), new Vector2f(1, 1), 0);
|
||||
public static final Texture White = new Texture("builtin/white", 0, 0, new Vector2f(0, 0), new Vector2f(1, 1), 0);
|
||||
private final String path;
|
||||
private final int flags;
|
||||
private final int blend;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.minecraftforge.client.model.obj;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -22,11 +21,13 @@ import org.apache.logging.log4j.Level;
|
||||
* To enable your mod call instance.addDomain(modid).
|
||||
* If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry.
|
||||
*/
|
||||
public class OBJLoader implements ICustomModelLoader {
|
||||
public static final OBJLoader instance = new OBJLoader();
|
||||
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>();
|
||||
|
||||
public void addDomain(String domain)
|
||||
{
|
||||
@@ -38,6 +39,7 @@ public class OBJLoader implements ICustomModelLoader {
|
||||
{
|
||||
this.manager = resourceManager;
|
||||
cache.clear();
|
||||
errors.clear();
|
||||
}
|
||||
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
@@ -45,45 +47,41 @@ public class OBJLoader implements ICustomModelLoader {
|
||||
return enabledDomains.contains(modelLocation.getResourceDomain()) && modelLocation.getResourcePath().endsWith(".obj");
|
||||
}
|
||||
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws IOException
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath());
|
||||
if (!cache.containsKey(file))
|
||||
{
|
||||
IResource resource = null;
|
||||
try
|
||||
{
|
||||
IResource resource = null;
|
||||
try
|
||||
{
|
||||
resource = manager.getResource(file);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
if (modelLocation.getResourcePath().startsWith("models/block/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/item/" + file.getResourcePath().substring("models/block/".length())));
|
||||
else if (modelLocation.getResourcePath().startsWith("models/item/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/block/" + file.getResourcePath().substring("models/item/".length())));
|
||||
else throw e;
|
||||
}
|
||||
OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
|
||||
OBJModel model = null;
|
||||
try
|
||||
{
|
||||
model = parser.parse();
|
||||
}
|
||||
finally
|
||||
{
|
||||
cache.put(modelLocation, model);
|
||||
}
|
||||
resource = manager.getResource(file);
|
||||
}
|
||||
catch (IOException e)
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// FMLLog.log(Level.ERROR, e, "Exception loading model '%s' with OBJ loader, skipping", modelLocation);
|
||||
throw e;
|
||||
if (modelLocation.getResourcePath().startsWith("models/block/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/item/" + file.getResourcePath().substring("models/block/".length())));
|
||||
else if (modelLocation.getResourcePath().startsWith("models/item/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/block/" + file.getResourcePath().substring("models/item/".length())));
|
||||
else throw e;
|
||||
}
|
||||
OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
|
||||
OBJModel model = null;
|
||||
try
|
||||
{
|
||||
model = parser.parse();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
errors.put(modelLocation, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
cache.put(modelLocation, model);
|
||||
}
|
||||
}
|
||||
OBJModel model = cache.get(file);
|
||||
if (model == null) return ModelLoaderRegistry.getMissingModel();
|
||||
if (model == null) throw new ModelLoaderRegistry.LoaderException("Error loading model previously: " + file, errors.get(modelLocation));
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -22,24 +22,30 @@ 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.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.*;
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IModelCustomData;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
import net.minecraftforge.client.model.IRetexturableModel;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.core.helpers.Strings;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Function;
|
||||
@@ -53,8 +59,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<OBJModel>
|
||||
public class OBJModel implements IRetexturableModel, IModelCustomData
|
||||
{
|
||||
//private Gson GSON = new GsonBuilder().create();
|
||||
private MaterialLibrary matLib;
|
||||
@@ -95,10 +100,10 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
ImmutableMap.Builder<String, TextureAtlasSprite> builder = ImmutableMap.builder();
|
||||
builder.put(ModelLoader.White.loc.toString(), ModelLoader.White.instance);
|
||||
builder.put(ModelLoader.White.LOCATION.toString(), ModelLoader.White.INSTANCE);
|
||||
TextureAtlasSprite missing = bakedTextureGetter.apply(new ResourceLocation("missingno"));
|
||||
for (Map.Entry<String, Material> e : matLib.materials.entrySet())
|
||||
{
|
||||
@@ -197,212 +202,164 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
return this.groupList;
|
||||
}
|
||||
|
||||
private float[] parseFloats(String[] data) // Helper converting strings to floats
|
||||
{
|
||||
float[] ret = new float[data.length];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
ret[i] = Float.parseFloat(data[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//Partial reading of the OBJ format. Documentation taken from http://paulbourke.net/dataformats/obj/
|
||||
public OBJModel parse() throws IOException
|
||||
{
|
||||
String currentLine = "";
|
||||
Material material = new Material();
|
||||
material.setName(Material.DEFAULT_NAME);
|
||||
int usemtlCounter = 0;
|
||||
|
||||
// float[] minUVBounds = new float[] {0.0f, 0.0f};
|
||||
// float[] maxUVBounds = new float[] {1.0f, 1.0f};
|
||||
int lineNum = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
lineNum++;
|
||||
currentLine = objReader.readLine();
|
||||
if (currentLine == null) break;
|
||||
currentLine.trim();
|
||||
if (currentLine.isEmpty() || currentLine.startsWith("#")) continue;
|
||||
|
||||
String[] fields = WHITE_SPACE.split(currentLine, 2);
|
||||
String key = fields[0];
|
||||
String data = fields[1];
|
||||
String[] splitData = WHITE_SPACE.split(data);
|
||||
|
||||
if (key.equalsIgnoreCase("mtllib"))
|
||||
this.materialLibrary.parseMaterials(manager, data, objFrom);
|
||||
else if (key.equalsIgnoreCase("usemtl"))
|
||||
try
|
||||
{
|
||||
material = this.materialLibrary.materials.get(data);
|
||||
usemtlCounter++;
|
||||
}
|
||||
else if (key.equalsIgnoreCase("v"))
|
||||
{
|
||||
float[] floatSplitData = new float[splitData.length];
|
||||
for (int i = 0; i < splitData.length; i++)
|
||||
floatSplitData[i] = Float.parseFloat(splitData[i]);
|
||||
Vector4f pos = new Vector4f(floatSplitData[0], floatSplitData[1], floatSplitData[2], floatSplitData.length == 4 ? floatSplitData[3] : 1);
|
||||
Vertex vertex = new Vertex(pos, material);
|
||||
this.vertices.add(vertex);
|
||||
}
|
||||
else if (key.equalsIgnoreCase("vn"))
|
||||
{
|
||||
float[] floatSplitData = new float[splitData.length];
|
||||
for (int i = 0; i < splitData.length; i++)
|
||||
floatSplitData[i] = Float.parseFloat(splitData[i]);
|
||||
Normal normal = new Normal(floatSplitData);
|
||||
this.normals.add(normal);
|
||||
}
|
||||
else if (key.equalsIgnoreCase("vt"))
|
||||
{
|
||||
float[] floatSplitData = new float[splitData.length];
|
||||
for (int i = 0; i < splitData.length; i++)
|
||||
floatSplitData[i] = Float.parseFloat(splitData[i]);
|
||||
TextureCoordinate texCoord = new TextureCoordinate(new Vector3f(floatSplitData[0], floatSplitData[1], floatSplitData.length == 3 ? floatSplitData[2] : 1));
|
||||
if (texCoord.u < 0.0f || texCoord.u > 1.0f || texCoord.v < 0.0f || texCoord.v > 1.0f)
|
||||
throw new UVsOutOfBoundsException(this.objFrom);
|
||||
// this.UVsOutOfBounds = (texCoord.u < 0.0f || texCoord.u > 1.0f || texCoord.v < 0.0f || texCoord.v > 1.0f);
|
||||
String[] fields = WHITE_SPACE.split(currentLine, 2);
|
||||
String key = fields[0];
|
||||
String data = fields[1];
|
||||
String[] splitData = WHITE_SPACE.split(data);
|
||||
|
||||
// if (texCoord.u < 0.0f || texCoord.u > 1.0f || texCoord.v < 0.0f || texCoord.v > 1.0f)
|
||||
// {
|
||||
// this.UVsOutOfBounds = true;
|
||||
// texCoord.u -= Math.floor(texCoord.u);
|
||||
// texCoord.v -= Math.floor(texCoord.v);
|
||||
// }
|
||||
|
||||
// minUVBounds[0] = floatSplitData[0] < minUVBounds[0] ? floatSplitData[0] : minUVBounds[0];
|
||||
// minUVBounds[1] = floatSplitData[1] < minUVBounds[1] ? floatSplitData[1] : minUVBounds[1];
|
||||
// maxUVBounds[0] = floatSplitData[0] > maxUVBounds[0] ? floatSplitData[0] : maxUVBounds[0];
|
||||
// maxUVBounds[1] = floatSplitData[1] > maxUVBounds[1] ? floatSplitData[1] : maxUVBounds[1];
|
||||
// FMLLog.info("u: [%f, %f] v: [%f, %f]", minUVBounds[]);
|
||||
this.texCoords.add(texCoord);
|
||||
}
|
||||
else if (key.equalsIgnoreCase("f"))
|
||||
{
|
||||
String[][] splitSlash = new String[splitData.length][];
|
||||
if (splitData.length > 4) FMLLog.warning("OBJModel.Parser: found a face ('f') with more than 4 vertices, only the first 4 of these vertices will be rendered!");
|
||||
|
||||
int vert = 0;
|
||||
int texCoord = 0;
|
||||
int norm = 0;
|
||||
|
||||
List<Vertex> v = Lists.newArrayListWithCapacity(splitData.length);
|
||||
// List<TextureCoordinate> t = Lists.newArrayListWithCapacity(splitData.length);
|
||||
// List<Normal> n = Lists.newArrayListWithCapacity(splitData.length);
|
||||
|
||||
for (int i = 0; i < splitData.length; i++)
|
||||
if (key.equalsIgnoreCase("mtllib"))
|
||||
{
|
||||
if (splitData[i].contains("//"))
|
||||
this.materialLibrary.parseMaterials(manager, data, objFrom);
|
||||
}
|
||||
else if (key.equalsIgnoreCase("usemtl"))
|
||||
{
|
||||
material = this.materialLibrary.materials.get(data);
|
||||
usemtlCounter++;
|
||||
}
|
||||
else if (key.equalsIgnoreCase("v")) // Vertices: x y z [w] - w Defaults to 1.0
|
||||
{
|
||||
float[] coords = parseFloats(splitData);
|
||||
Vector4f pos = new Vector4f(coords[0], coords[1], coords[2], coords.length == 4 ? coords[3] : 1.0F);
|
||||
this.vertices.add(new Vertex(pos, material));
|
||||
}
|
||||
else if (key.equalsIgnoreCase("vn")) // Vertex normals: x y z
|
||||
{
|
||||
this.normals.add(new Normal(parseFloats(splitData)));
|
||||
}
|
||||
else if (key.equalsIgnoreCase("vt")) // Vertex Textures: u [v] [w] - v/w Defaults to 0
|
||||
{
|
||||
float[] coords = parseFloats(splitData);
|
||||
TextureCoordinate texCoord = new TextureCoordinate(coords[0],
|
||||
coords.length >= 2 ? coords[1] : 0.0F,
|
||||
coords.length >= 3 ? coords[2] : 0.0F);
|
||||
if (texCoord.u < 0.0f || texCoord.u > 1.0f || texCoord.v < 0.0f || texCoord.v > 1.0f)
|
||||
throw new UVsOutOfBoundsException(this.objFrom);
|
||||
this.texCoords.add(texCoord);
|
||||
}
|
||||
else if (key.equalsIgnoreCase("f")) // Face Elements: f v1[/vt1][/vn1] ...
|
||||
{
|
||||
if (splitData.length > 4)
|
||||
FMLLog.warning("OBJModel.Parser: found a face ('f') with more than 4 vertices, only the first 4 of these vertices will be rendered!");
|
||||
|
||||
List<Vertex> v = Lists.newArrayListWithCapacity(splitData.length);
|
||||
|
||||
for (int i = 0; i < splitData.length; i++)
|
||||
{
|
||||
splitSlash[i] = splitData[i].split("//");
|
||||
String[] pts = splitData[i].split("/");
|
||||
|
||||
int vert = Integer.parseInt(pts[0]);
|
||||
Integer texture = pts.length < 2 || Strings.isEmpty(pts[1]) ? null : Integer.parseInt(pts[1]);
|
||||
Integer normal = pts.length < 3 || Strings.isEmpty(pts[2]) ? null : Integer.parseInt(pts[2]);
|
||||
|
||||
vert = Integer.parseInt(splitSlash[i][0]);
|
||||
vert = vert < 0 ? this.vertices.size() - 1 : vert - 1;
|
||||
norm = Integer.parseInt(splitSlash[i][1]);
|
||||
norm = norm < 0 ? this.normals.size() - 1 : norm - 1;
|
||||
|
||||
Vertex newV = new Vertex(new Vector4f(this.vertices.get(vert).getPos()), this.vertices.get(vert).getMaterial());
|
||||
newV.setNormal(this.normals.get(norm));
|
||||
|
||||
if (texture != null)
|
||||
newV.setTextureCoordinate(this.texCoords.get(texture < 0 ? this.texCoords.size() - 1 : texture - 1));
|
||||
if (normal != null)
|
||||
newV.setNormal(this.normals.get(normal < 0 ? this.normals.size() - 1 : normal - 1));
|
||||
|
||||
v.add(newV);
|
||||
// n.add(this.normals.get(norm));
|
||||
}
|
||||
else if (splitData[i].contains("/"))
|
||||
{
|
||||
splitSlash[i] = splitData[i].split("/");
|
||||
|
||||
vert = Integer.parseInt(splitSlash[i][0]);
|
||||
vert = vert < 0 ? this.vertices.size() - 1 : vert - 1;
|
||||
texCoord = Integer.parseInt(splitSlash[i][1]);
|
||||
texCoord = texCoord < 0 ? this.texCoords.size() - 1 : texCoord - 1;
|
||||
if (splitSlash[i].length > 2)
|
||||
Vertex[] va = v.toArray(new Vertex[v.size()]);
|
||||
|
||||
Face face = new Face(va, material.name);
|
||||
if (usemtlCounter < this.vertices.size())
|
||||
{
|
||||
for (Vertex ver : face.getVertices())
|
||||
{
|
||||
norm = Integer.parseInt(splitSlash[i][2]);
|
||||
norm = norm < 0 ? this.normals.size() - 1 : norm - 1;
|
||||
ver.setMaterial(material);
|
||||
}
|
||||
|
||||
Vertex newV = new Vertex(new Vector4f(this.vertices.get(vert).getPos()), this.vertices.get(vert).getMaterial());
|
||||
newV.setTextureCoordinate(this.texCoords.get(texCoord));
|
||||
newV.setNormal(splitSlash[i].length > 2 ? this.normals.get(norm) : null);
|
||||
|
||||
v.add(newV);
|
||||
// t.add(this.texCoords.get(texCoord));
|
||||
// if (splitSlash[i].length > 2) n.add(this.normals.get(norm));
|
||||
}
|
||||
else
|
||||
{
|
||||
splitSlash[i] = splitData[i].split("");
|
||||
|
||||
vert = Integer.parseInt(splitSlash[i][0]);
|
||||
vert = vert < 0 ? this.vertices.size() - 1 : vert - 1;
|
||||
|
||||
Vertex newV = new Vertex(new Vector4f(this.vertices.get(vert).getPos()), this.vertices.get(vert).getMaterial());
|
||||
v.add(newV);
|
||||
}
|
||||
}
|
||||
|
||||
Vertex[] va = new Vertex[v.size()];
|
||||
v.toArray(va);
|
||||
// TextureCoordinate[] ta = new TextureCoordinate[t.size()];
|
||||
// t.toArray(ta);
|
||||
// Normal[] na = new Normal[n.size()];
|
||||
// n.toArray(na);
|
||||
Face face = new Face(va, material.name);
|
||||
if (usemtlCounter < this.vertices.size())
|
||||
{
|
||||
for (Vertex ver : face.getVertices())
|
||||
if (groupList.isEmpty())
|
||||
{
|
||||
ver.setMaterial(material);
|
||||
}
|
||||
}
|
||||
|
||||
if (groupList.isEmpty())
|
||||
{
|
||||
if (this.materialLibrary.getGroups().containsKey(Group.DEFAULT_NAME))
|
||||
{
|
||||
this.materialLibrary.getGroups().get(Group.DEFAULT_NAME).addFace(face);
|
||||
}
|
||||
else
|
||||
{
|
||||
Group def = new Group(Group.DEFAULT_NAME, null);
|
||||
def.addFace(face);
|
||||
this.materialLibrary.getGroups().put(Group.DEFAULT_NAME, def);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : groupList)
|
||||
{
|
||||
if (this.materialLibrary.getGroups().containsKey(s))
|
||||
if (this.materialLibrary.getGroups().containsKey(Group.DEFAULT_NAME))
|
||||
{
|
||||
this.materialLibrary.getGroups().get(s).addFace(face);
|
||||
this.materialLibrary.getGroups().get(Group.DEFAULT_NAME).addFace(face);
|
||||
}
|
||||
else
|
||||
{
|
||||
Group e = new Group(s, null);
|
||||
e.addFace(face);
|
||||
this.materialLibrary.getGroups().put(s, e);
|
||||
Group def = new Group(Group.DEFAULT_NAME, null);
|
||||
def.addFace(face);
|
||||
this.materialLibrary.getGroups().put(Group.DEFAULT_NAME, def);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : groupList)
|
||||
{
|
||||
if (this.materialLibrary.getGroups().containsKey(s))
|
||||
{
|
||||
this.materialLibrary.getGroups().get(s).addFace(face);
|
||||
}
|
||||
else
|
||||
{
|
||||
Group e = new Group(s, null);
|
||||
e.addFace(face);
|
||||
this.materialLibrary.getGroups().put(s, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key.equalsIgnoreCase("g") || key.equalsIgnoreCase("o"))
|
||||
{
|
||||
groupList.clear();
|
||||
if (key.equalsIgnoreCase("g"))
|
||||
else if (key.equalsIgnoreCase("g") || key.equalsIgnoreCase("o"))
|
||||
{
|
||||
String[] splitSpace = data.split(" ");
|
||||
for (String s : splitSpace)
|
||||
groupList.add(s);
|
||||
groupList.clear();
|
||||
if (key.equalsIgnoreCase("g"))
|
||||
{
|
||||
String[] splitSpace = data.split(" ");
|
||||
for (String s : splitSpace)
|
||||
groupList.add(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
groupList.add(data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
groupList.add(data);
|
||||
if (!unknownObjectCommands.contains(key))
|
||||
{
|
||||
unknownObjectCommands.add(key);
|
||||
FMLLog.info("OBJLoader.Parser: command '%s' (model: '%s') is not currently supported, skipping. Line: %d '%s'", key, objFrom, lineNum, currentLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
if (!unknownObjectCommands.contains(key))
|
||||
{
|
||||
unknownObjectCommands.add(key);
|
||||
FMLLog.info("OBJLoader.Parser: command '%s' (model: '%s') is not currently supported, skipping", key, objFrom);
|
||||
}
|
||||
throw new RuntimeException(String.format("OBJLoader.Parser: Exception parsing line #%d: `%s`", lineNum, currentLine), e);
|
||||
}
|
||||
}
|
||||
|
||||
OBJModel model = new OBJModel(this.materialLibrary, this.objFrom);
|
||||
// model.getMatLib().setUVBounds(minUVBounds[0], maxUVBounds[0], minUVBounds[1], maxUVBounds[1]);
|
||||
return model;
|
||||
return new OBJModel(this.materialLibrary, this.objFrom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -821,8 +778,8 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
{
|
||||
return this.materialName;
|
||||
}
|
||||
|
||||
public boolean isTriangles()
|
||||
|
||||
public boolean isTriangles()
|
||||
{
|
||||
return isTri;
|
||||
}
|
||||
@@ -1275,10 +1232,10 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
|
||||
public enum OBJProperty implements IUnlistedProperty<OBJState>
|
||||
{
|
||||
instance;
|
||||
INSTANCE;
|
||||
public String getName()
|
||||
{
|
||||
return "OBJPropery";
|
||||
return "OBJProperty";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1300,14 +1257,14 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
}
|
||||
}
|
||||
|
||||
public class OBJBakedModel implements IFlexibleBakedModel, ISmartBlockModel, ISmartItemModel, IPerspectiveAwareModel
|
||||
public class OBJBakedModel implements IPerspectiveAwareModel
|
||||
{
|
||||
private final OBJModel model;
|
||||
private IModelState state;
|
||||
private final VertexFormat format;
|
||||
private Set<BakedQuad> quads;
|
||||
private ImmutableMap<String, TextureAtlasSprite> textures;
|
||||
private TextureAtlasSprite sprite = ModelLoader.White.instance;
|
||||
private TextureAtlasSprite sprite = ModelLoader.White.INSTANCE;
|
||||
|
||||
public OBJBakedModel(OBJModel model, IModelState state, VertexFormat format, ImmutableMap<String, TextureAtlasSprite> textures)
|
||||
{
|
||||
@@ -1323,15 +1280,11 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
this.quads = null;
|
||||
}
|
||||
|
||||
// FIXME: merge with getQuads
|
||||
@Override
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing side)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand)
|
||||
{
|
||||
if(side != null) return ImmutableList.of();
|
||||
if (quads == null)
|
||||
{
|
||||
quads = Collections.synchronizedSet(new LinkedHashSet<BakedQuad>());
|
||||
@@ -1400,11 +1353,12 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
v.setMaterial(this.model.getMatLib().getMaterial(v.getMaterial().getName()));
|
||||
}
|
||||
}
|
||||
sprite = ModelLoader.White.instance;
|
||||
sprite = ModelLoader.White.INSTANCE;
|
||||
} else sprite = this.textures.get(f.getMaterialName());
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
|
||||
builder.setContractUVs(true);
|
||||
builder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
|
||||
builder.setQuadColored();
|
||||
builder.setTexture(sprite);
|
||||
Normal faceNormal = f.getNormal();
|
||||
putVertexData(builder, f.verts[0], faceNormal, TextureCoordinate.getDefaultUVs()[0], sprite);
|
||||
putVertexData(builder, f.verts[1], faceNormal, TextureCoordinate.getDefaultUVs()[1], sprite);
|
||||
@@ -1427,20 +1381,14 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
builder.put(e, v.getPos().x, v.getPos().y, v.getPos().z, v.getPos().w);
|
||||
break;
|
||||
case COLOR:
|
||||
float d;
|
||||
if (v.hasNormal())
|
||||
d = LightUtil.diffuseLight(v.getNormal().x, v.getNormal().y, v.getNormal().z);
|
||||
else
|
||||
d = LightUtil.diffuseLight(faceNormal.x, faceNormal.y, faceNormal.z);
|
||||
|
||||
if (v.getMaterial() != null)
|
||||
builder.put(e,
|
||||
d * v.getMaterial().getColor().x,
|
||||
d * v.getMaterial().getColor().y,
|
||||
d * v.getMaterial().getColor().z,
|
||||
v.getMaterial().getColor().x,
|
||||
v.getMaterial().getColor().y,
|
||||
v.getMaterial().getColor().z,
|
||||
v.getMaterial().getColor().w);
|
||||
else
|
||||
builder.put(e, d, d, d, 1);
|
||||
builder.put(e, 1, 1, 1, 1);
|
||||
break;
|
||||
case UV:
|
||||
if (!v.hasTextureCoordinate())
|
||||
@@ -1496,19 +1444,8 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState(ItemStack stack)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
// FIXME: merge with getQuads
|
||||
/* @Override
|
||||
public OBJBakedModel handleBlockState(IBlockState state)
|
||||
{
|
||||
if (state instanceof IExtendedBlockState)
|
||||
@@ -1528,7 +1465,7 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}*/
|
||||
|
||||
private void updateStateVisibilityMap(OBJState state)
|
||||
{
|
||||
@@ -1591,7 +1528,7 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType);
|
||||
}
|
||||
@@ -1601,6 +1538,12 @@ public class OBJModel implements IRetexturableModel<OBJModel>, IModelCustomData<
|
||||
{
|
||||
return this.model.modelLocation.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Block.EnumOffsetType;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public class BlockInfo
|
||||
{
|
||||
private final BlockColors colors;
|
||||
private IBlockAccess world;
|
||||
private Block block;
|
||||
private IBlockState state;
|
||||
private BlockPos blockPos;
|
||||
|
||||
private final boolean[][][] translucent = new boolean[3][3][3];
|
||||
@@ -25,11 +27,16 @@ public class BlockInfo
|
||||
private int cachedTint = -1;
|
||||
private int cachedMultiplier = -1;
|
||||
|
||||
public BlockInfo(BlockColors colors)
|
||||
{
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public int getColorMultiplier(int tint)
|
||||
{
|
||||
if(cachedTint == tint) return cachedMultiplier;
|
||||
cachedTint = tint;
|
||||
cachedMultiplier = block.colorMultiplier(world, blockPos, tint);
|
||||
cachedMultiplier = colors.colorMultiplier(state, world, blockPos, tint);
|
||||
return cachedMultiplier;
|
||||
}
|
||||
|
||||
@@ -41,12 +48,12 @@ public class BlockInfo
|
||||
public void updateShift(boolean ignoreY)
|
||||
{
|
||||
long rand = 0;
|
||||
if(block.getOffsetType() != EnumOffsetType.NONE)
|
||||
if(state.getBlock().getOffsetType() != EnumOffsetType.NONE)
|
||||
{
|
||||
rand = MathHelper.getCoordinateRandom(blockPos.getX(), ignoreY ? 0 : blockPos.getY(), blockPos.getZ());
|
||||
shx = ((float)((rand >> 16) & 0xF) / 0xF - .5f) * .5f;
|
||||
shz = ((float)((rand >> 24) & 0xF) / 0xF - .5f) * .5f;
|
||||
if(block.getOffsetType() == EnumOffsetType.XYZ)
|
||||
if(state.getBlock().getOffsetType() == EnumOffsetType.XYZ)
|
||||
{
|
||||
shy = ((float)((rand >> 20) & 0xF) / 0xF - 1) * .2f;
|
||||
}
|
||||
@@ -60,9 +67,9 @@ public class BlockInfo
|
||||
cachedMultiplier = -1;
|
||||
}
|
||||
|
||||
public void setBlock(Block block)
|
||||
public void setState(IBlockState state)
|
||||
{
|
||||
this.block = block;
|
||||
this.state = state;
|
||||
cachedTint = -1;
|
||||
cachedMultiplier = -1;
|
||||
}
|
||||
@@ -94,16 +101,16 @@ public class BlockInfo
|
||||
for(int z = 0; z <= 2; z++)
|
||||
{
|
||||
BlockPos pos = blockPos.add(x - 1, y - 1, z - 1);
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
translucent[x][y][z] = block.isTranslucent();
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
translucent[x][y][z] = state.isTranslucent();
|
||||
//translucent[x][y][z] = world.getBlockState(pos).getBlock().getLightOpacity(world, pos) == 0;
|
||||
int brightness = this.block.getMixedBrightnessForBlock(world, pos);
|
||||
int brightness = state.getPackedLightmapCoords(world, pos);
|
||||
s[x][y][z] = (brightness >> 0x14) & 0xF;
|
||||
b[x][y][z] = (brightness >> 0x04) & 0xF;
|
||||
ao[x][y][z] = block.getAmbientOcclusionLightValue();
|
||||
ao[x][y][z] = state.getAmbientOcclusionLightValue();
|
||||
if(x == 1 && y == 1 && z == 1)
|
||||
{
|
||||
full = block.isFullCube();
|
||||
full = state.isFullCube();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,9 +157,9 @@ public class BlockInfo
|
||||
return world;
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
public IBlockState getState()
|
||||
{
|
||||
return block;
|
||||
return state;
|
||||
}
|
||||
|
||||
public BlockPos getBlockPos()
|
||||
|
||||
+37
-27
@@ -2,13 +2,14 @@ package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.BlockModelRenderer;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
|
||||
@@ -19,7 +20,7 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
@Override
|
||||
protected VertexLighterFlat initialValue()
|
||||
{
|
||||
return new VertexLighterFlat();
|
||||
return new VertexLighterFlat(colors);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,64 +29,73 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
@Override
|
||||
protected VertexLighterSmoothAo initialValue()
|
||||
{
|
||||
return new VertexLighterSmoothAo();
|
||||
return new VertexLighterSmoothAo(colors);
|
||||
}
|
||||
};
|
||||
|
||||
private final ThreadLocal<WorldRendererConsumer> wrFlat = new ThreadLocal<WorldRendererConsumer>();
|
||||
private final ThreadLocal<WorldRendererConsumer> wrSmooth = new ThreadLocal<WorldRendererConsumer>();
|
||||
private final ThreadLocal<WorldRenderer> lastRendererFlat = new ThreadLocal<WorldRenderer>();
|
||||
private final ThreadLocal<WorldRenderer> lastRendererSmooth = new ThreadLocal<WorldRenderer>();
|
||||
private final ThreadLocal<VertexBufferConsumer> wrFlat = new ThreadLocal<VertexBufferConsumer>();
|
||||
private final ThreadLocal<VertexBufferConsumer> wrSmooth = new ThreadLocal<VertexBufferConsumer>();
|
||||
private final ThreadLocal<VertexBuffer> lastRendererFlat = new ThreadLocal<VertexBuffer>();
|
||||
private final ThreadLocal<VertexBuffer> lastRendererSmooth = new ThreadLocal<VertexBuffer>();
|
||||
|
||||
private final BlockColors colors;
|
||||
|
||||
public ForgeBlockModelRenderer(BlockColors colors)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
super(colors);
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderModelStandard(IBlockAccess world, IBakedModel model, Block block, BlockPos pos, WorldRenderer wr, boolean checkSides)
|
||||
public boolean renderModelFlat(IBlockAccess world, IBakedModel model, IBlockState state, BlockPos pos, VertexBuffer buffer, boolean checkSides, long rand)
|
||||
{
|
||||
if(ForgeModContainer.forgeLightPipelineEnabled)
|
||||
{
|
||||
if(wr != lastRendererFlat.get())
|
||||
if(buffer != lastRendererFlat.get())
|
||||
{
|
||||
lastRendererFlat.set(wr);
|
||||
WorldRendererConsumer newCons = new WorldRendererConsumer(wr);
|
||||
lastRendererFlat.set(buffer);
|
||||
VertexBufferConsumer newCons = new VertexBufferConsumer(buffer);
|
||||
wrFlat.set(newCons);
|
||||
lighterFlat.get().setParent(newCons);
|
||||
}
|
||||
wrFlat.get().setOffset(pos);
|
||||
return render(lighterFlat.get(), world, model, block, pos, wr, checkSides);
|
||||
return render(lighterFlat.get(), world, model, state, pos, buffer, checkSides, rand);
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.renderModelStandard(world, model, block, pos, wr, checkSides);
|
||||
return super.renderModelFlat(world, model, state, pos, buffer, checkSides, rand);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderModelAmbientOcclusion(IBlockAccess world, IBakedModel model, Block block, BlockPos pos, WorldRenderer wr, boolean checkSides)
|
||||
public boolean renderModelSmooth(IBlockAccess world, IBakedModel model, IBlockState state, BlockPos pos, VertexBuffer buffer, boolean checkSides, long rand)
|
||||
{
|
||||
if(ForgeModContainer.forgeLightPipelineEnabled)
|
||||
{
|
||||
if(wr != lastRendererSmooth.get())
|
||||
if(buffer != lastRendererSmooth.get())
|
||||
{
|
||||
lastRendererSmooth.set(wr);
|
||||
WorldRendererConsumer newCons = new WorldRendererConsumer(wr);
|
||||
lastRendererSmooth.set(buffer);
|
||||
VertexBufferConsumer newCons = new VertexBufferConsumer(buffer);
|
||||
wrSmooth.set(newCons);
|
||||
lighterSmooth.get().setParent(newCons);
|
||||
}
|
||||
wrSmooth.get().setOffset(pos);
|
||||
return render(lighterSmooth.get(), world, model, block, pos, wr, checkSides);
|
||||
return render(lighterSmooth.get(), world, model, state, pos, buffer, checkSides, rand);
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.renderModelAmbientOcclusion(world, model, block, pos, wr, checkSides);
|
||||
return super.renderModelSmooth(world, model, state, pos, buffer, checkSides, rand);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean render(VertexLighterFlat lighter, IBlockAccess world, IBakedModel model, Block block, BlockPos pos, WorldRenderer wr, boolean checkSides)
|
||||
public static boolean render(VertexLighterFlat lighter, IBlockAccess world, IBakedModel model, IBlockState state, BlockPos pos, VertexBuffer wr, boolean checkSides, long rand)
|
||||
{
|
||||
lighter.setWorld(world);
|
||||
lighter.setBlock(block);
|
||||
lighter.setState(state);
|
||||
lighter.setBlockPos(pos);
|
||||
boolean empty = true;
|
||||
List<BakedQuad> quads = model.getGeneralQuads();
|
||||
List<BakedQuad> quads = model.getQuads(state, null, rand);
|
||||
if(!quads.isEmpty())
|
||||
{
|
||||
lighter.updateBlockInfo();
|
||||
@@ -97,10 +107,10 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
}
|
||||
for(EnumFacing side : EnumFacing.values())
|
||||
{
|
||||
quads = model.getFaceQuads(side);
|
||||
quads = model.getQuads(state, side, rand);
|
||||
if(!quads.isEmpty())
|
||||
{
|
||||
if(!checkSides || block.shouldSideBeRendered(world, pos.offset(side), side))
|
||||
if(!checkSides || state.shouldSideBeRendered(world, pos, side))
|
||||
{
|
||||
if(empty) lighter.updateBlockInfo();
|
||||
empty = false;
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface IVertexConsumer
|
||||
|
||||
void setQuadTint(int tint);
|
||||
void setQuadOrientation(EnumFacing orientation);
|
||||
void setQuadColored();
|
||||
void setApplyDiffuseLighting(boolean diffuse);
|
||||
|
||||
void put(int element, float... data);
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.model.IColoredBakedQuad;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
@@ -71,18 +71,16 @@ public class LightUtil
|
||||
}
|
||||
}
|
||||
|
||||
private static final LoadingCache<VertexFormat, int[]> formatMaps = CacheBuilder.newBuilder()
|
||||
private static final LoadingCache<Pair<VertexFormat, VertexFormat>, int[]> formatMaps = CacheBuilder.newBuilder()
|
||||
.maximumSize(10)
|
||||
.build(new CacheLoader<VertexFormat, int[]>()
|
||||
.build(new CacheLoader<Pair<VertexFormat, VertexFormat>, int[]>()
|
||||
{
|
||||
public int[] load(VertexFormat format)
|
||||
public int[] load(Pair<VertexFormat, VertexFormat> pair)
|
||||
{
|
||||
return mapFormats(format, DefaultVertexFormats.ITEM);
|
||||
return mapFormats(pair.getLeft(), pair.getRight());
|
||||
}
|
||||
});
|
||||
|
||||
private static final int itemCount = DefaultVertexFormats.ITEM.getElementCount();
|
||||
|
||||
public static void putBakedQuad(IVertexConsumer consumer, BakedQuad quad)
|
||||
{
|
||||
consumer.setQuadOrientation(quad.getFace());
|
||||
@@ -90,22 +88,21 @@ public class LightUtil
|
||||
{
|
||||
consumer.setQuadTint(quad.getTintIndex());
|
||||
}
|
||||
if(quad instanceof IColoredBakedQuad)
|
||||
{
|
||||
consumer.setQuadColored();
|
||||
}
|
||||
consumer.setApplyDiffuseLighting(quad.shouldApplyDiffuseLighting());
|
||||
//int[] eMap = mapFormats(consumer.getVertexFormat(), DefaultVertexFormats.ITEM);
|
||||
float[] data = new float[4];
|
||||
VertexFormat format = consumer.getVertexFormat();
|
||||
int count = format.getElementCount();
|
||||
int[] eMap = formatMaps.getUnchecked(format);
|
||||
VertexFormat formatFrom = consumer.getVertexFormat();
|
||||
VertexFormat formatTo = quad.getFormat();
|
||||
int countFrom = formatFrom.getElementCount();
|
||||
int countTo = formatTo.getElementCount();
|
||||
int[] eMap = formatMaps.getUnchecked(Pair.of(formatFrom, formatTo));
|
||||
for(int v = 0; v < 4; v++)
|
||||
{
|
||||
for(int e = 0; e < count; e++)
|
||||
for(int e = 0; e < countFrom; e++)
|
||||
{
|
||||
if(eMap[e] != itemCount)
|
||||
if(eMap[e] != countTo)
|
||||
{
|
||||
unpack(quad.getVertexData(), data, DefaultVertexFormats.ITEM, v, eMap[e]);
|
||||
unpack(quad.getVertexData(), data, quad.getFormat(), v, eMap[e]);
|
||||
consumer.put(e, data);
|
||||
}
|
||||
else
|
||||
@@ -143,7 +140,7 @@ public class LightUtil
|
||||
{
|
||||
int length = 4 < to.length ? 4 : to.length;
|
||||
VertexFormatElement element = formatFrom.getElement(e);
|
||||
int vertexStart = v * formatFrom.getNextOffset() + formatFrom.func_181720_d(e);
|
||||
int vertexStart = v * formatFrom.getNextOffset() + formatFrom.getOffset(e);
|
||||
int count = element.getElementCount();
|
||||
VertexFormatElement.EnumType type = element.getType();
|
||||
int size = type.getSize();
|
||||
@@ -197,7 +194,7 @@ public class LightUtil
|
||||
public static void pack(float[] from, int[] to, VertexFormat formatTo, int v, int e)
|
||||
{
|
||||
VertexFormatElement element = formatTo.getElement(e);
|
||||
int vertexStart = v * formatTo.getNextOffset() + formatTo.func_181720_d(e);
|
||||
int vertexStart = v * formatTo.getNextOffset() + formatTo.getOffset(e);
|
||||
int count = element.getElementCount();
|
||||
VertexFormatElement.EnumType type = element.getType();
|
||||
int size = type.getSize();
|
||||
@@ -240,8 +237,8 @@ public class LightUtil
|
||||
if(tessellator == null)
|
||||
{
|
||||
Tessellator tes = Tessellator.getInstance();
|
||||
WorldRenderer wr = tes.getWorldRenderer();
|
||||
tessellator = new WorldRendererConsumer(wr);
|
||||
VertexBuffer wr = tes.getBuffer();
|
||||
tessellator = new VertexBufferConsumer(wr);
|
||||
}
|
||||
return tessellator;
|
||||
}
|
||||
@@ -257,16 +254,16 @@ public class LightUtil
|
||||
}
|
||||
|
||||
// renders quad in any Vertex Format, but is slower
|
||||
public static void renderQuadColorSlow(WorldRenderer wr, BakedQuad quad, int auxColor)
|
||||
public static void renderQuadColorSlow(VertexBuffer wr, BakedQuad quad, int auxColor)
|
||||
{
|
||||
ItemConsumer cons;
|
||||
if(wr == Tessellator.getInstance().getWorldRenderer())
|
||||
if(wr == Tessellator.getInstance().getBuffer())
|
||||
{
|
||||
cons = getItemConsumer();
|
||||
}
|
||||
else
|
||||
{
|
||||
cons = new ItemConsumer(new WorldRendererConsumer(wr));
|
||||
cons = new ItemConsumer(new VertexBufferConsumer(wr));
|
||||
}
|
||||
float b = (float)(auxColor & 0xFF) / 0xFF;
|
||||
float g = (float)((auxColor >>> 8) & 0xFF) / 0xFF;
|
||||
@@ -277,22 +274,14 @@ public class LightUtil
|
||||
quad.pipe(cons);
|
||||
}
|
||||
|
||||
public static void renderQuadColor(WorldRenderer wr, BakedQuad quad, int auxColor)
|
||||
public static void renderQuadColor(VertexBuffer wr, BakedQuad quad, int auxColor)
|
||||
{
|
||||
wr.addVertexData(quad.getVertexData());
|
||||
if(quad instanceof IColoredBakedQuad)
|
||||
{
|
||||
ForgeHooksClient.putQuadColor(wr, quad, auxColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
wr.putColor4(auxColor);
|
||||
}
|
||||
ForgeHooksClient.putQuadColor(wr, quad, auxColor);
|
||||
}
|
||||
|
||||
public static class ItemConsumer extends VertexTransformer
|
||||
{
|
||||
private boolean colored = false;
|
||||
private int vertices = 0;
|
||||
|
||||
private float[] auxColor = new float[]{1, 1, 1, 1};
|
||||
@@ -308,23 +297,14 @@ public class LightUtil
|
||||
System.arraycopy(auxColor, 0, this.auxColor, 0, this.auxColor.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadColored()
|
||||
{
|
||||
colored = true;
|
||||
}
|
||||
|
||||
public void put(int element, float... data)
|
||||
{
|
||||
if(getVertexFormat().getElement(element).getUsage() == EnumUsage.COLOR)
|
||||
{
|
||||
System.arraycopy(auxColor, 0, buf, 0, buf.length);
|
||||
if(colored)
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
buf[i] *= data[i];
|
||||
}
|
||||
buf[i] *= data[i];
|
||||
}
|
||||
super.put(element, buf);
|
||||
}
|
||||
@@ -338,7 +318,6 @@ public class LightUtil
|
||||
if(vertices == 4)
|
||||
{
|
||||
vertices = 0;
|
||||
colored = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.client.model.IColoredBakedQuad;
|
||||
|
||||
// advantages: non-fixed-length vertex format, no overhead of packing and unpacking attributes to transform the model
|
||||
// disadvantages: (possibly) larger memory footprint, overhead on packing the attributes at the final rendering stage
|
||||
@@ -13,9 +14,9 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
protected final VertexFormat format;
|
||||
protected boolean packed = false;
|
||||
|
||||
public UnpackedBakedQuad(float[][][] unpackedData, int tint, EnumFacing orientation, VertexFormat format)
|
||||
public UnpackedBakedQuad(float[][][] unpackedData, int tint, EnumFacing orientation, TextureAtlasSprite texture, boolean applyDiffuseLighting, VertexFormat format)
|
||||
{
|
||||
super(new int[format.getNextOffset() /* / 4 * 4 */], tint, orientation);
|
||||
super(new int[format.getNextOffset() /* / 4 * 4 */], tint, orientation, texture, applyDiffuseLighting, format);
|
||||
this.unpackedData = unpackedData;
|
||||
this.format = format;
|
||||
}
|
||||
@@ -47,10 +48,6 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
consumer.setQuadTint(getTintIndex());
|
||||
}
|
||||
consumer.setQuadOrientation(getFace());
|
||||
if(this instanceof IColoredBakedQuad)
|
||||
{
|
||||
consumer.setQuadColored();
|
||||
}
|
||||
for(int v = 0; v < 4; v++)
|
||||
{
|
||||
for(int e = 0; e < consumer.getVertexFormat().getElementCount(); e++)
|
||||
@@ -67,25 +64,19 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
}
|
||||
}
|
||||
|
||||
public static class Colored extends UnpackedBakedQuad implements IColoredBakedQuad
|
||||
{
|
||||
public Colored(float[][][] unpackedData, int tint, EnumFacing orientation, VertexFormat format)
|
||||
{
|
||||
super(unpackedData, tint, orientation, format);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder implements IVertexConsumer
|
||||
{
|
||||
private final VertexFormat format;
|
||||
private final float[][][] unpackedData;
|
||||
private int tint = -1;
|
||||
private EnumFacing orientation;
|
||||
private boolean isColored = false;
|
||||
private TextureAtlasSprite texture;
|
||||
private boolean applyDiffuseLighting = true;
|
||||
|
||||
private int vertices = 0;
|
||||
private int elements = 0;
|
||||
private boolean full = false;
|
||||
private boolean contractUVs = false;
|
||||
|
||||
public Builder(VertexFormat format)
|
||||
{
|
||||
@@ -98,6 +89,10 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
return format;
|
||||
}
|
||||
|
||||
public void setContractUVs(boolean value)
|
||||
{
|
||||
this.contractUVs = value;
|
||||
}
|
||||
public void setQuadTint(int tint)
|
||||
{
|
||||
this.tint = tint;
|
||||
@@ -108,9 +103,14 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
public void setQuadColored()
|
||||
public void setTexture(TextureAtlasSprite texture)
|
||||
{
|
||||
this.isColored = true;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void setApplyDiffuseLighting(boolean diffuse)
|
||||
{
|
||||
this.applyDiffuseLighting = diffuse;
|
||||
}
|
||||
|
||||
public void put(int element, float... data)
|
||||
@@ -138,17 +138,69 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
}
|
||||
}
|
||||
|
||||
private final float eps = 1f / 0x100;
|
||||
|
||||
public UnpackedBakedQuad build()
|
||||
{
|
||||
if(!full)
|
||||
{
|
||||
throw new IllegalStateException("not enough data");
|
||||
}
|
||||
if(isColored)
|
||||
if(contractUVs)
|
||||
{
|
||||
return new Colored(unpackedData, tint, orientation, format);
|
||||
float tX = texture.getOriginX() / texture.getMinU();
|
||||
float tY = texture.getOriginY() / texture.getMinV();
|
||||
float tS = tX > tY ? tX : tY;
|
||||
float ep = 1f / (tS * 0x100);
|
||||
int uve = 0;
|
||||
while(uve < format.getElementCount())
|
||||
{
|
||||
VertexFormatElement e = format.getElement(uve);
|
||||
if(e.getUsage() == VertexFormatElement.EnumUsage.UV && e.getIndex() == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uve++;
|
||||
}
|
||||
if(uve == format.getElementCount())
|
||||
{
|
||||
throw new IllegalStateException("Can't contract UVs: format doesn't contain UVs");
|
||||
}
|
||||
float[] uvc = new float[4];
|
||||
for(int v = 0; v < 4; v++)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
uvc[i] += unpackedData[v][uve][i] / 4;
|
||||
}
|
||||
}
|
||||
for(int v = 0; v < 4; v++)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
float uo = unpackedData[v][uve][i];
|
||||
float un = uo * (1 - eps) + uvc[i] * eps;
|
||||
float ud = uo - un;
|
||||
float aud = ud;
|
||||
if(aud < 0) aud = -aud;
|
||||
if(aud < ep) // not moving a fraction of a pixel
|
||||
{
|
||||
float udc = uo - uvc[i];
|
||||
if(udc < 0) udc = -udc;
|
||||
if(udc < 2 * ep) // center is closer than 2 fractions of a pixel, don't move too close
|
||||
{
|
||||
un = (uo + uvc[i]) / 2;
|
||||
}
|
||||
else // move at least by a fraction
|
||||
{
|
||||
un = uo + (ud < 0 ? ep : -ep);
|
||||
}
|
||||
}
|
||||
unpackedData[v][uve][i] = un;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new UnpackedBakedQuad(unpackedData, tint, orientation, format);
|
||||
return new UnpackedBakedQuad(unpackedData, tint, orientation, texture, applyDiffuseLighting, format);
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,23 +1,23 @@
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/**
|
||||
* Assumes VertexFormatElement is present in the WorlRenderer's vertex format.
|
||||
* Assumes VertexFormatElement is present in the VertexBuffer's vertex format.
|
||||
*/
|
||||
public class WorldRendererConsumer implements IVertexConsumer
|
||||
public class VertexBufferConsumer implements IVertexConsumer
|
||||
{
|
||||
private static final float[] dummyColor = new float[]{ 1, 1, 1, 1 };
|
||||
private final WorldRenderer renderer;
|
||||
private final VertexBuffer renderer;
|
||||
private final int[] quadData;
|
||||
private int v = 0;
|
||||
private BlockPos offset = BlockPos.ORIGIN;
|
||||
|
||||
public WorldRendererConsumer(WorldRenderer renderer)
|
||||
public VertexBufferConsumer(VertexBuffer renderer)
|
||||
{
|
||||
super();
|
||||
this.renderer = renderer;
|
||||
@@ -57,5 +57,5 @@ public class WorldRendererConsumer implements IVertexConsumer
|
||||
|
||||
public void setQuadTint(int tint) {}
|
||||
public void setQuadOrientation(EnumFacing orientation) {}
|
||||
public void setQuadColored() {}
|
||||
public void setApplyDiffuseLighting(boolean diffuse) {}
|
||||
}
|
||||
@@ -2,26 +2,33 @@ package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
{
|
||||
protected final BlockInfo blockInfo = new BlockInfo();
|
||||
protected final BlockInfo blockInfo;
|
||||
private int tint = -1;
|
||||
private boolean diffuse = true;
|
||||
|
||||
protected int posIndex = -1;
|
||||
protected int normalIndex = -1;
|
||||
protected int colorIndex = -1;
|
||||
protected int lightmapIndex = -1;
|
||||
|
||||
public VertexLighterFlat(BlockColors colors)
|
||||
{
|
||||
this.blockInfo = new BlockInfo(colors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(IVertexConsumer parent)
|
||||
{
|
||||
@@ -142,6 +149,14 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
if(skyLight > lightmap[v][1]) lightmap[v][1] = skyLight;
|
||||
}
|
||||
updateColor(normal[v], color[v], x, y, z, tint, multiplier);
|
||||
if(diffuse)
|
||||
{
|
||||
float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
color[v][i] *= d;
|
||||
}
|
||||
}
|
||||
if(EntityRenderer.anaglyphEnable)
|
||||
{
|
||||
applyAnaglyph(color[v]);
|
||||
@@ -154,7 +169,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
switch(element.getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
// position adding moved to WorldRendererConsumer due to x and z not fitting completely into a float
|
||||
// position adding moved to VertexBufferConsumer due to x and z not fitting completely into a float
|
||||
/*float[] pos = new float[4];
|
||||
System.arraycopy(position[v], 0, pos, 0, position[v].length);
|
||||
pos[0] += blockInfo.getBlockPos().getX();
|
||||
@@ -197,7 +212,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
float e2 = 0.95f;
|
||||
BlockPos pos = blockInfo.getBlockPos();
|
||||
|
||||
boolean full = blockInfo.getBlock().isFullCube();
|
||||
boolean full = blockInfo.getState().isFullCube();
|
||||
|
||||
if((full || y < -e1) && normal[1] < -e2) pos = pos.down();
|
||||
if((full || y > e1) && normal[1] > e2) pos = pos.up();
|
||||
@@ -206,7 +221,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
if((full || x < -e1) && normal[0] < -e2) pos = pos.west();
|
||||
if((full || x > e1) && normal[0] > e2) pos = pos.east();
|
||||
|
||||
int brightness = blockInfo.getBlock().getMixedBrightnessForBlock(blockInfo.getWorld(), pos);
|
||||
int brightness = blockInfo.getState().getPackedLightmapCoords(blockInfo.getWorld(), pos);
|
||||
|
||||
lightmap[0] = ((float)((brightness >> 0x04) & 0xF) * 0x20) / 0xFFFF;
|
||||
lightmap[1] = ((float)((brightness >> 0x14) & 0xF) * 0x20) / 0xFFFF;
|
||||
@@ -228,16 +243,19 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
}
|
||||
public void setQuadOrientation(EnumFacing orientation) {}
|
||||
public void setQuadCulled() {}
|
||||
public void setQuadColored() {}
|
||||
public void setApplyDiffuseLighting(boolean diffuse)
|
||||
{
|
||||
this.diffuse = diffuse;
|
||||
}
|
||||
|
||||
public void setWorld(IBlockAccess world)
|
||||
{
|
||||
blockInfo.setWorld(world);
|
||||
}
|
||||
|
||||
public void setBlock(Block block)
|
||||
public void setState(IBlockState state)
|
||||
{
|
||||
blockInfo.setBlock(block);
|
||||
blockInfo.setState(state);
|
||||
}
|
||||
|
||||
public void setBlockPos(BlockPos blockPos)
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
|
||||
public class VertexLighterSmoothAo extends VertexLighterFlat
|
||||
{
|
||||
public VertexLighterSmoothAo(BlockColors colors)
|
||||
{
|
||||
super(colors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateLightmap(float[] normal, float[] lightmap, float x, float y, float z)
|
||||
{
|
||||
|
||||
@@ -27,9 +27,9 @@ public class VertexTransformer implements IVertexConsumer
|
||||
parent.setQuadOrientation(orientation);
|
||||
}
|
||||
|
||||
public void setQuadColored()
|
||||
public void setApplyDiffuseLighting(boolean diffuse)
|
||||
{
|
||||
parent.setQuadColored();
|
||||
parent.setApplyDiffuseLighting(diffuse);
|
||||
}
|
||||
|
||||
public void put(int element, float... data)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.minecraftforge.client.settings;
|
||||
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
|
||||
/**
|
||||
* Defines the context that a {@link KeyBinding} is used.
|
||||
* Key conflicts occur when a {@link KeyBinding} has the same {@link IKeyConflictContext} and has conflicting modifiers and keyCodes.
|
||||
*/
|
||||
public interface IKeyConflictContext {
|
||||
/**
|
||||
* @return true if conditions are met to activate {@link KeyBinding}s with this context
|
||||
*/
|
||||
boolean isActive();
|
||||
|
||||
/**
|
||||
* @return true if the other context can have {@link KeyBinding} conflicts with this one.
|
||||
* This will be called on both contexts to check for conflicts.
|
||||
*/
|
||||
boolean conflicts(IKeyConflictContext other);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package net.minecraftforge.client.settings;
|
||||
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.util.IntHashMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
public class KeyBindingMap
|
||||
{
|
||||
private static final EnumMap<KeyModifier, IntHashMap<Collection<KeyBinding>>> map = new java.util.EnumMap<KeyModifier, IntHashMap<Collection<KeyBinding>>>(KeyModifier.class);
|
||||
static
|
||||
{
|
||||
for (KeyModifier modifier : KeyModifier.values())
|
||||
{
|
||||
map.put(modifier, new IntHashMap<Collection<KeyBinding>>());
|
||||
}
|
||||
}
|
||||
|
||||
public KeyBinding lookupActive(int keyCode)
|
||||
{
|
||||
KeyModifier activeModifier = KeyModifier.getActiveModifier();
|
||||
if (!activeModifier.matches(keyCode))
|
||||
{
|
||||
KeyBinding binding = getBinding(keyCode, activeModifier);
|
||||
if (binding != null)
|
||||
{
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
return getBinding(keyCode, KeyModifier.NONE);
|
||||
}
|
||||
|
||||
private KeyBinding getBinding(int keyCode, KeyModifier keyModifier)
|
||||
{
|
||||
Collection<KeyBinding> bindings = map.get(keyModifier).lookup(keyCode);
|
||||
if (bindings != null)
|
||||
{
|
||||
for (KeyBinding binding : bindings)
|
||||
{
|
||||
if (binding.isActiveAndMatches(keyCode))
|
||||
{
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<KeyBinding> lookupAll(int keyCode)
|
||||
{
|
||||
List<KeyBinding> matchingBindings = new ArrayList<KeyBinding>();
|
||||
for (IntHashMap<Collection<KeyBinding>> bindingsMap : map.values())
|
||||
{
|
||||
Collection<KeyBinding> bindings = bindingsMap.lookup(keyCode);
|
||||
if (bindings != null)
|
||||
{
|
||||
matchingBindings.addAll(bindings);
|
||||
}
|
||||
}
|
||||
return matchingBindings;
|
||||
}
|
||||
|
||||
public void addKey(int keyCode, KeyBinding keyBinding)
|
||||
{
|
||||
KeyModifier keyModifier = keyBinding.getKeyModifier();
|
||||
IntHashMap<Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
|
||||
Collection<KeyBinding> bindingsForKey = bindingsMap.lookup(keyCode);
|
||||
if (bindingsForKey == null)
|
||||
{
|
||||
bindingsForKey = new ArrayList<KeyBinding>();
|
||||
bindingsMap.addKey(keyCode, bindingsForKey);
|
||||
}
|
||||
bindingsForKey.add(keyBinding);
|
||||
}
|
||||
|
||||
public void removeKey(KeyBinding keyBinding)
|
||||
{
|
||||
KeyModifier keyModifier = keyBinding.getKeyModifier();
|
||||
int keyCode = keyBinding.getKeyCode();
|
||||
IntHashMap<Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
|
||||
Collection<KeyBinding> bindingsForKey = bindingsMap.lookup(keyCode);
|
||||
if (bindingsForKey != null)
|
||||
{
|
||||
bindingsForKey.remove(keyBinding);
|
||||
if (bindingsForKey.isEmpty())
|
||||
{
|
||||
bindingsMap.removeObject(keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearMap()
|
||||
{
|
||||
for (IntHashMap<Collection<KeyBinding>> bindings : map.values())
|
||||
{
|
||||
bindings.clearMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.minecraftforge.client.settings;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
public enum KeyConflictContext implements IKeyConflictContext
|
||||
{
|
||||
/**
|
||||
* Universal key bindings are used in every context and will conflict with any other context.
|
||||
* Key Bindings are universal by default.
|
||||
*/
|
||||
UNIVERSAL {
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflicts(IKeyConflictContext other)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Gui key bindings are only used when a {@link GuiScreen} is open.
|
||||
*/
|
||||
GUI {
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return Minecraft.getMinecraft().currentScreen != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflicts(IKeyConflictContext other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* In-game key bindings are only used when a {@link GuiScreen} is not open.
|
||||
*/
|
||||
IN_GAME {
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return !GUI.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflicts(IKeyConflictContext other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package net.minecraftforge.client.settings;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public enum KeyModifier {
|
||||
CONTROL {
|
||||
@Override
|
||||
public boolean matches(int keyCode)
|
||||
{
|
||||
if (Minecraft.isRunningOnMac)
|
||||
{
|
||||
return keyCode == Keyboard.KEY_LMETA || keyCode == Keyboard.KEY_RMETA;
|
||||
}
|
||||
else
|
||||
{
|
||||
return keyCode == Keyboard.KEY_LCONTROL || keyCode == Keyboard.KEY_RCONTROL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return GuiScreen.isCtrlKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
{
|
||||
String keyName = GameSettings.getKeyDisplayString(keyCode);
|
||||
String localizationFormatKey = Minecraft.isRunningOnMac ? "forge.controlsgui.control.mac" : "forge.controlsgui.control";
|
||||
return I18n.format(localizationFormatKey, keyName);
|
||||
}
|
||||
},
|
||||
SHIFT {
|
||||
@Override
|
||||
public boolean matches(int keyCode)
|
||||
{
|
||||
return keyCode == Keyboard.KEY_LSHIFT || keyCode == Keyboard.KEY_RSHIFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return GuiScreen.isShiftKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
{
|
||||
String keyName = GameSettings.getKeyDisplayString(keyCode);
|
||||
return I18n.format("forge.controlsgui.shift", keyName);
|
||||
}
|
||||
},
|
||||
ALT {
|
||||
@Override
|
||||
public boolean matches(int keyCode)
|
||||
{
|
||||
return keyCode == Keyboard.KEY_LMENU || keyCode == Keyboard.KEY_RMENU;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return GuiScreen.isAltKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
{
|
||||
String keyName = GameSettings.getKeyDisplayString(keyCode);
|
||||
return I18n.format("forge.controlsgui.alt", keyName);
|
||||
}
|
||||
},
|
||||
NONE {
|
||||
@Override
|
||||
public boolean matches(int keyCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
{
|
||||
return GameSettings.getKeyDisplayString(keyCode);
|
||||
}
|
||||
};
|
||||
|
||||
public static final KeyModifier[] MODIFIER_VALUES = {SHIFT, CONTROL, ALT};
|
||||
|
||||
public static KeyModifier getActiveModifier()
|
||||
{
|
||||
for (KeyModifier keyModifier : MODIFIER_VALUES)
|
||||
{
|
||||
if (keyModifier.isActive())
|
||||
{
|
||||
return keyModifier;
|
||||
}
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
|
||||
public static boolean isKeyCodeModifier(int keyCode)
|
||||
{
|
||||
for (KeyModifier keyModifier : MODIFIER_VALUES)
|
||||
{
|
||||
if (keyModifier.matches(keyCode))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static KeyModifier valueFromString(String stringValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return valueOf(stringValue);
|
||||
}
|
||||
catch (NullPointerException ignored)
|
||||
{
|
||||
return NONE;
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean matches(int keyCode);
|
||||
|
||||
public abstract boolean isActive();
|
||||
|
||||
public abstract String getLocalizedComboName(int keyCode);
|
||||
}
|
||||
@@ -3,11 +3,13 @@ package net.minecraftforge.common;
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import net.minecraft.init.Biomes;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.biome.*;
|
||||
import net.minecraftforge.common.util.EnumHelper;
|
||||
import net.minecraftforge.event.terraingen.DeferredBiomeDecorator;
|
||||
import static net.minecraft.world.biome.BiomeGenBase.*;
|
||||
import static net.minecraftforge.common.BiomeDictionary.Type.*;
|
||||
|
||||
public class BiomeDictionary
|
||||
@@ -53,15 +55,7 @@ public class BiomeDictionary
|
||||
SANDY,
|
||||
SNOWY,
|
||||
WASTELAND,
|
||||
BEACH,
|
||||
|
||||
/*Deprecated tags, kept for compatibility*/
|
||||
@Deprecated
|
||||
/**Replaced by SANDY**/
|
||||
DESERT(SANDY),
|
||||
@Deprecated
|
||||
/**Replaced by SNOWY**/
|
||||
FROZEN(SNOWY);
|
||||
BEACH;
|
||||
|
||||
private List<Type> subTags;
|
||||
|
||||
@@ -78,8 +72,8 @@ public class BiomeDictionary
|
||||
/**
|
||||
* Retrieves a Type value by name,
|
||||
* if one does not exist already it creates one.
|
||||
* This can be used as interm measure for modders to
|
||||
* add there own category of Biome.
|
||||
* This can be used as intermediate measure for modders to
|
||||
* add their own category of Biome.
|
||||
*
|
||||
* There are NO naming conventions besides:
|
||||
* MUST be all upper case (enforced by name.toUpper())
|
||||
@@ -106,7 +100,7 @@ public class BiomeDictionary
|
||||
{
|
||||
typeInfoList = Arrays.copyOf(typeInfoList, ret.ordinal()+1);
|
||||
}
|
||||
for(BiomeInfo bInfo:biomeList)
|
||||
for(BiomeInfo bInfo:biomeInfoMap.values())
|
||||
{
|
||||
if(bInfo != null)
|
||||
{
|
||||
@@ -119,8 +113,7 @@ public class BiomeDictionary
|
||||
}
|
||||
}
|
||||
|
||||
private static final int BIOME_LIST_SIZE = BiomeGenBase.getBiomeGenArray().length;
|
||||
private static BiomeInfo[] biomeList = new BiomeInfo[BIOME_LIST_SIZE];
|
||||
private static HashMap<ResourceLocation, BiomeInfo> biomeInfoMap = new HashMap<ResourceLocation, BiomeInfo>();
|
||||
@SuppressWarnings("unchecked")
|
||||
private static ArrayList<BiomeGenBase>[] typeInfoList = new ArrayList[Type.values().length];
|
||||
|
||||
@@ -154,7 +147,7 @@ public class BiomeDictionary
|
||||
{
|
||||
types = listSubTags(types);
|
||||
|
||||
if(BiomeGenBase.getBiomeGenArray()[biome.biomeID] != null)
|
||||
if(BiomeGenBase.biomeRegistry.getNameForObject(biome) != null)
|
||||
{
|
||||
for(Type type : types)
|
||||
{
|
||||
@@ -166,15 +159,16 @@ public class BiomeDictionary
|
||||
typeInfoList[type.ordinal()].add(biome);
|
||||
}
|
||||
|
||||
if(biomeList[biome.biomeID] == null)
|
||||
if(!isBiomeRegistered(biome))
|
||||
{
|
||||
biomeList[biome.biomeID] = new BiomeInfo(types);
|
||||
ResourceLocation location = BiomeGenBase.biomeRegistry.getNameForObject(biome);
|
||||
biomeInfoMap.put(location, new BiomeInfo(types));
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Type type : types)
|
||||
{
|
||||
biomeList[biome.biomeID].typeList.add(type);
|
||||
getBiomeInfo(biome).typeList.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +188,7 @@ public class BiomeDictionary
|
||||
{
|
||||
if(typeInfoList[type.ordinal()] != null)
|
||||
{
|
||||
return (BiomeGenBase[])typeInfoList[type.ordinal()].toArray(new BiomeGenBase[0]);
|
||||
return typeInfoList[type.ordinal()].toArray(new BiomeGenBase[0]);
|
||||
}
|
||||
|
||||
return new BiomeGenBase[0];
|
||||
@@ -208,14 +202,8 @@ public class BiomeDictionary
|
||||
*/
|
||||
public static Type[] getTypesForBiome(BiomeGenBase biome)
|
||||
{
|
||||
checkRegistration(biome);
|
||||
|
||||
if(biomeList[biome.biomeID] != null)
|
||||
{
|
||||
return (Type[])biomeList[biome.biomeID].typeList.toArray(new Type[0]);
|
||||
}
|
||||
|
||||
return new Type[0];
|
||||
checkRegistration(biome);
|
||||
return getBiomeInfo(biome).typeList.toArray(new Type[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,21 +215,15 @@ public class BiomeDictionary
|
||||
*/
|
||||
public static boolean areBiomesEquivalent(BiomeGenBase biomeA, BiomeGenBase biomeB)
|
||||
{
|
||||
int a = biomeA.biomeID;
|
||||
int b = biomeB.biomeID;
|
||||
|
||||
checkRegistration(biomeA);
|
||||
checkRegistration(biomeB);
|
||||
|
||||
if(biomeList[a] != null && biomeList[b] != null)
|
||||
for(Type type : getTypesForBiome(biomeA))
|
||||
{
|
||||
for(Type type : biomeList[a].typeList)
|
||||
{
|
||||
if(containsType(biomeList[b], type))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(containsType(getBiomeInfo(biomeB), type))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -257,13 +239,7 @@ public class BiomeDictionary
|
||||
public static boolean isBiomeOfType(BiomeGenBase biome, Type type)
|
||||
{
|
||||
checkRegistration(biome);
|
||||
|
||||
if(biomeList[biome.biomeID] != null)
|
||||
{
|
||||
return containsType(biomeList[biome.biomeID], type);
|
||||
}
|
||||
|
||||
return false;
|
||||
return containsType(getBiomeInfo(biome), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,12 +249,7 @@ public class BiomeDictionary
|
||||
*/
|
||||
public static boolean isBiomeRegistered(BiomeGenBase biome)
|
||||
{
|
||||
return biomeList[biome.biomeID] != null;
|
||||
}
|
||||
|
||||
public static boolean isBiomeRegistered(int biomeID)
|
||||
{
|
||||
return biomeList[biomeID] != null;
|
||||
return biomeInfoMap.containsKey(BiomeGenBase.biomeRegistry.getNameForObject(biome));
|
||||
}
|
||||
|
||||
public static void registerAllBiomes()
|
||||
@@ -294,15 +265,10 @@ public class BiomeDictionary
|
||||
*/
|
||||
public static void registerAllBiomesAndGenerateEvents()
|
||||
{
|
||||
for(int i = 0; i < BiomeGenBase.getBiomeGenArray().length; i++)
|
||||
{
|
||||
BiomeGenBase biome = BiomeGenBase.getBiomeGenArray()[i];
|
||||
|
||||
if(biome == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (ResourceLocation biomeResource : BiomeGenBase.biomeRegistry.getKeys())
|
||||
{
|
||||
BiomeGenBase biome = BiomeGenBase.biomeRegistry.getObject(biomeResource);
|
||||
|
||||
if (biome.theBiomeDecorator instanceof DeferredBiomeDecorator)
|
||||
{
|
||||
DeferredBiomeDecorator decorator = (DeferredBiomeDecorator) biome.theBiomeDecorator;
|
||||
@@ -324,7 +290,7 @@ public class BiomeDictionary
|
||||
{
|
||||
if (biome.theBiomeDecorator.treesPerChunk >= 3)
|
||||
{
|
||||
if (biome.isHighHumidity() && biome.temperature >= 0.9F)
|
||||
if (biome.isHighHumidity() && biome.getTemperature() >= 0.9F)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, JUNGLE);
|
||||
}
|
||||
@@ -332,36 +298,36 @@ public class BiomeDictionary
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, FOREST);
|
||||
|
||||
if (biome.temperature <= 0.2f)
|
||||
if (biome.getTemperature() <= 0.2f)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, CONIFEROUS);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(biome.maxHeight <= 0.3F && biome.maxHeight >= 0.0F)
|
||||
else if(biome.getHeightVariation() <= 0.3F && biome.getHeightVariation() >= 0.0F)
|
||||
{
|
||||
if(!biome.isHighHumidity() || biome.minHeight >= 0.0F)
|
||||
if(!biome.isHighHumidity() || biome.getBaseHeight() >= 0.0F)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, PLAINS);
|
||||
}
|
||||
}
|
||||
|
||||
if (biome.rainfall > 0.85f)
|
||||
if (biome.getRainfall() > 0.85f)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, WET);
|
||||
}
|
||||
|
||||
if (biome.rainfall < 0.15f)
|
||||
if (biome.getRainfall() < 0.15f)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, DRY);
|
||||
}
|
||||
|
||||
if (biome.temperature > 0.85f)
|
||||
if (biome.getTemperature() > 0.85f)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, HOT);
|
||||
}
|
||||
|
||||
if (biome.temperature < 0.15f)
|
||||
if (biome.getTemperature() < 0.15f)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, COLD);
|
||||
}
|
||||
@@ -375,14 +341,14 @@ public class BiomeDictionary
|
||||
BiomeDictionary.registerBiomeType(biome, DENSE);
|
||||
}
|
||||
|
||||
if (biome.isHighHumidity() && biome.minHeight < 0.0F && (biome.maxHeight <= 0.3F && biome.maxHeight >= 0.0F))
|
||||
if (biome.isHighHumidity() && biome.getBaseHeight() < 0.0F && (biome.getHeightVariation() <= 0.3F && biome.getHeightVariation() >= 0.0F))
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, SWAMP);
|
||||
}
|
||||
|
||||
if (biome.minHeight <= -0.5F)
|
||||
if (biome.getBaseHeight() <= -0.5F)
|
||||
{
|
||||
if (biome.maxHeight == 0.0F)
|
||||
if (biome.getHeightVariation() == 0.0F)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, RIVER);
|
||||
}
|
||||
@@ -392,12 +358,12 @@ public class BiomeDictionary
|
||||
}
|
||||
}
|
||||
|
||||
if (biome.maxHeight >= 0.4F && biome.maxHeight < 1.5F)
|
||||
if (biome.getHeightVariation() >= 0.4F && biome.getHeightVariation() < 1.5F)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, HILLS);
|
||||
}
|
||||
|
||||
if (biome.maxHeight >= 1.5F)
|
||||
if (biome.getHeightVariation() >= 1.5F)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, MOUNTAIN);
|
||||
}
|
||||
@@ -407,7 +373,7 @@ public class BiomeDictionary
|
||||
BiomeDictionary.registerBiomeType(biome, SNOWY);
|
||||
}
|
||||
|
||||
if (biome.topBlock != Blocks.sand && biome.temperature >= 1.0f && biome.rainfall < 0.2f)
|
||||
if (biome.topBlock != Blocks.sand && biome.getTemperature() >= 1.0f && biome.getRainfall() < 0.2f)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, SAVANNA);
|
||||
}
|
||||
@@ -427,6 +393,11 @@ public class BiomeDictionary
|
||||
}
|
||||
|
||||
//Internal implementation
|
||||
private static BiomeInfo getBiomeInfo(BiomeGenBase biome)
|
||||
{
|
||||
return biomeInfoMap.get(BiomeGenBase.biomeRegistry.getNameForObject(biome));
|
||||
}
|
||||
|
||||
private static void checkRegistration(BiomeGenBase biome)
|
||||
{
|
||||
if(!isBiomeRegistered(biome))
|
||||
@@ -465,45 +436,45 @@ public class BiomeDictionary
|
||||
|
||||
private static void registerVanillaBiomes()
|
||||
{
|
||||
registerBiomeType(ocean, OCEAN );
|
||||
registerBiomeType(plains, PLAINS );
|
||||
registerBiomeType(desert, HOT, DRY, SANDY );
|
||||
registerBiomeType(extremeHills, MOUNTAIN, HILLS );
|
||||
registerBiomeType(forest, FOREST );
|
||||
registerBiomeType(taiga, COLD, CONIFEROUS, FOREST );
|
||||
registerBiomeType(taigaHills, COLD, CONIFEROUS, FOREST, HILLS );
|
||||
registerBiomeType(swampland, WET, SWAMP );
|
||||
registerBiomeType(river, RIVER );
|
||||
registerBiomeType(frozenOcean, COLD, OCEAN, SNOWY );
|
||||
registerBiomeType(frozenRiver, COLD, RIVER, SNOWY );
|
||||
registerBiomeType(icePlains, COLD, SNOWY, WASTELAND );
|
||||
registerBiomeType(iceMountains, COLD, SNOWY, MOUNTAIN );
|
||||
registerBiomeType(beach, BEACH );
|
||||
registerBiomeType(desertHills, HOT, DRY, SANDY, HILLS );
|
||||
registerBiomeType(jungle, HOT, WET, DENSE, JUNGLE );
|
||||
registerBiomeType(jungleHills, HOT, WET, DENSE, JUNGLE, HILLS);
|
||||
registerBiomeType(forestHills, FOREST, HILLS );
|
||||
registerBiomeType(sky, COLD, DRY, END );
|
||||
registerBiomeType(hell, HOT, DRY, NETHER );
|
||||
registerBiomeType(mushroomIsland, MUSHROOM );
|
||||
registerBiomeType(extremeHillsEdge, MOUNTAIN );
|
||||
registerBiomeType(mushroomIslandShore, MUSHROOM, BEACH );
|
||||
registerBiomeType(jungleEdge, HOT, WET, JUNGLE, FOREST );
|
||||
registerBiomeType(deepOcean, OCEAN );
|
||||
registerBiomeType(stoneBeach, BEACH );
|
||||
registerBiomeType(coldBeach, COLD, BEACH, SNOWY );
|
||||
registerBiomeType(birchForest, FOREST );
|
||||
registerBiomeType(birchForestHills, FOREST, HILLS );
|
||||
registerBiomeType(roofedForest, SPOOKY, DENSE, FOREST );
|
||||
registerBiomeType(coldTaiga, COLD, CONIFEROUS, FOREST, SNOWY );
|
||||
registerBiomeType(coldTaigaHills, COLD, CONIFEROUS, FOREST, SNOWY, HILLS);
|
||||
registerBiomeType(megaTaiga, COLD, CONIFEROUS, FOREST );
|
||||
registerBiomeType(megaTaigaHills, COLD, CONIFEROUS, FOREST, HILLS );
|
||||
registerBiomeType(extremeHillsPlus, MOUNTAIN, FOREST, SPARSE );
|
||||
registerBiomeType(savanna, HOT, SAVANNA, PLAINS, SPARSE );
|
||||
registerBiomeType(savannaPlateau, HOT, SAVANNA, PLAINS, SPARSE );
|
||||
registerBiomeType(mesa, MESA, SANDY );
|
||||
registerBiomeType(mesaPlateau_F, MESA, SPARSE, SANDY );
|
||||
registerBiomeType(mesaPlateau, MESA, SANDY );
|
||||
registerBiomeType(Biomes.ocean, OCEAN );
|
||||
registerBiomeType(Biomes.plains, PLAINS );
|
||||
registerBiomeType(Biomes.desert, HOT, DRY, SANDY );
|
||||
registerBiomeType(Biomes.extremeHills, MOUNTAIN, HILLS );
|
||||
registerBiomeType(Biomes.forest, FOREST );
|
||||
registerBiomeType(Biomes.taiga, COLD, CONIFEROUS, FOREST );
|
||||
registerBiomeType(Biomes.taigaHills, COLD, CONIFEROUS, FOREST, HILLS );
|
||||
registerBiomeType(Biomes.swampland, WET, SWAMP );
|
||||
registerBiomeType(Biomes.river, RIVER );
|
||||
registerBiomeType(Biomes.frozenOcean, COLD, OCEAN, SNOWY );
|
||||
registerBiomeType(Biomes.frozenRiver, COLD, RIVER, SNOWY );
|
||||
registerBiomeType(Biomes.icePlains, COLD, SNOWY, WASTELAND );
|
||||
registerBiomeType(Biomes.iceMountains, COLD, SNOWY, MOUNTAIN );
|
||||
registerBiomeType(Biomes.beach, BEACH );
|
||||
registerBiomeType(Biomes.desertHills, HOT, DRY, SANDY, HILLS );
|
||||
registerBiomeType(Biomes.jungle, HOT, WET, DENSE, JUNGLE );
|
||||
registerBiomeType(Biomes.jungleHills, HOT, WET, DENSE, JUNGLE, HILLS);
|
||||
registerBiomeType(Biomes.forestHills, FOREST, HILLS );
|
||||
registerBiomeType(Biomes.sky, COLD, DRY, END );
|
||||
registerBiomeType(Biomes.hell, HOT, DRY, NETHER );
|
||||
registerBiomeType(Biomes.mushroomIsland, MUSHROOM );
|
||||
registerBiomeType(Biomes.extremeHillsEdge, MOUNTAIN );
|
||||
registerBiomeType(Biomes.mushroomIslandShore, MUSHROOM, BEACH );
|
||||
registerBiomeType(Biomes.jungleEdge, HOT, WET, JUNGLE, FOREST );
|
||||
registerBiomeType(Biomes.deepOcean, OCEAN );
|
||||
registerBiomeType(Biomes.stoneBeach, BEACH );
|
||||
registerBiomeType(Biomes.coldBeach, COLD, BEACH, SNOWY );
|
||||
registerBiomeType(Biomes.birchForest, FOREST );
|
||||
registerBiomeType(Biomes.birchForestHills, FOREST, HILLS );
|
||||
registerBiomeType(Biomes.roofedForest, SPOOKY, DENSE, FOREST );
|
||||
registerBiomeType(Biomes.coldTaiga, COLD, CONIFEROUS, FOREST, SNOWY );
|
||||
registerBiomeType(Biomes.coldTaigaHills, COLD, CONIFEROUS, FOREST, SNOWY, HILLS);
|
||||
registerBiomeType(Biomes.megaTaiga, COLD, CONIFEROUS, FOREST );
|
||||
registerBiomeType(Biomes.megaTaigaHills, COLD, CONIFEROUS, FOREST, HILLS );
|
||||
registerBiomeType(Biomes.extremeHillsPlus, MOUNTAIN, FOREST, SPARSE );
|
||||
registerBiomeType(Biomes.savanna, HOT, SAVANNA, PLAINS, SPARSE );
|
||||
registerBiomeType(Biomes.savannaPlateau, HOT, SAVANNA, PLAINS, SPARSE );
|
||||
registerBiomeType(Biomes.mesa, MESA, SANDY );
|
||||
registerBiomeType(Biomes.mesaPlateau_F, MESA, SPARSE, SANDY );
|
||||
registerBiomeType(Biomes.mesaPlateau, MESA, SANDY );
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,10 @@ import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.init.Biomes;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.biome.WorldChunkManager;
|
||||
import net.minecraft.world.biome.BiomeProvider;
|
||||
import net.minecraft.world.gen.structure.MapGenVillage;
|
||||
import net.minecraftforge.common.util.EnumHelper;
|
||||
|
||||
@@ -24,9 +25,9 @@ public class BiomeManager
|
||||
|
||||
static
|
||||
{
|
||||
oceanBiomes.add(BiomeGenBase.ocean);
|
||||
oceanBiomes.add(BiomeGenBase.deepOcean);
|
||||
oceanBiomes.add(BiomeGenBase.frozenOcean);
|
||||
oceanBiomes.add(Biomes.ocean);
|
||||
oceanBiomes.add(Biomes.deepOcean);
|
||||
oceanBiomes.add(Biomes.frozenOcean);
|
||||
}
|
||||
|
||||
private static TrackedList<BiomeEntry>[] setupBiomes()
|
||||
@@ -35,26 +36,26 @@ public class BiomeManager
|
||||
TrackedList<BiomeEntry>[] currentBiomes = new TrackedList[BiomeType.values().length];
|
||||
List<BiomeEntry> list = new ArrayList<BiomeEntry>();
|
||||
|
||||
list.add(new BiomeEntry(BiomeGenBase.forest, 10));
|
||||
list.add(new BiomeEntry(BiomeGenBase.roofedForest, 10));
|
||||
list.add(new BiomeEntry(BiomeGenBase.extremeHills, 10));
|
||||
list.add(new BiomeEntry(BiomeGenBase.plains, 10));
|
||||
list.add(new BiomeEntry(BiomeGenBase.birchForest, 10));
|
||||
list.add(new BiomeEntry(BiomeGenBase.swampland, 10));
|
||||
list.add(new BiomeEntry(Biomes.forest, 10));
|
||||
list.add(new BiomeEntry(Biomes.roofedForest, 10));
|
||||
list.add(new BiomeEntry(Biomes.extremeHills, 10));
|
||||
list.add(new BiomeEntry(Biomes.plains, 10));
|
||||
list.add(new BiomeEntry(Biomes.birchForest, 10));
|
||||
list.add(new BiomeEntry(Biomes.swampland, 10));
|
||||
|
||||
currentBiomes[BiomeType.WARM.ordinal()] = new TrackedList<BiomeEntry>(list);
|
||||
list.clear();
|
||||
|
||||
list.add(new BiomeEntry(BiomeGenBase.forest, 10));
|
||||
list.add(new BiomeEntry(BiomeGenBase.extremeHills, 10));
|
||||
list.add(new BiomeEntry(BiomeGenBase.taiga, 10));
|
||||
list.add(new BiomeEntry(BiomeGenBase.plains, 10));
|
||||
list.add(new BiomeEntry(Biomes.forest, 10));
|
||||
list.add(new BiomeEntry(Biomes.extremeHills, 10));
|
||||
list.add(new BiomeEntry(Biomes.taiga, 10));
|
||||
list.add(new BiomeEntry(Biomes.plains, 10));
|
||||
|
||||
currentBiomes[BiomeType.COOL.ordinal()] = new TrackedList<BiomeEntry>(list);
|
||||
list.clear();
|
||||
|
||||
list.add(new BiomeEntry(BiomeGenBase.icePlains, 30));
|
||||
list.add(new BiomeEntry(BiomeGenBase.coldTaiga, 10));
|
||||
list.add(new BiomeEntry(Biomes.icePlains, 30));
|
||||
list.add(new BiomeEntry(Biomes.coldTaiga, 10));
|
||||
|
||||
currentBiomes[BiomeType.ICY.ordinal()] = new TrackedList<BiomeEntry>(list);
|
||||
list.clear();
|
||||
@@ -102,17 +103,17 @@ public class BiomeManager
|
||||
|
||||
public static void addSpawnBiome(BiomeGenBase biome)
|
||||
{
|
||||
if (!WorldChunkManager.allowedBiomes.contains(biome))
|
||||
if (!BiomeProvider.allowedBiomes.contains(biome))
|
||||
{
|
||||
WorldChunkManager.allowedBiomes.add(biome);
|
||||
BiomeProvider.allowedBiomes.add(biome);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeSpawnBiome(BiomeGenBase biome)
|
||||
{
|
||||
if (WorldChunkManager.allowedBiomes.contains(biome))
|
||||
if (BiomeProvider.allowedBiomes.contains(biome))
|
||||
{
|
||||
WorldChunkManager.allowedBiomes.remove(biome);
|
||||
BiomeProvider.allowedBiomes.remove(biome);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,246 +0,0 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.util.WeightedRandomChestContent;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.gen.feature.WorldGenDungeons;
|
||||
import net.minecraft.world.gen.structure.ComponentScatteredFeaturePieces.DesertPyramid;
|
||||
import net.minecraft.world.gen.structure.ComponentScatteredFeaturePieces.JunglePyramid;
|
||||
import net.minecraft.world.gen.structure.StructureMineshaftPieces;
|
||||
import net.minecraft.world.gen.structure.StructureNetherBridgePieces;
|
||||
import net.minecraft.world.gen.structure.StructureOceanMonument;
|
||||
import net.minecraft.world.gen.structure.StructureStrongholdPieces;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class ChestGenHooks
|
||||
{
|
||||
//Currently implemented categories for chests/dispensers, Dungeon loot is still in DungeonHooks
|
||||
public static final String MINESHAFT_CORRIDOR = "mineshaftCorridor";
|
||||
public static final String PYRAMID_DESERT_CHEST = "pyramidDesertyChest";
|
||||
public static final String PYRAMID_JUNGLE_CHEST = "pyramidJungleChest";
|
||||
public static final String PYRAMID_JUNGLE_DISPENSER = "pyramidJungleDispenser";
|
||||
public static final String STRONGHOLD_CORRIDOR = "strongholdCorridor";
|
||||
public static final String STRONGHOLD_LIBRARY = "strongholdLibrary";
|
||||
public static final String STRONGHOLD_CROSSING = "strongholdCrossing";
|
||||
public static final String VILLAGE_BLACKSMITH = "villageBlacksmith";
|
||||
public static final String BONUS_CHEST = "bonusChest";
|
||||
public static final String DUNGEON_CHEST = "dungeonChest";
|
||||
public static final String NETHER_FORTRESS = "netherFortress";
|
||||
|
||||
private static final HashMap<String, ChestGenHooks> chestInfo = new HashMap<String, ChestGenHooks>();
|
||||
private static boolean hasInit = false;
|
||||
static
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
private static void init()
|
||||
{
|
||||
if (hasInit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hasInit = true;
|
||||
// This causes the classes static initializers to run
|
||||
new WorldGenDungeons();
|
||||
new DesertPyramid();
|
||||
new JunglePyramid();
|
||||
new StructureMineshaftPieces();
|
||||
new StructureOceanMonument();
|
||||
new StructureStrongholdPieces.ChestCorridor();
|
||||
new StructureStrongholdPieces.Library();
|
||||
new StructureStrongholdPieces.RoomCrossing();
|
||||
new StructureVillagePieces.House2();
|
||||
new StructureNetherBridgePieces.Corridor();
|
||||
WorldServer.fillChestHook();
|
||||
}
|
||||
|
||||
// INTERNAL DO NO USE
|
||||
public static void init(String category, List<WeightedRandomChestContent> items, int min, int max)
|
||||
{
|
||||
chestInfo.put(category, new ChestGenHooks(category, items, min, max));
|
||||
}
|
||||
|
||||
static void addDungeonLoot(ChestGenHooks dungeon, ItemStack item, int weight, int min, int max)
|
||||
{
|
||||
dungeon.addItem(new WeightedRandomChestContent(item, min, max, weight));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves, or creates the info class for the specified category.
|
||||
*
|
||||
* @param category The category name
|
||||
* @return A instance of ChestGenHooks for the specified category.
|
||||
*/
|
||||
public static ChestGenHooks getInfo(String category)
|
||||
{
|
||||
if (!chestInfo.containsKey(category))
|
||||
{
|
||||
chestInfo.put(category, new ChestGenHooks(category));
|
||||
}
|
||||
return chestInfo.get(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array of items based on the input min/max count.
|
||||
* If the stack can not hold the total amount, it will be split into
|
||||
* stacks of size 1.
|
||||
*
|
||||
* @param rand A random number generator
|
||||
* @param source Source item stack
|
||||
* @param min Minimum number of items
|
||||
* @param max Maximum number of items
|
||||
* @return An array containing the generated item stacks
|
||||
*/
|
||||
public static ItemStack[] generateStacks(Random rand, ItemStack source, int min, int max)
|
||||
{
|
||||
int count = min + (rand.nextInt(max - min + 1));
|
||||
|
||||
ItemStack[] ret;
|
||||
if (source.getItem() == null)
|
||||
{
|
||||
ret = new ItemStack[0];
|
||||
}
|
||||
else if (count > source.getMaxStackSize())
|
||||
{
|
||||
ret = new ItemStack[count];
|
||||
for (int x = 0; x < count; x++)
|
||||
{
|
||||
ret[x] = source.copy();
|
||||
ret[x].stackSize = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = new ItemStack[1];
|
||||
ret[0] = source.copy();
|
||||
ret[0].stackSize = count;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//shortcut functions, See the non-static versions below
|
||||
public static List<WeightedRandomChestContent> getItems(String category, Random rnd){ return getInfo(category).getItems(rnd); }
|
||||
public static int getCount(String category, Random rand){ return getInfo(category).getCount(rand); }
|
||||
public static void addItem(String category, WeightedRandomChestContent item){ getInfo(category).addItem(item); }
|
||||
public static void removeItem(String category, ItemStack item){ getInfo(category).removeItem(item); }
|
||||
public static ItemStack getOneItem(String category, Random rand){ return getInfo(category).getOneItem(rand); }
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String category;
|
||||
private int countMin = 0;
|
||||
private int countMax = 0;
|
||||
private ArrayList<WeightedRandomChestContent> contents = new ArrayList<WeightedRandomChestContent>();
|
||||
|
||||
public ChestGenHooks(String category)
|
||||
{
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public ChestGenHooks(String category, List<WeightedRandomChestContent> items, int min, int max)
|
||||
{
|
||||
this(category);
|
||||
for (WeightedRandomChestContent item : items)
|
||||
{
|
||||
contents.add(item);
|
||||
}
|
||||
countMin = min;
|
||||
countMax = max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new entry into the possible items to generate.
|
||||
*
|
||||
* @param item The item to add.
|
||||
*/
|
||||
public void addItem(WeightedRandomChestContent item)
|
||||
{
|
||||
contents.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all items that match the input item stack, Only metadata and item ID are checked.
|
||||
* If the input item has a metadata of -1, all metadatas will match.
|
||||
*
|
||||
* @param item The item to check
|
||||
*/
|
||||
public void removeItem(ItemStack item)
|
||||
{
|
||||
Iterator<WeightedRandomChestContent> itr = contents.iterator();
|
||||
while(itr.hasNext())
|
||||
{
|
||||
WeightedRandomChestContent cont = itr.next();
|
||||
if (item.isItemEqual(cont.theItemId) || (item.getItemDamage() == OreDictionary.WILDCARD_VALUE && item.getItem() == cont.theItemId.getItem()))
|
||||
{
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of all random objects that are associated with this category.
|
||||
*
|
||||
* @return The random objects
|
||||
*/
|
||||
public List<WeightedRandomChestContent> getItems(Random rnd)
|
||||
{
|
||||
ArrayList<WeightedRandomChestContent> ret = new ArrayList<WeightedRandomChestContent>();
|
||||
|
||||
for (WeightedRandomChestContent orig : contents)
|
||||
{
|
||||
Item item = orig.theItemId.getItem();
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
WeightedRandomChestContent n = item.getChestGenBase(this, rnd, orig);
|
||||
if (n != null)
|
||||
{
|
||||
ret.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a random number between countMin and countMax.
|
||||
*
|
||||
* @param rand A RNG
|
||||
* @return A random number where countMin <= num <= countMax
|
||||
*/
|
||||
public int getCount(Random rand)
|
||||
{
|
||||
return countMin < countMax ? countMin + rand.nextInt(countMax - countMin) : countMin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single ItemStack from the possible items in this registry,
|
||||
* Useful if you just want a quick and dirty random Item.
|
||||
*
|
||||
* @param rand A Random Number gen
|
||||
* @return A single ItemStack, or null if it could not get one.
|
||||
*/
|
||||
public ItemStack getOneItem(Random rand)
|
||||
{
|
||||
WeightedRandomChestContent item = (WeightedRandomChestContent)WeightedRandom.getRandomItem(rand, getItems(rand));
|
||||
ItemStack[] stacks = ChestGenHooks.generateStacks(rand, item.theItemId, item.minStackSize, item.maxStackSize);
|
||||
return (stacks.length > 0 ? stacks[0] : null);
|
||||
}
|
||||
|
||||
//Accessors
|
||||
public int getMin(){ return countMin; }
|
||||
public int getMax(){ return countMax; }
|
||||
public void setMin(int value){ countMin = value; }
|
||||
public void setMax(int value){ countMax = value; }
|
||||
}
|
||||
@@ -20,13 +20,11 @@ import com.google.common.collect.Multiset;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.MinecraftException;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldManager;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraft.world.WorldProviderEnd;
|
||||
import net.minecraft.world.WorldProviderHell;
|
||||
import net.minecraft.world.WorldProviderSurface;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.WorldServerMulti;
|
||||
import net.minecraft.world.storage.ISaveHandler;
|
||||
@@ -37,51 +35,24 @@ import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
public class DimensionManager
|
||||
{
|
||||
private static Hashtable<Integer, Class<? extends WorldProvider>> providers = new Hashtable<Integer, Class<? extends WorldProvider>>();
|
||||
private static Hashtable<Integer, Boolean> spawnSettings = new Hashtable<Integer, Boolean>();
|
||||
private static Hashtable<Integer, WorldServer> worlds = new Hashtable<Integer, WorldServer>();
|
||||
private static boolean hasInit = false;
|
||||
private static Hashtable<Integer, Integer> dimensions = new Hashtable<Integer, Integer>();
|
||||
private static Hashtable<Integer, DimensionType> dimensions = new Hashtable<Integer, DimensionType>();
|
||||
private static ArrayList<Integer> unloadQueue = new ArrayList<Integer>();
|
||||
private static BitSet dimensionMap = new BitSet(Long.SIZE << 4);
|
||||
private static ConcurrentMap<World, World> weakWorldMap = new MapMaker().weakKeys().weakValues().<World,World>makeMap();
|
||||
private static Multiset<Integer> leakedWorlds = HashMultiset.create();
|
||||
|
||||
public static boolean registerProviderType(int id, Class<? extends WorldProvider> provider, boolean keepLoaded)
|
||||
{
|
||||
if (providers.containsKey(id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
providers.put(id, provider);
|
||||
spawnSettings.put(id, keepLoaded);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a Provider type, and returns a array of all dimensions that are
|
||||
* registered to this provider type.
|
||||
* If the return size is greater then 0, it is required that the caller either
|
||||
* change those dimensions's registered type, or replace this type before the
|
||||
* world is attempted to load, else the loader will throw an exception.
|
||||
*
|
||||
* @param id The provider type ID to unreigster
|
||||
* @return An array containing all dimension IDs still registered to this provider type.
|
||||
* Returns a list of dimensions associated with this DimensionType.
|
||||
*/
|
||||
public static int[] unregisterProviderType(int id)
|
||||
public static int[] getDimensions(DimensionType type)
|
||||
{
|
||||
if (!providers.containsKey(id))
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
providers.remove(id);
|
||||
spawnSettings.remove(id);
|
||||
|
||||
int[] ret = new int[dimensions.size()];
|
||||
int x = 0;
|
||||
for (Map.Entry<Integer, Integer> ent : dimensions.entrySet())
|
||||
for (Map.Entry<Integer, DimensionType> ent : dimensions.entrySet())
|
||||
{
|
||||
if (ent.getValue() == id)
|
||||
if (ent.getValue() == type)
|
||||
{
|
||||
ret[x++] = ent.getKey();
|
||||
}
|
||||
@@ -99,25 +70,19 @@ public class DimensionManager
|
||||
|
||||
hasInit = true;
|
||||
|
||||
registerProviderType( 0, WorldProviderSurface.class, true);
|
||||
registerProviderType(-1, WorldProviderHell.class, true);
|
||||
registerProviderType( 1, WorldProviderEnd.class, false);
|
||||
registerDimension( 0, 0);
|
||||
registerDimension(-1, -1);
|
||||
registerDimension( 1, 1);
|
||||
registerDimension( 0, DimensionType.OVERWORLD);
|
||||
registerDimension(-1, DimensionType.NETHER);
|
||||
registerDimension( 1, DimensionType.THE_END);
|
||||
}
|
||||
|
||||
public static void registerDimension(int id, int providerType)
|
||||
public static void registerDimension(int id, DimensionType type)
|
||||
{
|
||||
if (!providers.containsKey(providerType))
|
||||
{
|
||||
throw new IllegalArgumentException(String.format("Failed to register dimension for id %d, provider type %d does not exist", id, providerType));
|
||||
}
|
||||
DimensionType.getById(type.getId()); //Check if type is invalid {will throw an error} No clue how it would be invalid tho...
|
||||
if (dimensions.containsKey(id))
|
||||
{
|
||||
throw new IllegalArgumentException(String.format("Failed to register dimension for id %d, One is already registered", id));
|
||||
}
|
||||
dimensions.put(id, providerType);
|
||||
dimensions.put(id, type);
|
||||
if (id >= 0)
|
||||
{
|
||||
dimensionMap.set(id);
|
||||
@@ -141,7 +106,7 @@ public class DimensionManager
|
||||
return dimensions.containsKey(dim);
|
||||
}
|
||||
|
||||
public static int getProviderType(int dim)
|
||||
public static DimensionType getProviderType(int dim)
|
||||
{
|
||||
if (!dimensions.containsKey(dim))
|
||||
{
|
||||
@@ -171,7 +136,7 @@ public class DimensionManager
|
||||
int leakCount = leakedWorlds.count(System.identityHashCode(w));
|
||||
if (leakCount == 5)
|
||||
{
|
||||
FMLLog.fine("The world %x (%s) may have leaked: first encounter (5 occurences).\n", System.identityHashCode(w), w.getWorldInfo().getWorldName());
|
||||
FMLLog.fine("The world %x (%s) may have leaked: first encounter (5 occurrences).\n", System.identityHashCode(w), w.getWorldInfo().getWorldName());
|
||||
}
|
||||
else if (leakCount % 5 == 0)
|
||||
{
|
||||
@@ -186,19 +151,19 @@ public class DimensionManager
|
||||
return worlds.keySet().toArray(new Integer[worlds.size()]); //Only loaded dims, since usually used to cycle through loaded worlds
|
||||
}
|
||||
|
||||
public static void setWorld(int id, WorldServer world)
|
||||
public static void setWorld(int id, WorldServer world, MinecraftServer server)
|
||||
{
|
||||
if (world != null)
|
||||
{
|
||||
worlds.put(id, world);
|
||||
weakWorldMap.put(world, world);
|
||||
MinecraftServer.getServer().worldTickTimes.put(id, new long[100]);
|
||||
server.worldTickTimes.put(id, new long[100]);
|
||||
FMLLog.info("Loading dimension %d (%s) (%s)", id, world.getWorldInfo().getWorldName(), world.getMinecraftServer());
|
||||
}
|
||||
else
|
||||
{
|
||||
worlds.remove(id);
|
||||
MinecraftServer.getServer().worldTickTimes.remove(id);
|
||||
server.worldTickTimes.remove(id);
|
||||
FMLLog.info("Unloading dimension %d", id);
|
||||
}
|
||||
|
||||
@@ -220,7 +185,7 @@ public class DimensionManager
|
||||
tmp.add(entry.getValue());
|
||||
}
|
||||
|
||||
MinecraftServer.getServer().worldServers = tmp.toArray(new WorldServer[tmp.size()]);
|
||||
server.worldServers = tmp.toArray(new WorldServer[tmp.size()]);
|
||||
}
|
||||
|
||||
public static void initDimension(int dim)
|
||||
@@ -244,7 +209,7 @@ public class DimensionManager
|
||||
//WorldSettings worldSettings = new WorldSettings(overworld.getWorldInfo());
|
||||
|
||||
WorldServer world = (dim == 0 ? overworld : (WorldServer)(new WorldServerMulti(mcServer, savehandler, dim, overworld, mcServer.theProfiler).init()));
|
||||
world.addWorldAccess(new WorldManager(mcServer, world));
|
||||
world.addEventListener(new WorldManager(mcServer, world));
|
||||
MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world));
|
||||
if (!mcServer.isSinglePlayer())
|
||||
{
|
||||
@@ -264,12 +229,6 @@ public class DimensionManager
|
||||
return worlds.values().toArray(new WorldServer[worlds.size()]);
|
||||
}
|
||||
|
||||
public static boolean shouldLoadSpawn(int dim)
|
||||
{
|
||||
int id = getProviderType(dim);
|
||||
return spawnSettings.containsKey(id) && spawnSettings.get(id);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
init();
|
||||
@@ -289,9 +248,9 @@ public class DimensionManager
|
||||
{
|
||||
if (dimensions.containsKey(dim))
|
||||
{
|
||||
WorldProvider provider = providers.get(getProviderType(dim)).newInstance();
|
||||
provider.setDimension(dim);
|
||||
return provider;
|
||||
WorldProvider ret = getProviderType(dim).createDimension();
|
||||
ret.setDimension(dim);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -300,8 +259,8 @@ public class DimensionManager
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLCommonHandler.instance().getFMLLogger().log(Level.ERROR, String.format("An error occured trying to create an instance of WorldProvider %d (%s)",
|
||||
dim, providers.get(getProviderType(dim)).getSimpleName()),e);
|
||||
FMLCommonHandler.instance().getFMLLogger().log(Level.ERROR, String.format("An error occurred trying to create an instance of WorldProvider %d (%s)",
|
||||
dim, getProviderType(dim)),e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -334,7 +293,7 @@ public class DimensionManager
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(w));
|
||||
w.flush();
|
||||
setWorld(id, null);
|
||||
setWorld(id, null, w.getMinecraftServer());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,17 +372,17 @@ public class DimensionManager
|
||||
{
|
||||
if (DimensionManager.getWorld(0) != null)
|
||||
{
|
||||
return ((SaveHandler)DimensionManager.getWorld(0).getSaveHandler()).getWorldDirectory();
|
||||
}
|
||||
return DimensionManager.getWorld(0).getSaveHandler().getWorldDirectory();
|
||||
}/*
|
||||
else if (MinecraftServer.getServer() != null)
|
||||
{
|
||||
MinecraftServer srv = MinecraftServer.getServer();
|
||||
SaveHandler saveHandler = (SaveHandler) srv.getActiveAnvilConverter().getSaveLoader(srv.getFolderName(), false);
|
||||
return saveHandler.getWorldDirectory();
|
||||
}
|
||||
}*/
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class DungeonHooks
|
||||
*/
|
||||
public static String getRandomDungeonMob(Random rand)
|
||||
{
|
||||
DungeonMob mob = (DungeonMob)WeightedRandom.getRandomItem(rand, dungeonMobs);
|
||||
DungeonMob mob = WeightedRandom.getRandomItem(rand, dungeonMobs);
|
||||
if (mob == null)
|
||||
{
|
||||
return "";
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import net.minecraft.entity.projectile.EntityFishHook;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.StatBase;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.util.WeightedRandomFishable;
|
||||
|
||||
public class FishingHooks
|
||||
{
|
||||
private static ArrayList<WeightedRandomFishable> fish = new ArrayList<WeightedRandomFishable>();
|
||||
private static ArrayList<WeightedRandomFishable> junk = new ArrayList<WeightedRandomFishable>();
|
||||
private static ArrayList<WeightedRandomFishable> treasure = new ArrayList<WeightedRandomFishable>();
|
||||
|
||||
public static void addFish(WeightedRandomFishable item) { fish.add(item); }
|
||||
public static void addJunk(WeightedRandomFishable item) { junk.add(item); }
|
||||
public static void addTreasure(WeightedRandomFishable item) { treasure.add(item); }
|
||||
|
||||
public static void removeFish(Predicate<WeightedRandomFishable> test) { remove(fish.iterator(), test); }
|
||||
public static void removeJunk(Predicate<WeightedRandomFishable> test) { remove(junk.iterator(), test); }
|
||||
public static void removeTreasure(Predicate<WeightedRandomFishable> test) { remove(treasure.iterator(), test); }
|
||||
|
||||
public static ItemStack getRandomFishable(Random rand, float chance)
|
||||
{
|
||||
return getRandomFishable(rand, chance, 0, 0);
|
||||
}
|
||||
|
||||
public static ItemStack getRandomFishable(Random rand, float chance, int luck, int speed)
|
||||
{
|
||||
float junkChance = 0.1F - luck * 0.025F - speed * 0.01F;
|
||||
float treasureChance = 0.05F + luck * 0.01F - speed * 0.01F;
|
||||
junkChance = MathHelper.clamp_float(junkChance, 0.0F, 1.0F);
|
||||
treasureChance = MathHelper.clamp_float(treasureChance, 0.0F, 1.0F);
|
||||
|
||||
if (chance < junkChance)
|
||||
{
|
||||
return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, junk)).getItemStack(rand);
|
||||
}
|
||||
|
||||
chance -= junkChance;
|
||||
if (chance < treasureChance)
|
||||
{
|
||||
return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, treasure)).getItemStack(rand);
|
||||
}
|
||||
|
||||
chance -= treasureChance;
|
||||
// this is done in EntityFishHook.func_146033_f. more loot types expected?
|
||||
{
|
||||
return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, fish)).getItemStack(rand);
|
||||
}
|
||||
}
|
||||
|
||||
public static FishableCategory getFishableCategory(float chance, int luck, int speed)
|
||||
{
|
||||
float junkChance = 0.1F - luck * 0.025F - speed * 0.01F;
|
||||
float treasureChance = 0.05F + luck * 0.01F - speed * 0.01F;
|
||||
junkChance = MathHelper.clamp_float(junkChance, 0.0F, 1.0F);
|
||||
treasureChance = MathHelper.clamp_float(treasureChance, 0.0F, 1.0F);
|
||||
|
||||
if (chance < junkChance)
|
||||
{
|
||||
return FishableCategory.JUNK;
|
||||
}
|
||||
|
||||
chance -= junkChance;
|
||||
if (chance < treasureChance)
|
||||
{
|
||||
return FishableCategory.TREASURE;
|
||||
}
|
||||
|
||||
chance -= treasureChance;
|
||||
// this is done in EntityFishHook.func_146033_f. more loot types expected?
|
||||
{
|
||||
return FishableCategory.FISH;
|
||||
}
|
||||
}
|
||||
|
||||
private static void remove(Iterator<WeightedRandomFishable> iter, Predicate<WeightedRandomFishable> test)
|
||||
{
|
||||
while (iter.hasNext())
|
||||
if (!test.apply(iter.next()))
|
||||
iter.remove();
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
fish.addAll(EntityFishHook.FISH);
|
||||
junk.addAll(EntityFishHook.JUNK);
|
||||
treasure.addAll(EntityFishHook.TREASURE);
|
||||
}
|
||||
|
||||
public static enum FishableCategory
|
||||
{
|
||||
JUNK(StatList.junkFishedStat),
|
||||
TREASURE(StatList.treasureFishedStat),
|
||||
FISH(StatList.fishCaughtStat);
|
||||
|
||||
public final StatBase stat;
|
||||
|
||||
FishableCategory(StatBase stat)
|
||||
{
|
||||
this.stat = stat;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,32 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ClassInheritanceMultiMap;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
@@ -25,6 +50,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.MapMaker;
|
||||
@@ -32,25 +58,6 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ClassInheritanceMultiMap;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
/**
|
||||
* Manages chunkloading for mods.
|
||||
@@ -103,6 +110,25 @@ public class ForgeChunkManager
|
||||
MOD_PROP_ORDER.add("maximumChunksPerTicket");
|
||||
}
|
||||
|
||||
public static Iterator<Chunk> getPersistentChunksIterableFor(final World world, Iterator<Chunk> chunkIterator)
|
||||
{
|
||||
final ImmutableSetMultimap<ChunkCoordIntPair, Ticket> persistentChunksFor = getPersistentChunksFor(world);
|
||||
final ImmutableSet.Builder<Chunk> builder = ImmutableSet.builder();
|
||||
world.theProfiler.startSection("forcedChunkLoading");
|
||||
builder.addAll(Iterators.transform(persistentChunksFor.keys().iterator(), new Function<ChunkCoordIntPair, Chunk>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Chunk apply(@Nullable ChunkCoordIntPair input)
|
||||
{
|
||||
return world.getChunkFromChunkCoords(input.chunkXPos, input.chunkZPos);
|
||||
}
|
||||
}));
|
||||
world.theProfiler.endStartSection("regularChunkLoading");
|
||||
builder.addAll(chunkIterator);
|
||||
world.theProfiler.endSection();
|
||||
return builder.build().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* All mods requiring chunkloading need to implement this to handle the
|
||||
* re-registration of chunk tickets at world loading time
|
||||
@@ -344,25 +370,45 @@ public class ForgeChunkManager
|
||||
}
|
||||
|
||||
public static class ForceChunkEvent extends Event {
|
||||
public final Ticket ticket;
|
||||
public final ChunkCoordIntPair location;
|
||||
private final Ticket ticket;
|
||||
private final ChunkCoordIntPair location;
|
||||
|
||||
public ForceChunkEvent(Ticket ticket, ChunkCoordIntPair location)
|
||||
{
|
||||
this.ticket = ticket;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Ticket getTicket()
|
||||
{
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public ChunkCoordIntPair getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnforceChunkEvent extends Event {
|
||||
public final Ticket ticket;
|
||||
public final ChunkCoordIntPair location;
|
||||
private final Ticket ticket;
|
||||
private final ChunkCoordIntPair location;
|
||||
|
||||
public UnforceChunkEvent(Ticket ticket, ChunkCoordIntPair location)
|
||||
{
|
||||
this.ticket = ticket;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Ticket getTicket()
|
||||
{
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public ChunkCoordIntPair getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -395,7 +441,7 @@ public class ForgeChunkManager
|
||||
|
||||
static void loadWorld(World world)
|
||||
{
|
||||
ArrayListMultimap<String, Ticket> newTickets = ArrayListMultimap.<String, Ticket>create();
|
||||
ArrayListMultimap<String, Ticket> newTickets = ArrayListMultimap.create();
|
||||
tickets.put(world, newTickets);
|
||||
|
||||
forcedChunks.put(world, ImmutableSetMultimap.<ChunkCoordIntPair,Ticket>of());
|
||||
@@ -412,7 +458,7 @@ public class ForgeChunkManager
|
||||
|
||||
if (chunkLoaderData.exists() && chunkLoaderData.isFile())
|
||||
{
|
||||
ArrayListMultimap<String, Ticket> loadedTickets = ArrayListMultimap.<String, Ticket>create();
|
||||
ArrayListMultimap<String, Ticket> loadedTickets = ArrayListMultimap.create();
|
||||
Map<String,ListMultimap<String,Ticket>> playerLoadedTickets = Maps.newHashMap();
|
||||
NBTTagCompound forcedChunkData;
|
||||
try
|
||||
@@ -427,7 +473,7 @@ public class ForgeChunkManager
|
||||
NBTTagList ticketList = forcedChunkData.getTagList("TicketList", Constants.NBT.TAG_COMPOUND);
|
||||
for (int i = 0; i < ticketList.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound ticketHolder = (NBTTagCompound)ticketList.getCompoundTagAt(i);
|
||||
NBTTagCompound ticketHolder = ticketList.getCompoundTagAt(i);
|
||||
String modId = ticketHolder.getString("Owner");
|
||||
boolean isPlayer = "Forge".equals(modId);
|
||||
|
||||
@@ -446,7 +492,7 @@ public class ForgeChunkManager
|
||||
NBTTagList tickets = ticketHolder.getTagList("Tickets", Constants.NBT.TAG_COMPOUND);
|
||||
for (int j = 0; j < tickets.tagCount(); j++)
|
||||
{
|
||||
NBTTagCompound ticket = (NBTTagCompound) tickets.getCompoundTagAt(j);
|
||||
NBTTagCompound ticket = tickets.getCompoundTagAt(j);
|
||||
modId = ticket.hasKey("ModId") ? ticket.getString("ModId") : modId;
|
||||
Type type = Type.values()[ticket.getByte("Type")];
|
||||
//byte ticketChunkDepth = ticket.getByte("ChunkListDepth");
|
||||
@@ -551,8 +597,8 @@ public class ForgeChunkManager
|
||||
|
||||
forcedChunks.remove(world);
|
||||
dormantChunkCache.remove(world);
|
||||
// integrated server is shutting down
|
||||
if (!MinecraftServer.getServer().isServerRunning())
|
||||
// integrated server is shutting down
|
||||
if (!FMLCommonHandler.instance().getMinecraftServerInstance().isServerRunning())
|
||||
{
|
||||
playerTickets.clear();
|
||||
tickets.clear();
|
||||
@@ -913,7 +959,7 @@ public class ForgeChunkManager
|
||||
{
|
||||
for (ClassInheritanceMultiMap<Entity> eList : chunk.getEntityLists())
|
||||
{
|
||||
Iterator<Entity> itr = (Iterator<Entity>)eList.iterator();
|
||||
Iterator<Entity> itr = eList.iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
(itr.next()).resetEntityId();
|
||||
@@ -939,7 +985,7 @@ public class ForgeChunkManager
|
||||
dest.delete();
|
||||
}
|
||||
cfgFile.renameTo(dest);
|
||||
FMLLog.log(Level.ERROR, e, "A critical error occured reading the forgeChunkLoading.cfg file, defaults will be used - the invalid file is backed up at forgeChunkLoading.cfg.bak");
|
||||
FMLLog.log(Level.ERROR, e, "A critical error occurred reading the forgeChunkLoading.cfg file, defaults will be used - the invalid file is backed up at forgeChunkLoading.cfg.bak");
|
||||
}
|
||||
syncConfigDefaults();
|
||||
}
|
||||
@@ -957,37 +1003,37 @@ public class ForgeChunkManager
|
||||
.setCategoryRequiresWorldRestart("defaults", true);
|
||||
|
||||
Property temp = config.get("defaults", "enabled", true);
|
||||
temp.comment = "Are mod overrides enabled?";
|
||||
temp.setComment("Are mod overrides enabled?");
|
||||
temp.setLanguageKey("forge.configgui.enableModOverrides");
|
||||
overridesEnabled = temp.getBoolean(true);
|
||||
propOrder.add("enabled");
|
||||
|
||||
temp = config.get("defaults", "maximumChunksPerTicket", 25);
|
||||
temp.comment = "The default maximum number of chunks a mod can force, per ticket, \n" +
|
||||
"for a mod without an override. This is the maximum number of chunks a single ticket can force.";
|
||||
temp.setComment("The default maximum number of chunks a mod can force, per ticket, \n" +
|
||||
"for a mod without an override. This is the maximum number of chunks a single ticket can force.");
|
||||
temp.setLanguageKey("forge.configgui.maximumChunksPerTicket");
|
||||
temp.setMinValue(0);
|
||||
defaultMaxChunks = temp.getInt(25);
|
||||
propOrder.add("maximumChunksPerTicket");
|
||||
|
||||
temp = config.get("defaults", "maximumTicketCount", 200);
|
||||
temp.comment = "The default maximum ticket count for a mod which does not have an override\n" +
|
||||
"in this file. This is the number of chunk loading requests a mod is allowed to make.";
|
||||
temp.setComment("The default maximum ticket count for a mod which does not have an override\n" +
|
||||
"in this file. This is the number of chunk loading requests a mod is allowed to make.");
|
||||
temp.setLanguageKey("forge.configgui.maximumTicketCount");
|
||||
temp.setMinValue(0);
|
||||
defaultMaxCount = temp.getInt(200);
|
||||
propOrder.add("maximumTicketCount");
|
||||
|
||||
temp = config.get("defaults", "playerTicketCount", 500);
|
||||
temp.comment = "The number of tickets a player can be assigned instead of a mod. This is shared across all mods and it is up to the mods to use it.";
|
||||
temp.setComment("The number of tickets a player can be assigned instead of a mod. This is shared across all mods and it is up to the mods to use it.");
|
||||
temp.setLanguageKey("forge.configgui.playerTicketCount");
|
||||
temp.setMinValue(0);
|
||||
playerTicketLength = temp.getInt(500);
|
||||
propOrder.add("playerTicketCount");
|
||||
|
||||
temp = config.get("defaults", "dormantChunkCacheSize", 0);
|
||||
temp.comment = "Unloaded chunks can first be kept in a dormant cache for quicker\n" +
|
||||
"loading times. Specify the size (in chunks) of that cache here";
|
||||
temp.setComment("Unloaded chunks can first be kept in a dormant cache for quicker\n" +
|
||||
"loading times. Specify the size (in chunks) of that cache here");
|
||||
temp.setLanguageKey("forge.configgui.dormantChunkCacheSize");
|
||||
temp.setMinValue(0);
|
||||
dormantChunkCacheSize = temp.getInt(0);
|
||||
@@ -1002,9 +1048,9 @@ public class ForgeChunkManager
|
||||
"for that mod");
|
||||
|
||||
temp = config.get("Forge", "maximumTicketCount", 200);
|
||||
temp.comment = "Maximum ticket count for the mod. Zero disables chunkloading capabilities.";
|
||||
temp.setComment("Maximum ticket count for the mod. Zero disables chunkloading capabilities.");
|
||||
temp = config.get("Forge", "maximumChunksPerTicket", 25);
|
||||
temp.comment = "Maximum chunks per ticket for the mod.";
|
||||
temp.setComment("Maximum chunks per ticket for the mod.");
|
||||
for (String mod : config.getCategoryNames())
|
||||
{
|
||||
if (mod.equals("Forge") || mod.equals("defaults"))
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import static net.minecraft.init.Blocks.diamond_block;
|
||||
import static net.minecraft.init.Blocks.diamond_ore;
|
||||
import static net.minecraft.init.Blocks.emerald_block;
|
||||
import static net.minecraft.init.Blocks.emerald_ore;
|
||||
import static net.minecraft.init.Blocks.gold_block;
|
||||
import static net.minecraft.init.Blocks.gold_ore;
|
||||
import static net.minecraft.init.Blocks.lit_redstone_ore;
|
||||
import static net.minecraft.init.Blocks.redstone_ore;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
@@ -22,21 +13,22 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.item.EntityMinecartContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.event.ClickEvent;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ContainerRepair;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemAxe;
|
||||
import net.minecraft.item.ItemBucket;
|
||||
@@ -45,32 +37,30 @@ import net.minecraft.item.ItemSpade;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S23PacketBlockChange;
|
||||
import net.minecraft.network.play.server.SPacketBlockChange;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityNote;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
import net.minecraft.world.WorldSettings.GameType;
|
||||
import net.minecraft.world.gen.feature.WorldGeneratorBonusChest;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
@@ -87,16 +77,18 @@ import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
|
||||
import net.minecraftforge.event.entity.player.AnvilRepairEvent;
|
||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerOpenContainerEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.NoteBlockEvent;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class ForgeHooks
|
||||
{
|
||||
//TODO: Loot tables?
|
||||
static class SeedEntry extends WeightedRandom.Item
|
||||
{
|
||||
public final ItemStack seed;
|
||||
@@ -105,17 +97,21 @@ public class ForgeHooks
|
||||
super(weight);
|
||||
this.seed = seed;
|
||||
}
|
||||
public ItemStack getStack(Random rand, int fortune)
|
||||
{
|
||||
return seed.copy();
|
||||
}
|
||||
}
|
||||
static final List<SeedEntry> seedList = new ArrayList<SeedEntry>();
|
||||
|
||||
public static ItemStack getGrassSeed(Random rand)
|
||||
public static ItemStack getGrassSeed(Random rand, int fortune)
|
||||
{
|
||||
SeedEntry entry = (SeedEntry)WeightedRandom.getRandomItem(rand, seedList);
|
||||
SeedEntry entry = WeightedRandom.getRandomItem(rand, seedList);
|
||||
if (entry == null || entry.seed == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return entry.seed.copy();
|
||||
return entry.getStack(rand, fortune);
|
||||
}
|
||||
|
||||
private static boolean toolInit = false;
|
||||
@@ -123,24 +119,24 @@ public class ForgeHooks
|
||||
|
||||
public static boolean canHarvestBlock(Block block, EntityPlayer player, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
if (block.getMaterial().isToolNotRequired())
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
state = state.getBlock().getActualState(state, world, pos);
|
||||
if (state.getMaterial().isToolNotRequired())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack stack = player.inventory.getCurrentItem();
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
state = state.getBlock().getActualState(state, world, pos);
|
||||
String tool = block.getHarvestTool(state);
|
||||
if (stack == null || tool == null)
|
||||
{
|
||||
return player.canHarvestBlock(block);
|
||||
return player.canHarvestBlock(state);
|
||||
}
|
||||
|
||||
int toolLevel = stack.getItem().getHarvestLevel(stack, tool);
|
||||
if (toolLevel < 0)
|
||||
{
|
||||
return player.canHarvestBlock(block);
|
||||
return player.canHarvestBlock(state);
|
||||
}
|
||||
|
||||
return toolLevel >= block.getHarvestLevel(state);
|
||||
@@ -157,7 +153,7 @@ public class ForgeHooks
|
||||
|
||||
public static float blockStrength(IBlockState state, EntityPlayer player, World world, BlockPos pos)
|
||||
{
|
||||
float hardness = state.getBlock().getBlockHardness(world, pos);
|
||||
float hardness = state.getBlockHardness(world, pos);
|
||||
if (hardness < 0.0F)
|
||||
{
|
||||
return 0.0F;
|
||||
@@ -212,7 +208,11 @@ public class ForgeHooks
|
||||
}
|
||||
|
||||
Blocks.obsidian.setHarvestLevel("pickaxe", 3);
|
||||
for (Block block : new Block[]{emerald_ore, emerald_block, diamond_ore, diamond_block, gold_ore, gold_block, redstone_ore, lit_redstone_ore})
|
||||
Block[] oreBlocks = new Block[] {
|
||||
Blocks.emerald_ore, Blocks.emerald_block, Blocks.diamond_ore, Blocks.diamond_block,
|
||||
Blocks.gold_ore, Blocks.gold_block, Blocks.redstone_ore, Blocks.lit_redstone_ore
|
||||
};
|
||||
for (Block block : oreBlocks)
|
||||
{
|
||||
block.setHarvestLevel("pickaxe", 2);
|
||||
}
|
||||
@@ -243,83 +243,83 @@ public class ForgeHooks
|
||||
|
||||
static
|
||||
{
|
||||
seedList.add(new SeedEntry(new ItemStack(Items.wheat_seeds), 10));
|
||||
seedList.add(new SeedEntry(new ItemStack(Items.wheat_seeds), 10)
|
||||
{
|
||||
public ItemStack getStack(Random rand, int fortune)
|
||||
{
|
||||
return new ItemStack(Items.wheat_seeds, 1 + rand.nextInt(fortune * 2 + 1));
|
||||
}
|
||||
});
|
||||
initTools();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player uses 'pick block', calls new Entity and Block hooks.
|
||||
*/
|
||||
public static boolean onPickBlock(MovingObjectPosition target, EntityPlayer player, World world)
|
||||
public static boolean onPickBlock(RayTraceResult target, EntityPlayer player, World world)
|
||||
{
|
||||
/*
|
||||
int i = 0;
|
||||
boolean flag1 = false;
|
||||
TileEntity tileentity = null;
|
||||
Item item;
|
||||
ItemStack itemstack;
|
||||
|
||||
if (this.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
||||
if (this.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = this.objectMouseOver.getBlockPos();
|
||||
Block block = this.theWorld.getBlockState(blockpos).getBlock();
|
||||
IBlockState iblockstate = this.theWorld.getBlockState(blockpos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block.getMaterial() == Material.air)
|
||||
if (iblockstate.getMaterial() == Material.air)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
item = block.getItem(this.theWorld, blockpos);
|
||||
itemstack = block.func_185473_a(this.theWorld, blockpos, iblockstate);
|
||||
|
||||
if (item == null)
|
||||
if (itemstack == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (flag && GuiScreen.isCtrlKeyDown())
|
||||
if (flag && GuiScreen.isCtrlKeyDown() && block.hasTileEntity())
|
||||
{
|
||||
tileentity = this.theWorld.getTileEntity(blockpos);
|
||||
}
|
||||
|
||||
Block block1 = item instanceof ItemBlock && !block.isFlowerPot() ? Block.getBlockFromItem(item) : block;
|
||||
i = block1.getDamageValue(this.theWorld, blockpos);
|
||||
flag1 = item.getHasSubtypes();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.objectMouseOver.typeOfHit != MovingObjectPosition.MovingObjectType.ENTITY || this.objectMouseOver.entityHit == null || !flag)
|
||||
if (this.objectMouseOver.typeOfHit != RayTraceResult.Type.ENTITY || this.objectMouseOver.entityHit == null || !flag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.objectMouseOver.entityHit instanceof EntityPainting)
|
||||
{
|
||||
item = Items.painting;
|
||||
itemstack = new ItemStack(Items.painting);
|
||||
}
|
||||
else if (this.objectMouseOver.entityHit instanceof EntityLeashKnot)
|
||||
{
|
||||
item = Items.lead;
|
||||
itemstack = new ItemStack(Items.lead);
|
||||
}
|
||||
else if (this.objectMouseOver.entityHit instanceof EntityItemFrame)
|
||||
{
|
||||
EntityItemFrame entityitemframe = (EntityItemFrame)this.objectMouseOver.entityHit;
|
||||
ItemStack itemstack = entityitemframe.getDisplayedItem();
|
||||
ItemStack itemstack1 = entityitemframe.getDisplayedItem();
|
||||
|
||||
if (itemstack == null)
|
||||
if (itemstack1 == null)
|
||||
{
|
||||
item = Items.item_frame;
|
||||
itemstack = new ItemStack(Items.item_frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = itemstack.getItem();
|
||||
i = itemstack.getMetadata();
|
||||
flag1 = true;
|
||||
itemstack = ItemStack.copyItemStack(itemstack1);
|
||||
}
|
||||
}
|
||||
else if (this.objectMouseOver.entityHit instanceof EntityMinecart)
|
||||
{
|
||||
EntityMinecart entityminecart = (EntityMinecart)this.objectMouseOver.entityHit;
|
||||
Item item;
|
||||
|
||||
switch (entityminecart.getMinecartType())
|
||||
switch (entityminecart.func_184264_v())
|
||||
{
|
||||
case FURNACE:
|
||||
item = Items.furnace_minecart;
|
||||
@@ -339,61 +339,56 @@ public class ForgeHooks
|
||||
default:
|
||||
item = Items.minecart;
|
||||
}
|
||||
|
||||
itemstack = new ItemStack(item);
|
||||
}
|
||||
else if (this.objectMouseOver.entityHit instanceof EntityBoat)
|
||||
{
|
||||
item = Items.boat;
|
||||
itemstack = new ItemStack(((EntityBoat)this.objectMouseOver.entityHit).func_184455_j());
|
||||
}
|
||||
else if (this.objectMouseOver.entityHit instanceof EntityArmorStand)
|
||||
{
|
||||
item = Items.armor_stand;
|
||||
itemstack = new ItemStack(Items.armor_stand);
|
||||
}
|
||||
else if (this.objectMouseOver.entityHit instanceof EntityEnderCrystal)
|
||||
{
|
||||
itemstack = new ItemStack(Items.field_185158_cP);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = Items.spawn_egg;
|
||||
i = EntityList.getEntityID(this.objectMouseOver.entityHit);
|
||||
flag1 = true;
|
||||
String s = EntityList.getEntityString(this.objectMouseOver.entityHit);
|
||||
|
||||
if (!EntityList.entityEggs.containsKey(Integer.valueOf(i)))
|
||||
if (!EntityList.entityEggs.containsKey(s))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
itemstack = new ItemStack(Items.spawn_egg);
|
||||
ItemMonsterPlacer.func_185078_a(itemstack, s);
|
||||
}
|
||||
}
|
||||
|
||||
InventoryPlayer inventoryplayer = this.thePlayer.inventory;
|
||||
|
||||
if (tileentity == null)
|
||||
{
|
||||
inventoryplayer.setCurrentItem(item, i, flag1, flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack1 = this.func_181036_a(item, i, tileentity);
|
||||
inventoryplayer.setInventorySlotContents(inventoryplayer.currentItem, itemstack1);
|
||||
}
|
||||
*/
|
||||
ItemStack result = null;
|
||||
boolean isCreative = player.capabilities.isCreativeMode;
|
||||
TileEntity te = null;
|
||||
|
||||
if (target.typeOfHit == MovingObjectType.BLOCK)
|
||||
if (target.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
IBlockState state = world.getBlockState(target.getBlockPos());
|
||||
|
||||
if (state.getBlock().isAir(world, target.getBlockPos()))
|
||||
if (state.getBlock().isAir(state, world, target.getBlockPos()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isCreative && GuiScreen.isCtrlKeyDown())
|
||||
if (isCreative && GuiScreen.isCtrlKeyDown() && state.getBlock().hasTileEntity(state))
|
||||
te = world.getTileEntity(target.getBlockPos());
|
||||
|
||||
result = state.getBlock().getPickBlock(target, world, target.getBlockPos(), player);
|
||||
result = state.getBlock().getPickBlock(state, target, world, target.getBlockPos(), player);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target.typeOfHit != MovingObjectType.ENTITY || target.entityHit == null || !isCreative)
|
||||
if (target.typeOfHit != RayTraceResult.Type.ENTITY || target.entityHit == null || !isCreative)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -406,48 +401,48 @@ public class ForgeHooks
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result.getItem() == null)
|
||||
{
|
||||
String s1 = "";
|
||||
|
||||
if (target.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
s1 = Block.blockRegistry.getNameForObject(world.getBlockState(target.getBlockPos()).getBlock()).toString();
|
||||
}
|
||||
else if (target.typeOfHit == RayTraceResult.Type.ENTITY)
|
||||
{
|
||||
s1 = EntityList.getEntityString(target.entityHit);
|
||||
}
|
||||
|
||||
FMLLog.warning("Picking on: [%s] %s gave null item", target.typeOfHit, s1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (te != null)
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
te.writeToNBT(nbt);
|
||||
result.setTagInfo("BlockEntityTag", nbt);
|
||||
|
||||
NBTTagCompound display = new NBTTagCompound();
|
||||
result.setTagInfo("display", display);
|
||||
|
||||
NBTTagList lore = new NBTTagList();
|
||||
display.setTag("Lore", lore);
|
||||
lore.appendTag(new NBTTagString("(+NBT)"));
|
||||
Minecraft.getMinecraft().storeTEInStack(result, te);
|
||||
}
|
||||
|
||||
for (int x = 0; x < 9; x++)
|
||||
if (isCreative)
|
||||
{
|
||||
ItemStack stack = player.inventory.getStackInSlot(x);
|
||||
if (stack != null && stack.isItemEqual(result) && ItemStack.areItemStackTagsEqual(stack, result))
|
||||
{
|
||||
player.inventory.currentItem = x;
|
||||
return true;
|
||||
}
|
||||
player.inventory.func_184434_a(result);
|
||||
Minecraft.getMinecraft().playerController.sendSlotPacket(player.getHeldItem(EnumHand.MAIN_HAND), 36 + player.inventory.currentItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isCreative)
|
||||
int slot = player.inventory.getSlotFor(result);
|
||||
if (slot != -1)
|
||||
{
|
||||
return false;
|
||||
if (InventoryPlayer.isHotbar(slot))
|
||||
player.inventory.currentItem = slot;
|
||||
else
|
||||
Minecraft.getMinecraft().playerController.pickItem(slot);
|
||||
return true;
|
||||
}
|
||||
|
||||
int slot = player.inventory.getFirstEmptyStack();
|
||||
if (slot < 0 || slot >= 9)
|
||||
{
|
||||
slot = player.inventory.currentItem;
|
||||
}
|
||||
|
||||
player.inventory.setInventorySlotContents(slot, result);
|
||||
player.inventory.currentItem = slot;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//Optifine Helper Functions u.u, these are here specifically for Optifine
|
||||
//Note: When using Optfine, these methods are invoked using reflection, which
|
||||
//Note: When using Optifine, these methods are invoked using reflection, which
|
||||
//incurs a major performance penalty.
|
||||
public static void onLivingSetAttackTarget(EntityLivingBase entity, EntityLivingBase target)
|
||||
{
|
||||
@@ -467,7 +462,7 @@ public class ForgeHooks
|
||||
public static float onLivingHurt(EntityLivingBase entity, DamageSource src, float amount)
|
||||
{
|
||||
LivingHurtEvent event = new LivingHurtEvent(entity, src, amount);
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? 0 : event.ammount);
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? 0 : event.getAmount());
|
||||
}
|
||||
|
||||
public static boolean onLivingDeath(EntityLivingBase entity, DamageSource src)
|
||||
@@ -483,16 +478,16 @@ public class ForgeHooks
|
||||
public static float[] onLivingFall(EntityLivingBase entity, float distance, float damageMultiplier)
|
||||
{
|
||||
LivingFallEvent event = new LivingFallEvent(entity, distance, damageMultiplier);
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? null : new float[]{event.distance, event.damageMultiplier});
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? null : new float[]{event.getDistance(), event.getDamageMultiplier()});
|
||||
}
|
||||
|
||||
public static boolean isLivingOnLadder(Block block, World world, BlockPos pos, EntityLivingBase entity)
|
||||
public static boolean isLivingOnLadder(IBlockState state, World world, BlockPos pos, EntityLivingBase entity)
|
||||
{
|
||||
boolean isSpectator = (entity instanceof EntityPlayer && ((EntityPlayer)entity).isSpectator());
|
||||
if (isSpectator) return false;
|
||||
if (!ForgeModContainer.fullBoundingBoxLadders)
|
||||
{
|
||||
return block != null && block.isLadder(world, pos, entity);
|
||||
return state != null && state.getBlock().isLadder(state, world, pos, entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -507,7 +502,8 @@ public class ForgeHooks
|
||||
for (int z2 = mZ; z2 < bb.maxZ; z2++)
|
||||
{
|
||||
BlockPos tmp = new BlockPos(x2, y2, z2);
|
||||
if (world.getBlockState(tmp).getBlock().isLadder(world, tmp, entity))
|
||||
state = world.getBlockState(tmp);
|
||||
if (state.getBlock().isLadder(state, world, tmp, entity))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -541,8 +537,11 @@ public class ForgeHooks
|
||||
return null;
|
||||
}
|
||||
|
||||
player.joinEntityItemWithWorld(event.entityItem);
|
||||
return event.entityItem;
|
||||
if (!player.worldObj.isRemote)
|
||||
{
|
||||
player.getEntityWorld().spawnEntityInWorld(event.getEntityItem());
|
||||
}
|
||||
return event.getEntityItem();
|
||||
}
|
||||
|
||||
public static float getEnchantPower(World world, BlockPos pos)
|
||||
@@ -550,15 +549,14 @@ public class ForgeHooks
|
||||
return world.getBlockState(pos).getBlock().getEnchantPowerBonus(world, pos);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ChatComponentTranslation onServerChatEvent(NetHandlerPlayServer net, String raw, ChatComponentTranslation comp)
|
||||
public static ITextComponent onServerChatEvent(NetHandlerPlayServer net, String raw, ITextComponent comp)
|
||||
{
|
||||
ServerChatEvent event = new ServerChatEvent(net.playerEntity, raw, comp);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return event.component;
|
||||
return event.getComponent();
|
||||
}
|
||||
|
||||
|
||||
@@ -568,13 +566,13 @@ public class ForgeHooks
|
||||
"((?:[a-z0-9]{2,}:\\/\\/)?(?:(?:[0-9]{1,3}\\.){3}[0-9]{1,3}|(?:[-\\w_\\.]{1,}\\.[a-z]{2,}?))(?::[0-9]{1,5})?.*?(?=[!\"\u00A7 \n]|$))",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public static IChatComponent newChatWithLinks(String string){ return newChatWithLinks(string, true); }
|
||||
public static IChatComponent newChatWithLinks(String string, boolean allowMissingHeader)
|
||||
public static ITextComponent newChatWithLinks(String string){ return newChatWithLinks(string, true); }
|
||||
public static ITextComponent newChatWithLinks(String string, boolean allowMissingHeader)
|
||||
{
|
||||
// Includes ipv4 and domain pattern
|
||||
// Matches an ip (xx.xxx.xx.xxx) or a domain (something.com) with or
|
||||
// without a protocol or path.
|
||||
IChatComponent ichat = null;
|
||||
ITextComponent ichat = null;
|
||||
Matcher matcher = URL_PATTERN.matcher(string);
|
||||
int lastEnd = 0;
|
||||
|
||||
@@ -589,13 +587,13 @@ public class ForgeHooks
|
||||
if (part.length() > 0)
|
||||
{
|
||||
if (ichat == null)
|
||||
ichat = new ChatComponentText(part);
|
||||
ichat = new TextComponentString(part);
|
||||
else
|
||||
ichat.appendText(part);
|
||||
}
|
||||
lastEnd = end;
|
||||
String url = string.substring(start, end);
|
||||
IChatComponent link = new ChatComponentText(url);
|
||||
ITextComponent link = new TextComponentString(url);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -605,7 +603,7 @@ public class ForgeHooks
|
||||
if (!allowMissingHeader)
|
||||
{
|
||||
if (ichat == null)
|
||||
ichat = new ChatComponentText(url);
|
||||
ichat = new TextComponentString(url);
|
||||
else
|
||||
ichat.appendText(url);
|
||||
continue;
|
||||
@@ -616,7 +614,7 @@ public class ForgeHooks
|
||||
catch (URISyntaxException e)
|
||||
{
|
||||
// Bad syntax bail out!
|
||||
if (ichat == null) ichat = new ChatComponentText(url);
|
||||
if (ichat == null) ichat = new TextComponentString(url);
|
||||
else ichat.appendText(url);
|
||||
continue;
|
||||
}
|
||||
@@ -625,7 +623,7 @@ public class ForgeHooks
|
||||
ClickEvent click = new ClickEvent(ClickEvent.Action.OPEN_URL, url);
|
||||
link.getChatStyle().setChatClickEvent(click);
|
||||
link.getChatStyle().setUnderlined(true);
|
||||
link.getChatStyle().setColor(EnumChatFormatting.BLUE);
|
||||
link.getChatStyle().setColor(TextFormatting.BLUE);
|
||||
if (ichat == null)
|
||||
ichat = link;
|
||||
else
|
||||
@@ -635,7 +633,7 @@ public class ForgeHooks
|
||||
// Append the rest of the message.
|
||||
String end = string.substring(lastEnd);
|
||||
if (ichat == null)
|
||||
ichat = new ChatComponentText(end);
|
||||
ichat = new TextComponentString(end);
|
||||
else if (end.length() > 0)
|
||||
ichat.appendText(string.substring(lastEnd));
|
||||
return ichat;
|
||||
@@ -645,14 +643,14 @@ public class ForgeHooks
|
||||
{
|
||||
PlayerOpenContainerEvent event = new PlayerOpenContainerEvent(player, openContainer);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult() == Event.Result.DEFAULT ? event.canInteractWith : event.getResult() == Event.Result.ALLOW ? true : false;
|
||||
return event.getResult() == Event.Result.DEFAULT ? event.isCanInteractWith() : event.getResult() == Event.Result.ALLOW ? true : false;
|
||||
}
|
||||
|
||||
public static int onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, BlockPos pos)
|
||||
{
|
||||
// Logic from tryHarvestBlock for pre-canceling the event
|
||||
boolean preCancelEvent = false;
|
||||
if (gameType.isCreative() && entityPlayer.getHeldItem() != null && entityPlayer.getHeldItem().getItem() instanceof ItemSword)
|
||||
if (gameType.isCreative() && entityPlayer.getHeldItemMainhand() != null && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
|
||||
preCancelEvent = true;
|
||||
|
||||
if (gameType.isAdventure())
|
||||
@@ -662,7 +660,7 @@ public class ForgeHooks
|
||||
|
||||
if (!entityPlayer.isAllowEdit())
|
||||
{
|
||||
ItemStack itemstack = entityPlayer.getCurrentEquippedItem();
|
||||
ItemStack itemstack = entityPlayer.getHeldItemMainhand();
|
||||
if (itemstack == null || !itemstack.canDestroy(world.getBlockState(pos).getBlock()))
|
||||
preCancelEvent = true;
|
||||
}
|
||||
@@ -671,7 +669,7 @@ public class ForgeHooks
|
||||
// Tell client the block is gone immediately then process events
|
||||
if (world.getTileEntity(pos) == null)
|
||||
{
|
||||
S23PacketBlockChange packet = new S23PacketBlockChange(world, pos);
|
||||
SPacketBlockChange packet = new SPacketBlockChange(world, pos);
|
||||
packet.blockState = Blocks.air.getDefaultState();
|
||||
entityPlayer.playerNetServerHandler.sendPacket(packet);
|
||||
}
|
||||
@@ -686,7 +684,7 @@ public class ForgeHooks
|
||||
if (event.isCanceled())
|
||||
{
|
||||
// Let the client know the block still exists
|
||||
entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(world, pos));
|
||||
entityPlayer.playerNetServerHandler.sendPacket(new SPacketBlockChange(world, pos));
|
||||
|
||||
// Update any tile entity data for this block
|
||||
TileEntity tileentity = world.getTileEntity(pos);
|
||||
@@ -702,7 +700,7 @@ public class ForgeHooks
|
||||
return event.isCanceled() ? -1 : event.getExpToDrop();
|
||||
}
|
||||
|
||||
public static boolean onPlaceItemIntoWorld(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||
public static EnumActionResult onPlaceItemIntoWorld(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
|
||||
{
|
||||
// handle all placement events here
|
||||
int meta = itemstack.getItemDamage();
|
||||
@@ -718,10 +716,10 @@ public class ForgeHooks
|
||||
world.captureBlockSnapshots = true;
|
||||
}
|
||||
|
||||
boolean flag = itemstack.getItem().onItemUse(itemstack, player, world, pos, side, hitX, hitY, hitZ);
|
||||
EnumActionResult ret = itemstack.getItem().onItemUse(itemstack, player, world, pos, hand, side, hitX, hitY, hitZ);
|
||||
world.captureBlockSnapshots = false;
|
||||
|
||||
if (flag)
|
||||
if (ret == EnumActionResult.SUCCESS)
|
||||
{
|
||||
// save new item data
|
||||
int newMeta = itemstack.getItemDamage();
|
||||
@@ -754,7 +752,7 @@ public class ForgeHooks
|
||||
|
||||
if (placeEvent != null && (placeEvent.isCanceled()))
|
||||
{
|
||||
flag = false; // cancel placement
|
||||
ret = EnumActionResult.FAIL; // cancel placement
|
||||
// revert back all captured blocks
|
||||
for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots)
|
||||
{
|
||||
@@ -775,33 +773,33 @@ public class ForgeHooks
|
||||
|
||||
for (BlockSnapshot snap : blockSnapshots)
|
||||
{
|
||||
int updateFlag = snap.flag;
|
||||
IBlockState oldBlock = snap.replacedBlock;
|
||||
IBlockState newBlock = world.getBlockState(snap.pos);
|
||||
int updateFlag = snap.getFlag();
|
||||
IBlockState oldBlock = snap.getReplacedBlock();
|
||||
IBlockState newBlock = world.getBlockState(snap.getPos());
|
||||
if (newBlock != null && !(newBlock.getBlock().hasTileEntity(newBlock))) // Containers get placed automatically
|
||||
{
|
||||
newBlock.getBlock().onBlockAdded(world, snap.pos, newBlock);
|
||||
newBlock.getBlock().onBlockAdded(world, snap.getPos(), newBlock);
|
||||
}
|
||||
|
||||
world.markAndNotifyBlock(snap.pos, null, oldBlock, newBlock, updateFlag);
|
||||
world.markAndNotifyBlock(snap.getPos(), null, oldBlock, newBlock, updateFlag);
|
||||
}
|
||||
player.addStat(StatList.objectUseStats[Item.getIdFromItem(itemstack.getItem())], 1);
|
||||
player.addStat(StatList.func_188060_a(itemstack.getItem()));
|
||||
}
|
||||
}
|
||||
world.capturedBlockSnapshots.clear();
|
||||
|
||||
return flag;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static boolean onAnvilChange(ContainerRepair container, ItemStack left, ItemStack right, IInventory outputSlot, String name, int baseCost)
|
||||
{
|
||||
AnvilUpdateEvent e = new AnvilUpdateEvent(left, right, name, baseCost);
|
||||
if (MinecraftForge.EVENT_BUS.post(e)) return false;
|
||||
if (e.output == null) return true;
|
||||
if (e.getOutput() == null) return true;
|
||||
|
||||
outputSlot.setInventorySlotContents(0, e.output);
|
||||
container.maximumCost = e.cost;
|
||||
container.materialCost = e.materialCost;
|
||||
outputSlot.setInventorySlotContents(0, e.getOutput());
|
||||
container.maximumCost = e.getCost();
|
||||
container.materialCost = e.getMaterialCost();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -809,7 +807,7 @@ public class ForgeHooks
|
||||
{
|
||||
AnvilRepairEvent e = new AnvilRepairEvent(player, left, right, output);
|
||||
MinecraftForge.EVENT_BUS.post(e);
|
||||
return e.breakChance;
|
||||
return e.getBreakChance();
|
||||
}
|
||||
|
||||
public static boolean onNoteChange(TileEntityNote te, byte old)
|
||||
@@ -861,7 +859,7 @@ public class ForgeHooks
|
||||
stack = stack.getItem().getContainerItem(stack);
|
||||
if (stack != null && stack.isItemStackDamageable() && stack.getMetadata() > stack.getMaxDamage())
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(craftingPlayer.get(), stack));
|
||||
ForgeEventFactory.onPlayerDestroyItem(craftingPlayer.get(), stack, null);
|
||||
return null;
|
||||
}
|
||||
return stack;
|
||||
@@ -869,11 +867,6 @@ public class ForgeHooks
|
||||
return null;
|
||||
}
|
||||
|
||||
public static WorldGeneratorBonusChest getBonusChest(Random rand)
|
||||
{
|
||||
return new WorldGeneratorBonusChest(ChestGenHooks.getItems(ChestGenHooks.BONUS_CHEST, rand), ChestGenHooks.getCount(ChestGenHooks.BONUS_CHEST, rand));
|
||||
}
|
||||
|
||||
public static boolean isInsideOfMaterial(Material material, Entity entity, BlockPos pos)
|
||||
{
|
||||
IBlockState state = entity.worldObj.getBlockState(pos);
|
||||
@@ -894,18 +887,18 @@ public class ForgeHooks
|
||||
{
|
||||
filled *= -1;
|
||||
//filled -= 0.11111111F; //Why this is needed.. not sure...
|
||||
return eyes > (double)(pos.getY() + 1 + (1 - filled));
|
||||
return eyes > pos.getY() + 1 + (1 - filled);
|
||||
}
|
||||
else
|
||||
{
|
||||
return eyes < (double)(pos.getY() + 1 + filled);
|
||||
return eyes < pos.getY() + 1 + filled;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean onPlayerAttackTarget(EntityPlayer player, Entity target)
|
||||
{
|
||||
if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, target))) return false;
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
ItemStack stack = player.getHeldItemMainhand();
|
||||
if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return false;
|
||||
return true;
|
||||
}
|
||||
@@ -925,16 +918,56 @@ public class ForgeHooks
|
||||
return !event.isCanceled();
|
||||
}
|
||||
|
||||
public static MovingObjectPosition rayTraceEyes(EntityLivingBase entity, double length)
|
||||
public static RayTraceResult rayTraceEyes(EntityLivingBase entity, double length)
|
||||
{
|
||||
Vec3 startPos = new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
|
||||
Vec3 endPos = startPos.add(new Vec3(entity.getLookVec().xCoord * length, entity.getLookVec().yCoord * length, entity.getLookVec().zCoord * length));
|
||||
Vec3d startPos = new Vec3d(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
|
||||
Vec3d endPos = startPos.add(new Vec3d(entity.getLookVec().xCoord * length, entity.getLookVec().yCoord * length, entity.getLookVec().zCoord * length));
|
||||
return entity.worldObj.rayTraceBlocks(startPos, endPos);
|
||||
}
|
||||
|
||||
public static Vec3 rayTraceEyeHitVec(EntityLivingBase entity, double length)
|
||||
public static Vec3d rayTraceEyeHitVec(EntityLivingBase entity, double length)
|
||||
{
|
||||
MovingObjectPosition movingObjectPosition = rayTraceEyes(entity, length);
|
||||
return movingObjectPosition == null ? null : movingObjectPosition.hitVec;
|
||||
RayTraceResult git = rayTraceEyes(entity, length);
|
||||
return git == null ? null : git.hitVec;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean onInteractEntityAt(EntityPlayer player, Entity entity, RayTraceResult ray, ItemStack stack, EnumHand hand)
|
||||
{
|
||||
Vec3d vec3d = new Vec3d(ray.hitVec.xCoord - entity.posX, ray.hitVec.yCoord - entity.posY, ray.hitVec.zCoord - entity.posZ);
|
||||
return onInteractEntityAt(player, entity, vec3d, stack, hand);
|
||||
}
|
||||
|
||||
public static boolean onInteractEntityAt(EntityPlayer player, Entity entity, Vec3d vec3d, ItemStack stack, EnumHand hand)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.EntityInteractSpecific(player, hand, stack, entity, vec3d));
|
||||
}
|
||||
|
||||
public static boolean onInteractEntity(EntityPlayer player, Entity entity, ItemStack item, EnumHand hand)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.EntityInteract(player, hand, item, entity));
|
||||
}
|
||||
|
||||
public static boolean onItemRightClick(EntityPlayer player, EnumHand hand, ItemStack stack)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickItem(player, hand, stack));
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent.LeftClickBlock onLeftClickBlock(EntityPlayer player, BlockPos pos, EnumFacing face, Vec3d hitVec)
|
||||
{
|
||||
PlayerInteractEvent.LeftClickBlock evt = new PlayerInteractEvent.LeftClickBlock(player, pos, face, hitVec);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt;
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent.RightClickBlock onRightClickBlock(EntityPlayer player, EnumHand hand, ItemStack stack, BlockPos pos, EnumFacing face, Vec3d hitVec)
|
||||
{
|
||||
PlayerInteractEvent.RightClickBlock evt = new PlayerInteractEvent.RightClickBlock(player, hand, stack, pos, face, hitVec);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt;
|
||||
}
|
||||
|
||||
public static void onEmptyClick(EntityPlayer player, EnumHand hand)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickEmpty(player, hand));
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.event.entity.*;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class ForgeInternalHandler
|
||||
{
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onEntityJoinWorld(EntityJoinWorldEvent event)
|
||||
{
|
||||
if (!event.world.isRemote)
|
||||
if (!event.getWorld().isRemote)
|
||||
{
|
||||
ForgeChunkManager.loadEntity(event.entity);
|
||||
ForgeChunkManager.loadEntity(event.getEntity());
|
||||
}
|
||||
|
||||
Entity entity = event.entity;
|
||||
Entity entity = event.getEntity();
|
||||
if (entity.getClass().equals(EntityItem.class))
|
||||
{
|
||||
ItemStack stack = entity.getDataWatcher().getWatchableObjectItemStack(10);
|
||||
ItemStack stack = ((EntityItem)entity).getEntityItem();
|
||||
|
||||
if (stack == null)
|
||||
{
|
||||
@@ -47,12 +47,12 @@ public class ForgeInternalHandler
|
||||
|
||||
if (item.hasCustomEntity(stack))
|
||||
{
|
||||
Entity newEntity = item.createEntity(event.world, entity, stack);
|
||||
Entity newEntity = item.createEntity(event.getWorld(), entity, stack);
|
||||
if (newEntity != null)
|
||||
{
|
||||
entity.setDead();
|
||||
event.setCanceled(true);
|
||||
event.world.spawnEntityInWorld(newEntity);
|
||||
event.getWorld().spawnEntityInWorld(newEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,20 +61,20 @@ public class ForgeInternalHandler
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onDimensionLoad(WorldEvent.Load event)
|
||||
{
|
||||
ForgeChunkManager.loadWorld(event.world);
|
||||
ForgeChunkManager.loadWorld(event.getWorld());
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onDimensionSave(WorldEvent.Save event)
|
||||
{
|
||||
ForgeChunkManager.saveWorld(event.world);
|
||||
ForgeChunkManager.saveWorld(event.getWorld());
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onDimensionUnload(WorldEvent.Unload event)
|
||||
{
|
||||
ForgeChunkManager.unloadWorld(event.world);
|
||||
if (event.world instanceof WorldServer)
|
||||
FakePlayerFactory.unloadWorld((WorldServer)event.world);
|
||||
ForgeChunkManager.unloadWorld(event.getWorld());
|
||||
if (event.getWorld() instanceof WorldServer)
|
||||
FakePlayerFactory.unloadWorld((WorldServer) event.getWorld());
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.net.URL;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -24,6 +25,7 @@ import net.minecraft.world.storage.WorldInfo;
|
||||
import net.minecraftforge.classloading.FMLForgePlugin;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.common.model.animation.CapabilityAnimation;
|
||||
import net.minecraftforge.common.network.ForgeNetworkHandler;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
@@ -73,6 +75,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
public static boolean defaultHasSpawnFuzz = true;
|
||||
public static boolean forgeLightPipelineEnabled = true;
|
||||
public static boolean replaceVanillaBucketModel = true;
|
||||
public static long java8Reminder = 0;
|
||||
|
||||
private static Configuration config;
|
||||
private static ForgeModContainer INSTANCE;
|
||||
@@ -148,7 +151,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
Property prop;
|
||||
|
||||
prop = config.get(CATEGORY_GENERAL, "disableVersionCheck", false);
|
||||
prop.comment = "Set to true to disable Forge's version check mechanics. Forge queries a small json file on our server for version information. For more details see the ForgeVersion class in our github.";
|
||||
prop.setComment("Set to true to disable Forge's version check mechanics. Forge queries a small json file on our server for version information. For more details see the ForgeVersion class in our github.");
|
||||
// Language keys are a good idea to implement if you are using config GUIs. This allows you to use a .lang file that will hold the
|
||||
// "pretty" version of the property name as well as allow others to provide their own localizations.
|
||||
// This language key is also used to get the tooltip for a property. The tooltip language key is langKey + ".tooltip".
|
||||
@@ -169,13 +172,13 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
propOrder.add(prop.getName());
|
||||
|
||||
prop = config.get(CATEGORY_GENERAL, "sortRecipies", true);
|
||||
prop.comment = "Set to true to enable the post initialization sorting of crafting recipes using Forge's sorter. May cause desyncing on conflicting recipies. MUST RESTART MINECRAFT IF CHANGED FROM THE CONFIG GUI.";
|
||||
prop.setComment("Set to true to enable the post initialization sorting of crafting recipes using Forge's sorter. May cause desyncing on conflicting recipes. MUST RESTART MINECRAFT IF CHANGED FROM THE CONFIG GUI.");
|
||||
prop.setLanguageKey("forge.configgui.sortRecipies").setRequiresMcRestart(true);
|
||||
shouldSortRecipies = prop.getBoolean(shouldSortRecipies);
|
||||
propOrder.add(prop.getName());
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_GENERAL, "removeErroringEntities", false);
|
||||
prop.comment = "Set this to true to remove any Entity that throws an error in its update method instead of closing the server and reporting a crash log. BE WARNED THIS COULD SCREW UP EVERYTHING USE SPARINGLY WE ARE NOT RESPONSIBLE FOR DAMAGES.";
|
||||
prop.setComment("Set this to true to remove any Entity that throws an error in its update method instead of closing the server and reporting a crash log. BE WARNED THIS COULD SCREW UP EVERYTHING USE SPARINGLY WE ARE NOT RESPONSIBLE FOR DAMAGES.");
|
||||
prop.setLanguageKey("forge.configgui.removeErroringEntities").setRequiresWorldRestart(true);
|
||||
removeErroringEntities = prop.getBoolean(false);
|
||||
propOrder.add(prop.getName());
|
||||
@@ -186,7 +189,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
}
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_GENERAL, "removeErroringTileEntities", false);
|
||||
prop.comment = "Set this to true to remove any TileEntity that throws an error in its update method instead of closing the server and reporting a crash log. BE WARNED THIS COULD SCREW UP EVERYTHING USE SPARINGLY WE ARE NOT RESPONSIBLE FOR DAMAGES.";
|
||||
prop.setComment("Set this to true to remove any TileEntity that throws an error in its update method instead of closing the server and reporting a crash log. BE WARNED THIS COULD SCREW UP EVERYTHING USE SPARINGLY WE ARE NOT RESPONSIBLE FOR DAMAGES.");
|
||||
prop.setLanguageKey("forge.configgui.removeErroringTileEntities").setRequiresWorldRestart(true);
|
||||
removeErroringTileEntities = prop.getBoolean(false);
|
||||
propOrder.add(prop.getName());
|
||||
@@ -197,17 +200,17 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
}
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_GENERAL, "disableStitchedFileSaving", true);
|
||||
prop.comment = "Set this to just disable the texture stitcher from writing the '{name}_{mipmap}.png files to disc. Just a small performance tweak. Default: true";
|
||||
prop.setComment("Set this to just disable the texture stitcher from writing the '{name}_{mipmap}.png files to disc. Just a small performance tweak. Default: true");
|
||||
disableStitchedFileSaving = prop.getBoolean(true);
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_GENERAL, "fullBoundingBoxLadders", false);
|
||||
prop.comment = "Set this to true to check the entire entity's collision bounding box for ladders instead of just the block they are in. Causes noticable differences in mechanics so default is vanilla behavior. Default: false";
|
||||
prop.setComment("Set this to true to check the entire entity's collision bounding box for ladders instead of just the block they are in. Causes noticeable differences in mechanics so default is vanilla behavior. Default: false");
|
||||
prop.setLanguageKey("forge.configgui.fullBoundingBoxLadders").setRequiresWorldRestart(true);
|
||||
fullBoundingBoxLadders = prop.getBoolean(false);
|
||||
propOrder.add(prop.getName());
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_GENERAL, "biomeSkyBlendRange", new int[] { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34 });
|
||||
prop.comment = "Control the range of sky blending for colored skies in biomes.";
|
||||
prop.setComment("Control the range of sky blending for colored skies in biomes.");
|
||||
prop.setLanguageKey("forge.configgui.biomeSkyBlendRange");
|
||||
blendRanges = prop.getIntList();
|
||||
propOrder.add(prop.getName());
|
||||
@@ -225,7 +228,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
propOrder.add(prop.getName());
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_GENERAL, "defaultSpawnFuzz", 20,
|
||||
"The spawn fuzz when a player respawns in the world, this is controlable by WorldType, this config option is for the default overworld.",
|
||||
"The spawn fuzz when a player respawns in the world, this is controllable by WorldType, this config option is for the default overworld.",
|
||||
1, Integer.MAX_VALUE);
|
||||
prop.setLanguageKey("forge.configgui.spawnfuzz").setRequiresWorldRestart(false);
|
||||
defaultSpawnFuzz = prop.getInt(20);
|
||||
@@ -258,6 +261,11 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
replaceVanillaBucketModel = prop.getBoolean(Boolean.FALSE);
|
||||
propOrder.add(prop.getName());
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_CLIENT, "java8Reminder", java8Reminder,
|
||||
"The timestamp of the last reminder to update to Java 8 in number of milliseconds since January 1, 1970, 00:00:00 GMT. Nag will show only once every 24 hours. To disable it set this to some really high number.");
|
||||
java8Reminder = prop.getLong(java8Reminder);
|
||||
propOrder.add(prop.getName());
|
||||
|
||||
config.setCategoryPropertyOrder(CATEGORY_CLIENT, propOrder);
|
||||
|
||||
if (config.hasChanged())
|
||||
@@ -266,6 +274,13 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateNag()
|
||||
{
|
||||
Property prop = config.get(Configuration.CATEGORY_CLIENT, "java8Reminder", java8Reminder);
|
||||
prop.set((new Date()).getTime());
|
||||
config.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* By subscribing to the OnConfigChangedEvent we are able to execute code when our config screens are closed.
|
||||
* This implementation uses the optional configID string to handle multiple Configurations using one event handler.
|
||||
@@ -273,18 +288,18 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
@SubscribeEvent
|
||||
public void onConfigChanged(OnConfigChangedEvent event)
|
||||
{
|
||||
if (getMetadata().modId.equals(event.modID) && !event.isWorldRunning)
|
||||
if (getMetadata().modId.equals(event.getModID()) && !event.isWorldRunning())
|
||||
{
|
||||
if (Configuration.CATEGORY_GENERAL.equals(event.configID))
|
||||
if (Configuration.CATEGORY_GENERAL.equals(event.getConfigID()))
|
||||
{
|
||||
syncConfig(false);
|
||||
}
|
||||
else if ("chunkLoader".equals(event.configID))
|
||||
else if ("chunkLoader".equals(event.getConfigID()))
|
||||
{
|
||||
ForgeChunkManager.syncConfigDefaults();
|
||||
ForgeChunkManager.loadConfiguration();
|
||||
}
|
||||
else if (VERSION_CHECK_CAT.equals(event.configID))
|
||||
else if (VERSION_CHECK_CAT.equals(event.getConfigID()))
|
||||
{
|
||||
syncConfig(false);
|
||||
}
|
||||
@@ -315,6 +330,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
public void preInit(FMLPreInitializationEvent evt)
|
||||
{
|
||||
CapabilityItemHandler.register();
|
||||
CapabilityAnimation.register();
|
||||
MinecraftForge.EVENT_BUS.register(MinecraftForge.INTERNAL_HANDLER);
|
||||
ForgeChunkManager.captureConfig(evt.getModConfigurationDirectory());
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
@@ -354,7 +370,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
@Subscribe
|
||||
public void serverStarting(FMLServerStartingEvent evt)
|
||||
{
|
||||
evt.registerServerCommand(new ForgeCommand(evt.getServer()));
|
||||
evt.registerServerCommand(new ForgeCommand());
|
||||
}
|
||||
@Override
|
||||
public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info)
|
||||
|
||||
@@ -31,17 +31,17 @@ import net.minecraftforge.fml.common.versioning.ComparableVersion;
|
||||
public class ForgeVersion
|
||||
{
|
||||
//This number is incremented every time we remove deprecated code/major API changes, never reset
|
||||
public static final int majorVersion = 11;
|
||||
public static final int majorVersion = 12;
|
||||
//This number is incremented every minecraft release, never reset
|
||||
public static final int minorVersion = 15;
|
||||
public static final int minorVersion = 16;
|
||||
//This number is incremented every time a interface changes or new major feature is added, and reset every Minecraft version
|
||||
public static final int revisionVersion = 1;
|
||||
public static final int revisionVersion = 0;
|
||||
//This number is incremented every time Jenkins builds Forge, and never reset. Should always be 0 in the repo code.
|
||||
public static final int buildVersion = 0;
|
||||
// This is the minecraft version we're building for - used in various places in Forge/FML code
|
||||
public static final String mcVersion = "1.8.9";
|
||||
public static final String mcVersion = "1.9";
|
||||
// This is the MCP data version we're using
|
||||
public static final String mcpVersion = "9.19";
|
||||
public static final String mcpVersion = "9.23";
|
||||
@SuppressWarnings("unused")
|
||||
private static Status status = PENDING;
|
||||
@SuppressWarnings("unused")
|
||||
@@ -85,13 +85,54 @@ public class ForgeVersion
|
||||
|
||||
public static enum Status
|
||||
{
|
||||
PENDING,
|
||||
FAILED,
|
||||
UP_TO_DATE,
|
||||
OUTDATED,
|
||||
AHEAD,
|
||||
BETA,
|
||||
BETA_OUTDATED
|
||||
PENDING(),
|
||||
FAILED(),
|
||||
UP_TO_DATE(),
|
||||
OUTDATED(3, true),
|
||||
AHEAD(),
|
||||
BETA(),
|
||||
BETA_OUTDATED(6, true);
|
||||
|
||||
final int sheetOffset;
|
||||
final boolean draw, animated;
|
||||
|
||||
Status()
|
||||
{
|
||||
this(0, false, false);
|
||||
}
|
||||
|
||||
Status(int sheetOffset)
|
||||
{
|
||||
this(sheetOffset, true, false);
|
||||
}
|
||||
|
||||
Status(int sheetOffset, boolean animated)
|
||||
{
|
||||
this(sheetOffset, true, animated);
|
||||
}
|
||||
|
||||
Status(int sheetOffset, boolean draw, boolean animated)
|
||||
{
|
||||
this.sheetOffset = sheetOffset;
|
||||
this.draw = draw;
|
||||
this.animated = animated;
|
||||
}
|
||||
|
||||
public int getSheetOffset()
|
||||
{
|
||||
return sheetOffset;
|
||||
}
|
||||
|
||||
public boolean shouldDraw()
|
||||
{
|
||||
return draw;
|
||||
}
|
||||
|
||||
public boolean isAnimated()
|
||||
{
|
||||
return animated;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class CheckResult
|
||||
@@ -119,7 +160,7 @@ public class ForgeVersion
|
||||
{
|
||||
if (!ForgeModContainer.getConfig().get(ForgeModContainer.VERSION_CHECK_CAT, "Global", true).getBoolean())
|
||||
{
|
||||
FMLLog.log("ForgeVersionCheck", Level.INFO, "Global Forge version check system disabeld, no futher processing.");
|
||||
FMLLog.log("ForgeVersionCheck", Level.INFO, "Global Forge version check system disabled, no further processing.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,16 +280,12 @@ public class ForgeVersion
|
||||
}
|
||||
|
||||
// Gather a list of mods that have opted in to this update system by providing a URL.
|
||||
// Small hack needed to support a interface change until we force a recompile.
|
||||
public static Map<ModContainer, URL> gatherMods()
|
||||
{
|
||||
Map<ModContainer, URL> ret = new HashMap<ModContainer, URL>();
|
||||
for (ModContainer mod : Loader.instance().getActiveModList())
|
||||
{
|
||||
URL url = null;
|
||||
try {
|
||||
url = mod.getUpdateUrl();
|
||||
} catch (AbstractMethodError abs) { } //TODO: Remove this in 1.8.8+?
|
||||
URL url = mod.getUpdateUrl();
|
||||
if (url != null)
|
||||
ret.put(mod, url);
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Allows for custom entity data and logic to be hooked to existing entity classes.
|
||||
*
|
||||
* @author cpw, mithion
|
||||
*
|
||||
*/
|
||||
public interface IExtendedEntityProperties {
|
||||
/**
|
||||
* Called when the entity that this class is attached to is saved.
|
||||
* Any custom entity data that needs saving should be saved here.
|
||||
* @param compound The compound to save to.
|
||||
*/
|
||||
public void saveNBTData(NBTTagCompound compound);
|
||||
|
||||
/**
|
||||
* Called when the entity that this class is attached to is loaded.
|
||||
* In order to hook into this, you will need to subscribe to the EntityConstructing event.
|
||||
* Otherwise, you will need to initialize manually.
|
||||
* @param compound The compound to load from.
|
||||
*/
|
||||
public void loadNBTData(NBTTagCompound compound);
|
||||
|
||||
/**
|
||||
* Used to initialize the extended properties with the entity that this is attached to, as well
|
||||
* as the world object.
|
||||
* Called automatically if you register with the EntityConstructing event.
|
||||
* May be called multiple times if the extended properties is moved over to a new entity.
|
||||
* Such as when a player switches dimension {Minecraft re-creates the player entity}
|
||||
* @param entity The entity that this extended properties is attached to
|
||||
* @param world The world in which the entity exists
|
||||
*/
|
||||
public void init(Entity entity, World world);
|
||||
}
|
||||
Loaded 100 of 745 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user