mirror of
https://github.com/GTNewHorizons/EnderCore.git
synced 2026-11-19 19:49:48 +00:00
[ci skip] spotlessApply with the new settings
This commit is contained in:
1 parent
8153c38635
commit
3852dd21ac
168 files changed
+16571
-16033
No files matched your search
+1
-1
@@ -2,6 +2,6 @@
|
||||
|
||||
dependencies {
|
||||
compile("com.github.GTNewHorizons:NotEnoughItems:2.2.15-GTNH:dev")
|
||||
runtime("com.github.GTNewHorizons:CodeChickenLib:1.1.5.4:dev")
|
||||
runtimeOnly("com.github.GTNewHorizons:CodeChickenLib:1.1.5.4:dev")
|
||||
compileOnly("curse.maven:cofh-core-69162:2388751")
|
||||
}
|
||||
@@ -42,109 +42,119 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
|
||||
@Mod(modid = EnderCore.MODID, name = EnderCore.NAME, version = EnderCore.VERSION, dependencies = "after:ttCore", guiFactory = "com.enderio.core.common.config.BaseConfigFactory")
|
||||
@Mod(
|
||||
modid = EnderCore.MODID,
|
||||
name = EnderCore.NAME,
|
||||
version = EnderCore.VERSION,
|
||||
dependencies = "after:ttCore",
|
||||
guiFactory = "com.enderio.core.common.config.BaseConfigFactory")
|
||||
public class EnderCore implements IEnderMod {
|
||||
|
||||
public static final String MODID = "endercore";
|
||||
public static final String NAME = "EnderCore";
|
||||
public static final String BASE_PACKAGE = "com.enderio";
|
||||
public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||
public static final String MODID = "endercore";
|
||||
public static final String NAME = "EnderCore";
|
||||
public static final String BASE_PACKAGE = "com.enderio";
|
||||
public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||
|
||||
public static final Logger logger = LogManager.getLogger(NAME);
|
||||
public static final Lang lang = new Lang(MODID);
|
||||
public static final Logger logger = LogManager.getLogger(NAME);
|
||||
public static final Lang lang = new Lang(MODID);
|
||||
|
||||
@Instance(MODID)
|
||||
public static EnderCore instance;
|
||||
@Instance(MODID)
|
||||
public static EnderCore instance;
|
||||
|
||||
@SidedProxy(serverSide = "com.enderio.core.common.CommonProxy", clientSide = "com.enderio.core.client.ClientProxy")
|
||||
public static CommonProxy proxy;
|
||||
@SidedProxy(serverSide = "com.enderio.core.common.CommonProxy", clientSide = "com.enderio.core.client.ClientProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
public List<IConfigHandler> configs = Lists.newArrayList();
|
||||
public List<IConfigHandler> configs = Lists.newArrayList();
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
if (Loader.isModLoaded("ttCore")) {
|
||||
proxy.throwModCompatibilityError(lang.localize("error.ttcore.1"), lang.localize("error.ttcore.2"), lang.localize("error.ttcore.3"));
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
if (Loader.isModLoaded("ttCore")) {
|
||||
proxy.throwModCompatibilityError(
|
||||
lang.localize("error.ttcore.1"),
|
||||
lang.localize("error.ttcore.2"),
|
||||
lang.localize("error.ttcore.3"));
|
||||
}
|
||||
|
||||
if (event.getSide().isClient()) {
|
||||
TextureErrorRemover.beginIntercepting();
|
||||
}
|
||||
|
||||
ConfigHandler.configFolder = event.getModConfigurationDirectory();
|
||||
ConfigHandler.enderConfigFolder = new File(ConfigHandler.configFolder.getPath() + "/" + MODID);
|
||||
ConfigHandler.configFile = new File(
|
||||
ConfigHandler.enderConfigFolder.getPath() + "/" + event.getSuggestedConfigurationFile().getName());
|
||||
|
||||
if (!ConfigHandler.configFile.exists() && event.getSuggestedConfigurationFile().exists()) {
|
||||
try {
|
||||
FileUtils.copyFile(event.getSuggestedConfigurationFile(), ConfigHandler.configFile);
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
EnderFileUtils.safeDelete(event.getSuggestedConfigurationFile());
|
||||
}
|
||||
|
||||
ConfigHandler.instance().initialize(ConfigHandler.configFile);
|
||||
Handlers.preInit(event);
|
||||
|
||||
CompatRegistry.INSTANCE.handle(event);
|
||||
OreDict.registerVanilla();
|
||||
|
||||
EnchantXPBoost.INSTANCE.register();
|
||||
EnchantAutoSmelt.INSTANCE.register();
|
||||
}
|
||||
|
||||
if (event.getSide().isClient()) {
|
||||
TextureErrorRemover.beginIntercepting();
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
EnderPacketHandler.init();
|
||||
|
||||
for (IConfigHandler c : configs) {
|
||||
c.initHook();
|
||||
}
|
||||
|
||||
Handlers.register(event);
|
||||
CompatRegistry.INSTANCE.handle(event);
|
||||
ClientCommandHandler.instance.registerCommand(CommandReloadConfigs.CLIENT);
|
||||
if (event.getSide().isServer()) {
|
||||
((CommandHandler) MinecraftServer.getServer().getCommandManager())
|
||||
.registerCommand(CommandReloadConfigs.SERVER);
|
||||
}
|
||||
|
||||
IMCRegistry.INSTANCE.init();
|
||||
}
|
||||
|
||||
ConfigHandler.configFolder = event.getModConfigurationDirectory();
|
||||
ConfigHandler.enderConfigFolder = new File(ConfigHandler.configFolder.getPath() + "/" + MODID);
|
||||
ConfigHandler.configFile = new File(ConfigHandler.enderConfigFolder.getPath() + "/" + event.getSuggestedConfigurationFile().getName());
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
for (IConfigHandler c : configs) {
|
||||
c.postInitHook();
|
||||
}
|
||||
|
||||
if (!ConfigHandler.configFile.exists() && event.getSuggestedConfigurationFile().exists()) {
|
||||
try {
|
||||
FileUtils.copyFile(event.getSuggestedConfigurationFile(), ConfigHandler.configFile);
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
EnderFileUtils.safeDelete(event.getSuggestedConfigurationFile());
|
||||
CompatRegistry.INSTANCE.handle(event);
|
||||
ConfigHandler.instance().loadRightClickCrops();
|
||||
}
|
||||
|
||||
ConfigHandler.instance().initialize(ConfigHandler.configFile);
|
||||
Handlers.preInit(event);
|
||||
|
||||
CompatRegistry.INSTANCE.handle(event);
|
||||
OreDict.registerVanilla();
|
||||
|
||||
EnchantXPBoost.INSTANCE.register();
|
||||
EnchantAutoSmelt.INSTANCE.register();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
EnderPacketHandler.init();
|
||||
|
||||
for (IConfigHandler c : configs) {
|
||||
c.initHook();
|
||||
@EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent event) {
|
||||
event.registerServerCommand(new CommandScoreboardInfo());
|
||||
PermanentCache.saveCaches();
|
||||
}
|
||||
|
||||
Handlers.register(event);
|
||||
CompatRegistry.INSTANCE.handle(event);
|
||||
ClientCommandHandler.instance.registerCommand(CommandReloadConfigs.CLIENT);
|
||||
if (event.getSide().isServer()) {
|
||||
((CommandHandler) MinecraftServer.getServer().getCommandManager()).registerCommand(CommandReloadConfigs.SERVER);
|
||||
@EventHandler
|
||||
public void onIMCEvent(IMCEvent event) {
|
||||
IMCRegistry.INSTANCE.handleEvent(event);
|
||||
}
|
||||
|
||||
IMCRegistry.INSTANCE.init();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
for (IConfigHandler c : configs) {
|
||||
c.postInitHook();
|
||||
@Override
|
||||
public String modid() {
|
||||
return MODID;
|
||||
}
|
||||
|
||||
CompatRegistry.INSTANCE.handle(event);
|
||||
ConfigHandler.instance().loadRightClickCrops();
|
||||
}
|
||||
@Override
|
||||
public String name() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent event) {
|
||||
event.registerServerCommand(new CommandScoreboardInfo());
|
||||
PermanentCache.saveCaches();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onIMCEvent(IMCEvent event) {
|
||||
IMCRegistry.INSTANCE.handleEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modid() {
|
||||
return MODID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String version() {
|
||||
return VERSION;
|
||||
}
|
||||
@Override
|
||||
public String version() {
|
||||
return VERSION;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.enderio.core;
|
||||
|
||||
/**
|
||||
* By implementing this interface, your mod package will automatically be added
|
||||
* to the handler search and other package based functionality.
|
||||
* By implementing this interface, your mod package will automatically be added to the handler search and other package
|
||||
* based functionality.
|
||||
*
|
||||
* It also provides convenience functions for later use.
|
||||
*/
|
||||
public interface IEnderMod {
|
||||
String modid();
|
||||
|
||||
String name();
|
||||
String modid();
|
||||
|
||||
String version();
|
||||
String name();
|
||||
|
||||
String version();
|
||||
}
|
||||
@@ -2,20 +2,21 @@ package com.enderio.core.api.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public interface IAdvancedTooltipProvider {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List<String> list, boolean flag);
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List<String> list, boolean flag);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List<String> list, boolean flag);
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List<String> list, boolean flag);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addDetailedEntries(ItemStack itemstack, EntityPlayer entityplayer, List<String> list, boolean flag);
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addDetailedEntries(ItemStack itemstack, EntityPlayer entityplayer, List<String> list, boolean flag);
|
||||
|
||||
}
|
||||
@@ -4,21 +4,21 @@ import java.awt.Rectangle;
|
||||
|
||||
public interface IGuiOverlay extends IHideable {
|
||||
|
||||
void init(IGuiScreen screen);
|
||||
void init(IGuiScreen screen);
|
||||
|
||||
Rectangle getBounds();
|
||||
Rectangle getBounds();
|
||||
|
||||
void draw(int mouseX, int mouseY, float partialTick);
|
||||
void draw(int mouseX, int mouseY, float partialTick);
|
||||
|
||||
// //consume event?
|
||||
// boolean mouseClicked(int par1, int par2, int par3);
|
||||
//
|
||||
// boolean mouseClickMove(int par1, int par2, int par3, long p_146273_4_);
|
||||
//
|
||||
// boolean mouseMovedOrUp(int par1, int par2, int par3);
|
||||
// //consume event?
|
||||
// boolean mouseClicked(int par1, int par2, int par3);
|
||||
//
|
||||
// boolean mouseClickMove(int par1, int par2, int par3, long p_146273_4_);
|
||||
//
|
||||
// boolean mouseMovedOrUp(int par1, int par2, int par3);
|
||||
|
||||
boolean handleMouseInput(int x, int y, int b);
|
||||
boolean handleMouseInput(int x, int y, int b);
|
||||
|
||||
boolean isMouseInBounds(int mouseX, int mouseY);
|
||||
boolean isMouseInBounds(int mouseX, int mouseY);
|
||||
|
||||
}
|
||||
@@ -2,33 +2,33 @@ package com.enderio.core.api.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import com.enderio.core.client.gui.widget.GhostSlot;
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
public interface IGuiScreen {
|
||||
|
||||
void addToolTip(GuiToolTip toolTip);
|
||||
void addToolTip(GuiToolTip toolTip);
|
||||
|
||||
boolean removeToolTip(GuiToolTip toolTip);
|
||||
boolean removeToolTip(GuiToolTip toolTip);
|
||||
|
||||
int getGuiLeft();
|
||||
int getGuiLeft();
|
||||
|
||||
int getGuiTop();
|
||||
int getGuiTop();
|
||||
|
||||
int getXSize();
|
||||
int getXSize();
|
||||
|
||||
int getYSize();
|
||||
int getYSize();
|
||||
|
||||
void addButton(GuiButton button);
|
||||
void addButton(GuiButton button);
|
||||
|
||||
void removeButton(GuiButton button);
|
||||
void removeButton(GuiButton button);
|
||||
|
||||
int getOverlayOffsetX();
|
||||
int getOverlayOffsetX();
|
||||
|
||||
void doActionPerformed(GuiButton but);
|
||||
void doActionPerformed(GuiButton but);
|
||||
|
||||
List<GhostSlot> getGhostSlots();
|
||||
List<GhostSlot> getGhostSlots();
|
||||
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IResourceTooltipProvider {
|
||||
|
||||
String getUnlocalizedNameForTooltip(ItemStack itemStack);
|
||||
String getUnlocalizedNameForTooltip(ItemStack itemStack);
|
||||
|
||||
}
|
||||
@@ -1,33 +1,33 @@
|
||||
package com.enderio.core.api.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public interface ITabPanel {
|
||||
|
||||
void onGuiInit(int x, int y, int width, int height);
|
||||
void onGuiInit(int x, int y, int width, int height);
|
||||
|
||||
void deactivate();
|
||||
void deactivate();
|
||||
|
||||
IWidgetIcon getIcon();
|
||||
IWidgetIcon getIcon();
|
||||
|
||||
void render(float par1, int par2, int par3);
|
||||
void render(float par1, int par2, int par3);
|
||||
|
||||
void actionPerformed(GuiButton guiButton);
|
||||
void actionPerformed(GuiButton guiButton);
|
||||
|
||||
void mouseClicked(int x, int y, int par3);
|
||||
void mouseClicked(int x, int y, int par3);
|
||||
|
||||
void keyTyped(char par1, int par2);
|
||||
void keyTyped(char par1, int par2);
|
||||
|
||||
void updateScreen();
|
||||
void updateScreen();
|
||||
|
||||
/**
|
||||
* @return The location of the texture used for slot backgrounds, etc.
|
||||
*/
|
||||
default ResourceLocation getTexture() {
|
||||
return new ResourceLocation("enderio", "textures/gui/23/externalConduitConnection.png");
|
||||
}
|
||||
/**
|
||||
* @return The location of the texture used for slot backgrounds, etc.
|
||||
*/
|
||||
default ResourceLocation getTexture() {
|
||||
return new ResourceLocation("enderio", "textures/gui/23/externalConduitConnection.png");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import com.enderio.core.client.gui.widget.GuiScrollableList;
|
||||
|
||||
public interface ListSelectionListener<T> {
|
||||
|
||||
void selectionChanged(GuiScrollableList<T> list, int selectedIndex);
|
||||
void selectionChanged(GuiScrollableList<T> list, int selectedIndex);
|
||||
|
||||
}
|
||||
@@ -6,22 +6,21 @@ import net.minecraft.client.model.ModelRenderer;
|
||||
* To be used on techne-style box models
|
||||
*/
|
||||
public interface IEnderModel {
|
||||
/**
|
||||
* Renders all parts of the model
|
||||
*
|
||||
* @param size
|
||||
* - Size of the model (usually 0.0625f)
|
||||
*/
|
||||
public void render(float size);
|
||||
|
||||
/**
|
||||
* Rotates the model part in the given directions
|
||||
*
|
||||
* @param model
|
||||
* - part of the model to rotate
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public void setRotation(ModelRenderer model, float x, float y, float z);
|
||||
/**
|
||||
* Renders all parts of the model
|
||||
*
|
||||
* @param size - Size of the model (usually 0.0625f)
|
||||
*/
|
||||
public void render(float size);
|
||||
|
||||
/**
|
||||
* Rotates the model part in the given directions
|
||||
*
|
||||
* @param model - part of the model to rotate
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public void setRotation(ModelRenderer model, float x, float y, float z);
|
||||
}
|
||||
@@ -2,6 +2,6 @@ package com.enderio.core.api.client.render;
|
||||
|
||||
public interface IConnectedTextureRenderer {
|
||||
|
||||
boolean matchesMetadata(int meta1, int meta2);
|
||||
boolean matchesMetadata(int meta1, int meta2);
|
||||
|
||||
}
|
||||
@@ -2,16 +2,16 @@ package com.enderio.core.api.client.render;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.enderio.core.client.render.CustomRenderBlocks;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.enderio.core.client.render.CustomRenderBlocks;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
public interface IRenderFace {
|
||||
|
||||
void renderFace(CustomRenderBlocks rb, ForgeDirection face, Block par1Block, double x, double y, double z, IIcon texture, List<Vertex> refVertices,
|
||||
boolean translateToXyz);
|
||||
void renderFace(CustomRenderBlocks rb, ForgeDirection face, Block par1Block, double x, double y, double z,
|
||||
IIcon texture, List<Vertex> refVertices, boolean translateToXyz);
|
||||
|
||||
}
|
||||
@@ -4,16 +4,16 @@ import javax.annotation.Nullable;
|
||||
|
||||
public interface IWidgetIcon {
|
||||
|
||||
int getX();
|
||||
int getX();
|
||||
|
||||
int getY();
|
||||
int getY();
|
||||
|
||||
int getWidth();
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
int getHeight();
|
||||
|
||||
@Nullable
|
||||
IWidgetIcon getOverlay();
|
||||
@Nullable
|
||||
IWidgetIcon getOverlay();
|
||||
|
||||
IWidgetMap getMap();
|
||||
IWidgetMap getMap();
|
||||
}
|
||||
@@ -7,104 +7,107 @@ import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
public interface IWidgetMap {
|
||||
|
||||
int getSize();
|
||||
int getSize();
|
||||
|
||||
ResourceLocation getTexture();
|
||||
ResourceLocation getTexture();
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y);
|
||||
void render(IWidgetIcon widget, double x, double y);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, boolean doDraw);
|
||||
void render(IWidgetIcon widget, double x, double y, boolean doDraw);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, boolean doDraw, boolean flipY);
|
||||
void render(IWidgetIcon widget, double x, double y, boolean doDraw, boolean flipY);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw);
|
||||
void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw, boolean flipY);
|
||||
void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw, boolean flipY);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw);
|
||||
void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw, boolean flipY);
|
||||
void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw,
|
||||
boolean flipY);
|
||||
|
||||
static class WidgetMapImpl implements IWidgetMap {
|
||||
static class WidgetMapImpl implements IWidgetMap {
|
||||
|
||||
private final int size;
|
||||
private final ResourceLocation res;
|
||||
|
||||
public WidgetMapImpl(int size, ResourceLocation res) {
|
||||
this.size = size;
|
||||
this.res = res;
|
||||
private final int size;
|
||||
private final ResourceLocation res;
|
||||
|
||||
public WidgetMapImpl(int size, ResourceLocation res) {
|
||||
this.size = size;
|
||||
this.res = res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTexture() {
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y) {
|
||||
render(widget, x, y, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, boolean doDraw) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), 0, doDraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, boolean doDraw, boolean flipY) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), 0, doDraw, flipY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), zLevel, doDraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw, boolean flipY) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), zLevel, doDraw, flipY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel,
|
||||
boolean doDraw) {
|
||||
render(widget, x, y, width, height, zLevel, doDraw, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel,
|
||||
boolean doDraw, boolean flipY) {
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
if (doDraw) {
|
||||
RenderUtil.bindTexture(getTexture());
|
||||
tessellator.startDrawingQuads();
|
||||
}
|
||||
double minU = (double) widget.getX() / getSize();
|
||||
double maxU = (double) (widget.getX() + widget.getWidth()) / getSize();
|
||||
double minV = (double) widget.getY() / getSize();
|
||||
double maxV = (double) (widget.getY() + widget.getHeight()) / getSize();
|
||||
|
||||
if (flipY) {
|
||||
tessellator.addVertexWithUV(x, y + height, zLevel, minU, minV);
|
||||
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, minV);
|
||||
tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, maxV);
|
||||
tessellator.addVertexWithUV(x, y + 0, zLevel, minU, maxV);
|
||||
} else {
|
||||
tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV);
|
||||
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
|
||||
tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, minV);
|
||||
tessellator.addVertexWithUV(x, y + 0, zLevel, minU, minV);
|
||||
}
|
||||
if (widget.getOverlay() != null) {
|
||||
widget.getOverlay().getMap().render(widget.getOverlay(), x, y, width, height, zLevel, false, flipY);
|
||||
}
|
||||
if (doDraw) {
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTexture() {
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y) {
|
||||
render(widget, x, y, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, boolean doDraw) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), 0, doDraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, boolean doDraw, boolean flipY) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), 0, doDraw, flipY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), zLevel, doDraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw, boolean flipY) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), zLevel, doDraw, flipY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw) {
|
||||
render(widget, x, y, width, height, zLevel, doDraw, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw, boolean flipY) {
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
if (doDraw) {
|
||||
RenderUtil.bindTexture(getTexture());
|
||||
tessellator.startDrawingQuads();
|
||||
}
|
||||
double minU = (double) widget.getX() / getSize();
|
||||
double maxU = (double) (widget.getX() + widget.getWidth()) / getSize();
|
||||
double minV = (double) widget.getY() / getSize();
|
||||
double maxV = (double) (widget.getY() + widget.getHeight()) / getSize();
|
||||
|
||||
if (flipY) {
|
||||
tessellator.addVertexWithUV(x, y + height, zLevel, minU, minV);
|
||||
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, minV);
|
||||
tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, maxV);
|
||||
tessellator.addVertexWithUV(x, y + 0, zLevel, minU, maxV);
|
||||
} else {
|
||||
tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV);
|
||||
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
|
||||
tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, minV);
|
||||
tessellator.addVertexWithUV(x, y + 0, zLevel, minU, minV);
|
||||
}
|
||||
if (widget.getOverlay() != null) {
|
||||
widget.getOverlay().getMap().render(widget.getOverlay(), x, y, width, height, zLevel, false, flipY);
|
||||
}
|
||||
if (doDraw) {
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
public interface VertexTransform {
|
||||
|
||||
void apply(Vertex vertex);
|
||||
void apply(Vertex vertex);
|
||||
|
||||
void apply(Vector3d vec);
|
||||
void apply(Vector3d vec);
|
||||
|
||||
void applyToNormal(Vector3f vec);
|
||||
void applyToNormal(Vector3f vec);
|
||||
|
||||
}
|
||||
@@ -3,28 +3,30 @@ package com.enderio.core.api.common.config;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
|
||||
import com.enderio.core.common.config.AbstractConfigHandler.Section;
|
||||
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
|
||||
public interface IConfigHandler {
|
||||
void initialize(File cfg);
|
||||
|
||||
List<Section> getSections();
|
||||
void initialize(File cfg);
|
||||
|
||||
ConfigCategory getCategory(String name);
|
||||
List<Section> getSections();
|
||||
|
||||
String getModID();
|
||||
ConfigCategory getCategory(String name);
|
||||
|
||||
/**
|
||||
* A hook for the {@link FMLInitializationEvent}.
|
||||
*/
|
||||
void initHook();
|
||||
String getModID();
|
||||
|
||||
/**
|
||||
* A hook for the {@link FMLPostInitializationEvent}.
|
||||
*/
|
||||
void postInitHook();
|
||||
/**
|
||||
* A hook for the {@link FMLInitializationEvent}.
|
||||
*/
|
||||
void initHook();
|
||||
|
||||
/**
|
||||
* A hook for the {@link FMLPostInitializationEvent}.
|
||||
*/
|
||||
void postInitHook();
|
||||
}
|
||||
@@ -6,11 +6,12 @@ import net.minecraft.item.ItemStack;
|
||||
* Allows your enchants to have some flavor or descrtiption text underneath them
|
||||
*/
|
||||
public interface IAdvancedEnchant {
|
||||
/**
|
||||
* Get the detail for this itemstack
|
||||
*
|
||||
* @param stack
|
||||
* @return a list of <code>String</code>s to be bulleted under the enchantment
|
||||
*/
|
||||
public String[] getTooltipDetails(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Get the detail for this itemstack
|
||||
*
|
||||
* @param stack
|
||||
* @return a list of <code>String</code>s to be bulleted under the enchantment
|
||||
*/
|
||||
public String[] getTooltipDetails(ItemStack stack);
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.enderio.core.api.common.imc;
|
||||
|
||||
public class IMC {
|
||||
/**
|
||||
* Use an IMC event with this string to add a right click crop as compatible.
|
||||
* Syntax is a single string, with '|' separating the values, in the order
|
||||
* seed, block, meta, resetMeta. A valid entry would look like this:
|
||||
* <p>
|
||||
* {@literal "minecraft:wheat_seeds|minecraft:wheat|7|0"}
|
||||
* <p>
|
||||
* The "reset meta" is the metadata that the plant will be reset to when it is
|
||||
* harvested. Regular meta is the meta that must match the plant in world for
|
||||
* the harvest to occur.
|
||||
*/
|
||||
public static final String ADD_RIGHT_CLICK_CROP = "addRightClickCrop";
|
||||
|
||||
/**
|
||||
* Use an IMC event with this string to add a right click crop as compatible. Syntax is a single string, with '|'
|
||||
* separating the values, in the order seed, block, meta, resetMeta. A valid entry would look like this:
|
||||
* <p>
|
||||
* {@literal "minecraft:wheat_seeds|minecraft:wheat|7|0"}
|
||||
* <p>
|
||||
* The "reset meta" is the metadata that the plant will be reset to when it is harvested. Regular meta is the meta
|
||||
* that must match the plant in world for the harvest to occur.
|
||||
*/
|
||||
public static final String ADD_RIGHT_CLICK_CROP = "addRightClickCrop";
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public interface IFluidReceptor {
|
||||
|
||||
boolean isValidReceptor(IFluidHandler handler);
|
||||
boolean isValidReceptor(IFluidHandler handler);
|
||||
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IItemReceptor {
|
||||
|
||||
boolean canInsertIntoObject(Object into, ForgeDirection side);
|
||||
boolean canInsertIntoObject(Object into, ForgeDirection side);
|
||||
|
||||
int doInsertItem(Object into, ItemStack item, ForgeDirection side);
|
||||
int doInsertItem(Object into, ItemStack item, ForgeDirection side);
|
||||
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
package com.enderio.core.api.common.util;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public interface IProgressTile {
|
||||
|
||||
float getProgress();
|
||||
float getProgress();
|
||||
|
||||
/**
|
||||
* Client-only. Called to set clientside progress for syncing/rendering
|
||||
* purposes.
|
||||
*
|
||||
* @param progress
|
||||
* The % progress.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
void setProgress(float progress);
|
||||
/**
|
||||
* Client-only. Called to set clientside progress for syncing/rendering purposes.
|
||||
*
|
||||
* @param progress The % progress.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
void setProgress(float progress);
|
||||
|
||||
TileEntity getTileEntity();
|
||||
TileEntity getTileEntity();
|
||||
}
|
||||
@@ -5,29 +5,26 @@ import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
public interface ITankAccess {
|
||||
|
||||
/**
|
||||
* Find tank to insert fluid.
|
||||
*
|
||||
* @param forFluidType
|
||||
* The type of fluid that should be inserted. May be null.
|
||||
* @return An internal tank that can take the given type of fluid. If multiple
|
||||
* tanks can take the fluid, the first one that is not full will be
|
||||
* returned. If no tank can take the fluid, returns null.
|
||||
*/
|
||||
FluidTank getInputTank(FluidStack forFluidType);
|
||||
/**
|
||||
* Find tank to insert fluid.
|
||||
*
|
||||
* @param forFluidType The type of fluid that should be inserted. May be null.
|
||||
* @return An internal tank that can take the given type of fluid. If multiple tanks can take the fluid, the first
|
||||
* one that is not full will be returned. If no tank can take the fluid, returns null.
|
||||
*/
|
||||
FluidTank getInputTank(FluidStack forFluidType);
|
||||
|
||||
/**
|
||||
* Get tank(s) to remove liquid from.
|
||||
*
|
||||
* @return Tank that can be drained. Tanks are returned in order or priority.
|
||||
* If there's no tank, an empty array is returned.
|
||||
*/
|
||||
FluidTank[] getOutputTanks();
|
||||
/**
|
||||
* Get tank(s) to remove liquid from.
|
||||
*
|
||||
* @return Tank that can be drained. Tanks are returned in order or priority. If there's no tank, an empty array is
|
||||
* returned.
|
||||
*/
|
||||
FluidTank[] getOutputTanks();
|
||||
|
||||
/**
|
||||
* Will be called after a tank that was returned by one of the other methods
|
||||
* was manipulated.
|
||||
*/
|
||||
void setTanksDirty();
|
||||
/**
|
||||
* Will be called after a tank that was returned by one of the other methods was manipulated.
|
||||
*/
|
||||
void setTanksDirty();
|
||||
|
||||
}
|
||||
@@ -8,22 +8,22 @@ import com.enderio.core.common.util.Scheduler;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
|
||||
@Override
|
||||
public Scheduler getScheduler() {
|
||||
if (scheduler == null) {
|
||||
scheduler = new Scheduler(false);
|
||||
@Override
|
||||
public Scheduler getScheduler() {
|
||||
if (scheduler == null) {
|
||||
scheduler = new Scheduler(false);
|
||||
}
|
||||
return scheduler;
|
||||
}
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getClientWorld() {
|
||||
return Minecraft.getMinecraft().theWorld;
|
||||
}
|
||||
@Override
|
||||
public World getClientWorld() {
|
||||
return Minecraft.getMinecraft().theWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void throwModCompatibilityError(String... msgs) {
|
||||
throw new EnderCoreModConflictException(msgs);
|
||||
}
|
||||
@Override
|
||||
public void throwModCompatibilityError(String... msgs) {
|
||||
throw new EnderCoreModConflictException(msgs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +1,32 @@
|
||||
package com.enderio.core.client;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
|
||||
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class EnderCoreModConflictException extends CustomModLoadingErrorDisplayException {
|
||||
|
||||
private final String[] msgs;
|
||||
private final String[] msgs;
|
||||
|
||||
public EnderCoreModConflictException(String[] msgs) {
|
||||
super(msgs[0], new RuntimeException());
|
||||
this.msgs = msgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) {
|
||||
int y = errorScreen.height / 2 - msgs.length * 5;
|
||||
for (String msg : msgs) {
|
||||
errorScreen.drawCenteredString(fontRenderer, msg, errorScreen.width / 2, y, 0xFFFFFF);
|
||||
y += 10;
|
||||
public EnderCoreModConflictException(String[] msgs) {
|
||||
super(msgs[0], new RuntimeException());
|
||||
this.msgs = msgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {}
|
||||
|
||||
@Override
|
||||
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY,
|
||||
float tickTime) {
|
||||
int y = errorScreen.height / 2 - msgs.length * 5;
|
||||
for (String msg : msgs) {
|
||||
errorScreen.drawCenteredString(fontRenderer, msg, errorScreen.width / 2, y, 0xFFFFFF);
|
||||
y += 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,125 +19,128 @@ import cpw.mods.fml.client.config.GuiConfig;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
|
||||
public class BaseConfigGui extends GuiConfig {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public BaseConfigGui(GuiScreen parentScreen) {
|
||||
// dummy super so we can call instance methods
|
||||
super(parentScreen, new ArrayList<IConfigElement>(), null, false, false, null);
|
||||
|
||||
try {
|
||||
// pffft final, what a wimpy modifier
|
||||
Field modID = GuiConfig.class.getDeclaredField("modID");
|
||||
Field configElements = GuiConfig.class.getDeclaredField("configElements");
|
||||
@SuppressWarnings("rawtypes")
|
||||
public BaseConfigGui(GuiScreen parentScreen) {
|
||||
// dummy super so we can call instance methods
|
||||
super(parentScreen, new ArrayList<IConfigElement>(), null, false, false, null);
|
||||
|
||||
modID.setAccessible(true);
|
||||
configElements.setAccessible(true);
|
||||
try {
|
||||
// pffft final, what a wimpy modifier
|
||||
Field modID = GuiConfig.class.getDeclaredField("modID");
|
||||
Field configElements = GuiConfig.class.getDeclaredField("configElements");
|
||||
|
||||
modID.set(this, getConfigHandler().getModID());
|
||||
configElements.set(this, getConfigElements());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
modID.setAccessible(true);
|
||||
configElements.setAccessible(true);
|
||||
|
||||
this.title = getTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* The <b>localized</b> title of this config screen
|
||||
*/
|
||||
protected String getTitle() {
|
||||
return EnderCore.lang.localize("config.title");
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link IConfigHandler} to refer to when generating this config screen
|
||||
*/
|
||||
protected IConfigHandler getConfigHandler() {
|
||||
return ConfigHandler.instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* The lang prefix to use before your section lang keys. Default is "config.".
|
||||
*/
|
||||
protected String getLangPrefix() {
|
||||
return "config.";
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<IConfigElement> getConfigElements() {
|
||||
List<IConfigElement> list = new ArrayList<IConfigElement>();
|
||||
String prefix = getLangPrefix();
|
||||
IConfigHandler config = getConfigHandler();
|
||||
|
||||
prefix = prefix.endsWith(".") ? prefix : prefix + ".";
|
||||
|
||||
for (Section s : config.getSections()) {
|
||||
list.add(new ConfigSection(s, prefix));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private class ConfigSection extends ConfigElement<ConfigCategory> {
|
||||
private Section section;
|
||||
private String prefix;
|
||||
|
||||
private ConfigSection(Section s, String prefix) {
|
||||
super(BaseConfigGui.this.getConfigHandler().getCategory(s.lc()).setLanguageKey(prefix + s.lang));
|
||||
this.section = s;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IConfigElement> getChildElements() {
|
||||
List<IConfigElement> temp = super.getChildElements();
|
||||
List<IConfigElement> ret = new ArrayList<IConfigElement>(temp.size());
|
||||
for (IConfigElement e : temp) {
|
||||
if (e.isProperty()) {
|
||||
ret.add(new ConfigElementExtended(e));
|
||||
} else {
|
||||
ret.add(new ConfigSection(section, prefix));
|
||||
modID.set(this, getConfigHandler().getModID());
|
||||
configElements.set(this, getConfigElements());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static class ConfigElementExtended<T> extends ConfigElement<T> {
|
||||
private static final Field _prop;
|
||||
static {
|
||||
try {
|
||||
_prop = ConfigElement.class.getDeclaredField("prop");
|
||||
_prop.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.title = getTitle();
|
||||
}
|
||||
|
||||
private ConfigElementExtended(IConfigElement other) {
|
||||
super(getProp(other));
|
||||
/**
|
||||
* The <b>localized</b> title of this config screen
|
||||
*/
|
||||
protected String getTitle() {
|
||||
return EnderCore.lang.localize("config.title");
|
||||
}
|
||||
|
||||
private static Property getProp(IConfigElement other) {
|
||||
try {
|
||||
return (Property) _prop.get(other);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
/**
|
||||
* The {@link IConfigHandler} to refer to when generating this config screen
|
||||
*/
|
||||
protected IConfigHandler getConfigHandler() {
|
||||
return ConfigHandler.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment() {
|
||||
String comment = super.getComment();
|
||||
String range = "[range:";
|
||||
String def = "[default:";
|
||||
if (comment.contains(range)) {
|
||||
comment = comment.substring(0, comment.indexOf(range) - 1);
|
||||
} else if (comment.contains(def)) {
|
||||
comment = comment.substring(0, comment.indexOf(def) - 1);
|
||||
}
|
||||
return comment;
|
||||
/**
|
||||
* The lang prefix to use before your section lang keys. Default is "config.".
|
||||
*/
|
||||
protected String getLangPrefix() {
|
||||
return "config.";
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<IConfigElement> getConfigElements() {
|
||||
List<IConfigElement> list = new ArrayList<IConfigElement>();
|
||||
String prefix = getLangPrefix();
|
||||
IConfigHandler config = getConfigHandler();
|
||||
|
||||
prefix = prefix.endsWith(".") ? prefix : prefix + ".";
|
||||
|
||||
for (Section s : config.getSections()) {
|
||||
list.add(new ConfigSection(s, prefix));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private class ConfigSection extends ConfigElement<ConfigCategory> {
|
||||
|
||||
private Section section;
|
||||
private String prefix;
|
||||
|
||||
private ConfigSection(Section s, String prefix) {
|
||||
super(BaseConfigGui.this.getConfigHandler().getCategory(s.lc()).setLanguageKey(prefix + s.lang));
|
||||
this.section = s;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IConfigElement> getChildElements() {
|
||||
List<IConfigElement> temp = super.getChildElements();
|
||||
List<IConfigElement> ret = new ArrayList<IConfigElement>(temp.size());
|
||||
for (IConfigElement e : temp) {
|
||||
if (e.isProperty()) {
|
||||
ret.add(new ConfigElementExtended(e));
|
||||
} else {
|
||||
ret.add(new ConfigSection(section, prefix));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static class ConfigElementExtended<T> extends ConfigElement<T> {
|
||||
|
||||
private static final Field _prop;
|
||||
static {
|
||||
try {
|
||||
_prop = ConfigElement.class.getDeclaredField("prop");
|
||||
_prop.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigElementExtended(IConfigElement other) {
|
||||
super(getProp(other));
|
||||
}
|
||||
|
||||
private static Property getProp(IConfigElement other) {
|
||||
try {
|
||||
return (Property) _prop.get(other);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment() {
|
||||
String comment = super.getComment();
|
||||
String range = "[range:";
|
||||
String def = "[default:";
|
||||
if (comment.contains(range)) {
|
||||
comment = comment.substring(0, comment.indexOf(range) - 1);
|
||||
} else if (comment.contains(def)) {
|
||||
comment = comment.substring(0, comment.indexOf(def) - 1);
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import static com.enderio.core.client.render.EnderWidget.NEUTRAL_SLOT_BACKGROUND
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.client.gui.widget.GhostSlot;
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
import com.enderio.core.common.util.ItemUtil;
|
||||
@@ -16,215 +16,215 @@ import com.google.common.collect.Lists;
|
||||
|
||||
public class GhostSlotHandler {
|
||||
|
||||
protected List<GhostSlot> ghostSlots = Lists.newArrayList();
|
||||
protected GhostSlot hoverGhostSlot;
|
||||
protected List<GhostSlot> ghostSlots = Lists.newArrayList();
|
||||
protected GhostSlot hoverGhostSlot;
|
||||
|
||||
public GhostSlotHandler() {
|
||||
}
|
||||
public GhostSlotHandler() {}
|
||||
|
||||
// GhostSlot managing
|
||||
// GhostSlot managing
|
||||
|
||||
protected List<GhostSlot> getGhostSlots() {
|
||||
return ghostSlots;
|
||||
}
|
||||
|
||||
protected GhostSlot getGhostSlot(GuiContainerBase guiContainerBase, int mouseX, int mouseY) {
|
||||
mouseX -= guiContainerBase.getGuiLeft();
|
||||
mouseY -= guiContainerBase.getGuiTop();
|
||||
for (GhostSlot slot : ghostSlots) {
|
||||
if (slot.isVisible() && slot.isMouseOver(mouseX, mouseY)) {
|
||||
return slot;
|
||||
}
|
||||
protected List<GhostSlot> getGhostSlots() {
|
||||
return ghostSlots;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Slot interaction
|
||||
|
||||
/**
|
||||
* Called when a ghost slot is clicked or mouse wheeled.
|
||||
*
|
||||
* @param gui
|
||||
* The GUI the GhostSlot is in
|
||||
* @param slot
|
||||
* The GhostSlot
|
||||
* @param x
|
||||
* Mouse position x
|
||||
* @param y
|
||||
* Mouse position y
|
||||
* @param button
|
||||
* The button used (0=left, 1=right). The mouse wheel is mapped to
|
||||
* -1=down and -2=up.
|
||||
*/
|
||||
protected void ghostSlotClicked(GuiContainerBase gui, GhostSlot slot, int x, int y, int button) {
|
||||
ItemStack handStack = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
|
||||
ItemStack existingStack = slot.getStack();
|
||||
if (button == 0) { // left
|
||||
ghostSlotClickedPrimaryMouseButton(slot, handStack, existingStack);
|
||||
} else if (button == 1) { // right
|
||||
ghostSlotClickedSecondaryMouseButton(slot, handStack, existingStack);
|
||||
} else if (button == -2) { // wheel up
|
||||
ghostSlotClickedMouseWheelUp(slot, handStack, existingStack);
|
||||
} else if (button == -1) { // wheel down
|
||||
ghostSlotClickedMouseWheelDown(slot, handStack, existingStack);
|
||||
protected GhostSlot getGhostSlot(GuiContainerBase guiContainerBase, int mouseX, int mouseY) {
|
||||
mouseX -= guiContainerBase.getGuiLeft();
|
||||
mouseY -= guiContainerBase.getGuiTop();
|
||||
for (GhostSlot slot : ghostSlots) {
|
||||
if (slot.isVisible() && slot.isMouseOver(mouseX, mouseY)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedPrimaryMouseButton(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (handStack == null || handStack.getItem() == null || handStack.stackSize == 0) { // empty hand
|
||||
slot.putStack(null);
|
||||
} else { // item in hand
|
||||
if (existingStack == null || existingStack.getItem() == null || existingStack.stackSize == 0) { // empty slot
|
||||
replaceSlot(slot, handStack);
|
||||
} else { // filled slot
|
||||
if (ItemUtil.areStackMergable(existingStack, handStack)) { // same item
|
||||
if (existingStack.stackSize < existingStack.getMaxStackSize() && existingStack.stackSize < slot.getStackSizeLimit()) {
|
||||
// Slot interaction
|
||||
|
||||
/**
|
||||
* Called when a ghost slot is clicked or mouse wheeled.
|
||||
*
|
||||
* @param gui The GUI the GhostSlot is in
|
||||
* @param slot The GhostSlot
|
||||
* @param x Mouse position x
|
||||
* @param y Mouse position y
|
||||
* @param button The button used (0=left, 1=right). The mouse wheel is mapped to -1=down and -2=up.
|
||||
*/
|
||||
protected void ghostSlotClicked(GuiContainerBase gui, GhostSlot slot, int x, int y, int button) {
|
||||
ItemStack handStack = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
|
||||
ItemStack existingStack = slot.getStack();
|
||||
if (button == 0) { // left
|
||||
ghostSlotClickedPrimaryMouseButton(slot, handStack, existingStack);
|
||||
} else if (button == 1) { // right
|
||||
ghostSlotClickedSecondaryMouseButton(slot, handStack, existingStack);
|
||||
} else if (button == -2) { // wheel up
|
||||
ghostSlotClickedMouseWheelUp(slot, handStack, existingStack);
|
||||
} else if (button == -1) { // wheel down
|
||||
ghostSlotClickedMouseWheelDown(slot, handStack, existingStack);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedPrimaryMouseButton(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (handStack == null || handStack.getItem() == null || handStack.stackSize == 0) { // empty hand
|
||||
slot.putStack(null);
|
||||
} else { // item in hand
|
||||
if (existingStack == null || existingStack.getItem() == null || existingStack.stackSize == 0) { // empty
|
||||
// slot
|
||||
replaceSlot(slot, handStack);
|
||||
} else { // filled slot
|
||||
if (ItemUtil.areStackMergable(existingStack, handStack)) { // same item
|
||||
if (existingStack.stackSize < existingStack.getMaxStackSize()
|
||||
&& existingStack.stackSize < slot.getStackSizeLimit()) {
|
||||
increaseSlot(slot, existingStack);
|
||||
} else {
|
||||
// NOP
|
||||
}
|
||||
} else { // different item
|
||||
replaceSlot(slot, handStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedSecondaryMouseButton(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (handStack == null || handStack.getItem() == null || handStack.stackSize == 0) { // empty hand
|
||||
slot.putStack(null);
|
||||
} else { // item in hand
|
||||
if (existingStack == null || existingStack.getItem() == null || existingStack.stackSize == 0) { // empty
|
||||
// slot
|
||||
replaceSlot1Item(slot, handStack);
|
||||
} else { // filled slot
|
||||
if (ItemUtil.areStackMergable(existingStack, handStack)) { // same item
|
||||
descreaseSlot(slot, existingStack);
|
||||
} else { // different item
|
||||
replaceSlot1Item(slot, handStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedMouseWheelUp(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (existingStack != null && existingStack.getItem() != null
|
||||
&& existingStack.stackSize > 0
|
||||
&& existingStack.stackSize < existingStack.getMaxStackSize()
|
||||
&& existingStack.stackSize < slot.getStackSizeLimit()) {
|
||||
increaseSlot(slot, existingStack);
|
||||
} else {
|
||||
// NOP
|
||||
}
|
||||
} else { // different item
|
||||
replaceSlot(slot, handStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedSecondaryMouseButton(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (handStack == null || handStack.getItem() == null || handStack.stackSize == 0) { // empty hand
|
||||
slot.putStack(null);
|
||||
} else { // item in hand
|
||||
if (existingStack == null || existingStack.getItem() == null || existingStack.stackSize == 0) { // empty slot
|
||||
replaceSlot1Item(slot, handStack);
|
||||
} else { // filled slot
|
||||
if (ItemUtil.areStackMergable(existingStack, handStack)) { // same item
|
||||
descreaseSlot(slot, existingStack);
|
||||
} else { // different item
|
||||
replaceSlot1Item(slot, handStack);
|
||||
protected void ghostSlotClickedMouseWheelDown(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (existingStack != null && existingStack.getItem() != null) {
|
||||
descreaseSlot(slot, existingStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedMouseWheelUp(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (existingStack != null && existingStack.getItem() != null && existingStack.stackSize > 0 && existingStack.stackSize < existingStack.getMaxStackSize()
|
||||
&& existingStack.stackSize < slot.getStackSizeLimit()) {
|
||||
increaseSlot(slot, existingStack);
|
||||
// Slot interaction tools
|
||||
|
||||
protected void descreaseSlot(GhostSlot slot, ItemStack existingStack) {
|
||||
if (existingStack.stackSize > 1) {
|
||||
existingStack.stackSize--;
|
||||
slot.putStack(existingStack);
|
||||
} else {
|
||||
slot.putStack(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedMouseWheelDown(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (existingStack != null && existingStack.getItem() != null) {
|
||||
descreaseSlot(slot, existingStack);
|
||||
protected void increaseSlot(GhostSlot slot, ItemStack existingStack) {
|
||||
existingStack.stackSize++;
|
||||
slot.putStack(existingStack);
|
||||
}
|
||||
}
|
||||
|
||||
// Slot interaction tools
|
||||
|
||||
protected void descreaseSlot(GhostSlot slot, ItemStack existingStack) {
|
||||
if (existingStack.stackSize > 1) {
|
||||
existingStack.stackSize--;
|
||||
slot.putStack(existingStack);
|
||||
} else {
|
||||
slot.putStack(null);
|
||||
protected void replaceSlot1Item(GhostSlot slot, ItemStack handStack) {
|
||||
ItemStack oneItem = handStack.copy();
|
||||
oneItem.stackSize = 1;
|
||||
slot.putStack(oneItem);
|
||||
}
|
||||
}
|
||||
|
||||
protected void increaseSlot(GhostSlot slot, ItemStack existingStack) {
|
||||
existingStack.stackSize++;
|
||||
slot.putStack(existingStack);
|
||||
}
|
||||
|
||||
protected void replaceSlot1Item(GhostSlot slot, ItemStack handStack) {
|
||||
ItemStack oneItem = handStack.copy();
|
||||
oneItem.stackSize = 1;
|
||||
slot.putStack(oneItem);
|
||||
}
|
||||
|
||||
protected void replaceSlot(GhostSlot slot, ItemStack handStack) {
|
||||
if (handStack.stackSize <= slot.getStackSizeLimit()) {
|
||||
slot.putStack(handStack);
|
||||
} else {
|
||||
ItemStack tmp = handStack.copy();
|
||||
tmp.stackSize = slot.getStackSizeLimit();
|
||||
slot.putStack(tmp);
|
||||
protected void replaceSlot(GhostSlot slot, ItemStack handStack) {
|
||||
if (handStack.stackSize <= slot.getStackSizeLimit()) {
|
||||
slot.putStack(handStack);
|
||||
} else {
|
||||
ItemStack tmp = handStack.copy();
|
||||
tmp.stackSize = slot.getStackSizeLimit();
|
||||
slot.putStack(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rendering
|
||||
// Rendering
|
||||
|
||||
protected void startDrawing(GuiContainerBase gui) {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = null;
|
||||
}
|
||||
protected void startDrawing(GuiContainerBase gui) {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = null;
|
||||
}
|
||||
|
||||
protected void drawGhostSlots(GuiContainerBase gui, int mouseX, int mouseY) {
|
||||
int sx = gui.getGuiLeft();
|
||||
int sy = gui.getGuiTop();
|
||||
gui.drawFakeItemsStart();
|
||||
try {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = null;
|
||||
for (GhostSlot slot : ghostSlots) {
|
||||
protected void drawGhostSlots(GuiContainerBase gui, int mouseX, int mouseY) {
|
||||
int sx = gui.getGuiLeft();
|
||||
int sy = gui.getGuiTop();
|
||||
gui.drawFakeItemsStart();
|
||||
try {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = null;
|
||||
for (GhostSlot slot : ghostSlots) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if (slot.isVisible()) {
|
||||
if (stack != null) {
|
||||
gui.drawFakeItemStack(slot.x + sx, slot.y + sy, stack);
|
||||
if (slot.shouldDisplayStdOverlay()) {
|
||||
gui.drawFakeItemStackStdOverlay(slot.x + sx, slot.y + sy, stack);
|
||||
}
|
||||
if (slot.shouldGrayOut()) {
|
||||
gui.ghostSlotHandler.drawGhostSlotGrayout(gui, slot);
|
||||
}
|
||||
}
|
||||
if (slot.isMouseOver(mouseX - sx, mouseY - sy)) {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hoverGhostSlot != null) {
|
||||
// draw hover last to prevent it from affecting rendering of other slots ...
|
||||
gui.drawFakeItemHover(hoverGhostSlot.x + sx, hoverGhostSlot.y + sy);
|
||||
}
|
||||
} finally {
|
||||
gui.drawFakeItemsEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gray out the item that was just painted into a GhostSlot by overpainting it with 50% transparent background. This
|
||||
* gives the illusion that the item was painted with 50% transparency. (100%*a ° 100%*b ° 50%*a == 100%*a ° 50%*b)
|
||||
*/
|
||||
protected void drawGhostSlotGrayout(GuiContainerBase gui, GhostSlot slot) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, slot.getGrayOutLevel());
|
||||
String guiTexture = gui.getGuiTexture();
|
||||
if (guiTexture == null) {
|
||||
NEUTRAL_SLOT_BACKGROUND.getMap().render(
|
||||
NEUTRAL_SLOT_BACKGROUND,
|
||||
gui.getGuiLeft() + slot.x,
|
||||
gui.getGuiTop() + slot.y,
|
||||
gui.getZlevel(),
|
||||
true);
|
||||
} else {
|
||||
RenderUtil.bindTexture(guiTexture);
|
||||
gui.drawTexturedModalRect(gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, slot.x, slot.y, 16, 16);
|
||||
}
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
protected void drawGhostSlotTooltip(GuiContainerBase guiContainerBase, GhostSlot slot, int mouseX, int mouseY) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if (slot.isVisible()) {
|
||||
if (stack != null) {
|
||||
gui.drawFakeItemStack(slot.x + sx, slot.y + sy, stack);
|
||||
if (slot.shouldDisplayStdOverlay()) {
|
||||
gui.drawFakeItemStackStdOverlay(slot.x + sx, slot.y + sy, stack);
|
||||
}
|
||||
if (slot.shouldGrayOut()) {
|
||||
gui.ghostSlotHandler.drawGhostSlotGrayout(gui, slot);
|
||||
}
|
||||
}
|
||||
if (slot.isMouseOver(mouseX - sx, mouseY - sy)) {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = slot;
|
||||
}
|
||||
if (stack != null) {
|
||||
guiContainerBase.renderToolTip(stack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
if (hoverGhostSlot != null) {
|
||||
// draw hover last to prevent it from affecting rendering of other slots ...
|
||||
gui.drawFakeItemHover(hoverGhostSlot.x + sx, hoverGhostSlot.y + sy);
|
||||
}
|
||||
} finally {
|
||||
gui.drawFakeItemsEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gray out the item that was just painted into a GhostSlot by overpainting it
|
||||
* with 50% transparent background. This gives the illusion that the item was
|
||||
* painted with 50% transparency. (100%*a ° 100%*b ° 50%*a == 100%*a ° 50%*b)
|
||||
*/
|
||||
protected void drawGhostSlotGrayout(GuiContainerBase gui, GhostSlot slot) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, slot.getGrayOutLevel());
|
||||
String guiTexture = gui.getGuiTexture();
|
||||
if (guiTexture == null) {
|
||||
NEUTRAL_SLOT_BACKGROUND.getMap().render(NEUTRAL_SLOT_BACKGROUND, gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, gui.getZlevel(), true);
|
||||
} else {
|
||||
RenderUtil.bindTexture(guiTexture);
|
||||
gui.drawTexturedModalRect(gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, slot.x, slot.y, 16, 16);
|
||||
}
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
protected void drawGhostSlotTooltip(GuiContainerBase guiContainerBase, GhostSlot slot, int mouseX, int mouseY) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if (stack != null) {
|
||||
guiContainerBase.renderToolTip(stack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void drawGhostSlotToolTip(GuiContainerBase gui, int mouseX, int mouseY) {
|
||||
if (hoverGhostSlot != null && gui.mc.thePlayer.inventory.getItemStack() == null) {
|
||||
gui.drawGhostSlotTooltip(hoverGhostSlot, mouseX, mouseY);
|
||||
}
|
||||
|
||||
}
|
||||
protected void drawGhostSlotToolTip(GuiContainerBase gui, int mouseX, int mouseY) {
|
||||
if (hoverGhostSlot != null && gui.mc.thePlayer.inventory.getItemStack() == null) {
|
||||
gui.drawGhostSlotTooltip(hoverGhostSlot, mouseX, mouseY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -11,91 +11,91 @@ import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
public class GuiIconRenderer extends Gui {
|
||||
|
||||
public static final int DEFAULT_WIDTH = 24;
|
||||
public static final int HWIDTH = DEFAULT_WIDTH / 2;
|
||||
public static final int DEFAULT_HEIGHT = 24;
|
||||
public static final int HHEIGHT = DEFAULT_HEIGHT / 2;
|
||||
public static final int DEFAULT_WIDTH = 24;
|
||||
public static final int HWIDTH = DEFAULT_WIDTH / 2;
|
||||
public static final int DEFAULT_HEIGHT = 24;
|
||||
public static final int HHEIGHT = DEFAULT_HEIGHT / 2;
|
||||
|
||||
protected int hwidth = HWIDTH;
|
||||
protected int hheight = HHEIGHT;
|
||||
protected int width = DEFAULT_WIDTH;
|
||||
protected int height = DEFAULT_HEIGHT;
|
||||
protected int hwidth = HWIDTH;
|
||||
protected int hheight = HHEIGHT;
|
||||
protected int width = DEFAULT_WIDTH;
|
||||
protected int height = DEFAULT_HEIGHT;
|
||||
|
||||
protected IIcon icon;
|
||||
protected ResourceLocation texture;
|
||||
protected IIcon icon;
|
||||
protected ResourceLocation texture;
|
||||
|
||||
private int yPosition;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private int xPosition;
|
||||
|
||||
private float alpha = 1.0f;
|
||||
private float alpha = 1.0f;
|
||||
|
||||
public GuiIconRenderer(int x, int y, int itemId, int itemMeta) {
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
icon = IconUtil.getIconForItem(itemId, itemMeta);
|
||||
texture = RenderUtil.ITEM_TEX;
|
||||
}
|
||||
public GuiIconRenderer(int x, int y, int itemId, int itemMeta) {
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
icon = IconUtil.getIconForItem(itemId, itemMeta);
|
||||
texture = RenderUtil.ITEM_TEX;
|
||||
}
|
||||
|
||||
public GuiIconRenderer(int x, int y, IIcon icon, ResourceLocation texture) {
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
this.icon = icon;
|
||||
this.texture = texture;
|
||||
}
|
||||
public GuiIconRenderer(int x, int y, IIcon icon, ResourceLocation texture) {
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
this.icon = icon;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
hwidth = width / 2;
|
||||
hheight = height / 2;
|
||||
}
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
hwidth = width / 2;
|
||||
hheight = height / 2;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public IIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
public IIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public float getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
public float getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public void setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
public void setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public void setIcon(IIcon icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
public void setIcon(IIcon icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public ResourceLocation getTexture() {
|
||||
return texture;
|
||||
}
|
||||
public ResourceLocation getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public void setTexture(ResourceLocation textureName) {
|
||||
this.texture = textureName;
|
||||
}
|
||||
public void setTexture(ResourceLocation textureName) {
|
||||
this.texture = textureName;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
public void draw() {
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, alpha);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, alpha);
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
RenderUtil.bindTexture(texture);
|
||||
drawTexturedModelRectFromIcon(xPosition, yPosition, icon, width, height);
|
||||
RenderUtil.bindTexture(texture);
|
||||
drawTexturedModelRectFromIcon(xPosition, yPosition, icon, width, height);
|
||||
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopAttrib();
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,220 +19,218 @@ import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
|
||||
public abstract class GuiScreenBase extends GuiScreen implements ToolTipRenderer, IGuiScreen {
|
||||
|
||||
protected ToolTipManager ttMan = new ToolTipManager();
|
||||
protected ToolTipManager ttMan = new ToolTipManager();
|
||||
|
||||
/** The X size of the inventory window in pixels. */
|
||||
protected int xSize = 176;
|
||||
/** The X size of the inventory window in pixels. */
|
||||
protected int xSize = 176;
|
||||
|
||||
/** The Y size of the inventory window in pixels. */
|
||||
protected int ySize = 166;
|
||||
/** The Y size of the inventory window in pixels. */
|
||||
protected int ySize = 166;
|
||||
|
||||
/**
|
||||
* Starting X position for the Gui. Inconsistent use for Gui backgrounds.
|
||||
*/
|
||||
protected int guiLeft;
|
||||
/**
|
||||
* Starting X position for the Gui. Inconsistent use for Gui backgrounds.
|
||||
*/
|
||||
protected int guiLeft;
|
||||
|
||||
/**
|
||||
* Starting Y position for the Gui. Inconsistent use for Gui backgrounds.
|
||||
*/
|
||||
protected int guiTop;
|
||||
/**
|
||||
* Starting Y position for the Gui. Inconsistent use for Gui backgrounds.
|
||||
*/
|
||||
protected int guiTop;
|
||||
|
||||
protected boolean drawButtons = true;
|
||||
protected boolean drawButtons = true;
|
||||
|
||||
protected GuiScreenBase() {
|
||||
}
|
||||
protected GuiScreenBase() {}
|
||||
|
||||
protected GuiScreenBase(int xSize, int ySize) {
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToolTip(GuiToolTip toolTip) {
|
||||
ttMan.addToolTip(toolTip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeToolTip(GuiToolTip toolTip) {
|
||||
return ttMan.removeToolTip(toolTip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
guiLeft = (this.width - this.xSize) / 2;
|
||||
guiTop = (this.height - this.ySize) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
drawDefaultBackground();
|
||||
|
||||
drawBackgroundLayer(par3, par1, par2);
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
if (drawButtons) {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
super.drawScreen(par1, par2, par3);
|
||||
protected GuiScreenBase(int xSize, int ySize) {
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
}
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(guiLeft, guiTop, 0.0F);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
@Override
|
||||
public void addToolTip(GuiToolTip toolTip) {
|
||||
ttMan.addToolTip(toolTip);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
drawForegroundLayer(par1, par2);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
@Override
|
||||
public boolean removeToolTip(GuiToolTip toolTip) {
|
||||
return ttMan.removeToolTip(toolTip);
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
guiLeft = (this.width - this.xSize) / 2;
|
||||
guiTop = (this.height - this.ySize) / 2;
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
drawDefaultBackground();
|
||||
|
||||
protected abstract void drawBackgroundLayer(float par3, int par1, int par2);
|
||||
drawBackgroundLayer(par3, par1, par2);
|
||||
|
||||
protected final void drawForegroundLayer(int mouseX, int mouseY) {
|
||||
drawForegroundImpl(mouseX, mouseY);
|
||||
ttMan.drawTooltips(this, mouseX, mouseY);
|
||||
}
|
||||
|
||||
protected void drawForegroundImpl(int mouseX, int mouseY) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawHoveringText(List par1List, int par2, int par3, FontRenderer font) {
|
||||
|
||||
if (!par1List.isEmpty()) {
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
|
||||
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
int k = 0;
|
||||
Iterator iterator = par1List.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
String s = (String) iterator.next();
|
||||
int l = font.getStringWidth(s);
|
||||
|
||||
if (l > k) {
|
||||
k = l;
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
if (drawButtons) {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
}
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
|
||||
int i1 = par2 + 12;
|
||||
int j1 = par3 - 12;
|
||||
int k1 = 8;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(guiLeft, guiTop, 0.0F);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
if (par1List.size() > 1) {
|
||||
k1 += 2 + (par1List.size() - 1) * 10;
|
||||
}
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
drawForegroundLayer(par1, par2);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
if (i1 + k > this.width) {
|
||||
i1 -= 28 + k;
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
|
||||
if (j1 + k1 + 6 > this.height) {
|
||||
j1 = this.height - k1 - 6;
|
||||
}
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
|
||||
this.zLevel = 300.0F;
|
||||
protected abstract void drawBackgroundLayer(float par3, int par1, int par2);
|
||||
|
||||
int l1 = -267386864;
|
||||
this.drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1);
|
||||
this.drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1);
|
||||
this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1);
|
||||
this.drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1);
|
||||
this.drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1);
|
||||
int i2 = 1347420415;
|
||||
int j2 = (i2 & 16711422) >> 1 | i2 & -16777216;
|
||||
this.drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2);
|
||||
this.drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2);
|
||||
this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2);
|
||||
this.drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2);
|
||||
protected final void drawForegroundLayer(int mouseX, int mouseY) {
|
||||
drawForegroundImpl(mouseX, mouseY);
|
||||
ttMan.drawTooltips(this, mouseX, mouseY);
|
||||
}
|
||||
|
||||
for (int k2 = 0; k2 < par1List.size(); ++k2) {
|
||||
String s1 = (String) par1List.get(k2);
|
||||
font.drawStringWithShadow(s1, i1, j1, -1);
|
||||
protected void drawForegroundImpl(int mouseX, int mouseY) {}
|
||||
|
||||
@Override
|
||||
public void drawHoveringText(List par1List, int par2, int par3, FontRenderer font) {
|
||||
|
||||
if (!par1List.isEmpty()) {
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
|
||||
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
int k = 0;
|
||||
Iterator iterator = par1List.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
String s = (String) iterator.next();
|
||||
int l = font.getStringWidth(s);
|
||||
|
||||
if (l > k) {
|
||||
k = l;
|
||||
}
|
||||
}
|
||||
|
||||
int i1 = par2 + 12;
|
||||
int j1 = par3 - 12;
|
||||
int k1 = 8;
|
||||
|
||||
if (par1List.size() > 1) {
|
||||
k1 += 2 + (par1List.size() - 1) * 10;
|
||||
}
|
||||
|
||||
if (i1 + k > this.width) {
|
||||
i1 -= 28 + k;
|
||||
}
|
||||
|
||||
if (j1 + k1 + 6 > this.height) {
|
||||
j1 = this.height - k1 - 6;
|
||||
}
|
||||
|
||||
this.zLevel = 300.0F;
|
||||
|
||||
int l1 = -267386864;
|
||||
this.drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1);
|
||||
this.drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1);
|
||||
this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1);
|
||||
this.drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1);
|
||||
this.drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1);
|
||||
int i2 = 1347420415;
|
||||
int j2 = (i2 & 16711422) >> 1 | i2 & -16777216;
|
||||
this.drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2);
|
||||
this.drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2);
|
||||
this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2);
|
||||
this.drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2);
|
||||
|
||||
for (int k2 = 0; k2 < par1List.size(); ++k2) {
|
||||
String s1 = (String) par1List.get(k2);
|
||||
font.drawStringWithShadow(s1, i1, j1, -1);
|
||||
|
||||
if (k2 == 0) {
|
||||
j1 += 2;
|
||||
}
|
||||
|
||||
j1 += 10;
|
||||
}
|
||||
|
||||
this.zLevel = 0.0F;
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopAttrib();
|
||||
|
||||
if (k2 == 0) {
|
||||
j1 += 2;
|
||||
}
|
||||
|
||||
j1 += 10;
|
||||
}
|
||||
|
||||
this.zLevel = 0.0F;
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopAttrib();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiLeft() {
|
||||
return guiLeft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiTop() {
|
||||
return guiTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXSize() {
|
||||
return xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYSize() {
|
||||
return xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FontRenderer getFontRenderer() {
|
||||
return Minecraft.getMinecraft().fontRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addButton(GuiButton button) {
|
||||
if (!buttonList.contains(button)) {
|
||||
buttonList.add(button);
|
||||
@Override
|
||||
public int getGuiLeft() {
|
||||
return guiLeft;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeButton(GuiButton button) {
|
||||
buttonList.remove(button);
|
||||
}
|
||||
@Override
|
||||
public int getGuiTop() {
|
||||
return guiTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doActionPerformed(GuiButton guiButton) {
|
||||
actionPerformed(guiButton);
|
||||
}
|
||||
@Override
|
||||
public int getXSize() {
|
||||
return xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOverlayOffsetX() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getYSize() {
|
||||
return xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GhostSlot> getGhostSlots() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public FontRenderer getFontRenderer() {
|
||||
return Minecraft.getMinecraft().fontRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addButton(GuiButton button) {
|
||||
if (!buttonList.contains(button)) {
|
||||
buttonList.add(button);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeButton(GuiButton button) {
|
||||
buttonList.remove(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doActionPerformed(GuiButton guiButton) {
|
||||
actionPerformed(guiButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOverlayOffsetX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GhostSlot> getGhostSlots() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -10,67 +10,68 @@ import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
|
||||
public class ToolTipManager {
|
||||
|
||||
public static interface ToolTipRenderer {
|
||||
int getGuiLeft();
|
||||
public static interface ToolTipRenderer {
|
||||
|
||||
int getGuiTop();
|
||||
int getGuiLeft();
|
||||
|
||||
int getXSize();
|
||||
int getGuiTop();
|
||||
|
||||
FontRenderer getFontRenderer();
|
||||
int getXSize();
|
||||
|
||||
void drawHoveringText(List<String> par1List, int par2, int par3, FontRenderer font);
|
||||
}
|
||||
FontRenderer getFontRenderer();
|
||||
|
||||
private List<GuiToolTip> toolTips = new ArrayList<GuiToolTip>();
|
||||
|
||||
public void addToolTip(GuiToolTip toolTip) {
|
||||
if (!toolTips.contains(toolTip)) {
|
||||
toolTips.add(toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeToolTip(GuiToolTip toolTip) {
|
||||
return toolTips.remove(toolTip);
|
||||
}
|
||||
|
||||
protected final void drawTooltips(ToolTipRenderer renderer, int mouseX, int mouseY) {
|
||||
for (GuiToolTip toolTip : toolTips) {
|
||||
toolTip.onTick(mouseX - renderer.getGuiLeft(), mouseY - renderer.getGuiTop());
|
||||
if (toolTip.shouldDraw()) {
|
||||
drawTooltip(toolTip, mouseX, mouseY, renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawTooltip(GuiToolTip toolTip, int mouseX, int mouseY, ToolTipRenderer renderer) {
|
||||
List<String> list = toolTip.getToolTipText();
|
||||
if (list == null) {
|
||||
return;
|
||||
void drawHoveringText(List<String> par1List, int par2, int par3, FontRenderer font);
|
||||
}
|
||||
|
||||
List<String> formatted = new ArrayList<String>(list.size());
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (i == 0) {
|
||||
formatted.add("\u00a7f" + list.get(i));
|
||||
} else {
|
||||
formatted.add("\u00a77" + list.get(i));
|
||||
}
|
||||
}
|
||||
private List<GuiToolTip> toolTips = new ArrayList<GuiToolTip>();
|
||||
|
||||
if (mouseX > renderer.getGuiLeft() + renderer.getXSize() / 2) {
|
||||
int maxWidth = 0;
|
||||
Iterator<String> iterator = formatted.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String s = (String) iterator.next();
|
||||
int w = renderer.getFontRenderer().getStringWidth(s);
|
||||
if (w > maxWidth) {
|
||||
maxWidth = w;
|
||||
public void addToolTip(GuiToolTip toolTip) {
|
||||
if (!toolTips.contains(toolTip)) {
|
||||
toolTips.add(toolTip);
|
||||
}
|
||||
}
|
||||
mouseX -= (maxWidth + 18);
|
||||
}
|
||||
renderer.drawHoveringText(formatted, mouseX, mouseY, renderer.getFontRenderer());
|
||||
}
|
||||
|
||||
public boolean removeToolTip(GuiToolTip toolTip) {
|
||||
return toolTips.remove(toolTip);
|
||||
}
|
||||
|
||||
protected final void drawTooltips(ToolTipRenderer renderer, int mouseX, int mouseY) {
|
||||
for (GuiToolTip toolTip : toolTips) {
|
||||
toolTip.onTick(mouseX - renderer.getGuiLeft(), mouseY - renderer.getGuiTop());
|
||||
if (toolTip.shouldDraw()) {
|
||||
drawTooltip(toolTip, mouseX, mouseY, renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawTooltip(GuiToolTip toolTip, int mouseX, int mouseY, ToolTipRenderer renderer) {
|
||||
List<String> list = toolTip.getToolTipText();
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> formatted = new ArrayList<String>(list.size());
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (i == 0) {
|
||||
formatted.add("\u00a7f" + list.get(i));
|
||||
} else {
|
||||
formatted.add("\u00a77" + list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (mouseX > renderer.getGuiLeft() + renderer.getXSize() / 2) {
|
||||
int maxWidth = 0;
|
||||
Iterator<String> iterator = formatted.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String s = (String) iterator.next();
|
||||
int w = renderer.getFontRenderer().getStringWidth(s);
|
||||
if (w > maxWidth) {
|
||||
maxWidth = w;
|
||||
}
|
||||
}
|
||||
mouseX -= (maxWidth + 18);
|
||||
}
|
||||
renderer.drawHoveringText(formatted, mouseX, mouseY, renderer.getFontRenderer());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,35 +15,37 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Handler
|
||||
public class EventHandlerGui {
|
||||
private static Field _mainMenu, _parentScreen;
|
||||
|
||||
static {
|
||||
try {
|
||||
_mainMenu = GuiModList.class.getDeclaredField("mainMenu");
|
||||
_mainMenu.setAccessible(true);
|
||||
_parentScreen = GuiIngameModOptions.class.getDeclaredField("parentScreen");
|
||||
_parentScreen.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
private static Field _mainMenu, _parentScreen;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(GuiOpenEvent event) {
|
||||
if (event.gui == null) {
|
||||
return;
|
||||
static {
|
||||
try {
|
||||
_mainMenu = GuiModList.class.getDeclaredField("mainMenu");
|
||||
_mainMenu.setAccessible(true);
|
||||
_parentScreen = GuiIngameModOptions.class.getDeclaredField("parentScreen");
|
||||
_parentScreen.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (event.gui.getClass() == GuiModList.class) {
|
||||
event.setCanceled(true);
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiEnhancedModList((GuiScreen) _mainMenu.get(event.gui)));
|
||||
}
|
||||
if (event.gui.getClass() == GuiIngameModOptions.class) {
|
||||
event.setCanceled(true);
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiEnhancedModList((GuiScreen) _parentScreen.get(event.gui)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(GuiOpenEvent event) {
|
||||
if (event.gui == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (event.gui.getClass() == GuiModList.class) {
|
||||
event.setCanceled(true);
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiEnhancedModList((GuiScreen) _mainMenu.get(event.gui)));
|
||||
}
|
||||
if (event.gui.getClass() == GuiIngameModOptions.class) {
|
||||
event.setCanceled(true);
|
||||
Minecraft.getMinecraft()
|
||||
.displayGuiScreen(new GuiEnhancedModList((GuiScreen) _parentScreen.get(event.gui)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,390 +24,404 @@ import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
|
||||
public class GuiEnhancedModList extends GuiModList {
|
||||
private enum SortType {
|
||||
NORMAL(24),
|
||||
A_TO_Z(25),
|
||||
Z_TO_A(26);
|
||||
|
||||
private final int buttonID;
|
||||
private final ModComparator comparator;
|
||||
private enum SortType {
|
||||
|
||||
private SortType(int buttonID) {
|
||||
this.buttonID = buttonID;
|
||||
this.comparator = new ModComparator(this);
|
||||
}
|
||||
NORMAL(24),
|
||||
A_TO_Z(25),
|
||||
Z_TO_A(26);
|
||||
|
||||
public static SortType getTypeForButton(GuiButton button) {
|
||||
for (SortType t : values()) {
|
||||
if (t.buttonID == button.id) {
|
||||
return t;
|
||||
private final int buttonID;
|
||||
private final ModComparator comparator;
|
||||
|
||||
private SortType(int buttonID) {
|
||||
this.buttonID = buttonID;
|
||||
this.comparator = new ModComparator(this);
|
||||
}
|
||||
|
||||
public static SortType getTypeForButton(GuiButton button) {
|
||||
for (SortType t : values()) {
|
||||
if (t.buttonID == button.id) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ModComparator implements Comparator<ModContainer> {
|
||||
private SortType type;
|
||||
private static class ModComparator implements Comparator<ModContainer> {
|
||||
|
||||
private ModComparator(SortType type) {
|
||||
this.type = type;
|
||||
private SortType type;
|
||||
|
||||
private ModComparator(SortType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ModContainer o1, ModContainer o2) {
|
||||
String name1 = StringUtils.stripControlCodes(o1.getName()).toLowerCase(Locale.US);
|
||||
String name2 = StringUtils.stripControlCodes(o2.getName()).toLowerCase(Locale.US);
|
||||
switch (type) {
|
||||
case A_TO_Z:
|
||||
return name1.compareTo(name2);
|
||||
case Z_TO_A:
|
||||
return name2.compareTo(name1);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class InfoButton extends GuiButton {
|
||||
|
||||
public InfoButton() {
|
||||
super(30, GuiEnhancedModList.this.width - 22, 2, 20, 20, "?");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft p_146112_1_, int p_146112_2_, int p_146112_3_) {
|
||||
if (this.field_146123_n) {
|
||||
ModContainer sel = GuiEnhancedModList.this.getSelectedMod();
|
||||
if (sel != null && sel.getName().equals(EnderCore.NAME)) {
|
||||
this.displayString = EnderCore.lang.localize("gui.modlistinfo2");
|
||||
} else {
|
||||
this.displayString = EnderCore.lang.localize("gui.modlistinfo1");
|
||||
}
|
||||
|
||||
this.width = p_146112_1_.fontRenderer.getStringWidth(this.displayString) + 10;
|
||||
if (this.width % 2 != 0) // Fixes the button shifting to the left
|
||||
{
|
||||
this.width++;
|
||||
}
|
||||
|
||||
this.xPosition = GuiEnhancedModList.this.width - this.width - 2;
|
||||
} else {
|
||||
this.displayString = "?";
|
||||
this.width = 20;
|
||||
this.xPosition = GuiEnhancedModList.this.width - this.width - 2;
|
||||
}
|
||||
|
||||
super.drawButton(p_146112_1_, p_146112_2_, p_146112_3_);
|
||||
}
|
||||
}
|
||||
|
||||
private static Field _mods, _selected, _selectedMod;
|
||||
private static Field _modList, _modListRight, _modListBottom, _modListMods, _listWidth, _scrollDistance;
|
||||
static {
|
||||
try {
|
||||
_mods = GuiModList.class.getDeclaredField("mods");
|
||||
_mods.setAccessible(true);
|
||||
_selected = GuiModList.class.getDeclaredField("selected");
|
||||
_selected.setAccessible(true);
|
||||
_selectedMod = GuiModList.class.getDeclaredField("selectedMod");
|
||||
_selectedMod.setAccessible(true);
|
||||
_modList = GuiModList.class.getDeclaredField("modList");
|
||||
_modList.setAccessible(true);
|
||||
_modListRight = GuiScrollingList.class.getDeclaredField("right");
|
||||
_modListRight.setAccessible(true);
|
||||
_modListBottom = GuiScrollingList.class.getDeclaredField("bottom");
|
||||
_modListBottom.setAccessible(true);
|
||||
_modListMods = GuiSlotModList.class.getDeclaredField("mods");
|
||||
_modListMods.setAccessible(true);
|
||||
_listWidth = GuiModList.class.getDeclaredField("listWidth");
|
||||
_listWidth.setAccessible(true);
|
||||
_scrollDistance = GuiScrollingList.class.getDeclaredField("scrollDistance");
|
||||
_scrollDistance.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private int buttonMargin = 1;
|
||||
private int numButtons = SortType.values().length;
|
||||
|
||||
private String lastFilterText = "";
|
||||
|
||||
private GuiTextField search;
|
||||
private boolean sorted = false;
|
||||
private SortType sortType = SortType.values()[ConfigHandler.defaultModSort];
|
||||
|
||||
public GuiEnhancedModList(GuiScreen mainMenu) {
|
||||
super(mainMenu);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
// Super code reinitializes the mod list every time, need to preserve scroll state
|
||||
float scroll = 0;
|
||||
if (getGuiModList() != null) {
|
||||
scroll = getGuiModListScroll();
|
||||
}
|
||||
|
||||
super.initGui();
|
||||
|
||||
// Let's move some buttons
|
||||
for (GuiButton button : (List<GuiButton>) buttonList) {
|
||||
if (button.id == 6) // Done button
|
||||
{
|
||||
int min = getGuiModListRight();
|
||||
int max = width;
|
||||
button.xPosition = ((min + max) / 2) - (button.width / 2);
|
||||
button.yPosition += 10;
|
||||
} else if (button.id == 20 || button.id == 21) // Config/Disable
|
||||
{
|
||||
button.yPosition += 10;
|
||||
}
|
||||
}
|
||||
|
||||
setGuiModListBottom(getGuiModListBottom() - 25);
|
||||
if (search == null) {
|
||||
search = new GuiTextField(mc.fontRenderer, 12, getGuiModListBottom() + 17, getListWidth() - 4, 14);
|
||||
search.setFocused(true);
|
||||
search.setCanLoseFocus(true);
|
||||
}
|
||||
|
||||
int width = (getListWidth() / numButtons);
|
||||
int x = 10, y = 10;
|
||||
GuiButton normalSort = new GuiButton(
|
||||
SortType.NORMAL.buttonID,
|
||||
x,
|
||||
y,
|
||||
width - buttonMargin,
|
||||
20,
|
||||
EnderCore.lang.localize("gui.normal"));
|
||||
normalSort.enabled = false;
|
||||
buttonList.add(normalSort);
|
||||
x += width + buttonMargin;
|
||||
buttonList.add(new GuiButton(SortType.A_TO_Z.buttonID, x, y, width - buttonMargin, 20, "A-Z"));
|
||||
x += width + buttonMargin;
|
||||
buttonList.add(new GuiButton(SortType.Z_TO_A.buttonID, x, y, width - buttonMargin, 20, "Z-A"));
|
||||
|
||||
buttonList.add(new InfoButton());
|
||||
|
||||
reloadMods();
|
||||
disableButton();
|
||||
|
||||
setGuiModListScroll(scroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ModContainer o1, ModContainer o2) {
|
||||
String name1 = StringUtils.stripControlCodes(o1.getName()).toLowerCase(Locale.US);
|
||||
String name2 = StringUtils.stripControlCodes(o2.getName()).toLowerCase(Locale.US);
|
||||
switch (type) {
|
||||
case A_TO_Z:
|
||||
return name1.compareTo(name2);
|
||||
case Z_TO_A:
|
||||
return name2.compareTo(name1);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class InfoButton extends GuiButton {
|
||||
public InfoButton() {
|
||||
super(30, GuiEnhancedModList.this.width - 22, 2, 20, 20, "?");
|
||||
@SuppressWarnings("unchecked")
|
||||
public int drawLine(String line, int offset, int shifty) {
|
||||
String before = line.substring(0, line.indexOf(':') + 2);
|
||||
int followingLineOffset = this.fontRendererObj.getStringWidth(before);
|
||||
String[] manualSplit = line.split("\n");
|
||||
List<String> split = Lists.newArrayList();
|
||||
for (String s : manualSplit) {
|
||||
split.addAll(this.fontRendererObj.listFormattedStringToWidth(s, width - offset));
|
||||
}
|
||||
for (int i = 0; i < split.size(); i++) {
|
||||
this.fontRendererObj.drawString(split.get(i), offset + (i > 0 ? followingLineOffset : 0), shifty, 0xd7edea);
|
||||
shifty += 10;
|
||||
}
|
||||
if (split.size() > 1) {
|
||||
shifty += 10;
|
||||
}
|
||||
return shifty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft p_146112_1_, int p_146112_2_, int p_146112_3_) {
|
||||
if (this.field_146123_n) {
|
||||
ModContainer sel = GuiEnhancedModList.this.getSelectedMod();
|
||||
if (sel != null && sel.getName().equals(EnderCore.NAME)) {
|
||||
this.displayString = EnderCore.lang.localize("gui.modlistinfo2");
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
super.mouseClicked(x, y, button);
|
||||
search.mouseClicked(x, y, button);
|
||||
if (button == 1 && x >= search.xPosition
|
||||
&& x < search.xPosition + search.width
|
||||
&& y >= search.yPosition
|
||||
&& y < search.yPosition + search.height) {
|
||||
search.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char p_73869_1_, int p_73869_2_) {
|
||||
super.keyTyped(p_73869_1_, p_73869_2_);
|
||||
search.textboxKeyTyped(p_73869_1_, p_73869_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
search.updateCursorCounter();
|
||||
|
||||
if (!search.getText().equals(lastFilterText)) {
|
||||
reloadMods();
|
||||
sorted = false;
|
||||
}
|
||||
|
||||
if (!sorted) {
|
||||
reloadMods();
|
||||
Collections.sort(getMods(), sortType.comparator);
|
||||
setMods();
|
||||
sorted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadMods() {
|
||||
List<ModContainer> mods = getMods();
|
||||
mods.clear();
|
||||
for (ModContainer m : Loader.instance().getActiveModList()) {
|
||||
if (m.getName().toLowerCase(Locale.US).contains(search.getText().toLowerCase(Locale.US))
|
||||
&& m.getMetadata().parentMod == null) {
|
||||
mods.add(m);
|
||||
}
|
||||
}
|
||||
setMods();
|
||||
lastFilterText = search.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int p_571_1_, int p_571_2_, float p_571_3_) {
|
||||
super.drawScreen(p_571_1_, p_571_2_, p_571_3_);
|
||||
|
||||
String text = EnderCore.lang.localize("gui.search");
|
||||
int x = ((10 + getGuiModListRight()) / 2) - (mc.fontRenderer.getStringWidth(text) / 2);
|
||||
mc.fontRenderer.drawString(text, x, getGuiModListBottom() + 5, 0xFFFFFF);
|
||||
search.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
|
||||
if (button.id == 30) {
|
||||
search.setText("");
|
||||
reloadMods();
|
||||
for (ModContainer m : getMods()) {
|
||||
if (m.getName().equals(EnderCore.NAME)) {
|
||||
setSelectedMod(m);
|
||||
setMods();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SortType type = SortType.getTypeForButton(button);
|
||||
|
||||
if (type == null) {
|
||||
return;
|
||||
} else {
|
||||
this.displayString = EnderCore.lang.localize("gui.modlistinfo1");
|
||||
sorted = false;
|
||||
sortType = type;
|
||||
disableButton();
|
||||
}
|
||||
|
||||
this.width = p_146112_1_.fontRenderer.getStringWidth(this.displayString) + 10;
|
||||
if (this.width % 2 != 0) // Fixes the button shifting to the left
|
||||
{
|
||||
this.width++;
|
||||
setMods();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void disableButton() {
|
||||
for (GuiButton b : (List<GuiButton>) buttonList) {
|
||||
if (SortType.getTypeForButton(b) != null) {
|
||||
b.enabled = true;
|
||||
}
|
||||
if (b.id == sortType.buttonID) {
|
||||
b.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.xPosition = GuiEnhancedModList.this.width - this.width - 2;
|
||||
} else {
|
||||
this.displayString = "?";
|
||||
this.width = 20;
|
||||
this.xPosition = GuiEnhancedModList.this.width - this.width - 2;
|
||||
}
|
||||
|
||||
super.drawButton(p_146112_1_, p_146112_2_, p_146112_3_);
|
||||
}
|
||||
}
|
||||
|
||||
private static Field _mods, _selected, _selectedMod;
|
||||
private static Field _modList, _modListRight, _modListBottom, _modListMods, _listWidth, _scrollDistance;
|
||||
static {
|
||||
try {
|
||||
_mods = GuiModList.class.getDeclaredField("mods");
|
||||
_mods.setAccessible(true);
|
||||
_selected = GuiModList.class.getDeclaredField("selected");
|
||||
_selected.setAccessible(true);
|
||||
_selectedMod = GuiModList.class.getDeclaredField("selectedMod");
|
||||
_selectedMod.setAccessible(true);
|
||||
_modList = GuiModList.class.getDeclaredField("modList");
|
||||
_modList.setAccessible(true);
|
||||
_modListRight = GuiScrollingList.class.getDeclaredField("right");
|
||||
_modListRight.setAccessible(true);
|
||||
_modListBottom = GuiScrollingList.class.getDeclaredField("bottom");
|
||||
_modListBottom.setAccessible(true);
|
||||
_modListMods = GuiSlotModList.class.getDeclaredField("mods");
|
||||
_modListMods.setAccessible(true);
|
||||
_listWidth = GuiModList.class.getDeclaredField("listWidth");
|
||||
_listWidth.setAccessible(true);
|
||||
_scrollDistance = GuiScrollingList.class.getDeclaredField("scrollDistance");
|
||||
_scrollDistance.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private int buttonMargin = 1;
|
||||
private int numButtons = SortType.values().length;
|
||||
|
||||
private String lastFilterText = "";
|
||||
|
||||
private GuiTextField search;
|
||||
private boolean sorted = false;
|
||||
private SortType sortType = SortType.values()[ConfigHandler.defaultModSort];
|
||||
|
||||
public GuiEnhancedModList(GuiScreen mainMenu) {
|
||||
super(mainMenu);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
// Super code reinitializes the mod list every time, need to preserve scroll state
|
||||
float scroll = 0;
|
||||
if (getGuiModList() != null) {
|
||||
scroll = getGuiModListScroll();
|
||||
}
|
||||
|
||||
super.initGui();
|
||||
private void setMods() {
|
||||
List<ModContainer> mods = getMods();
|
||||
|
||||
// Let's move some buttons
|
||||
for (GuiButton button : (List<GuiButton>) buttonList) {
|
||||
if (button.id == 6) // Done button
|
||||
{
|
||||
int min = getGuiModListRight();
|
||||
int max = width;
|
||||
button.xPosition = ((min + max) / 2) - (button.width / 2);
|
||||
button.yPosition += 10;
|
||||
} else if (button.id == 20 || button.id == 21) // Config/Disable
|
||||
{
|
||||
button.yPosition += 10;
|
||||
}
|
||||
}
|
||||
ModContainer sel = getSelectedMod();
|
||||
boolean found = false;
|
||||
try {
|
||||
for (int i = 0; !found && i < mods.size(); i++) {
|
||||
if (sel == mods.get(i)) {
|
||||
_selected.setInt(this, i);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
_selected.setInt(this, -1);
|
||||
_selectedMod.set(this, null);
|
||||
}
|
||||
|
||||
setGuiModListBottom(getGuiModListBottom() - 25);
|
||||
if (search == null) {
|
||||
search = new GuiTextField(mc.fontRenderer, 12, getGuiModListBottom() + 17, getListWidth() - 4, 14);
|
||||
search.setFocused(true);
|
||||
search.setCanLoseFocus(true);
|
||||
}
|
||||
|
||||
int width = (getListWidth() / numButtons);
|
||||
int x = 10, y = 10;
|
||||
GuiButton normalSort = new GuiButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, EnderCore.lang.localize("gui.normal"));
|
||||
normalSort.enabled = false;
|
||||
buttonList.add(normalSort);
|
||||
x += width + buttonMargin;
|
||||
buttonList.add(new GuiButton(SortType.A_TO_Z.buttonID, x, y, width - buttonMargin, 20, "A-Z"));
|
||||
x += width + buttonMargin;
|
||||
buttonList.add(new GuiButton(SortType.Z_TO_A.buttonID, x, y, width - buttonMargin, 20, "Z-A"));
|
||||
|
||||
buttonList.add(new InfoButton());
|
||||
|
||||
reloadMods();
|
||||
disableButton();
|
||||
|
||||
setGuiModListScroll(scroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int drawLine(String line, int offset, int shifty) {
|
||||
String before = line.substring(0, line.indexOf(':') + 2);
|
||||
int followingLineOffset = this.fontRendererObj.getStringWidth(before);
|
||||
String[] manualSplit = line.split("\n");
|
||||
List<String> split = Lists.newArrayList();
|
||||
for (String s : manualSplit) {
|
||||
split.addAll(this.fontRendererObj.listFormattedStringToWidth(s, width - offset));
|
||||
}
|
||||
for (int i = 0; i < split.size(); i++) {
|
||||
this.fontRendererObj.drawString(split.get(i), offset + (i > 0 ? followingLineOffset : 0), shifty, 0xd7edea);
|
||||
shifty += 10;
|
||||
}
|
||||
if (split.size() > 1) {
|
||||
shifty += 10;
|
||||
}
|
||||
return shifty;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
super.mouseClicked(x, y, button);
|
||||
search.mouseClicked(x, y, button);
|
||||
if (button == 1 && x >= search.xPosition && x < search.xPosition + search.width && y >= search.yPosition && y < search.yPosition + search.height) {
|
||||
search.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char p_73869_1_, int p_73869_2_) {
|
||||
super.keyTyped(p_73869_1_, p_73869_2_);
|
||||
search.textboxKeyTyped(p_73869_1_, p_73869_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
search.updateCursorCounter();
|
||||
|
||||
if (!search.getText().equals(lastFilterText)) {
|
||||
reloadMods();
|
||||
sorted = false;
|
||||
}
|
||||
|
||||
if (!sorted) {
|
||||
reloadMods();
|
||||
Collections.sort(getMods(), sortType.comparator);
|
||||
setMods();
|
||||
sorted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadMods() {
|
||||
List<ModContainer> mods = getMods();
|
||||
mods.clear();
|
||||
for (ModContainer m : Loader.instance().getActiveModList()) {
|
||||
if (m.getName().toLowerCase(Locale.US).contains(search.getText().toLowerCase(Locale.US)) && m.getMetadata().parentMod == null) {
|
||||
mods.add(m);
|
||||
}
|
||||
}
|
||||
setMods();
|
||||
lastFilterText = search.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int p_571_1_, int p_571_2_, float p_571_3_) {
|
||||
super.drawScreen(p_571_1_, p_571_2_, p_571_3_);
|
||||
|
||||
String text = EnderCore.lang.localize("gui.search");
|
||||
int x = ((10 + getGuiModListRight()) / 2) - (mc.fontRenderer.getStringWidth(text) / 2);
|
||||
mc.fontRenderer.drawString(text, x, getGuiModListBottom() + 5, 0xFFFFFF);
|
||||
search.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
|
||||
if (button.id == 30) {
|
||||
search.setText("");
|
||||
reloadMods();
|
||||
for (ModContainer m : getMods()) {
|
||||
if (m.getName().equals(EnderCore.NAME)) {
|
||||
setSelectedMod(m);
|
||||
setMods();
|
||||
_mods.set(this, getMods());
|
||||
sorted = false;
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SortType type = SortType.getTypeForButton(button);
|
||||
|
||||
if (type == null) {
|
||||
return;
|
||||
} else {
|
||||
sorted = false;
|
||||
sortType = type;
|
||||
disableButton();
|
||||
}
|
||||
|
||||
setMods();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void disableButton() {
|
||||
for (GuiButton b : (List<GuiButton>) buttonList) {
|
||||
if (SortType.getTypeForButton(b) != null) {
|
||||
b.enabled = true;
|
||||
}
|
||||
if (b.id == sortType.buttonID) {
|
||||
b.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setMods() {
|
||||
List<ModContainer> mods = getMods();
|
||||
|
||||
ModContainer sel = getSelectedMod();
|
||||
boolean found = false;
|
||||
try {
|
||||
for (int i = 0; !found && i < mods.size(); i++) {
|
||||
if (sel == mods.get(i)) {
|
||||
_selected.setInt(this, i);
|
||||
found = true;
|
||||
private GuiSlotModList getGuiModList() {
|
||||
try {
|
||||
return (GuiSlotModList) _modList.get(this);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
_selected.setInt(this, -1);
|
||||
_selectedMod.set(this, null);
|
||||
}
|
||||
|
||||
_mods.set(this, getMods());
|
||||
sorted = false;
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
private GuiSlotModList getGuiModList() {
|
||||
try {
|
||||
return (GuiSlotModList) _modList.get(this);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
private int getGuiModListRight() {
|
||||
try {
|
||||
return _modListRight.getInt(getGuiModList());
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getGuiModListRight() {
|
||||
try {
|
||||
return _modListRight.getInt(getGuiModList());
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
private void setGuiModListBottom(int bottom) {
|
||||
try {
|
||||
_modListBottom.set(getGuiModList(), bottom);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setGuiModListBottom(int bottom) {
|
||||
try {
|
||||
_modListBottom.set(getGuiModList(), bottom);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
private int getGuiModListBottom() {
|
||||
try {
|
||||
return _modListBottom.getInt(getGuiModList());
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getGuiModListBottom() {
|
||||
try {
|
||||
return _modListBottom.getInt(getGuiModList());
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
private float getGuiModListScroll() {
|
||||
try {
|
||||
return _scrollDistance.getFloat(getGuiModList());
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float getGuiModListScroll() {
|
||||
try {
|
||||
return _scrollDistance.getFloat(getGuiModList());
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
private void setGuiModListScroll(float scroll) {
|
||||
try {
|
||||
_scrollDistance.setFloat(getGuiModList(), scroll);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setGuiModListScroll(float scroll) {
|
||||
try {
|
||||
_scrollDistance.setFloat(getGuiModList(), scroll);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<ModContainer> getMods() {
|
||||
try {
|
||||
return (List<ModContainer>) _modListMods.get(_modList.get(this));
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<ModContainer> getMods() {
|
||||
try {
|
||||
return (List<ModContainer>) _modListMods.get(_modList.get(this));
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
private int getListWidth() {
|
||||
try {
|
||||
return _listWidth.getInt(this);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getListWidth() {
|
||||
try {
|
||||
return _listWidth.getInt(this);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
private ModContainer getSelectedMod() {
|
||||
try {
|
||||
return (ModContainer) _selectedMod.get(this);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ModContainer getSelectedMod() {
|
||||
try {
|
||||
return (ModContainer) _selectedMod.get(this);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
private void setSelectedMod(ModContainer mod) {
|
||||
try {
|
||||
_selectedMod.set(this, mod);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setSelectedMod(ModContainer mod) {
|
||||
try {
|
||||
_selectedMod.set(this, mod);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import com.enderio.core.client.render.EnderWidget;
|
||||
|
||||
public class CheckBox extends ToggleButton {
|
||||
|
||||
public CheckBox(IGuiScreen gui, int id, int x, int y) {
|
||||
super(gui, id, x, y, EnderWidget.BUTTON, EnderWidget.BUTTON_CHECKED);
|
||||
}
|
||||
public CheckBox(IGuiScreen gui, int id, int x, int y) {
|
||||
super(gui, id, x, y, EnderWidget.BUTTON, EnderWidget.BUTTON_CHECKED);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,97 +12,97 @@ import com.enderio.core.common.util.DyeColor;
|
||||
|
||||
public class ColorButton extends IconButton {
|
||||
|
||||
private int colorIndex = 0;
|
||||
private int colorIndex = 0;
|
||||
|
||||
private String tooltipPrefix = "";
|
||||
private String tooltipPrefix = "";
|
||||
|
||||
public ColorButton(IGuiScreen gui, int id, int x, int y) {
|
||||
super(gui, id, x, y, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if (result) {
|
||||
nextColor();
|
||||
public ColorButton(IGuiScreen gui, int id, int x, int y) {
|
||||
super(gui, id, x, y, null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
boolean result = button == 1 && super.checkMousePress(mc, x, y);
|
||||
if (result) {
|
||||
prevColor();
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if (result) {
|
||||
nextColor();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getTooltipPrefix() {
|
||||
return tooltipPrefix;
|
||||
}
|
||||
|
||||
public void setToolTipHeading(String tooltipPrefix) {
|
||||
if (tooltipPrefix == null) {
|
||||
this.tooltipPrefix = "";
|
||||
} else {
|
||||
this.tooltipPrefix = tooltipPrefix;
|
||||
@Override
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
boolean result = button == 1 && super.checkMousePress(mc, x, y);
|
||||
if (result) {
|
||||
prevColor();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private void nextColor() {
|
||||
colorIndex++;
|
||||
if (colorIndex >= ItemDye.field_150923_a.length) {
|
||||
colorIndex = 0;
|
||||
public String getTooltipPrefix() {
|
||||
return tooltipPrefix;
|
||||
}
|
||||
setColorIndex(colorIndex);
|
||||
}
|
||||
|
||||
private void prevColor() {
|
||||
colorIndex--;
|
||||
if (colorIndex < 0) {
|
||||
colorIndex = ItemDye.field_150923_a.length - 1;
|
||||
public void setToolTipHeading(String tooltipPrefix) {
|
||||
if (tooltipPrefix == null) {
|
||||
this.tooltipPrefix = "";
|
||||
} else {
|
||||
this.tooltipPrefix = tooltipPrefix;
|
||||
}
|
||||
}
|
||||
setColorIndex(colorIndex);
|
||||
}
|
||||
|
||||
public int getColorIndex() {
|
||||
return colorIndex;
|
||||
}
|
||||
|
||||
public void setColorIndex(int colorIndex) {
|
||||
this.colorIndex = MathHelper.clamp_int(colorIndex, 0, ItemDye.field_150923_a.length - 1);
|
||||
String colStr = DyeColor.values()[colorIndex].getLocalisedName();
|
||||
if (tooltipPrefix != null && tooltipPrefix.length() > 0) {
|
||||
setToolTip(tooltipPrefix, colStr);
|
||||
} else {
|
||||
setToolTip(colStr);
|
||||
private void nextColor() {
|
||||
colorIndex++;
|
||||
if (colorIndex >= ItemDye.field_150923_a.length) {
|
||||
colorIndex = 0;
|
||||
}
|
||||
setColorIndex(colorIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
if (visible) {
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
|
||||
int x = xPosition + 2;
|
||||
int y = yPosition + 2;
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
int col = ItemDye.field_150922_c[colorIndex];
|
||||
tes.setColorOpaque_I(col);
|
||||
tes.addVertex(x, y + height - 4, zLevel);
|
||||
tes.addVertex(x + width - 4, y + height - 4, zLevel);
|
||||
tes.addVertex(x + width - 4, y + 0, zLevel);
|
||||
tes.addVertex(x, y + 0, zLevel);
|
||||
|
||||
tes.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
private void prevColor() {
|
||||
colorIndex--;
|
||||
if (colorIndex < 0) {
|
||||
colorIndex = ItemDye.field_150923_a.length - 1;
|
||||
}
|
||||
setColorIndex(colorIndex);
|
||||
}
|
||||
|
||||
public int getColorIndex() {
|
||||
return colorIndex;
|
||||
}
|
||||
|
||||
public void setColorIndex(int colorIndex) {
|
||||
this.colorIndex = MathHelper.clamp_int(colorIndex, 0, ItemDye.field_150923_a.length - 1);
|
||||
String colStr = DyeColor.values()[colorIndex].getLocalisedName();
|
||||
if (tooltipPrefix != null && tooltipPrefix.length() > 0) {
|
||||
setToolTip(tooltipPrefix, colStr);
|
||||
} else {
|
||||
setToolTip(colStr);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
if (visible) {
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
|
||||
int x = xPosition + 2;
|
||||
int y = yPosition + 2;
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
int col = ItemDye.field_150922_c[colorIndex];
|
||||
tes.setColorOpaque_I(col);
|
||||
tes.addVertex(x, y + height - 4, zLevel);
|
||||
tes.addVertex(x + width - 4, y + height - 4, zLevel);
|
||||
tes.addVertex(x + width - 4, y + 0, zLevel);
|
||||
tes.addVertex(x, y + 0, zLevel);
|
||||
|
||||
tes.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,79 +9,77 @@ import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import com.enderio.core.client.gui.button.CycleButton.ICycleEnum;
|
||||
|
||||
/**
|
||||
* A button which automatically parses enum constants and cycles between them
|
||||
* when clicked.
|
||||
* A button which automatically parses enum constants and cycles between them when clicked.
|
||||
*
|
||||
* @param <T>
|
||||
* The enum type for this button.
|
||||
* @param <T> The enum type for this button.
|
||||
*/
|
||||
public class CycleButton<T extends Enum<T> & ICycleEnum> extends IconButton {
|
||||
|
||||
public interface ICycleEnum {
|
||||
public interface ICycleEnum {
|
||||
|
||||
/**
|
||||
* @return The icon to display when the button has selected this mode.
|
||||
*/
|
||||
IWidgetIcon getIcon();
|
||||
/**
|
||||
* @return The icon to display when the button has selected this mode.
|
||||
*/
|
||||
IWidgetIcon getIcon();
|
||||
|
||||
/**
|
||||
* @return Localized tooltip lines.
|
||||
*/
|
||||
List<String> getTooltipLines();
|
||||
}
|
||||
|
||||
private final T[] modes;
|
||||
|
||||
private T mode;
|
||||
|
||||
public CycleButton(IGuiScreen gui, int id, int x, int y, Class<T> enumClass) {
|
||||
super(gui, id, x, y, null);
|
||||
modes = enumClass.getEnumConstants();
|
||||
setMode(modes[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if (result) {
|
||||
nextMode();
|
||||
/**
|
||||
* @return Localized tooltip lines.
|
||||
*/
|
||||
List<String> getTooltipLines();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
boolean result = button == 1 && super.checkMousePress(mc, x, y);
|
||||
if (result) {
|
||||
prevMode();
|
||||
private final T[] modes;
|
||||
|
||||
private T mode;
|
||||
|
||||
public CycleButton(IGuiScreen gui, int id, int x, int y, Class<T> enumClass) {
|
||||
super(gui, id, x, y, null);
|
||||
modes = enumClass.getEnumConstants();
|
||||
setMode(modes[0]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void nextMode() {
|
||||
setMode(modes[(mode.ordinal() + 1) % modes.length]);
|
||||
}
|
||||
|
||||
private void prevMode() {
|
||||
int ord = mode.ordinal() - 1;
|
||||
if (ord < 0) {
|
||||
ord = modes.length - 1;
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if (result) {
|
||||
nextMode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
setMode(modes[ord]);
|
||||
}
|
||||
|
||||
public T getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(T newMode) {
|
||||
if (mode == newMode) {
|
||||
return;
|
||||
@Override
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
boolean result = button == 1 && super.checkMousePress(mc, x, y);
|
||||
if (result) {
|
||||
prevMode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
mode = newMode;
|
||||
List<String> tooltip = mode.getTooltipLines();
|
||||
setToolTip(tooltip.toArray(new String[tooltip.size()]));
|
||||
|
||||
this.icon = mode.getIcon();
|
||||
}
|
||||
private void nextMode() {
|
||||
setMode(modes[(mode.ordinal() + 1) % modes.length]);
|
||||
}
|
||||
|
||||
private void prevMode() {
|
||||
int ord = mode.ordinal() - 1;
|
||||
if (ord < 0) {
|
||||
ord = modes.length - 1;
|
||||
}
|
||||
setMode(modes[ord]);
|
||||
}
|
||||
|
||||
public T getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(T newMode) {
|
||||
if (mode == newMode) {
|
||||
return;
|
||||
}
|
||||
mode = newMode;
|
||||
List<String> tooltip = mode.getTooltipLines();
|
||||
setToolTip(tooltip.toArray(new String[tooltip.size()]));
|
||||
|
||||
this.icon = mode.getIcon();
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@ package com.enderio.core.client.gui.button;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.enderio.core.api.client.gui.IHideable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import com.enderio.core.api.client.gui.IHideable;
|
||||
|
||||
public class GuiButtonHideable extends GuiButton implements IHideable {
|
||||
|
||||
public GuiButtonHideable(int buttonId, int x, int y, @Nonnull String buttonText) {
|
||||
|
||||
@@ -12,86 +12,94 @@ import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
public class IIconButton extends GuiButton {
|
||||
|
||||
public static final int DEFAULT_WIDTH = 24;
|
||||
public static final int HWIDTH = DEFAULT_WIDTH / 2;
|
||||
public static final int DEFAULT_HEIGHT = 24;
|
||||
public static final int HHEIGHT = DEFAULT_HEIGHT / 2;
|
||||
public static final int DEFAULT_WIDTH = 24;
|
||||
public static final int HWIDTH = DEFAULT_WIDTH / 2;
|
||||
public static final int DEFAULT_HEIGHT = 24;
|
||||
public static final int HHEIGHT = DEFAULT_HEIGHT / 2;
|
||||
|
||||
protected int hwidth;
|
||||
protected int hheight;
|
||||
protected int hwidth;
|
||||
protected int hheight;
|
||||
|
||||
protected IIcon icon;
|
||||
protected ResourceLocation texture;
|
||||
|
||||
public IIconButton(FontRenderer fr, int id, int x, int y, IIcon icon, ResourceLocation texture) {
|
||||
super(id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
|
||||
hwidth = HWIDTH;
|
||||
hheight = HHEIGHT;
|
||||
this.icon = icon;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
hwidth = width / 2;
|
||||
hheight = height / 2;
|
||||
}
|
||||
|
||||
public IIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(IIcon icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public ResourceLocation getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public void setTexture(ResourceLocation textureName) {
|
||||
this.texture = textureName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
|
||||
if (visible) {
|
||||
|
||||
RenderUtil.bindTexture("textures/gui/widgets.png");
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + width && par3 < this.yPosition + height;
|
||||
int hoverState = getHoverState(this.field_146123_n);
|
||||
|
||||
// x, y, u, v, width, height
|
||||
|
||||
// top half
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 46 + hoverState * 20, hwidth, hheight);
|
||||
drawTexturedModalRect(xPosition + hwidth, yPosition, 200 - hwidth, 46 + hoverState * 20, hwidth, hheight);
|
||||
|
||||
// bottom half
|
||||
drawTexturedModalRect(xPosition, yPosition + hheight, 0, 66 - hheight + (hoverState * 20), hwidth, hheight);
|
||||
drawTexturedModalRect(xPosition + hwidth, yPosition + hheight, 200 - hwidth, 66 - hheight + (hoverState * 20), hwidth, hheight);
|
||||
|
||||
mouseDragged(par1Minecraft, par2, par3);
|
||||
|
||||
if (icon != null && texture != null) {
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
RenderUtil.bindTexture(texture);
|
||||
int xLoc = xPosition + 2;
|
||||
int yLoc = yPosition + 2;
|
||||
drawTexturedModelRectFromIcon(xLoc, yLoc, icon, width - 4, height - 4);
|
||||
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
protected IIcon icon;
|
||||
protected ResourceLocation texture;
|
||||
|
||||
public IIconButton(FontRenderer fr, int id, int x, int y, IIcon icon, ResourceLocation texture) {
|
||||
super(id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
|
||||
hwidth = HWIDTH;
|
||||
hheight = HHEIGHT;
|
||||
this.icon = icon;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
hwidth = width / 2;
|
||||
hheight = height / 2;
|
||||
}
|
||||
|
||||
public IIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(IIcon icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public ResourceLocation getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public void setTexture(ResourceLocation textureName) {
|
||||
this.texture = textureName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
|
||||
if (visible) {
|
||||
|
||||
RenderUtil.bindTexture("textures/gui/widgets.png");
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition
|
||||
&& par2 < this.xPosition + width
|
||||
&& par3 < this.yPosition + height;
|
||||
int hoverState = getHoverState(this.field_146123_n);
|
||||
|
||||
// x, y, u, v, width, height
|
||||
|
||||
// top half
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 46 + hoverState * 20, hwidth, hheight);
|
||||
drawTexturedModalRect(xPosition + hwidth, yPosition, 200 - hwidth, 46 + hoverState * 20, hwidth, hheight);
|
||||
|
||||
// bottom half
|
||||
drawTexturedModalRect(xPosition, yPosition + hheight, 0, 66 - hheight + (hoverState * 20), hwidth, hheight);
|
||||
drawTexturedModalRect(
|
||||
xPosition + hwidth,
|
||||
yPosition + hheight,
|
||||
200 - hwidth,
|
||||
66 - hheight + (hoverState * 20),
|
||||
hwidth,
|
||||
hheight);
|
||||
|
||||
mouseDragged(par1Minecraft, par2, par3);
|
||||
|
||||
if (icon != null && texture != null) {
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
RenderUtil.bindTexture(texture);
|
||||
int xLoc = xPosition + 2;
|
||||
int yLoc = yPosition + 2;
|
||||
drawTexturedModelRectFromIcon(xLoc, yLoc, icon, width - 4, height - 4);
|
||||
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,118 +1,113 @@
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
import com.enderio.core.client.render.EnderWidget;
|
||||
|
||||
public class IconButton extends TooltipButton {
|
||||
|
||||
public static final int DEFAULT_WIDTH = 16;
|
||||
public static final int DEFAULT_HEIGHT = 16;
|
||||
public static final int DEFAULT_WIDTH = 16;
|
||||
public static final int DEFAULT_HEIGHT = 16;
|
||||
|
||||
protected IWidgetIcon icon;
|
||||
private int xOrigin;
|
||||
private int yOrigin;
|
||||
protected IWidgetIcon icon;
|
||||
private int xOrigin;
|
||||
private int yOrigin;
|
||||
|
||||
protected IGuiScreen gui;
|
||||
protected IGuiScreen gui;
|
||||
|
||||
private int marginY = 0;
|
||||
private int marginX = 0;
|
||||
|
||||
public IconButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon icon) {
|
||||
super(gui, id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
|
||||
this.gui = gui;
|
||||
this.icon = icon;
|
||||
this.xOrigin = x;
|
||||
this.yOrigin = y;
|
||||
}
|
||||
|
||||
public IconButton setIconMargin(int x, int y) {
|
||||
marginX = x;
|
||||
marginY = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IWidgetIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(IWidgetIcon icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to handle mouse clicks with other buttons than the left
|
||||
*
|
||||
* @param mc
|
||||
* The MC instance
|
||||
* @param x
|
||||
* X coordinate of mouse click
|
||||
* @param y
|
||||
* Y coordinate of mouse click
|
||||
* @param button
|
||||
* the mouse button - only called for button {@literal >}= 1
|
||||
* @return true if the mouse click is handled
|
||||
*/
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean checkMousePress(Minecraft mc, int x, int y) {
|
||||
// call super here so that we only get the area check
|
||||
return super.mousePressed(mc, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
updateTooltip(mc, mouseX, mouseY);
|
||||
if (isVisible()) {
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + width && mouseY < this.yPosition + height;
|
||||
int hoverState = getHoverState(this.field_146123_n);
|
||||
mouseDragged(mc, mouseX, mouseY);
|
||||
|
||||
IWidgetIcon background = getIconForHoverState(hoverState);
|
||||
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
|
||||
int x = xPosition;
|
||||
int y = yPosition;
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
background.getMap().render(background, x, y, width, height, 0, true);
|
||||
if (icon != null) {
|
||||
icon.getMap().render(icon, x + marginX, y + marginY, width - (2 * marginX), height - (2 * marginY), 0, true);
|
||||
}
|
||||
|
||||
GL11.glPopAttrib();
|
||||
private int marginY = 0;
|
||||
private int marginX = 0;
|
||||
|
||||
public IconButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon icon) {
|
||||
super(gui, id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
|
||||
this.gui = gui;
|
||||
this.icon = icon;
|
||||
this.xOrigin = x;
|
||||
this.yOrigin = y;
|
||||
}
|
||||
}
|
||||
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (hoverState == 0) {
|
||||
return EnderWidget.BUTTON_DISABLED;
|
||||
public IconButton setIconMargin(int x, int y) {
|
||||
marginX = x;
|
||||
marginY = y;
|
||||
return this;
|
||||
}
|
||||
if (hoverState == 2) {
|
||||
return EnderWidget.BUTTON_HIGHLIGHT;
|
||||
|
||||
public IWidgetIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(IWidgetIcon icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to handle mouse clicks with other buttons than the left
|
||||
*
|
||||
* @param mc The MC instance
|
||||
* @param x X coordinate of mouse click
|
||||
* @param y Y coordinate of mouse click
|
||||
* @param button the mouse button - only called for button {@literal >}= 1
|
||||
* @return true if the mouse click is handled
|
||||
*/
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean checkMousePress(Minecraft mc, int x, int y) {
|
||||
// call super here so that we only get the area check
|
||||
return super.mousePressed(mc, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
updateTooltip(mc, mouseX, mouseY);
|
||||
if (isVisible()) {
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition
|
||||
&& mouseX < this.xPosition + width
|
||||
&& mouseY < this.yPosition + height;
|
||||
int hoverState = getHoverState(this.field_146123_n);
|
||||
mouseDragged(mc, mouseX, mouseY);
|
||||
|
||||
IWidgetIcon background = getIconForHoverState(hoverState);
|
||||
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
|
||||
int x = xPosition;
|
||||
int y = yPosition;
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
background.getMap().render(background, x, y, width, height, 0, true);
|
||||
if (icon != null) {
|
||||
icon.getMap()
|
||||
.render(icon, x + marginX, y + marginY, width - (2 * marginX), height - (2 * marginY), 0, true);
|
||||
}
|
||||
|
||||
GL11.glPopAttrib();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (hoverState == 0) {
|
||||
return EnderWidget.BUTTON_DISABLED;
|
||||
}
|
||||
if (hoverState == 2) {
|
||||
return EnderWidget.BUTTON_HIGHLIGHT;
|
||||
}
|
||||
return EnderWidget.BUTTON;
|
||||
}
|
||||
return EnderWidget.BUTTON;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,28 +6,28 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class IconToggleButton extends IIconButton {
|
||||
|
||||
private boolean selected = false;
|
||||
private boolean selected = false;
|
||||
|
||||
public IconToggleButton(FontRenderer fr, int id, int x, int y, IIcon icon, ResourceLocation texture) {
|
||||
super(fr, id, x, y, icon, texture);
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHoverState(boolean par1) {
|
||||
int result = 1;
|
||||
if (!enabled || selected) {
|
||||
result = 0;
|
||||
} else if (par1) {
|
||||
result = 2;
|
||||
public IconToggleButton(FontRenderer fr, int id, int x, int y, IIcon icon, ResourceLocation texture) {
|
||||
super(fr, id, x, y, icon, texture);
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHoverState(boolean par1) {
|
||||
int result = 1;
|
||||
if (!enabled || selected) {
|
||||
result = 0;
|
||||
} else if (par1) {
|
||||
result = 2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package com.enderio.core.client.gui.button;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
|
||||
public class InvisibleButton extends TooltipButton {
|
||||
|
||||
private static final int DEFAULT_WIDTH = 8;
|
||||
|
||||
@@ -13,72 +13,80 @@ import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
public class ItemButton extends GuiButton {
|
||||
|
||||
public static final RenderItem ITEM_RENDERER = new RenderItem();
|
||||
public static final RenderItem ITEM_RENDERER = new RenderItem();
|
||||
|
||||
public static final int DEFAULT_WIDTH = 24;
|
||||
public static final int HWIDTH = DEFAULT_WIDTH / 2;
|
||||
public static final int DEFAULT_HEIGHT = 24;
|
||||
public static final int HHEIGHT = DEFAULT_HEIGHT / 2;
|
||||
public static final int DEFAULT_WIDTH = 24;
|
||||
public static final int HWIDTH = DEFAULT_WIDTH / 2;
|
||||
public static final int DEFAULT_HEIGHT = 24;
|
||||
public static final int HHEIGHT = DEFAULT_HEIGHT / 2;
|
||||
|
||||
private ItemStack item;
|
||||
private ItemStack item;
|
||||
|
||||
private FontRenderer fr;
|
||||
private FontRenderer fr;
|
||||
|
||||
protected int hwidth;
|
||||
protected int hheight;
|
||||
protected int hwidth;
|
||||
protected int hheight;
|
||||
|
||||
public ItemButton(FontRenderer fr, int id, int x, int y, Item item) {
|
||||
super(id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
|
||||
this.fr = fr;
|
||||
this.item = new ItemStack(item, 1, 0);
|
||||
hwidth = HWIDTH;
|
||||
hheight = HHEIGHT;
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
hwidth = width / 2;
|
||||
hheight = height / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
|
||||
if (visible) {
|
||||
|
||||
RenderUtil.bindTexture("textures/gui/widgets.png");
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + width && par3 < this.yPosition + height;
|
||||
int hoverState = this.getHoverState(this.field_146123_n);
|
||||
|
||||
// x, y, u, v, width, height
|
||||
|
||||
// top half
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 46 + hoverState * 20, hwidth, hheight);
|
||||
drawTexturedModalRect(xPosition + hwidth, yPosition, 200 - hwidth, 46 + hoverState * 20, hwidth, hheight);
|
||||
|
||||
// bottom half
|
||||
drawTexturedModalRect(xPosition, yPosition + hheight, 0, 66 - hheight + (hoverState * 20), hwidth, hheight);
|
||||
drawTexturedModalRect(xPosition + hwidth, yPosition + hheight, 200 - hwidth, 66 - hheight + (hoverState * 20), hwidth, hheight);
|
||||
|
||||
mouseDragged(par1Minecraft, par2, par3);
|
||||
|
||||
int l = 14737632;
|
||||
|
||||
if (!this.enabled) {
|
||||
l = -6250336;
|
||||
} else if (this.field_146123_n) {
|
||||
l = 16777120;
|
||||
}
|
||||
|
||||
int xLoc = xPosition + hwidth - 8;
|
||||
int yLoc = yPosition + hheight - 10;
|
||||
ITEM_RENDERER.renderItemIntoGUI(fr, par1Minecraft.renderEngine, item, xLoc, yLoc);
|
||||
public ItemButton(FontRenderer fr, int id, int x, int y, Item item) {
|
||||
super(id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
|
||||
this.fr = fr;
|
||||
this.item = new ItemStack(item, 1, 0);
|
||||
hwidth = HWIDTH;
|
||||
hheight = HHEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
hwidth = width / 2;
|
||||
hheight = height / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
|
||||
if (visible) {
|
||||
|
||||
RenderUtil.bindTexture("textures/gui/widgets.png");
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition
|
||||
&& par2 < this.xPosition + width
|
||||
&& par3 < this.yPosition + height;
|
||||
int hoverState = this.getHoverState(this.field_146123_n);
|
||||
|
||||
// x, y, u, v, width, height
|
||||
|
||||
// top half
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 46 + hoverState * 20, hwidth, hheight);
|
||||
drawTexturedModalRect(xPosition + hwidth, yPosition, 200 - hwidth, 46 + hoverState * 20, hwidth, hheight);
|
||||
|
||||
// bottom half
|
||||
drawTexturedModalRect(xPosition, yPosition + hheight, 0, 66 - hheight + (hoverState * 20), hwidth, hheight);
|
||||
drawTexturedModalRect(
|
||||
xPosition + hwidth,
|
||||
yPosition + hheight,
|
||||
200 - hwidth,
|
||||
66 - hheight + (hoverState * 20),
|
||||
hwidth,
|
||||
hheight);
|
||||
|
||||
mouseDragged(par1Minecraft, par2, par3);
|
||||
|
||||
int l = 14737632;
|
||||
|
||||
if (!this.enabled) {
|
||||
l = -6250336;
|
||||
} else if (this.field_146123_n) {
|
||||
l = 16777120;
|
||||
}
|
||||
|
||||
int xLoc = xPosition + hwidth - 8;
|
||||
int yLoc = yPosition + hheight - 10;
|
||||
ITEM_RENDERER.renderItemIntoGUI(fr, par1Minecraft.renderEngine, item, xLoc, yLoc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,42 +6,71 @@ import com.enderio.core.client.render.EnderWidget;
|
||||
|
||||
public class MultiIconButton extends IconButton {
|
||||
|
||||
private final IWidgetIcon unpressed;
|
||||
private final IWidgetIcon pressed;
|
||||
private final IWidgetIcon hover;
|
||||
private final IWidgetIcon unpressed;
|
||||
private final IWidgetIcon pressed;
|
||||
private final IWidgetIcon hover;
|
||||
|
||||
public MultiIconButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon unpressed, IWidgetIcon pressed, IWidgetIcon hover) {
|
||||
super(gui, id, x, y, null);
|
||||
this.unpressed = unpressed;
|
||||
this.pressed = pressed;
|
||||
this.hover = hover;
|
||||
setSize((int) unpressed.getWidth(), (int) unpressed.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (hoverState == 0) {
|
||||
return pressed;
|
||||
public MultiIconButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon unpressed, IWidgetIcon pressed,
|
||||
IWidgetIcon hover) {
|
||||
super(gui, id, x, y, null);
|
||||
this.unpressed = unpressed;
|
||||
this.pressed = pressed;
|
||||
this.hover = hover;
|
||||
setSize((int) unpressed.getWidth(), (int) unpressed.getHeight());
|
||||
}
|
||||
if (hoverState == 2) {
|
||||
return hover;
|
||||
|
||||
@Override
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (hoverState == 0) {
|
||||
return pressed;
|
||||
}
|
||||
if (hoverState == 2) {
|
||||
return hover;
|
||||
}
|
||||
return unpressed;
|
||||
}
|
||||
return unpressed;
|
||||
}
|
||||
|
||||
public static MultiIconButton createRightArrowButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(gui, id, x, y, EnderWidget.RIGHT_ARROW, EnderWidget.RIGHT_ARROW_PRESSED, EnderWidget.RIGHT_ARROW_HOVER);
|
||||
}
|
||||
public static MultiIconButton createRightArrowButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(
|
||||
gui,
|
||||
id,
|
||||
x,
|
||||
y,
|
||||
EnderWidget.RIGHT_ARROW,
|
||||
EnderWidget.RIGHT_ARROW_PRESSED,
|
||||
EnderWidget.RIGHT_ARROW_HOVER);
|
||||
}
|
||||
|
||||
public static MultiIconButton createLeftArrowButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(gui, id, x, y, EnderWidget.LEFT_ARROW, EnderWidget.LEFT_ARROW_PRESSED, EnderWidget.LEFT_ARROW_HOVER);
|
||||
}
|
||||
public static MultiIconButton createLeftArrowButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(
|
||||
gui,
|
||||
id,
|
||||
x,
|
||||
y,
|
||||
EnderWidget.LEFT_ARROW,
|
||||
EnderWidget.LEFT_ARROW_PRESSED,
|
||||
EnderWidget.LEFT_ARROW_HOVER);
|
||||
}
|
||||
|
||||
public static MultiIconButton createAddButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(gui, id, x, y, EnderWidget.ADD_BUT, EnderWidget.ADD_BUT_PRESSED, EnderWidget.ADD_BUT_HOVER);
|
||||
}
|
||||
public static MultiIconButton createAddButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(
|
||||
gui,
|
||||
id,
|
||||
x,
|
||||
y,
|
||||
EnderWidget.ADD_BUT,
|
||||
EnderWidget.ADD_BUT_PRESSED,
|
||||
EnderWidget.ADD_BUT_HOVER);
|
||||
}
|
||||
|
||||
public static MultiIconButton createMinusButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(gui, id, x, y, EnderWidget.MINUS_BUT, EnderWidget.MINUS_BUT_PRESSED, EnderWidget.MINUS_BUT_HOVER);
|
||||
}
|
||||
public static MultiIconButton createMinusButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(
|
||||
gui,
|
||||
id,
|
||||
x,
|
||||
y,
|
||||
EnderWidget.MINUS_BUT,
|
||||
EnderWidget.MINUS_BUT_PRESSED,
|
||||
EnderWidget.MINUS_BUT_HOVER);
|
||||
}
|
||||
}
|
||||
@@ -12,76 +12,76 @@ import com.google.common.collect.Lists;
|
||||
|
||||
public class ToggleButton extends IconButton {
|
||||
|
||||
private boolean selected;
|
||||
private final IWidgetIcon unselectedIcon;
|
||||
private final IWidgetIcon selectedIcon;
|
||||
private boolean selected;
|
||||
private final IWidgetIcon unselectedIcon;
|
||||
private final IWidgetIcon selectedIcon;
|
||||
|
||||
private GuiToolTip selectedTooltip, unselectedTooltip;
|
||||
private boolean paintSelectionBorder;
|
||||
private GuiToolTip selectedTooltip, unselectedTooltip;
|
||||
private boolean paintSelectionBorder;
|
||||
|
||||
public ToggleButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon unselectedIcon, IWidgetIcon selectedIcon) {
|
||||
super(gui, id, x, y, unselectedIcon);
|
||||
this.unselectedIcon = unselectedIcon;
|
||||
this.selectedIcon = selectedIcon;
|
||||
selected = false;
|
||||
paintSelectionBorder = true;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public ToggleButton setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
icon = selected ? selectedIcon : unselectedIcon;
|
||||
if (selected && selectedTooltip != null) {
|
||||
setToolTip(selectedTooltip);
|
||||
} else if (!selected && unselectedTooltip != null) {
|
||||
setToolTip(unselectedTooltip);
|
||||
public ToggleButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon unselectedIcon, IWidgetIcon selectedIcon) {
|
||||
super(gui, id, x, y, unselectedIcon);
|
||||
this.unselectedIcon = unselectedIcon;
|
||||
this.selectedIcon = selectedIcon;
|
||||
selected = false;
|
||||
paintSelectionBorder = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (!selected || !paintSelectionBorder) {
|
||||
return super.getIconForHoverState(hoverState);
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
if (hoverState == 0) {
|
||||
return EnderWidget.BUTTON_DISABLED;
|
||||
|
||||
public ToggleButton setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
icon = selected ? selectedIcon : unselectedIcon;
|
||||
if (selected && selectedTooltip != null) {
|
||||
setToolTip(selectedTooltip);
|
||||
} else if (!selected && unselectedTooltip != null) {
|
||||
setToolTip(unselectedTooltip);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
if (hoverState == 2) {
|
||||
return EnderWidget.BUTTON_DOWN_HIGHLIGHT;
|
||||
|
||||
@Override
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (!selected || !paintSelectionBorder) {
|
||||
return super.getIconForHoverState(hoverState);
|
||||
}
|
||||
if (hoverState == 0) {
|
||||
return EnderWidget.BUTTON_DISABLED;
|
||||
}
|
||||
if (hoverState == 2) {
|
||||
return EnderWidget.BUTTON_DOWN_HIGHLIGHT;
|
||||
}
|
||||
return EnderWidget.BUTTON_DOWN;
|
||||
}
|
||||
return EnderWidget.BUTTON_DOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
if (super.mousePressed(par1Minecraft, par2, par3)) {
|
||||
return toggleSelected();
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
if (super.mousePressed(par1Minecraft, par2, par3)) {
|
||||
return toggleSelected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean toggleSelected() {
|
||||
setSelected(!selected);
|
||||
return true;
|
||||
}
|
||||
protected boolean toggleSelected() {
|
||||
setSelected(!selected);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setSelectedToolTip(String... tt) {
|
||||
String[] combinedTooltip = ArrayUtils.addAll(toolTipText, tt);
|
||||
selectedTooltip = new GuiToolTip(getBounds(), Lists.newArrayList(combinedTooltip));
|
||||
setSelected(selected);
|
||||
}
|
||||
public void setSelectedToolTip(String... tt) {
|
||||
String[] combinedTooltip = ArrayUtils.addAll(toolTipText, tt);
|
||||
selectedTooltip = new GuiToolTip(getBounds(), Lists.newArrayList(combinedTooltip));
|
||||
setSelected(selected);
|
||||
}
|
||||
|
||||
public void setUnselectedToolTip(String... tt) {
|
||||
String[] combinedTooltip = ArrayUtils.addAll(toolTipText, tt);
|
||||
unselectedTooltip = new GuiToolTip(getBounds(), Lists.newArrayList(combinedTooltip));
|
||||
setSelected(selected);
|
||||
}
|
||||
public void setUnselectedToolTip(String... tt) {
|
||||
String[] combinedTooltip = ArrayUtils.addAll(toolTipText, tt);
|
||||
unselectedTooltip = new GuiToolTip(getBounds(), Lists.newArrayList(combinedTooltip));
|
||||
setSelected(selected);
|
||||
}
|
||||
|
||||
public void setPaintSelectedBorder(boolean b) {
|
||||
this.paintSelectionBorder = b;
|
||||
}
|
||||
public void setPaintSelectedBorder(boolean b) {
|
||||
this.paintSelectionBorder = b;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,11 @@ import java.awt.Rectangle;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class TooltipButton extends GuiButtonHideable {
|
||||
|
||||
protected int xOrigin;
|
||||
@@ -18,7 +18,8 @@ public class TooltipButton extends GuiButtonHideable {
|
||||
protected @Nullable String[] toolTipText;
|
||||
protected @Nullable GuiToolTip toolTip;
|
||||
|
||||
public TooltipButton(@Nonnull IGuiScreen gui, int id, int x, int y, int widthIn, int heightIn, @Nonnull String buttonText) {
|
||||
public TooltipButton(@Nonnull IGuiScreen gui, int id, int x, int y, int widthIn, int heightIn,
|
||||
@Nonnull String buttonText) {
|
||||
super(id, x, y, widthIn, heightIn, buttonText);
|
||||
this.gui = gui;
|
||||
this.xOrigin = x;
|
||||
|
||||
@@ -7,60 +7,59 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public class GhostBackgroundItemSlot extends GhostSlot {
|
||||
|
||||
private final ItemStack stack;
|
||||
private final Slot parent;
|
||||
private final ItemStack stack;
|
||||
private final Slot parent;
|
||||
|
||||
public GhostBackgroundItemSlot(ItemStack stack, int x, int y) {
|
||||
this.stack = stack;
|
||||
this.parent = null;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.grayOut = true;
|
||||
this.grayOutLevel = .75f;
|
||||
}
|
||||
public GhostBackgroundItemSlot(ItemStack stack, int x, int y) {
|
||||
this.stack = stack;
|
||||
this.parent = null;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.grayOut = true;
|
||||
this.grayOutLevel = .75f;
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(ItemStack stack, Slot parent) {
|
||||
this.stack = stack;
|
||||
this.parent = parent;
|
||||
this.x = parent.xDisplayPosition;
|
||||
this.y = parent.yDisplayPosition;
|
||||
this.grayOut = true;
|
||||
this.grayOutLevel = .75f;
|
||||
}
|
||||
public GhostBackgroundItemSlot(ItemStack stack, Slot parent) {
|
||||
this.stack = stack;
|
||||
this.parent = parent;
|
||||
this.x = parent.xDisplayPosition;
|
||||
this.y = parent.yDisplayPosition;
|
||||
this.grayOut = true;
|
||||
this.grayOutLevel = .75f;
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(Item item, int x, int y) {
|
||||
this(new ItemStack(item), x, y);
|
||||
}
|
||||
public GhostBackgroundItemSlot(Item item, int x, int y) {
|
||||
this(new ItemStack(item), x, y);
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(Block block, int x, int y) {
|
||||
this(new ItemStack(block), x, y);
|
||||
}
|
||||
public GhostBackgroundItemSlot(Block block, int x, int y) {
|
||||
this(new ItemStack(block), x, y);
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(Item item, Slot parent) {
|
||||
this(new ItemStack(item), parent);
|
||||
}
|
||||
public GhostBackgroundItemSlot(Item item, Slot parent) {
|
||||
this(new ItemStack(item), parent);
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(Block block, Slot parent) {
|
||||
this(new ItemStack(block), parent);
|
||||
}
|
||||
public GhostBackgroundItemSlot(Block block, Slot parent) {
|
||||
this(new ItemStack(block), parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(int mx, int my) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isMouseOver(int mx, int my) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack) {
|
||||
}
|
||||
@Override
|
||||
public void putStack(ItemStack stack) {}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return parent != null ? parent.xDisplayPosition >= 0 && parent.yDisplayPosition >= 0 : super.isVisible();
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return parent != null ? parent.xDisplayPosition >= 0 && parent.yDisplayPosition >= 0 : super.isVisible();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,62 +8,62 @@ import com.enderio.core.common.network.PacketGhostSlot;
|
||||
|
||||
public abstract class GhostSlot {
|
||||
|
||||
public TileEntityEnder te = null;
|
||||
public int slot = -1;
|
||||
public int x;
|
||||
public int y;
|
||||
public TileEntityEnder te = null;
|
||||
public int slot = -1;
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public boolean visible = true;
|
||||
public boolean grayOut = true;
|
||||
public float grayOutLevel = 0.5f;
|
||||
public boolean displayStdOverlay = false;
|
||||
public int stackSizeLimit = 1;
|
||||
public boolean visible = true;
|
||||
public boolean grayOut = true;
|
||||
public float grayOutLevel = 0.5f;
|
||||
public boolean displayStdOverlay = false;
|
||||
public int stackSizeLimit = 1;
|
||||
|
||||
public boolean isMouseOver(int mx, int my) {
|
||||
return mx >= x && mx < (x + 16) && my >= y && my < (y + 16);
|
||||
}
|
||||
|
||||
public abstract ItemStack getStack();
|
||||
|
||||
public void putStack(ItemStack stack) {
|
||||
if (te != null) {
|
||||
EnderPacketHandler.sendToServer(PacketGhostSlot.setGhostSlotContents(te, slot, stack));
|
||||
public boolean isMouseOver(int mx, int my) {
|
||||
return mx >= x && mx < (x + 16) && my >= y && my < (y + 16);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the slot be displayed at all?
|
||||
*/
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
public abstract ItemStack getStack();
|
||||
|
||||
/**
|
||||
* Should the slot be grayed out?
|
||||
*/
|
||||
public boolean shouldGrayOut() {
|
||||
return grayOut;
|
||||
}
|
||||
public void putStack(ItemStack stack) {
|
||||
if (te != null) {
|
||||
EnderPacketHandler.sendToServer(PacketGhostSlot.setGhostSlotContents(te, slot, stack));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If it should be grayed out, how far? (1=no graying, 0=fully invisible)
|
||||
*/
|
||||
public float getGrayOutLevel() {
|
||||
return grayOutLevel;
|
||||
}
|
||||
/**
|
||||
* Should the slot be displayed at all?
|
||||
*/
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the items in the slot have their standard overlay (stacksize)?
|
||||
*/
|
||||
public boolean shouldDisplayStdOverlay() {
|
||||
return displayStdOverlay;
|
||||
}
|
||||
/**
|
||||
* Should the slot be grayed out?
|
||||
*/
|
||||
public boolean shouldGrayOut() {
|
||||
return grayOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the stack size? (Enable the standard overlay if this is not 1.)
|
||||
*/
|
||||
public int getStackSizeLimit() {
|
||||
return stackSizeLimit;
|
||||
}
|
||||
/**
|
||||
* If it should be grayed out, how far? (1=no graying, 0=fully invisible)
|
||||
*/
|
||||
public float getGrayOutLevel() {
|
||||
return grayOutLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the items in the slot have their standard overlay (stacksize)?
|
||||
*/
|
||||
public boolean shouldDisplayStdOverlay() {
|
||||
return displayStdOverlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the stack size? (Enable the standard overlay if this is not 1.)
|
||||
*/
|
||||
public int getStackSizeLimit() {
|
||||
return stackSizeLimit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,395 +16,398 @@ import com.enderio.core.api.client.gui.ListSelectionListener;
|
||||
|
||||
public abstract class GuiScrollableList<T> {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
protected int originX;
|
||||
protected int originY;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int minY;
|
||||
protected int maxY;
|
||||
protected int minX;
|
||||
protected int maxX;
|
||||
protected int originX;
|
||||
protected int originY;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int minY;
|
||||
protected int maxY;
|
||||
protected int minX;
|
||||
protected int maxX;
|
||||
|
||||
protected final int slotHeight;
|
||||
protected final int slotHeight;
|
||||
|
||||
private int scrollUpButtonID;
|
||||
private int scrollUpButtonID;
|
||||
|
||||
private int scrollDownButtonID;
|
||||
private int scrollDownButtonID;
|
||||
|
||||
protected int mouseX;
|
||||
protected int mouseX;
|
||||
|
||||
protected int mouseY;
|
||||
protected int mouseY;
|
||||
|
||||
private float initialClickY = -2.0F;
|
||||
private float initialClickY = -2.0F;
|
||||
|
||||
private float scrollMultiplier;
|
||||
private float scrollMultiplier;
|
||||
|
||||
private float amountScrolled;
|
||||
private float amountScrolled;
|
||||
|
||||
protected int selectedIndex = -1;
|
||||
protected int selectedIndex = -1;
|
||||
|
||||
private long lastClickedTime;
|
||||
private long lastClickedTime;
|
||||
|
||||
private boolean showSelectionBox = true;
|
||||
private boolean showSelectionBox = true;
|
||||
|
||||
protected int margin = 4;
|
||||
protected int margin = 4;
|
||||
|
||||
protected List<ListSelectionListener<T>> listeners = new CopyOnWriteArrayList<ListSelectionListener<T>>();
|
||||
protected List<ListSelectionListener<T>> listeners = new CopyOnWriteArrayList<ListSelectionListener<T>>();
|
||||
|
||||
public GuiScrollableList(int width, int height, int originX, int originY, int slotHeight) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.originX = originX;
|
||||
this.originY = originY;
|
||||
this.slotHeight = slotHeight;
|
||||
public GuiScrollableList(int width, int height, int originX, int originY, int slotHeight) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.originX = originX;
|
||||
this.originY = originY;
|
||||
this.slotHeight = slotHeight;
|
||||
|
||||
minY = originY;
|
||||
maxY = minY + height;
|
||||
minX = originX;
|
||||
maxX = minX + width;
|
||||
}
|
||||
|
||||
public void onGuiInit(IGuiScreen gui) {
|
||||
minY = originY + gui.getGuiTop();
|
||||
maxY = minY + height;
|
||||
minX = originX + gui.getGuiLeft();
|
||||
maxX = minX + width;
|
||||
}
|
||||
|
||||
public void addSelectionListener(ListSelectionListener<T> listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeSelectionListener(ListSelectionListener<T> listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public T getSelectedElement() {
|
||||
return getElementAt(selectedIndex);
|
||||
}
|
||||
|
||||
public void setSelection(T selection) {
|
||||
setSelection(getIndexOf(selection));
|
||||
}
|
||||
|
||||
public void setSelection(int index) {
|
||||
if (index == selectedIndex) {
|
||||
return;
|
||||
minY = originY;
|
||||
maxY = minY + height;
|
||||
minX = originX;
|
||||
maxX = minX + width;
|
||||
}
|
||||
selectedIndex = index;
|
||||
for (ListSelectionListener<T> listener : listeners) {
|
||||
listener.selectionChanged(this, selectedIndex);
|
||||
|
||||
public void onGuiInit(IGuiScreen gui) {
|
||||
minY = originY + gui.getGuiTop();
|
||||
maxY = minY + height;
|
||||
minX = originX + gui.getGuiLeft();
|
||||
maxX = minX + width;
|
||||
}
|
||||
}
|
||||
|
||||
public int getIndexOf(T element) {
|
||||
if (element == null) {
|
||||
return -1;
|
||||
public void addSelectionListener(ListSelectionListener<T> listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
for (int i = 0; i < getNumElements(); i++) {
|
||||
if (element.equals(getElementAt(i))) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public void removeSelectionListener(ListSelectionListener<T> listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public abstract T getElementAt(int index);
|
||||
|
||||
public abstract int getNumElements();
|
||||
|
||||
protected abstract void drawElement(int elementIndex, int x, int y, int height, Tessellator tessellator);
|
||||
|
||||
protected boolean elementClicked(int elementIndex, boolean doubleClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setShowSelectionBox(boolean val) {
|
||||
showSelectionBox = val;
|
||||
}
|
||||
|
||||
protected int getContentHeight() {
|
||||
return getNumElements() * slotHeight;
|
||||
}
|
||||
|
||||
public void setScrollButtonIds(int scrollUpButtonID, int scrollDownButtonID) {
|
||||
this.scrollUpButtonID = scrollUpButtonID;
|
||||
this.scrollDownButtonID = scrollDownButtonID;
|
||||
}
|
||||
|
||||
private void clampScrollToBounds() {
|
||||
int i = getContentOverhang();
|
||||
if (i < 0) {
|
||||
i *= -1;
|
||||
public T getSelectedElement() {
|
||||
return getElementAt(selectedIndex);
|
||||
}
|
||||
if (amountScrolled < 0.0F) {
|
||||
amountScrolled = 0.0F;
|
||||
}
|
||||
if (amountScrolled > i) {
|
||||
amountScrolled = i;
|
||||
}
|
||||
}
|
||||
|
||||
public int getContentOverhang() {
|
||||
return getContentHeight() - (height - margin);
|
||||
}
|
||||
public void setSelection(T selection) {
|
||||
setSelection(getIndexOf(selection));
|
||||
}
|
||||
|
||||
public void setSelection(int index) {
|
||||
if (index == selectedIndex) {
|
||||
return;
|
||||
}
|
||||
selectedIndex = index;
|
||||
for (ListSelectionListener<T> listener : listeners) {
|
||||
listener.selectionChanged(this, selectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public int getIndexOf(T element) {
|
||||
if (element == null) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < getNumElements(); i++) {
|
||||
if (element.equals(getElementAt(i))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public abstract T getElementAt(int index);
|
||||
|
||||
public abstract int getNumElements();
|
||||
|
||||
protected abstract void drawElement(int elementIndex, int x, int y, int height, Tessellator tessellator);
|
||||
|
||||
protected boolean elementClicked(int elementIndex, boolean doubleClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setShowSelectionBox(boolean val) {
|
||||
showSelectionBox = val;
|
||||
}
|
||||
|
||||
protected int getContentHeight() {
|
||||
return getNumElements() * slotHeight;
|
||||
}
|
||||
|
||||
public void setScrollButtonIds(int scrollUpButtonID, int scrollDownButtonID) {
|
||||
this.scrollUpButtonID = scrollUpButtonID;
|
||||
this.scrollDownButtonID = scrollDownButtonID;
|
||||
}
|
||||
|
||||
private void clampScrollToBounds() {
|
||||
int i = getContentOverhang();
|
||||
if (i < 0) {
|
||||
i *= -1;
|
||||
}
|
||||
if (amountScrolled < 0.0F) {
|
||||
amountScrolled = 0.0F;
|
||||
}
|
||||
if (amountScrolled > i) {
|
||||
amountScrolled = i;
|
||||
}
|
||||
}
|
||||
|
||||
public int getContentOverhang() {
|
||||
return getContentHeight() - (height - margin);
|
||||
}
|
||||
|
||||
public void actionPerformed(GuiButton b) {
|
||||
if (b.enabled) {
|
||||
if (b.id == scrollUpButtonID) {
|
||||
amountScrolled -= slotHeight * 2 / 3;
|
||||
initialClickY = -2.0F;
|
||||
clampScrollToBounds();
|
||||
} else if (b.id == scrollDownButtonID) {
|
||||
amountScrolled += slotHeight * 2 / 3;
|
||||
initialClickY = -2.0F;
|
||||
clampScrollToBounds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* draws the slot to the screen, pass in mouse's current x and y and partial ticks
|
||||
*/
|
||||
public void drawScreen(int mX, int mY, float partialTick) {
|
||||
this.mouseX = mX;
|
||||
this.mouseY = mY;
|
||||
|
||||
processMouseEvents();
|
||||
|
||||
public void actionPerformed(GuiButton b) {
|
||||
if (b.enabled) {
|
||||
if (b.id == scrollUpButtonID) {
|
||||
amountScrolled -= slotHeight * 2 / 3;
|
||||
initialClickY = -2.0F;
|
||||
clampScrollToBounds();
|
||||
} else if (b.id == scrollDownButtonID) {
|
||||
amountScrolled += slotHeight * 2 / 3;
|
||||
initialClickY = -2.0F;
|
||||
clampScrollToBounds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* draws the slot to the screen, pass in mouse's current x and y and partial
|
||||
* ticks
|
||||
*/
|
||||
public void drawScreen(int mX, int mY, float partialTick) {
|
||||
this.mouseX = mX;
|
||||
this.mouseY = mY;
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_FOG);
|
||||
|
||||
processMouseEvents();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int sx = minX * sr.getScaleFactor();
|
||||
int sw = width * sr.getScaleFactor();
|
||||
int sy = mc.displayHeight - (maxY * sr.getScaleFactor());
|
||||
int sh = height * sr.getScaleFactor();
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(sx, sy, sw, sh);
|
||||
|
||||
clampScrollToBounds();
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
drawContainerBackground(tessellator);
|
||||
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_FOG);
|
||||
int contentYOffset = this.minY + margin - (int) this.amountScrolled;
|
||||
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int sx = minX * sr.getScaleFactor();
|
||||
int sw = width * sr.getScaleFactor();
|
||||
int sy = mc.displayHeight - (maxY * sr.getScaleFactor());
|
||||
int sh = height * sr.getScaleFactor();
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(sx, sy, sw, sh);
|
||||
for (int i = 0; i < getNumElements(); ++i) {
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
drawContainerBackground(tessellator);
|
||||
int elementY = contentYOffset + i * this.slotHeight;
|
||||
int slotHeight = this.slotHeight - margin;
|
||||
|
||||
int contentYOffset = this.minY + margin - (int) this.amountScrolled;
|
||||
if (elementY <= maxY && elementY + slotHeight >= minY) {
|
||||
|
||||
for (int i = 0; i < getNumElements(); ++i) {
|
||||
if (showSelectionBox && i == selectedIndex) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorOpaque_I(8421504);
|
||||
tessellator.addVertexWithUV(minX, elementY + slotHeight + 2, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(maxX, elementY + slotHeight + 2, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(maxX, elementY - 2, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(minX, elementY - 2, 0.0D, 0.0D, 0.0D);
|
||||
tessellator.setColorOpaque_I(0);
|
||||
tessellator.addVertexWithUV(minX + 1, elementY + slotHeight + 1, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(maxX - 1, elementY + slotHeight + 1, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(maxX - 1, elementY - 1, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(minX + 1, elementY - 1, 0.0D, 0.0D, 0.0D);
|
||||
tessellator.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
int elementY = contentYOffset + i * this.slotHeight;
|
||||
int slotHeight = this.slotHeight - margin;
|
||||
|
||||
if (elementY <= maxY && elementY + slotHeight >= minY) {
|
||||
|
||||
if (showSelectionBox && i == selectedIndex) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorOpaque_I(8421504);
|
||||
tessellator.addVertexWithUV(minX, elementY + slotHeight + 2, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(maxX, elementY + slotHeight + 2, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(maxX, elementY - 2, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(minX, elementY - 2, 0.0D, 0.0D, 0.0D);
|
||||
tessellator.setColorOpaque_I(0);
|
||||
tessellator.addVertexWithUV(minX + 1, elementY + slotHeight + 1, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(maxX - 1, elementY + slotHeight + 1, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(maxX - 1, elementY - 1, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(minX + 1, elementY - 1, 0.0D, 0.0D, 0.0D);
|
||||
tessellator.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
drawElement(i, minX, elementY, slotHeight, tessellator);
|
||||
}
|
||||
}
|
||||
|
||||
drawElement(i, minX, elementY, slotHeight, tessellator);
|
||||
}
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_I(0, 0);
|
||||
tessellator.addVertexWithUV(this.minX, this.minY + margin, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(this.maxX, this.minY + margin, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.setColorRGBA_I(0, 255);
|
||||
tessellator.addVertexWithUV(this.maxX, this.minY, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(this.minX, this.minY, 0.0D, 0.0D, 0.0D);
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_I(0, 255);
|
||||
tessellator.addVertexWithUV(this.minX, this.maxY, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(this.maxX, this.maxY, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.setColorRGBA_I(0, 0);
|
||||
tessellator.addVertexWithUV(this.maxX, this.maxY - margin, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(this.minX, this.maxY - margin, 0.0D, 0.0D, 0.0D);
|
||||
tessellator.draw();
|
||||
|
||||
renderScrollBar(tessellator);
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
protected void renderScrollBar(Tessellator tessellator) {
|
||||
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
int contentHeightOverBounds = getContentOverhang();
|
||||
if (contentHeightOverBounds > 0) {
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_I(0, 0);
|
||||
tessellator.addVertexWithUV(this.minX, this.minY + margin, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(this.maxX, this.minY + margin, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.setColorRGBA_I(0, 255);
|
||||
tessellator.addVertexWithUV(this.maxX, this.minY, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(this.minX, this.minY, 0.0D, 0.0D, 0.0D);
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_I(0, 255);
|
||||
tessellator.addVertexWithUV(this.minX, this.maxY, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(this.maxX, this.maxY, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.setColorRGBA_I(0, 0);
|
||||
tessellator.addVertexWithUV(this.maxX, this.maxY - margin, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(this.minX, this.maxY - margin, 0.0D, 0.0D, 0.0D);
|
||||
tessellator.draw();
|
||||
int clear = (maxY - minY) * (maxY - minY) / getContentHeight();
|
||||
|
||||
renderScrollBar(tessellator);
|
||||
if (clear < 32) {
|
||||
clear = 32;
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
if (clear > maxY - minY - 8) {
|
||||
clear = maxY - minY - 8;
|
||||
}
|
||||
|
||||
protected void renderScrollBar(Tessellator tessellator) {
|
||||
int y = (int) this.amountScrolled * (maxY - minY - clear) / contentHeightOverBounds + minY;
|
||||
if (y < minY) {
|
||||
y = minY;
|
||||
}
|
||||
|
||||
int contentHeightOverBounds = getContentOverhang();
|
||||
if (contentHeightOverBounds > 0) {
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
int scrollBarMinX = getScrollBarX();
|
||||
int scrollBarMaxX = scrollBarMinX + 6;
|
||||
tessellator.startDrawingQuads();
|
||||
|
||||
int clear = (maxY - minY) * (maxY - minY) / getContentHeight();
|
||||
tessellator.setColorRGBA_I(0, 255);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, maxY, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMaxX, maxY, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMaxX, minY, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, minY, 0.0D, 0.0D, 0.0D);
|
||||
|
||||
if (clear < 32) {
|
||||
clear = 32;
|
||||
}
|
||||
tessellator.setColorRGBA_F(0.3f, 0.3f, 0.3f, 1);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, (y + clear), 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMaxX, (y + clear), 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMaxX, y, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, y, 0.0D, 0.0D, 0.0D);
|
||||
|
||||
if (clear > maxY - minY - 8) {
|
||||
clear = maxY - minY - 8;
|
||||
}
|
||||
tessellator.setColorRGBA_F(0.7f, 0.7f, 0.7f, 1);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, (y + clear - 1), 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV((scrollBarMaxX - 1), (y + clear - 1), 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV((scrollBarMaxX - 1), y, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, y, 0.0D, 0.0D, 0.0D);
|
||||
|
||||
int y = (int) this.amountScrolled * (maxY - minY - clear) / contentHeightOverBounds + minY;
|
||||
if (y < minY) {
|
||||
y = minY;
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
int scrollBarMinX = getScrollBarX();
|
||||
int scrollBarMaxX = scrollBarMinX + 6;
|
||||
tessellator.startDrawingQuads();
|
||||
|
||||
tessellator.setColorRGBA_I(0, 255);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, maxY, 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMaxX, maxY, 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMaxX, minY, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, minY, 0.0D, 0.0D, 0.0D);
|
||||
|
||||
tessellator.setColorRGBA_F(0.3f, 0.3f, 0.3f, 1);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, (y + clear), 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMaxX, (y + clear), 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMaxX, y, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, y, 0.0D, 0.0D, 0.0D);
|
||||
|
||||
tessellator.setColorRGBA_F(0.7f, 0.7f, 0.7f, 1);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, (y + clear - 1), 0.0D, 0.0D, 1.0D);
|
||||
tessellator.addVertexWithUV((scrollBarMaxX - 1), (y + clear - 1), 0.0D, 1.0D, 1.0D);
|
||||
tessellator.addVertexWithUV((scrollBarMaxX - 1), y, 0.0D, 1.0D, 0.0D);
|
||||
tessellator.addVertexWithUV(scrollBarMinX, y, 0.0D, 0.0D, 0.0D);
|
||||
|
||||
tessellator.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
|
||||
private void processMouseEvents() {
|
||||
if (Mouse.isButtonDown(0)) {
|
||||
processMouseBown();
|
||||
} else {
|
||||
while (!mc.gameSettings.touchscreen && Mouse.next()) {
|
||||
|
||||
int mouseWheelDelta = Mouse.getEventDWheel();
|
||||
|
||||
if (mouseWheelDelta != 0) {
|
||||
if (mouseWheelDelta > 0) {
|
||||
mouseWheelDelta = -1;
|
||||
} else if (mouseWheelDelta < 0) {
|
||||
mouseWheelDelta = 1;
|
||||
}
|
||||
amountScrolled += mouseWheelDelta * slotHeight / 2;
|
||||
tessellator.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
initialClickY = -1.0F;
|
||||
}
|
||||
}
|
||||
|
||||
private void processMouseBown() {
|
||||
int contentHeightOverBounds;
|
||||
if (initialClickY == -1.0F) {
|
||||
|
||||
if (mouseY >= minY && mouseY <= maxY && mouseX >= minX && mouseX <= maxX + 6) {
|
||||
|
||||
boolean clickInBounds = true;
|
||||
|
||||
int y = mouseY - minY + (int) amountScrolled - margin;
|
||||
int mouseOverElement = y / slotHeight;
|
||||
|
||||
if (mouseX >= minX && mouseX <= maxX && mouseOverElement >= 0 && y >= 0 && mouseOverElement < getNumElements()) {
|
||||
boolean doubleClick = mouseOverElement == selectedIndex && Minecraft.getSystemTime() - lastClickedTime < 250L;
|
||||
if (elementClicked(mouseOverElement, doubleClick)) {
|
||||
setSelection(mouseOverElement);
|
||||
}
|
||||
lastClickedTime = Minecraft.getSystemTime();
|
||||
|
||||
} else if (mouseX >= minX && mouseX <= maxX && y < 0) {
|
||||
clickInBounds = false;
|
||||
}
|
||||
|
||||
int scrollBarMinX = getScrollBarX();
|
||||
int scrollBarMaxX = scrollBarMinX + 6;
|
||||
if (mouseX >= scrollBarMinX && mouseX <= scrollBarMaxX) {
|
||||
|
||||
scrollMultiplier = -1.0F;
|
||||
contentHeightOverBounds = getContentOverhang();
|
||||
|
||||
if (contentHeightOverBounds < 1) {
|
||||
contentHeightOverBounds = 1;
|
||||
}
|
||||
|
||||
int empty = (int) ((float) ((maxY - minY) * (maxY - minY)) / (float) getContentHeight());
|
||||
if (empty < 32) {
|
||||
empty = 32;
|
||||
}
|
||||
if (empty > maxY - minY - 8) {
|
||||
empty = maxY - minY - 8;
|
||||
}
|
||||
scrollMultiplier /= (float) (maxY - minY - empty) / (float) contentHeightOverBounds;
|
||||
|
||||
private void processMouseEvents() {
|
||||
if (Mouse.isButtonDown(0)) {
|
||||
processMouseBown();
|
||||
} else {
|
||||
scrollMultiplier = 1.0F;
|
||||
while (!mc.gameSettings.touchscreen && Mouse.next()) {
|
||||
|
||||
int mouseWheelDelta = Mouse.getEventDWheel();
|
||||
|
||||
if (mouseWheelDelta != 0) {
|
||||
if (mouseWheelDelta > 0) {
|
||||
mouseWheelDelta = -1;
|
||||
} else if (mouseWheelDelta < 0) {
|
||||
mouseWheelDelta = 1;
|
||||
}
|
||||
amountScrolled += mouseWheelDelta * slotHeight / 2;
|
||||
}
|
||||
}
|
||||
initialClickY = -1.0F;
|
||||
}
|
||||
|
||||
if (clickInBounds) {
|
||||
initialClickY = mouseY;
|
||||
} else {
|
||||
initialClickY = -2.0F;
|
||||
}
|
||||
|
||||
} else {
|
||||
initialClickY = -2.0F;
|
||||
}
|
||||
|
||||
} else if (initialClickY >= 0.0F) {
|
||||
// Scrolling
|
||||
amountScrolled -= (mouseY - initialClickY) * scrollMultiplier;
|
||||
initialClickY = mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getScrollBarX() {
|
||||
return minX + width;
|
||||
}
|
||||
private void processMouseBown() {
|
||||
int contentHeightOverBounds;
|
||||
if (initialClickY == -1.0F) {
|
||||
|
||||
protected void drawContainerBackground(Tessellator tess) {
|
||||
if (mouseY >= minY && mouseY <= maxY && mouseX >= minX && mouseX <= maxX + 6) {
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorOpaque_I(2105376);
|
||||
tess.addVertex(minX, maxY, 0.0D);
|
||||
tess.addVertex(maxX, maxY, 0.0D);
|
||||
tess.addVertex(maxX, minY, 0.0D);
|
||||
tess.addVertex(minX, minY, 0.0D);
|
||||
tess.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
boolean clickInBounds = true;
|
||||
|
||||
}
|
||||
int y = mouseY - minY + (int) amountScrolled - margin;
|
||||
int mouseOverElement = y / slotHeight;
|
||||
|
||||
if (mouseX >= minX && mouseX <= maxX
|
||||
&& mouseOverElement >= 0
|
||||
&& y >= 0
|
||||
&& mouseOverElement < getNumElements()) {
|
||||
boolean doubleClick = mouseOverElement == selectedIndex
|
||||
&& Minecraft.getSystemTime() - lastClickedTime < 250L;
|
||||
if (elementClicked(mouseOverElement, doubleClick)) {
|
||||
setSelection(mouseOverElement);
|
||||
}
|
||||
lastClickedTime = Minecraft.getSystemTime();
|
||||
|
||||
} else if (mouseX >= minX && mouseX <= maxX && y < 0) {
|
||||
clickInBounds = false;
|
||||
}
|
||||
|
||||
int scrollBarMinX = getScrollBarX();
|
||||
int scrollBarMaxX = scrollBarMinX + 6;
|
||||
if (mouseX >= scrollBarMinX && mouseX <= scrollBarMaxX) {
|
||||
|
||||
scrollMultiplier = -1.0F;
|
||||
contentHeightOverBounds = getContentOverhang();
|
||||
|
||||
if (contentHeightOverBounds < 1) {
|
||||
contentHeightOverBounds = 1;
|
||||
}
|
||||
|
||||
int empty = (int) ((float) ((maxY - minY) * (maxY - minY)) / (float) getContentHeight());
|
||||
if (empty < 32) {
|
||||
empty = 32;
|
||||
}
|
||||
if (empty > maxY - minY - 8) {
|
||||
empty = maxY - minY - 8;
|
||||
}
|
||||
scrollMultiplier /= (float) (maxY - minY - empty) / (float) contentHeightOverBounds;
|
||||
|
||||
} else {
|
||||
scrollMultiplier = 1.0F;
|
||||
}
|
||||
|
||||
if (clickInBounds) {
|
||||
initialClickY = mouseY;
|
||||
} else {
|
||||
initialClickY = -2.0F;
|
||||
}
|
||||
|
||||
} else {
|
||||
initialClickY = -2.0F;
|
||||
}
|
||||
|
||||
} else if (initialClickY >= 0.0F) {
|
||||
// Scrolling
|
||||
amountScrolled -= (mouseY - initialClickY) * scrollMultiplier;
|
||||
initialClickY = mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getScrollBarX() {
|
||||
return minX + width;
|
||||
}
|
||||
|
||||
protected void drawContainerBackground(Tessellator tess) {
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorOpaque_I(2105376);
|
||||
tess.addVertex(minX, maxY, 0.0D);
|
||||
tess.addVertex(maxX, maxY, 0.0D);
|
||||
tess.addVertex(maxX, minY, 0.0D);
|
||||
tess.addVertex(minX, minY, 0.0D);
|
||||
tess.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,107 +1,106 @@
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import com.enderio.core.api.client.gui.IHideable;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.enderio.core.api.client.gui.IHideable;
|
||||
|
||||
public class GuiToolTip implements IHideable {
|
||||
|
||||
private static final long DELAY = 0;
|
||||
private static final long DELAY = 0;
|
||||
|
||||
protected Rectangle bounds;
|
||||
protected Rectangle bounds;
|
||||
|
||||
private long mouseOverStart;
|
||||
private long mouseOverStart;
|
||||
|
||||
protected final List<String> text;
|
||||
protected final List<String> text;
|
||||
|
||||
private int lastMouseX = -1;
|
||||
private int lastMouseX = -1;
|
||||
|
||||
private int lastMouseY = -1;
|
||||
private int lastMouseY = -1;
|
||||
|
||||
private boolean visible = true;
|
||||
private boolean visible = true;
|
||||
|
||||
public GuiToolTip(Rectangle bounds, String... lines) {
|
||||
this.bounds = bounds;
|
||||
if (lines != null) {
|
||||
text = new ArrayList<String>(lines.length);
|
||||
for (String line : lines) {
|
||||
text.add(line);
|
||||
}
|
||||
} else {
|
||||
text = new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
|
||||
public GuiToolTip(Rectangle bounds, List<String> lines) {
|
||||
this.bounds = bounds;
|
||||
if (lines == null) {
|
||||
text = new ArrayList<String>();
|
||||
} else {
|
||||
text = new ArrayList<String>(lines);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public Rectangle getBounds() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public void setBounds(Rectangle bounds) {
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
public void onTick(int mouseX, int mouseY) {
|
||||
if (lastMouseX != mouseX || lastMouseY != mouseY) {
|
||||
mouseOverStart = 0;
|
||||
public GuiToolTip(Rectangle bounds, String... lines) {
|
||||
this.bounds = bounds;
|
||||
if (lines != null) {
|
||||
text = new ArrayList<String>(lines.length);
|
||||
for (String line : lines) {
|
||||
text.add(line);
|
||||
}
|
||||
} else {
|
||||
text = new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
|
||||
if (bounds.contains(mouseX, mouseY)) {
|
||||
|
||||
if (mouseOverStart == 0) {
|
||||
mouseOverStart = System.currentTimeMillis();
|
||||
}
|
||||
} else {
|
||||
mouseOverStart = 0;
|
||||
public GuiToolTip(Rectangle bounds, List<String> lines) {
|
||||
this.bounds = bounds;
|
||||
if (lines == null) {
|
||||
text = new ArrayList<String>();
|
||||
} else {
|
||||
text = new ArrayList<String>(lines);
|
||||
}
|
||||
}
|
||||
|
||||
lastMouseX = mouseX;
|
||||
lastMouseY = mouseY;
|
||||
}
|
||||
|
||||
public boolean shouldDraw() {
|
||||
if (!visible) {
|
||||
return false;
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
updateText();
|
||||
if (mouseOverStart == 0) {
|
||||
return false;
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
return System.currentTimeMillis() - mouseOverStart >= DELAY;
|
||||
}
|
||||
|
||||
protected void updateText() {
|
||||
}
|
||||
|
||||
public void setToolTipText(String... txt) {
|
||||
text.clear();
|
||||
if (txt != null) {
|
||||
for (String line : txt) {
|
||||
text.add(line);
|
||||
}
|
||||
public Rectangle getBounds() {
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getToolTipText() {
|
||||
return text;
|
||||
}
|
||||
public void setBounds(Rectangle bounds) {
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
public void onTick(int mouseX, int mouseY) {
|
||||
if (lastMouseX != mouseX || lastMouseY != mouseY) {
|
||||
mouseOverStart = 0;
|
||||
}
|
||||
|
||||
if (bounds.contains(mouseX, mouseY)) {
|
||||
|
||||
if (mouseOverStart == 0) {
|
||||
mouseOverStart = System.currentTimeMillis();
|
||||
}
|
||||
} else {
|
||||
mouseOverStart = 0;
|
||||
}
|
||||
|
||||
lastMouseX = mouseX;
|
||||
lastMouseY = mouseY;
|
||||
}
|
||||
|
||||
public boolean shouldDraw() {
|
||||
if (!visible) {
|
||||
return false;
|
||||
}
|
||||
updateText();
|
||||
if (mouseOverStart == 0) {
|
||||
return false;
|
||||
}
|
||||
return System.currentTimeMillis() - mouseOverStart >= DELAY;
|
||||
}
|
||||
|
||||
protected void updateText() {}
|
||||
|
||||
public void setToolTipText(String... txt) {
|
||||
text.clear();
|
||||
if (txt != null) {
|
||||
for (String line : txt) {
|
||||
text.add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getToolTipText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,106 +2,118 @@ package com.enderio.core.client.gui.widget;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.enderio.core.api.client.gui.IHideable;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.api.client.gui.IHideable;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class TextFieldEnder extends GuiTextField implements IHideable {
|
||||
|
||||
public interface ICharFilter {
|
||||
public interface ICharFilter {
|
||||
|
||||
boolean passesFilter(TextFieldEnder tf, char c);
|
||||
}
|
||||
boolean passesFilter(TextFieldEnder tf, char c);
|
||||
}
|
||||
|
||||
public static final ICharFilter FILTER_NUMERIC = new ICharFilter() {
|
||||
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return Character.isDigit(c) || (c == '-' && Strings.isNullOrEmpty(tf.getText()));
|
||||
}
|
||||
};
|
||||
|
||||
public static ICharFilter FILTER_ALPHABETICAL = new ICharFilter() {
|
||||
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return Character.isLetter(c);
|
||||
}
|
||||
};
|
||||
|
||||
public static ICharFilter FILTER_ALPHANUMERIC = new ICharFilter() {
|
||||
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return FILTER_NUMERIC.passesFilter(tf, c) || FILTER_ALPHABETICAL.passesFilter(tf, c);
|
||||
}
|
||||
};
|
||||
|
||||
private final int xOrigin;
|
||||
private final int yOrigin;
|
||||
private ICharFilter filter;
|
||||
|
||||
private static Field canLoseFocus;
|
||||
|
||||
static {
|
||||
try {
|
||||
canLoseFocus = ReflectionHelper.findField(GuiTextField.class, "canLoseFocus", "field_146212_n", "n");
|
||||
canLoseFocus.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public TextFieldEnder(FontRenderer fnt, int x, int y, int width, int height) {
|
||||
this(fnt, x, y, width, height, null);
|
||||
}
|
||||
|
||||
public TextFieldEnder(FontRenderer fnt, int x, int y, int width, int height, ICharFilter charFilter) {
|
||||
super(fnt, x, y, width, height);
|
||||
this.xOrigin = x;
|
||||
this.yOrigin = y;
|
||||
this.filter = charFilter;
|
||||
}
|
||||
|
||||
public void init(IGuiScreen gui) {
|
||||
this.xPosition = xOrigin + gui.getGuiLeft();
|
||||
this.yPosition = yOrigin + gui.getGuiTop();
|
||||
}
|
||||
|
||||
public TextFieldEnder setCharFilter(ICharFilter filter) {
|
||||
this.filter = filter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static final ICharFilter FILTER_NUMERIC = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return Character.isDigit(c) || (c == '-' && Strings.isNullOrEmpty(tf.getText()));
|
||||
public boolean textboxKeyTyped(char c, int key) {
|
||||
if (filter == null || filter.passesFilter(this, c) || isSpecialChar(c, key)) {
|
||||
return super.textboxKeyTyped(c, key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSpecialChar(char c, int key) {
|
||||
// taken from the giant switch statement in GuiTextField
|
||||
return c == 1 || c == 3
|
||||
|| c == 22
|
||||
|| c == 24
|
||||
|| key == 14
|
||||
|| key == 199
|
||||
|| key == 203
|
||||
|| key == 205
|
||||
|| key == 207
|
||||
|| key == 211;
|
||||
}
|
||||
|
||||
public boolean getCanLoseFocus() {
|
||||
try {
|
||||
return canLoseFocus.getBoolean(this);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(int x, int y) {
|
||||
return x >= this.xPosition && x < this.xPosition + this.width
|
||||
&& y >= this.yPosition
|
||||
&& y < this.yPosition + this.height;
|
||||
}
|
||||
};
|
||||
|
||||
public static ICharFilter FILTER_ALPHABETICAL = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return Character.isLetter(c);
|
||||
public boolean isVisible() {
|
||||
return super.getVisible();
|
||||
}
|
||||
};
|
||||
|
||||
public static ICharFilter FILTER_ALPHANUMERIC = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return FILTER_NUMERIC.passesFilter(tf, c) || FILTER_ALPHABETICAL.passesFilter(tf, c);
|
||||
}
|
||||
};
|
||||
|
||||
private final int xOrigin;
|
||||
private final int yOrigin;
|
||||
private ICharFilter filter;
|
||||
|
||||
private static Field canLoseFocus;
|
||||
|
||||
static {
|
||||
try {
|
||||
canLoseFocus = ReflectionHelper.findField(GuiTextField.class, "canLoseFocus", "field_146212_n", "n");
|
||||
canLoseFocus.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public TextFieldEnder(FontRenderer fnt, int x, int y, int width, int height) {
|
||||
this(fnt, x, y, width, height, null);
|
||||
}
|
||||
|
||||
public TextFieldEnder(FontRenderer fnt, int x, int y, int width, int height, ICharFilter charFilter) {
|
||||
super(fnt, x, y, width, height);
|
||||
this.xOrigin = x;
|
||||
this.yOrigin = y;
|
||||
this.filter = charFilter;
|
||||
}
|
||||
|
||||
public void init(IGuiScreen gui) {
|
||||
this.xPosition = xOrigin + gui.getGuiLeft();
|
||||
this.yPosition = yOrigin + gui.getGuiTop();
|
||||
}
|
||||
|
||||
public TextFieldEnder setCharFilter(ICharFilter filter) {
|
||||
this.filter = filter;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean textboxKeyTyped(char c, int key) {
|
||||
if (filter == null || filter.passesFilter(this, c) || isSpecialChar(c, key)) {
|
||||
return super.textboxKeyTyped(c, key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSpecialChar(char c, int key) {
|
||||
// taken from the giant switch statement in GuiTextField
|
||||
return c == 1 || c == 3 || c == 22 || c == 24 || key == 14 || key == 199 || key == 203 || key == 205 || key == 207 || key == 211;
|
||||
}
|
||||
|
||||
public boolean getCanLoseFocus() {
|
||||
try {
|
||||
return canLoseFocus.getBoolean(this);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(int x, int y) {
|
||||
return x >= this.xPosition && x < this.xPosition + this.width && y >= this.yPosition && y < this.yPosition + this.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return super.getVisible();
|
||||
}
|
||||
}
|
||||
@@ -2,205 +2,216 @@ package com.enderio.core.client.gui.widget;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import com.enderio.core.api.client.gui.IHideable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.api.client.gui.IHideable;
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import com.enderio.core.client.render.EnderWidget;
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
public class VScrollbar implements IHideable {
|
||||
|
||||
protected final IGuiScreen gui;
|
||||
protected final IGuiScreen gui;
|
||||
|
||||
protected int xOrigin;
|
||||
protected int yOrigin;
|
||||
protected int height;
|
||||
protected int xOrigin;
|
||||
protected int yOrigin;
|
||||
protected int height;
|
||||
|
||||
protected int xPosition;
|
||||
protected int yPosition;
|
||||
protected Rectangle wholeArea;
|
||||
protected Rectangle btnUp;
|
||||
protected Rectangle btnDown;
|
||||
protected Rectangle thumbArea;
|
||||
protected int xPosition;
|
||||
protected int yPosition;
|
||||
protected Rectangle wholeArea;
|
||||
protected Rectangle btnUp;
|
||||
protected Rectangle btnDown;
|
||||
protected Rectangle thumbArea;
|
||||
|
||||
protected int scrollPos;
|
||||
protected int scrollMax;
|
||||
protected int scrollPos;
|
||||
protected int scrollMax;
|
||||
|
||||
protected boolean pressedUp;
|
||||
protected boolean pressedDown;
|
||||
protected boolean pressedThumb;
|
||||
protected int scrollDir;
|
||||
protected long timeNextScroll;
|
||||
protected boolean pressedUp;
|
||||
protected boolean pressedDown;
|
||||
protected boolean pressedThumb;
|
||||
protected int scrollDir;
|
||||
protected long timeNextScroll;
|
||||
|
||||
protected boolean visible = true;
|
||||
protected boolean visible = true;
|
||||
|
||||
public VScrollbar(IGuiScreen gui, int xOrigin, int yOrigin, int height) {
|
||||
this.gui = gui;
|
||||
this.xOrigin = xOrigin;
|
||||
this.yOrigin = yOrigin;
|
||||
this.height = height;
|
||||
}
|
||||
public VScrollbar(IGuiScreen gui, int xOrigin, int yOrigin, int height) {
|
||||
this.gui = gui;
|
||||
this.xOrigin = xOrigin;
|
||||
this.yOrigin = yOrigin;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void adjustPosition() {
|
||||
xPosition = xOrigin + gui.getGuiLeft();
|
||||
yPosition = yOrigin + gui.getGuiTop();
|
||||
wholeArea = new Rectangle(xPosition, yPosition, (int) EnderWidget.VSCROLL_THUMB_OFF.width, height);
|
||||
btnUp = new Rectangle(xPosition, yPosition, (int) EnderWidget.UP_ARROW_OFF.width, (int) EnderWidget.UP_ARROW_OFF.height);
|
||||
btnDown = new Rectangle(xPosition, yPosition + Math.max(0, height - (int) EnderWidget.DOWN_ARROW_OFF.height), (int) EnderWidget.DOWN_ARROW_OFF.width,
|
||||
(int) EnderWidget.DOWN_ARROW_OFF.height);
|
||||
thumbArea = new Rectangle(xPosition, yPosition + btnUp.height, (int) EnderWidget.VSCROLL_THUMB_OFF.width, Math.max(0, height
|
||||
- (btnUp.height + btnDown.height)));
|
||||
}
|
||||
public void adjustPosition() {
|
||||
xPosition = xOrigin + gui.getGuiLeft();
|
||||
yPosition = yOrigin + gui.getGuiTop();
|
||||
wholeArea = new Rectangle(xPosition, yPosition, (int) EnderWidget.VSCROLL_THUMB_OFF.width, height);
|
||||
btnUp = new Rectangle(
|
||||
xPosition,
|
||||
yPosition,
|
||||
(int) EnderWidget.UP_ARROW_OFF.width,
|
||||
(int) EnderWidget.UP_ARROW_OFF.height);
|
||||
btnDown = new Rectangle(
|
||||
xPosition,
|
||||
yPosition + Math.max(0, height - (int) EnderWidget.DOWN_ARROW_OFF.height),
|
||||
(int) EnderWidget.DOWN_ARROW_OFF.width,
|
||||
(int) EnderWidget.DOWN_ARROW_OFF.height);
|
||||
thumbArea = new Rectangle(
|
||||
xPosition,
|
||||
yPosition + btnUp.height,
|
||||
(int) EnderWidget.VSCROLL_THUMB_OFF.width,
|
||||
Math.max(0, height - (btnUp.height + btnDown.height)));
|
||||
}
|
||||
|
||||
public int getScrollPos() {
|
||||
return scrollPos;
|
||||
}
|
||||
public int getScrollPos() {
|
||||
return scrollPos;
|
||||
}
|
||||
|
||||
public void setScrollPos(int scrollPos) {
|
||||
this.scrollPos = limitPos(scrollPos);
|
||||
}
|
||||
public void setScrollPos(int scrollPos) {
|
||||
this.scrollPos = limitPos(scrollPos);
|
||||
}
|
||||
|
||||
public void scrollBy(int amount) {
|
||||
setScrollPos(scrollPos + amount);
|
||||
}
|
||||
public void scrollBy(int amount) {
|
||||
setScrollPos(scrollPos + amount);
|
||||
}
|
||||
|
||||
public int getScrollMax() {
|
||||
return scrollMax;
|
||||
}
|
||||
public int getScrollMax() {
|
||||
return scrollMax;
|
||||
}
|
||||
|
||||
public void setScrollMax(int scrollMax) {
|
||||
this.scrollMax = scrollMax;
|
||||
setScrollPos(scrollPos);
|
||||
}
|
||||
public void setScrollMax(int scrollMax) {
|
||||
this.scrollMax = scrollMax;
|
||||
setScrollPos(scrollPos);
|
||||
}
|
||||
|
||||
public void drawScrollbar(int mouseX, int mouseY) {
|
||||
if (visible) {
|
||||
boolean hoverUp = btnUp.contains(mouseX, mouseY);
|
||||
boolean hoverDown = btnDown.contains(mouseX, mouseY);
|
||||
public void drawScrollbar(int mouseX, int mouseY) {
|
||||
if (visible) {
|
||||
boolean hoverUp = btnUp.contains(mouseX, mouseY);
|
||||
boolean hoverDown = btnDown.contains(mouseX, mouseY);
|
||||
|
||||
IWidgetIcon iconUp;
|
||||
if (pressedUp) {
|
||||
iconUp = hoverUp ? EnderWidget.UP_ARROW_HOVER_ON : EnderWidget.UP_ARROW_ON;
|
||||
} else {
|
||||
iconUp = hoverUp ? EnderWidget.UP_ARROW_HOVER_OFF : EnderWidget.UP_ARROW_OFF;
|
||||
}
|
||||
IWidgetIcon iconUp;
|
||||
if (pressedUp) {
|
||||
iconUp = hoverUp ? EnderWidget.UP_ARROW_HOVER_ON : EnderWidget.UP_ARROW_ON;
|
||||
} else {
|
||||
iconUp = hoverUp ? EnderWidget.UP_ARROW_HOVER_OFF : EnderWidget.UP_ARROW_OFF;
|
||||
}
|
||||
|
||||
IWidgetIcon iconDown;
|
||||
if (pressedDown) {
|
||||
iconDown = hoverDown ? EnderWidget.DOWN_ARROW_HOVER_ON : EnderWidget.DOWN_ARROW_ON;
|
||||
} else {
|
||||
iconDown = hoverDown ? EnderWidget.DOWN_ARROW_HOVER_OFF : EnderWidget.DOWN_ARROW_OFF;
|
||||
}
|
||||
IWidgetIcon iconDown;
|
||||
if (pressedDown) {
|
||||
iconDown = hoverDown ? EnderWidget.DOWN_ARROW_HOVER_ON : EnderWidget.DOWN_ARROW_ON;
|
||||
} else {
|
||||
iconDown = hoverDown ? EnderWidget.DOWN_ARROW_HOVER_OFF : EnderWidget.DOWN_ARROW_OFF;
|
||||
}
|
||||
|
||||
if (scrollDir != 0) {
|
||||
long time = Minecraft.getSystemTime();
|
||||
if ((timeNextScroll - time) <= 0) {
|
||||
timeNextScroll = time + 100;
|
||||
scrollBy(scrollDir);
|
||||
if (scrollDir != 0) {
|
||||
long time = Minecraft.getSystemTime();
|
||||
if ((timeNextScroll - time) <= 0) {
|
||||
timeNextScroll = time + 100;
|
||||
scrollBy(scrollDir);
|
||||
}
|
||||
}
|
||||
|
||||
RenderUtil.bindTexture(EnderWidget.TEXTURE);
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
|
||||
iconUp.getMap().render(iconUp, btnUp.x, btnUp.y, false);
|
||||
iconDown.getMap().render(iconDown, btnDown.x, btnDown.y, false);
|
||||
|
||||
if (scrollMax > 0) {
|
||||
int thumbPos = getThumbPosition();
|
||||
boolean hoverThumb = thumbArea.contains(mouseX, mouseY) && mouseY >= thumbPos
|
||||
&& mouseY < thumbPos + (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
|
||||
EnderWidget iconThumb;
|
||||
if (pressedThumb) {
|
||||
iconThumb = EnderWidget.VSCROLL_THUMB_HOVER_ON;
|
||||
} else {
|
||||
iconThumb = hoverThumb ? EnderWidget.VSCROLL_THUMB_HOVER_OFF : EnderWidget.VSCROLL_THUMB_OFF;
|
||||
}
|
||||
iconThumb.getMap().render(iconThumb, thumbArea.x, thumbPos, false);
|
||||
}
|
||||
|
||||
tes.draw();
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RenderUtil.bindTexture(EnderWidget.TEXTURE);
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
public boolean mouseClicked(int x, int y, int button) {
|
||||
if (button == 0) {
|
||||
if (scrollMax > 0 && thumbArea.contains(x, y)) {
|
||||
int thumbPos = getThumbPosition();
|
||||
pressedUp = y < thumbPos;
|
||||
pressedDown = y >= thumbPos + (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
pressedThumb = !pressedUp && !pressedDown;
|
||||
} else {
|
||||
pressedUp = btnUp.contains(x, y);
|
||||
pressedDown = btnDown.contains(x, y);
|
||||
pressedThumb = false;
|
||||
}
|
||||
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
scrollDir = (pressedDown ? 1 : 0) - (pressedUp ? 1 : 0);
|
||||
if (scrollDir != 0) {
|
||||
timeNextScroll = Minecraft.getSystemTime() + 200;
|
||||
scrollBy(scrollDir);
|
||||
}
|
||||
}
|
||||
return isDragActive();
|
||||
}
|
||||
|
||||
iconUp.getMap().render(iconUp, btnUp.x, btnUp.y, false);
|
||||
iconDown.getMap().render(iconDown, btnDown.x, btnDown.y, false);
|
||||
|
||||
if (scrollMax > 0) {
|
||||
int thumbPos = getThumbPosition();
|
||||
boolean hoverThumb = thumbArea.contains(mouseX, mouseY) && mouseY >= thumbPos && mouseY < thumbPos + (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
|
||||
EnderWidget iconThumb;
|
||||
public boolean mouseClickMove(int x, int y, int button, long time) {
|
||||
if (pressedThumb) {
|
||||
iconThumb = EnderWidget.VSCROLL_THUMB_HOVER_ON;
|
||||
} else {
|
||||
iconThumb = hoverThumb ? EnderWidget.VSCROLL_THUMB_HOVER_OFF : EnderWidget.VSCROLL_THUMB_OFF;
|
||||
int pos = y - (thumbArea.y + (int) EnderWidget.VSCROLL_THUMB_OFF.height / 2);
|
||||
int len = thumbArea.height - (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
if (len > 0) {
|
||||
setScrollPos(Math.round(pos * (float) scrollMax / (float) len));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
iconThumb.getMap().render(iconThumb, thumbArea.x, thumbPos, false);
|
||||
}
|
||||
|
||||
tes.draw();
|
||||
GL11.glPopAttrib();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mouseClicked(int x, int y, int button) {
|
||||
if (button == 0) {
|
||||
if (scrollMax > 0 && thumbArea.contains(x, y)) {
|
||||
int thumbPos = getThumbPosition();
|
||||
pressedUp = y < thumbPos;
|
||||
pressedDown = y >= thumbPos + (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
pressedThumb = !pressedUp && !pressedDown;
|
||||
} else {
|
||||
pressedUp = btnUp.contains(x, y);
|
||||
pressedDown = btnDown.contains(x, y);
|
||||
public void mouseMovedOrUp(int x, int y, int button) {
|
||||
pressedUp = false;
|
||||
pressedDown = false;
|
||||
pressedThumb = false;
|
||||
}
|
||||
|
||||
scrollDir = (pressedDown ? 1 : 0) - (pressedUp ? 1 : 0);
|
||||
if (scrollDir != 0) {
|
||||
timeNextScroll = Minecraft.getSystemTime() + 200;
|
||||
scrollBy(scrollDir);
|
||||
}
|
||||
scrollDir = 0;
|
||||
}
|
||||
return isDragActive();
|
||||
}
|
||||
|
||||
public boolean mouseClickMove(int x, int y, int button, long time) {
|
||||
if (pressedThumb) {
|
||||
int pos = y - (thumbArea.y + (int) EnderWidget.VSCROLL_THUMB_OFF.height / 2);
|
||||
int len = thumbArea.height - (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
if (len > 0) {
|
||||
setScrollPos(Math.round(pos * (float) scrollMax / (float) len));
|
||||
}
|
||||
return true;
|
||||
public void mouseWheel(int x, int y, int delta) {
|
||||
if (!isDragActive() && wholeArea.contains(x, y)) {
|
||||
scrollBy(-Integer.signum(delta));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void mouseMovedOrUp(int x, int y, int button) {
|
||||
pressedUp = false;
|
||||
pressedDown = false;
|
||||
pressedThumb = false;
|
||||
scrollDir = 0;
|
||||
}
|
||||
|
||||
public void mouseWheel(int x, int y, int delta) {
|
||||
if (!isDragActive() && wholeArea.contains(x, y)) {
|
||||
scrollBy(-Integer.signum(delta));
|
||||
public boolean isDragActive() {
|
||||
return pressedUp || pressedDown || pressedThumb;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDragActive() {
|
||||
return pressedUp || pressedDown || pressedThumb;
|
||||
}
|
||||
protected int getThumbPosition() {
|
||||
return thumbArea.y + (thumbArea.height - (int) EnderWidget.VSCROLL_THUMB_OFF.height) * scrollPos / scrollMax;
|
||||
}
|
||||
|
||||
protected int getThumbPosition() {
|
||||
return thumbArea.y + (thumbArea.height - (int) EnderWidget.VSCROLL_THUMB_OFF.height) * scrollPos / scrollMax;
|
||||
}
|
||||
protected int limitPos(int pos) {
|
||||
return Math.max(0, Math.min(pos, scrollMax));
|
||||
}
|
||||
|
||||
protected int limitPos(int pos) {
|
||||
return Math.max(0, Math.min(pos, scrollMax));
|
||||
}
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return this.visible;
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return this.visible;
|
||||
}
|
||||
}
|
||||
@@ -9,16 +9,16 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
@Handler
|
||||
public class ClientHandler {
|
||||
|
||||
private static int ticksElapsed;
|
||||
|
||||
public static int getTicksElapsed() {
|
||||
return ticksElapsed;
|
||||
}
|
||||
private static int ticksElapsed;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTick(ClientTickEvent event) {
|
||||
if (event.phase == Phase.END) {
|
||||
ticksElapsed++;
|
||||
public static int getTicksElapsed() {
|
||||
return ticksElapsed;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTick(ClientTickEvent event) {
|
||||
if (event.phase == Phase.END) {
|
||||
ticksElapsed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,31 +10,35 @@ import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
|
||||
import com.enderio.core.api.common.enchant.IAdvancedEnchant;
|
||||
import com.enderio.core.common.Handlers.Handler;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Handler
|
||||
public class EnchantTooltipHandler {
|
||||
@SuppressWarnings("unchecked")
|
||||
@SubscribeEvent
|
||||
public void handleTooltip(ItemTooltipEvent event) {
|
||||
if (event.itemStack.hasTagCompound()) {
|
||||
Map<Integer, Integer> enchantments = EnchantmentHelper.getEnchantments(event.itemStack);
|
||||
|
||||
for (Integer integer : enchantments.keySet()) {
|
||||
Enchantment enchant = Enchantment.enchantmentsList[integer];
|
||||
@SuppressWarnings("unchecked")
|
||||
@SubscribeEvent
|
||||
public void handleTooltip(ItemTooltipEvent event) {
|
||||
if (event.itemStack.hasTagCompound()) {
|
||||
Map<Integer, Integer> enchantments = EnchantmentHelper.getEnchantments(event.itemStack);
|
||||
|
||||
if (enchant instanceof IAdvancedEnchant) {
|
||||
for (int i = 0; i < event.toolTip.size(); i++) {
|
||||
if (event.toolTip.get(i).contains(StatCollector.translateToLocal(enchant.getName()))) {
|
||||
for (String s : ((IAdvancedEnchant) enchant).getTooltipDetails(event.itemStack)) {
|
||||
event.toolTip.add(i + 1, EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + " - " + s);
|
||||
i++;
|
||||
}
|
||||
for (Integer integer : enchantments.keySet()) {
|
||||
Enchantment enchant = Enchantment.enchantmentsList[integer];
|
||||
|
||||
if (enchant instanceof IAdvancedEnchant) {
|
||||
for (int i = 0; i < event.toolTip.size(); i++) {
|
||||
if (event.toolTip.get(i).contains(StatCollector.translateToLocal(enchant.getName()))) {
|
||||
for (String s : ((IAdvancedEnchant) enchant).getTooltipDetails(event.itemStack)) {
|
||||
event.toolTip.add(
|
||||
i + 1,
|
||||
EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC
|
||||
+ " - "
|
||||
+ s);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.enderio.core.client.handlers;
|
||||
|
||||
import static com.enderio.core.common.config.ConfigHandler.*;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
@@ -9,33 +11,33 @@ import org.lwjgl.input.Keyboard;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.common.Handlers.Handler;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import static com.enderio.core.common.config.ConfigHandler.*;
|
||||
|
||||
@Handler
|
||||
public class OreDictTooltipHandler {
|
||||
@SubscribeEvent
|
||||
public void onItemTooltip(ItemTooltipEvent event) {
|
||||
boolean shiftDown = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
boolean debugMode = Minecraft.getMinecraft().gameSettings.advancedItemTooltips;
|
||||
boolean doRegistry = showRegistryNameTooltips == 3 ? debugMode : showRegistryNameTooltips == 2 ? shiftDown : showRegistryNameTooltips == 1;
|
||||
boolean doOredict = showOredictTooltips == 3 ? debugMode : showOredictTooltips == 2 ? shiftDown : showOredictTooltips == 1;
|
||||
|
||||
if (doRegistry) {
|
||||
event.toolTip.add(Item.itemRegistry.getNameForObject(event.itemStack.getItem()));
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onItemTooltip(ItemTooltipEvent event) {
|
||||
boolean shiftDown = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
boolean debugMode = Minecraft.getMinecraft().gameSettings.advancedItemTooltips;
|
||||
boolean doRegistry = showRegistryNameTooltips == 3 ? debugMode
|
||||
: showRegistryNameTooltips == 2 ? shiftDown : showRegistryNameTooltips == 1;
|
||||
boolean doOredict = showOredictTooltips == 3 ? debugMode
|
||||
: showOredictTooltips == 2 ? shiftDown : showOredictTooltips == 1;
|
||||
|
||||
if (doOredict) {
|
||||
int[] ids = OreDictionary.getOreIDs(event.itemStack);
|
||||
|
||||
if (ids.length > 0) {
|
||||
event.toolTip.add(EnderCore.lang.localize("tooltip.oreDictNames"));
|
||||
for (int i : ids) {
|
||||
event.toolTip.add(" - " + OreDictionary.getOreName(i));
|
||||
if (doRegistry) {
|
||||
event.toolTip.add(Item.itemRegistry.getNameForObject(event.itemStack.getItem()));
|
||||
}
|
||||
|
||||
if (doOredict) {
|
||||
int[] ids = OreDictionary.getOreIDs(event.itemStack);
|
||||
|
||||
if (ids.length > 0) {
|
||||
event.toolTip.add(EnderCore.lang.localize("tooltip.oreDictNames"));
|
||||
for (int i : ids) {
|
||||
event.toolTip.add(" - " + OreDictionary.getOreName(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.enderio.core.client.handlers;
|
||||
|
||||
import static com.enderio.core.common.config.ConfigHandler.showDurabilityTooltips;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,177 +26,186 @@ import com.enderio.core.api.client.gui.IResourceTooltipProvider;
|
||||
import com.enderio.core.common.Handlers.Handler;
|
||||
import com.enderio.core.common.util.ItemUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import static com.enderio.core.common.config.ConfigHandler.showDurabilityTooltips;
|
||||
|
||||
@Handler
|
||||
public enum SpecialTooltipHandler {
|
||||
INSTANCE;
|
||||
|
||||
public interface ITooltipCallback extends IAdvancedTooltipProvider {
|
||||
boolean shouldHandleItem(ItemStack item);
|
||||
}
|
||||
|
||||
private final List<ITooltipCallback> callbacks = Lists.newArrayList();
|
||||
INSTANCE;
|
||||
|
||||
public void addCallback(ITooltipCallback callback) {
|
||||
callbacks.add(callback);
|
||||
}
|
||||
public interface ITooltipCallback extends IAdvancedTooltipProvider {
|
||||
|
||||
@SubscribeEvent
|
||||
public void addTooltip(ItemTooltipEvent evt) {
|
||||
if (evt.itemStack == null) {
|
||||
return;
|
||||
boolean shouldHandleItem(ItemStack item);
|
||||
}
|
||||
|
||||
boolean shiftDown = showAdvancedTooltips();
|
||||
boolean debugMode = Minecraft.getMinecraft().gameSettings.advancedItemTooltips;
|
||||
boolean doDurability = showDurabilityTooltips == 3 ? debugMode : showDurabilityTooltips == 2 ? shiftDown : showDurabilityTooltips == 1;
|
||||
private final List<ITooltipCallback> callbacks = Lists.newArrayList();
|
||||
|
||||
if (doDurability) {
|
||||
addDurabilityTooltip(evt.toolTip, evt.itemStack);
|
||||
public void addCallback(ITooltipCallback callback) {
|
||||
callbacks.add(callback);
|
||||
}
|
||||
|
||||
if (evt.itemStack.getItem() instanceof IAdvancedTooltipProvider) {
|
||||
IAdvancedTooltipProvider ttp = (IAdvancedTooltipProvider) evt.itemStack.getItem();
|
||||
addInformation(ttp, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
return;
|
||||
} else if (evt.itemStack.getItem() instanceof IResourceTooltipProvider) {
|
||||
addInformation((IResourceTooltipProvider) evt.itemStack.getItem(), evt);
|
||||
return;
|
||||
@SubscribeEvent
|
||||
public void addTooltip(ItemTooltipEvent evt) {
|
||||
if (evt.itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean shiftDown = showAdvancedTooltips();
|
||||
boolean debugMode = Minecraft.getMinecraft().gameSettings.advancedItemTooltips;
|
||||
boolean doDurability = showDurabilityTooltips == 3 ? debugMode
|
||||
: showDurabilityTooltips == 2 ? shiftDown : showDurabilityTooltips == 1;
|
||||
|
||||
if (doDurability) {
|
||||
addDurabilityTooltip(evt.toolTip, evt.itemStack);
|
||||
}
|
||||
|
||||
if (evt.itemStack.getItem() instanceof IAdvancedTooltipProvider) {
|
||||
IAdvancedTooltipProvider ttp = (IAdvancedTooltipProvider) evt.itemStack.getItem();
|
||||
addInformation(ttp, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
return;
|
||||
} else if (evt.itemStack.getItem() instanceof IResourceTooltipProvider) {
|
||||
addInformation((IResourceTooltipProvider) evt.itemStack.getItem(), evt);
|
||||
return;
|
||||
}
|
||||
|
||||
Block blk = Block.getBlockFromItem(evt.itemStack.getItem());
|
||||
if (blk instanceof IAdvancedTooltipProvider) {
|
||||
addInformation((IAdvancedTooltipProvider) blk, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
return;
|
||||
} else if (blk instanceof IResourceTooltipProvider) {
|
||||
addInformation((IResourceTooltipProvider) blk, evt);
|
||||
return;
|
||||
}
|
||||
|
||||
for (ITooltipCallback callback : callbacks) {
|
||||
if (callback.shouldHandleItem(evt.itemStack)) {
|
||||
addInformation(callback, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Block blk = Block.getBlockFromItem(evt.itemStack.getItem());
|
||||
if (blk instanceof IAdvancedTooltipProvider) {
|
||||
addInformation((IAdvancedTooltipProvider) blk, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
return;
|
||||
} else if (blk instanceof IResourceTooltipProvider) {
|
||||
addInformation((IResourceTooltipProvider) blk, evt);
|
||||
return;
|
||||
public void addDurabilityTooltip(List<String> toolTip, ItemStack itemStack) {
|
||||
if (!itemStack.isItemStackDamageable()) {
|
||||
return;
|
||||
}
|
||||
Item item = itemStack.getItem();
|
||||
if (item instanceof ItemTool || item instanceof ItemArmor
|
||||
|| item instanceof ItemSword
|
||||
|| item instanceof ItemHoe
|
||||
|| item instanceof ItemBow) {
|
||||
toolTip.add(ItemUtil.getDurabilityString(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
for (ITooltipCallback callback : callbacks) {
|
||||
if (callback.shouldHandleItem(evt.itemStack)) {
|
||||
addInformation(callback, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
}
|
||||
public void addInformation(IResourceTooltipProvider item, ItemTooltipEvent evt) {
|
||||
addInformation(item, evt.itemStack, evt.entityPlayer, evt.toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
public void addDurabilityTooltip(List<String> toolTip, ItemStack itemStack) {
|
||||
if (!itemStack.isItemStackDamageable()) {
|
||||
return;
|
||||
public void addInformation(IResourceTooltipProvider tt, ItemStack itemstack, EntityPlayer entityplayer, List list) {
|
||||
String name = tt.getUnlocalizedNameForTooltip(itemstack);
|
||||
if (showAdvancedTooltips()) {
|
||||
addCommonTooltipFromResources(list, name);
|
||||
addDetailedTooltipFromResources(list, name);
|
||||
} else {
|
||||
addBasicTooltipFromResources(list, name);
|
||||
addCommonTooltipFromResources(list, name);
|
||||
if (hasDetailedTooltip(tt, itemstack)) {
|
||||
addShowDetailsTooltip(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
Item item = itemStack.getItem();
|
||||
if (item instanceof ItemTool || item instanceof ItemArmor || item instanceof ItemSword || item instanceof ItemHoe || item instanceof ItemBow) {
|
||||
toolTip.add(ItemUtil.getDurabilityString(itemStack));
|
||||
|
||||
public void addInformation(IAdvancedTooltipProvider tt, ItemStack itemstack, EntityPlayer entityplayer, List list,
|
||||
boolean flag) {
|
||||
tt.addCommonEntries(itemstack, entityplayer, list, flag);
|
||||
if (showAdvancedTooltips()) {
|
||||
tt.addDetailedEntries(itemstack, entityplayer, list, flag);
|
||||
} else {
|
||||
tt.addBasicEntries(itemstack, entityplayer, list, flag);
|
||||
if (hasDetailedTooltip(tt, itemstack, entityplayer, flag)) {
|
||||
addShowDetailsTooltip(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addInformation(IResourceTooltipProvider item, ItemTooltipEvent evt) {
|
||||
addInformation(item, evt.itemStack, evt.entityPlayer, evt.toolTip);
|
||||
}
|
||||
private static final List<String> throwaway = new ArrayList<String>();
|
||||
|
||||
public void addInformation(IResourceTooltipProvider tt, ItemStack itemstack, EntityPlayer entityplayer, List list) {
|
||||
String name = tt.getUnlocalizedNameForTooltip(itemstack);
|
||||
if (showAdvancedTooltips()) {
|
||||
addCommonTooltipFromResources(list, name);
|
||||
addDetailedTooltipFromResources(list, name);
|
||||
} else {
|
||||
addBasicTooltipFromResources(list, name);
|
||||
addCommonTooltipFromResources(list, name);
|
||||
if (hasDetailedTooltip(tt, itemstack)) {
|
||||
addShowDetailsTooltip(list);
|
||||
}
|
||||
private static boolean hasDetailedTooltip(IResourceTooltipProvider tt, ItemStack stack) {
|
||||
throwaway.clear();
|
||||
String name = tt.getUnlocalizedNameForTooltip(stack);
|
||||
addDetailedTooltipFromResources(throwaway, name);
|
||||
return !throwaway.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public void addInformation(IAdvancedTooltipProvider tt, ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
tt.addCommonEntries(itemstack, entityplayer, list, flag);
|
||||
if (showAdvancedTooltips()) {
|
||||
tt.addDetailedEntries(itemstack, entityplayer, list, flag);
|
||||
} else {
|
||||
tt.addBasicEntries(itemstack, entityplayer, list, flag);
|
||||
if (hasDetailedTooltip(tt, itemstack, entityplayer, flag)) {
|
||||
addShowDetailsTooltip(list);
|
||||
}
|
||||
private static boolean hasDetailedTooltip(IAdvancedTooltipProvider tt, ItemStack stack, EntityPlayer player,
|
||||
boolean flag) {
|
||||
throwaway.clear();
|
||||
tt.addDetailedEntries(stack, player, throwaway, flag);
|
||||
return !throwaway.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<String> throwaway = new ArrayList<String>();
|
||||
|
||||
private static boolean hasDetailedTooltip(IResourceTooltipProvider tt, ItemStack stack) {
|
||||
throwaway.clear();
|
||||
String name = tt.getUnlocalizedNameForTooltip(stack);
|
||||
addDetailedTooltipFromResources(throwaway, name);
|
||||
return !throwaway.isEmpty();
|
||||
}
|
||||
|
||||
private static boolean hasDetailedTooltip(IAdvancedTooltipProvider tt, ItemStack stack, EntityPlayer player, boolean flag) {
|
||||
throwaway.clear();
|
||||
tt.addDetailedEntries(stack, player, throwaway, flag);
|
||||
return !throwaway.isEmpty();
|
||||
}
|
||||
|
||||
public static void addShowDetailsTooltip(List list) {
|
||||
list.add(EnumChatFormatting.WHITE + "" + EnumChatFormatting.ITALIC + EnderCore.lang.localize("tooltip.showDetails"));
|
||||
}
|
||||
|
||||
public static boolean showAdvancedTooltips() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
|
||||
public static void addDetailedTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.detailed.line"));
|
||||
}
|
||||
|
||||
public static void addBasicTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.basic.line"));
|
||||
}
|
||||
|
||||
public static void addCommonTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.common.line"));
|
||||
}
|
||||
|
||||
public static void addTooltipFromResources(List list, String keyBase) {
|
||||
boolean done = false;
|
||||
int line = 1;
|
||||
while (!done) {
|
||||
String key = keyBase + line;
|
||||
String val = EnderCore.lang.localizeExact(key);
|
||||
if (val == null || val.trim().length() < 0 || val.equals(key) || line > 12) {
|
||||
done = true;
|
||||
} else {
|
||||
list.add(val);
|
||||
line++;
|
||||
}
|
||||
public static void addShowDetailsTooltip(List list) {
|
||||
list.add(
|
||||
EnumChatFormatting.WHITE + ""
|
||||
+ EnumChatFormatting.ITALIC
|
||||
+ EnderCore.lang.localize("tooltip.showDetails"));
|
||||
}
|
||||
}
|
||||
|
||||
private static String getUnlocalizedNameForTooltip(ItemStack itemstack) {
|
||||
String unlocalizedNameForTooltip = null;
|
||||
if (itemstack.getItem() instanceof IResourceTooltipProvider) {
|
||||
unlocalizedNameForTooltip = ((IResourceTooltipProvider) itemstack.getItem()).getUnlocalizedNameForTooltip(itemstack);
|
||||
public static boolean showAdvancedTooltips() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
if (unlocalizedNameForTooltip == null) {
|
||||
unlocalizedNameForTooltip = itemstack.getItem().getUnlocalizedName(itemstack);
|
||||
}
|
||||
return unlocalizedNameForTooltip;
|
||||
}
|
||||
|
||||
public static void addCommonTooltipFromResources(List list, ItemStack itemstack) {
|
||||
if (itemstack.getItem() == null) {
|
||||
return;
|
||||
public static void addDetailedTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.detailed.line"));
|
||||
}
|
||||
addCommonTooltipFromResources(list, getUnlocalizedNameForTooltip(itemstack));
|
||||
}
|
||||
|
||||
public static void addDetailedTooltipFromResources(List list, ItemStack itemstack) {
|
||||
if (itemstack.getItem() == null) {
|
||||
return;
|
||||
public static void addBasicTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.basic.line"));
|
||||
}
|
||||
|
||||
public static void addCommonTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.common.line"));
|
||||
}
|
||||
|
||||
public static void addTooltipFromResources(List list, String keyBase) {
|
||||
boolean done = false;
|
||||
int line = 1;
|
||||
while (!done) {
|
||||
String key = keyBase + line;
|
||||
String val = EnderCore.lang.localizeExact(key);
|
||||
if (val == null || val.trim().length() < 0 || val.equals(key) || line > 12) {
|
||||
done = true;
|
||||
} else {
|
||||
list.add(val);
|
||||
line++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getUnlocalizedNameForTooltip(ItemStack itemstack) {
|
||||
String unlocalizedNameForTooltip = null;
|
||||
if (itemstack.getItem() instanceof IResourceTooltipProvider) {
|
||||
unlocalizedNameForTooltip = ((IResourceTooltipProvider) itemstack.getItem())
|
||||
.getUnlocalizedNameForTooltip(itemstack);
|
||||
}
|
||||
if (unlocalizedNameForTooltip == null) {
|
||||
unlocalizedNameForTooltip = itemstack.getItem().getUnlocalizedName(itemstack);
|
||||
}
|
||||
return unlocalizedNameForTooltip;
|
||||
}
|
||||
|
||||
public static void addCommonTooltipFromResources(List list, ItemStack itemstack) {
|
||||
if (itemstack.getItem() == null) {
|
||||
return;
|
||||
}
|
||||
addCommonTooltipFromResources(list, getUnlocalizedNameForTooltip(itemstack));
|
||||
}
|
||||
|
||||
public static void addDetailedTooltipFromResources(List list, ItemStack itemstack) {
|
||||
if (itemstack.getItem() == null) {
|
||||
return;
|
||||
}
|
||||
addDetailedTooltipFromResources(list, getUnlocalizedNameForTooltip(itemstack));
|
||||
}
|
||||
addDetailedTooltipFromResources(list, getUnlocalizedNameForTooltip(itemstack));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,10 @@ package com.enderio.core.client.render;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.util.BlockCoord;
|
||||
import com.enderio.core.common.vecmath.Vector2f;
|
||||
@@ -10,371 +14,400 @@ import com.enderio.core.common.vecmath.Vector3d;
|
||||
import com.enderio.core.common.vecmath.Vector3f;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public final class BoundingBox {
|
||||
|
||||
public static final BoundingBox UNIT_CUBE = new BoundingBox(0, 0, 0, 1, 1, 1);
|
||||
public static final BoundingBox UNIT_CUBE = new BoundingBox(0, 0, 0, 1, 1, 1);
|
||||
|
||||
public final float minX;
|
||||
public final float minY;
|
||||
public final float minZ;
|
||||
public final float maxX;
|
||||
public final float maxY;
|
||||
public final float maxZ;
|
||||
public final float minX;
|
||||
public final float minY;
|
||||
public final float minZ;
|
||||
public final float maxX;
|
||||
public final float maxY;
|
||||
public final float maxZ;
|
||||
|
||||
public BoundingBox(AxisAlignedBB bb) {
|
||||
this(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
||||
}
|
||||
|
||||
public BoundingBox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
|
||||
public BoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
|
||||
this.minX = (float) minX;
|
||||
this.minY = (float) minY;
|
||||
this.minZ = (float) minZ;
|
||||
this.maxX = (float) maxX;
|
||||
this.maxY = (float) maxY;
|
||||
this.maxZ = (float) maxZ;
|
||||
}
|
||||
|
||||
public BoundingBox(Vector3d min, Vector3d max) {
|
||||
this(min.x, min.y, min.z, max.x, max.y, max.z);
|
||||
}
|
||||
|
||||
public BoundingBox(BoundingBox copy) {
|
||||
this(copy.minX, copy.minY, copy.minZ, copy.maxX, copy.maxY, copy.maxZ);
|
||||
}
|
||||
|
||||
public BoundingBox(BlockCoord bc) {
|
||||
this(bc.x, bc.y, bc.z, bc.x + 1, bc.y + 1, bc.z + 1);
|
||||
}
|
||||
|
||||
public BoundingBox(Block block) {
|
||||
this(block.getBlockBoundsMinX(), block.getBlockBoundsMinY(), block.getBlockBoundsMinZ(), block.getBlockBoundsMaxX(), block.getBlockBoundsMaxY(), block
|
||||
.getBlockBoundsMaxZ());
|
||||
}
|
||||
|
||||
public BoundingBox expandBy(BoundingBox other) {
|
||||
return new BoundingBox(Math.min(minX, other.minX), Math.min(minY, other.minY), Math.min(minZ, other.minZ), Math.max(maxX, other.maxX), Math.max(maxY,
|
||||
other.maxY), Math.max(maxZ, other.maxZ));
|
||||
}
|
||||
|
||||
public boolean contains(BoundingBox other) {
|
||||
return minX >= other.minX && minY <= other.minY && minZ <= other.minZ && maxX >= other.maxX && maxY <= other.maxY && maxZ <= other.maxZ;
|
||||
}
|
||||
|
||||
public boolean intersects(BoundingBox other) {
|
||||
return other.maxX > this.minX && other.minX < this.maxX ? (other.maxY > this.minY && other.minY < this.maxY ? other.maxZ > this.minZ
|
||||
&& other.minZ < this.maxZ : false) : false;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return minX < maxX && minY < maxY && minZ < maxZ;
|
||||
}
|
||||
|
||||
public BoundingBox scale(double x, double y, double z) {
|
||||
return scale((float) x, (float) y, (float) z);
|
||||
}
|
||||
|
||||
public BoundingBox scale(float x, float y, float z) {
|
||||
x = 1 - x;
|
||||
y = 1 - y;
|
||||
z = 1 - z;
|
||||
float w = ((maxX - minX) * x) / 2;
|
||||
float h = ((maxY - minY) * y) / 2;
|
||||
float d = ((maxZ - minZ) * z) / 2;
|
||||
return new BoundingBox(minX + w, minY + h, minZ + d, maxX - w, maxY - h, maxZ - d);
|
||||
}
|
||||
|
||||
public BoundingBox translate(float x, float y, float z) {
|
||||
return new BoundingBox(minX + x, minY + y, minZ + z, maxX + x, maxY + y, maxZ + z);
|
||||
}
|
||||
|
||||
public BoundingBox translate(Vector3d translation) {
|
||||
return translate((float) translation.x, (float) translation.y, (float) translation.z);
|
||||
}
|
||||
|
||||
public BoundingBox translate(Vector3f vec) {
|
||||
return translate(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
public BoundingBox transform(VertexTransform iTransformation) {
|
||||
Vector3d min = new Vector3d(minX, minY, minZ);
|
||||
Vector3d max = new Vector3d(maxX, maxY, maxZ);
|
||||
|
||||
iTransformation.apply(min);
|
||||
iTransformation.apply(max);
|
||||
|
||||
return new BoundingBox(Math.min(min.x, max.x), Math.min(min.y, max.y), Math.min(min.z, max.z), Math.max(min.x, max.x), Math.max(min.y, max.y), Math.max(
|
||||
min.z, max.z));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertices of the corners for the specified face in counter
|
||||
* clockwise order.
|
||||
*/
|
||||
public List<Vertex> getCornersWithUvForFace(ForgeDirection face) {
|
||||
return getCornersWithUvForFace(face, 0, 1, 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertices of the corners for the specified face in counter
|
||||
* clockwise order.
|
||||
*/
|
||||
public List<Vertex> getCornersWithUvForFace(ForgeDirection face, float minU, float maxU, float minV, float maxV) {
|
||||
List<Vertex> result = new ArrayList<Vertex>(4);
|
||||
switch (face) {
|
||||
case NORTH:
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(0, 0, -1), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(0, 0, -1), new Vector2f(maxU, minV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(0, 0, -1), new Vector2f(maxU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(0, 0, -1), new Vector2f(minU, maxV)));
|
||||
break;
|
||||
case SOUTH:
|
||||
result.add(new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(0, 0, 1), new Vector2f(maxU, minV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(0, 0, 1), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(0, 0, 1), new Vector2f(minU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(0, 0, 1), new Vector2f(maxU, maxV)));
|
||||
break;
|
||||
case EAST:
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(1, 0, 0), new Vector2f(maxU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(1, 0, 0), new Vector2f(minU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(1, 0, 0), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(1, 0, 0), new Vector2f(maxU, minV)));
|
||||
break;
|
||||
case WEST:
|
||||
result.add(new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(-1, 0, 0), new Vector2f(maxU, minV)));
|
||||
result.add(new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(-1, 0, 0), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(-1, 0, 0), new Vector2f(minU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(-1, 0, 0), new Vector2f(maxU, maxV)));
|
||||
break;
|
||||
case UP:
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(0, 1, 0), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(0, 1, 0), new Vector2f(minU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(0, 1, 0), new Vector2f(maxU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(0, 1, 0), new Vector2f(maxU, minV)));
|
||||
break;
|
||||
case DOWN: //
|
||||
case UNKNOWN:
|
||||
default:
|
||||
result.add(new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(0, -1, 0), new Vector2f(maxU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(0, -1, 0), new Vector2f(minU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(0, -1, 0), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(0, -1, 0), new Vector2f(maxU, minV)));
|
||||
break;
|
||||
public BoundingBox(AxisAlignedBB bb) {
|
||||
this(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertices of the corners for the specified face in counter
|
||||
* clockwise order, starting with the top left.
|
||||
*/
|
||||
public List<Vector3f> getCornersForFace(ForgeDirection face) {
|
||||
List<Vector3f> result = new ArrayList<Vector3f>(4);
|
||||
switch (face) {
|
||||
case NORTH:
|
||||
result.add(new Vector3f(minX, maxY, minZ));
|
||||
result.add(new Vector3f(maxX, maxY, minZ));
|
||||
result.add(new Vector3f(maxX, minY, minZ));
|
||||
result.add(new Vector3f(minX, minY, minZ));
|
||||
break;
|
||||
case SOUTH:
|
||||
result.add(new Vector3f(minX, maxY, maxZ));
|
||||
result.add(new Vector3f(minX, minY, maxZ));
|
||||
result.add(new Vector3f(maxX, minY, maxZ));
|
||||
result.add(new Vector3f(maxX, maxY, maxZ));
|
||||
break;
|
||||
case EAST:
|
||||
result.add(new Vector3f(maxX, minY, maxZ));
|
||||
result.add(new Vector3f(maxX, minY, minZ));
|
||||
result.add(new Vector3f(maxX, maxY, minZ));
|
||||
result.add(new Vector3f(maxX, maxY, maxZ));
|
||||
break;
|
||||
case WEST:
|
||||
result.add(new Vector3f(minX, maxY, maxZ));
|
||||
result.add(new Vector3f(minX, maxY, minZ));
|
||||
result.add(new Vector3f(minX, minY, minZ));
|
||||
result.add(new Vector3f(minX, minY, maxZ));
|
||||
break;
|
||||
case UP:
|
||||
result.add(new Vector3f(maxX, maxY, maxZ));
|
||||
result.add(new Vector3f(maxX, maxY, minZ));
|
||||
result.add(new Vector3f(minX, maxY, minZ));
|
||||
result.add(new Vector3f(minX, maxY, maxZ));
|
||||
break;
|
||||
case DOWN:
|
||||
case UNKNOWN:
|
||||
default:
|
||||
result.add(new Vector3f(minX, minY, maxZ));
|
||||
result.add(new Vector3f(minX, minY, minZ));
|
||||
result.add(new Vector3f(maxX, minY, minZ));
|
||||
result.add(new Vector3f(maxX, minY, maxZ));
|
||||
break;
|
||||
public BoundingBox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertices of the corners for the specified face in counter
|
||||
* clockwise order, starting with the top left.
|
||||
*/
|
||||
public List<Vector3d> getCornersForFaceD(ForgeDirection face) {
|
||||
List<Vector3d> result = new ArrayList<Vector3d>(4);
|
||||
switch (face) {
|
||||
case NORTH:
|
||||
result.add(new Vector3d(minX, maxY, minZ));
|
||||
result.add(new Vector3d(maxX, maxY, minZ));
|
||||
result.add(new Vector3d(maxX, minY, minZ));
|
||||
result.add(new Vector3d(minX, minY, minZ));
|
||||
break;
|
||||
case SOUTH:
|
||||
result.add(new Vector3d(minX, maxY, maxZ));
|
||||
result.add(new Vector3d(minX, minY, maxZ));
|
||||
result.add(new Vector3d(maxX, minY, maxZ));
|
||||
result.add(new Vector3d(maxX, maxY, maxZ));
|
||||
break;
|
||||
case EAST:
|
||||
result.add(new Vector3d(maxX, minY, maxZ));
|
||||
result.add(new Vector3d(maxX, minY, minZ));
|
||||
result.add(new Vector3d(maxX, maxY, minZ));
|
||||
result.add(new Vector3d(maxX, maxY, maxZ));
|
||||
break;
|
||||
case WEST:
|
||||
result.add(new Vector3d(minX, maxY, maxZ));
|
||||
result.add(new Vector3d(minX, maxY, minZ));
|
||||
result.add(new Vector3d(minX, minY, minZ));
|
||||
result.add(new Vector3d(minX, minY, maxZ));
|
||||
break;
|
||||
case UP:
|
||||
result.add(new Vector3d(maxX, maxY, maxZ));
|
||||
result.add(new Vector3d(maxX, maxY, minZ));
|
||||
result.add(new Vector3d(minX, maxY, minZ));
|
||||
result.add(new Vector3d(minX, maxY, maxZ));
|
||||
break;
|
||||
case DOWN:
|
||||
case UNKNOWN:
|
||||
default:
|
||||
result.add(new Vector3d(minX, minY, maxZ));
|
||||
result.add(new Vector3d(minX, minY, minZ));
|
||||
result.add(new Vector3d(maxX, minY, minZ));
|
||||
result.add(new Vector3d(maxX, minY, maxZ));
|
||||
break;
|
||||
public BoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
|
||||
this.minX = (float) minX;
|
||||
this.minY = (float) minY;
|
||||
this.minZ = (float) minZ;
|
||||
this.maxX = (float) maxX;
|
||||
this.maxY = (float) maxY;
|
||||
this.maxZ = (float) maxZ;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Vector3d getCenter() {
|
||||
return new Vector3d(minX + (maxX - minX) / 2, minY + (maxY - minY) / 2, minZ + (maxZ - minZ) / 2);
|
||||
}
|
||||
|
||||
public float sizeX() {
|
||||
return Math.abs(maxX - minX);
|
||||
}
|
||||
|
||||
public float sizeY() {
|
||||
return Math.abs(maxY - minY);
|
||||
}
|
||||
|
||||
public float sizeZ() {
|
||||
return Math.abs(maxZ - minZ);
|
||||
}
|
||||
|
||||
public Vector3d getMin() {
|
||||
return new Vector3d(minX, minY, minZ);
|
||||
}
|
||||
|
||||
public Vector3d getMax() {
|
||||
return new Vector3d(maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public float getArea() {
|
||||
return sizeX() * sizeY() * sizeZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BoundingBox [minX=" + minX + ", minY=" + minY + ", minZ=" + minZ + ", maxX=" + maxX + ", maxY=" + maxY + ", maxZ=" + maxZ + "]";
|
||||
}
|
||||
|
||||
public BoundingBox fixMinMax() {
|
||||
float mnX = minX;
|
||||
float mnY = minY;
|
||||
float mnZ = minZ;
|
||||
float mxX = maxX;
|
||||
float mxY = maxY;
|
||||
float mxZ = maxZ;
|
||||
boolean mod = false;
|
||||
if (minX > maxX) {
|
||||
mnX = maxX;
|
||||
mxX = minX;
|
||||
mod = true;
|
||||
public BoundingBox(Vector3d min, Vector3d max) {
|
||||
this(min.x, min.y, min.z, max.x, max.y, max.z);
|
||||
}
|
||||
if (minY > maxY) {
|
||||
mnY = maxY;
|
||||
mxY = minY;
|
||||
mod = true;
|
||||
}
|
||||
if (minZ > maxZ) {
|
||||
mnZ = maxZ;
|
||||
mxZ = minZ;
|
||||
mod = true;
|
||||
}
|
||||
if (!mod) {
|
||||
return this;
|
||||
}
|
||||
return new BoundingBox(mnX, mnY, mnZ, mxX, mxY, mxZ);
|
||||
}
|
||||
|
||||
public AxisAlignedBB getAxisAlignedBB() {
|
||||
return AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
public BoundingBox(BoundingBox copy) {
|
||||
this(copy.minX, copy.minY, copy.minZ, copy.maxX, copy.maxY, copy.maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Float.floatToIntBits(maxX);
|
||||
result = prime * result + Float.floatToIntBits(maxY);
|
||||
result = prime * result + Float.floatToIntBits(maxZ);
|
||||
result = prime * result + Float.floatToIntBits(minX);
|
||||
result = prime * result + Float.floatToIntBits(minY);
|
||||
result = prime * result + Float.floatToIntBits(minZ);
|
||||
return result;
|
||||
}
|
||||
public BoundingBox(BlockCoord bc) {
|
||||
this(bc.x, bc.y, bc.z, bc.x + 1, bc.y + 1, bc.z + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BoundingBox other = (BoundingBox) obj;
|
||||
if (Float.floatToIntBits(maxX) != Float.floatToIntBits(other.maxX))
|
||||
return false;
|
||||
if (Float.floatToIntBits(maxY) != Float.floatToIntBits(other.maxY))
|
||||
return false;
|
||||
if (Float.floatToIntBits(maxZ) != Float.floatToIntBits(other.maxZ))
|
||||
return false;
|
||||
if (Float.floatToIntBits(minX) != Float.floatToIntBits(other.minX))
|
||||
return false;
|
||||
if (Float.floatToIntBits(minY) != Float.floatToIntBits(other.minY))
|
||||
return false;
|
||||
if (Float.floatToIntBits(minZ) != Float.floatToIntBits(other.minZ))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public BoundingBox(Block block) {
|
||||
this(
|
||||
block.getBlockBoundsMinX(),
|
||||
block.getBlockBoundsMinY(),
|
||||
block.getBlockBoundsMinZ(),
|
||||
block.getBlockBoundsMaxX(),
|
||||
block.getBlockBoundsMaxY(),
|
||||
block.getBlockBoundsMaxZ());
|
||||
}
|
||||
|
||||
public BoundingBox expandBy(BoundingBox other) {
|
||||
return new BoundingBox(
|
||||
Math.min(minX, other.minX),
|
||||
Math.min(minY, other.minY),
|
||||
Math.min(minZ, other.minZ),
|
||||
Math.max(maxX, other.maxX),
|
||||
Math.max(maxY, other.maxY),
|
||||
Math.max(maxZ, other.maxZ));
|
||||
}
|
||||
|
||||
public boolean contains(BoundingBox other) {
|
||||
return minX >= other.minX && minY <= other.minY
|
||||
&& minZ <= other.minZ
|
||||
&& maxX >= other.maxX
|
||||
&& maxY <= other.maxY
|
||||
&& maxZ <= other.maxZ;
|
||||
}
|
||||
|
||||
public boolean intersects(BoundingBox other) {
|
||||
return other.maxX > this.minX && other.minX < this.maxX
|
||||
? (other.maxY > this.minY && other.minY < this.maxY ? other.maxZ > this.minZ && other.minZ < this.maxZ
|
||||
: false)
|
||||
: false;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return minX < maxX && minY < maxY && minZ < maxZ;
|
||||
}
|
||||
|
||||
public BoundingBox scale(double x, double y, double z) {
|
||||
return scale((float) x, (float) y, (float) z);
|
||||
}
|
||||
|
||||
public BoundingBox scale(float x, float y, float z) {
|
||||
x = 1 - x;
|
||||
y = 1 - y;
|
||||
z = 1 - z;
|
||||
float w = ((maxX - minX) * x) / 2;
|
||||
float h = ((maxY - minY) * y) / 2;
|
||||
float d = ((maxZ - minZ) * z) / 2;
|
||||
return new BoundingBox(minX + w, minY + h, minZ + d, maxX - w, maxY - h, maxZ - d);
|
||||
}
|
||||
|
||||
public BoundingBox translate(float x, float y, float z) {
|
||||
return new BoundingBox(minX + x, minY + y, minZ + z, maxX + x, maxY + y, maxZ + z);
|
||||
}
|
||||
|
||||
public BoundingBox translate(Vector3d translation) {
|
||||
return translate((float) translation.x, (float) translation.y, (float) translation.z);
|
||||
}
|
||||
|
||||
public BoundingBox translate(Vector3f vec) {
|
||||
return translate(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
public BoundingBox transform(VertexTransform iTransformation) {
|
||||
Vector3d min = new Vector3d(minX, minY, minZ);
|
||||
Vector3d max = new Vector3d(maxX, maxY, maxZ);
|
||||
|
||||
iTransformation.apply(min);
|
||||
iTransformation.apply(max);
|
||||
|
||||
return new BoundingBox(
|
||||
Math.min(min.x, max.x),
|
||||
Math.min(min.y, max.y),
|
||||
Math.min(min.z, max.z),
|
||||
Math.max(min.x, max.x),
|
||||
Math.max(min.y, max.y),
|
||||
Math.max(min.z, max.z));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertices of the corners for the specified face in counter clockwise order.
|
||||
*/
|
||||
public List<Vertex> getCornersWithUvForFace(ForgeDirection face) {
|
||||
return getCornersWithUvForFace(face, 0, 1, 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertices of the corners for the specified face in counter clockwise order.
|
||||
*/
|
||||
public List<Vertex> getCornersWithUvForFace(ForgeDirection face, float minU, float maxU, float minV, float maxV) {
|
||||
List<Vertex> result = new ArrayList<Vertex>(4);
|
||||
switch (face) {
|
||||
case NORTH:
|
||||
result.add(
|
||||
new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(0, 0, -1), new Vector2f(minU, minV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(0, 0, -1), new Vector2f(maxU, minV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(0, 0, -1), new Vector2f(maxU, maxV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(0, 0, -1), new Vector2f(minU, maxV)));
|
||||
break;
|
||||
case SOUTH:
|
||||
result.add(new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(0, 0, 1), new Vector2f(maxU, minV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(0, 0, 1), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(0, 0, 1), new Vector2f(minU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(0, 0, 1), new Vector2f(maxU, maxV)));
|
||||
break;
|
||||
case EAST:
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(1, 0, 0), new Vector2f(maxU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(1, 0, 0), new Vector2f(minU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(1, 0, 0), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(1, 0, 0), new Vector2f(maxU, minV)));
|
||||
break;
|
||||
case WEST:
|
||||
result.add(
|
||||
new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(-1, 0, 0), new Vector2f(maxU, minV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(-1, 0, 0), new Vector2f(minU, minV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(-1, 0, 0), new Vector2f(minU, maxV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(-1, 0, 0), new Vector2f(maxU, maxV)));
|
||||
break;
|
||||
case UP:
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(0, 1, 0), new Vector2f(minU, minV)));
|
||||
result.add(new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(0, 1, 0), new Vector2f(minU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(0, 1, 0), new Vector2f(maxU, maxV)));
|
||||
result.add(new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(0, 1, 0), new Vector2f(maxU, minV)));
|
||||
break;
|
||||
case DOWN: //
|
||||
case UNKNOWN:
|
||||
default:
|
||||
result.add(
|
||||
new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(0, -1, 0), new Vector2f(maxU, maxV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(0, -1, 0), new Vector2f(minU, maxV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(0, -1, 0), new Vector2f(minU, minV)));
|
||||
result.add(
|
||||
new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(0, -1, 0), new Vector2f(maxU, minV)));
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertices of the corners for the specified face in counter clockwise order, starting with the top
|
||||
* left.
|
||||
*/
|
||||
public List<Vector3f> getCornersForFace(ForgeDirection face) {
|
||||
List<Vector3f> result = new ArrayList<Vector3f>(4);
|
||||
switch (face) {
|
||||
case NORTH:
|
||||
result.add(new Vector3f(minX, maxY, minZ));
|
||||
result.add(new Vector3f(maxX, maxY, minZ));
|
||||
result.add(new Vector3f(maxX, minY, minZ));
|
||||
result.add(new Vector3f(minX, minY, minZ));
|
||||
break;
|
||||
case SOUTH:
|
||||
result.add(new Vector3f(minX, maxY, maxZ));
|
||||
result.add(new Vector3f(minX, minY, maxZ));
|
||||
result.add(new Vector3f(maxX, minY, maxZ));
|
||||
result.add(new Vector3f(maxX, maxY, maxZ));
|
||||
break;
|
||||
case EAST:
|
||||
result.add(new Vector3f(maxX, minY, maxZ));
|
||||
result.add(new Vector3f(maxX, minY, minZ));
|
||||
result.add(new Vector3f(maxX, maxY, minZ));
|
||||
result.add(new Vector3f(maxX, maxY, maxZ));
|
||||
break;
|
||||
case WEST:
|
||||
result.add(new Vector3f(minX, maxY, maxZ));
|
||||
result.add(new Vector3f(minX, maxY, minZ));
|
||||
result.add(new Vector3f(minX, minY, minZ));
|
||||
result.add(new Vector3f(minX, minY, maxZ));
|
||||
break;
|
||||
case UP:
|
||||
result.add(new Vector3f(maxX, maxY, maxZ));
|
||||
result.add(new Vector3f(maxX, maxY, minZ));
|
||||
result.add(new Vector3f(minX, maxY, minZ));
|
||||
result.add(new Vector3f(minX, maxY, maxZ));
|
||||
break;
|
||||
case DOWN:
|
||||
case UNKNOWN:
|
||||
default:
|
||||
result.add(new Vector3f(minX, minY, maxZ));
|
||||
result.add(new Vector3f(minX, minY, minZ));
|
||||
result.add(new Vector3f(maxX, minY, minZ));
|
||||
result.add(new Vector3f(maxX, minY, maxZ));
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertices of the corners for the specified face in counter clockwise order, starting with the top
|
||||
* left.
|
||||
*/
|
||||
public List<Vector3d> getCornersForFaceD(ForgeDirection face) {
|
||||
List<Vector3d> result = new ArrayList<Vector3d>(4);
|
||||
switch (face) {
|
||||
case NORTH:
|
||||
result.add(new Vector3d(minX, maxY, minZ));
|
||||
result.add(new Vector3d(maxX, maxY, minZ));
|
||||
result.add(new Vector3d(maxX, minY, minZ));
|
||||
result.add(new Vector3d(minX, minY, minZ));
|
||||
break;
|
||||
case SOUTH:
|
||||
result.add(new Vector3d(minX, maxY, maxZ));
|
||||
result.add(new Vector3d(minX, minY, maxZ));
|
||||
result.add(new Vector3d(maxX, minY, maxZ));
|
||||
result.add(new Vector3d(maxX, maxY, maxZ));
|
||||
break;
|
||||
case EAST:
|
||||
result.add(new Vector3d(maxX, minY, maxZ));
|
||||
result.add(new Vector3d(maxX, minY, minZ));
|
||||
result.add(new Vector3d(maxX, maxY, minZ));
|
||||
result.add(new Vector3d(maxX, maxY, maxZ));
|
||||
break;
|
||||
case WEST:
|
||||
result.add(new Vector3d(minX, maxY, maxZ));
|
||||
result.add(new Vector3d(minX, maxY, minZ));
|
||||
result.add(new Vector3d(minX, minY, minZ));
|
||||
result.add(new Vector3d(minX, minY, maxZ));
|
||||
break;
|
||||
case UP:
|
||||
result.add(new Vector3d(maxX, maxY, maxZ));
|
||||
result.add(new Vector3d(maxX, maxY, minZ));
|
||||
result.add(new Vector3d(minX, maxY, minZ));
|
||||
result.add(new Vector3d(minX, maxY, maxZ));
|
||||
break;
|
||||
case DOWN:
|
||||
case UNKNOWN:
|
||||
default:
|
||||
result.add(new Vector3d(minX, minY, maxZ));
|
||||
result.add(new Vector3d(minX, minY, minZ));
|
||||
result.add(new Vector3d(maxX, minY, minZ));
|
||||
result.add(new Vector3d(maxX, minY, maxZ));
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Vector3d getCenter() {
|
||||
return new Vector3d(minX + (maxX - minX) / 2, minY + (maxY - minY) / 2, minZ + (maxZ - minZ) / 2);
|
||||
}
|
||||
|
||||
public float sizeX() {
|
||||
return Math.abs(maxX - minX);
|
||||
}
|
||||
|
||||
public float sizeY() {
|
||||
return Math.abs(maxY - minY);
|
||||
}
|
||||
|
||||
public float sizeZ() {
|
||||
return Math.abs(maxZ - minZ);
|
||||
}
|
||||
|
||||
public Vector3d getMin() {
|
||||
return new Vector3d(minX, minY, minZ);
|
||||
}
|
||||
|
||||
public Vector3d getMax() {
|
||||
return new Vector3d(maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public float getArea() {
|
||||
return sizeX() * sizeY() * sizeZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BoundingBox [minX=" + minX
|
||||
+ ", minY="
|
||||
+ minY
|
||||
+ ", minZ="
|
||||
+ minZ
|
||||
+ ", maxX="
|
||||
+ maxX
|
||||
+ ", maxY="
|
||||
+ maxY
|
||||
+ ", maxZ="
|
||||
+ maxZ
|
||||
+ "]";
|
||||
}
|
||||
|
||||
public BoundingBox fixMinMax() {
|
||||
float mnX = minX;
|
||||
float mnY = minY;
|
||||
float mnZ = minZ;
|
||||
float mxX = maxX;
|
||||
float mxY = maxY;
|
||||
float mxZ = maxZ;
|
||||
boolean mod = false;
|
||||
if (minX > maxX) {
|
||||
mnX = maxX;
|
||||
mxX = minX;
|
||||
mod = true;
|
||||
}
|
||||
if (minY > maxY) {
|
||||
mnY = maxY;
|
||||
mxY = minY;
|
||||
mod = true;
|
||||
}
|
||||
if (minZ > maxZ) {
|
||||
mnZ = maxZ;
|
||||
mxZ = minZ;
|
||||
mod = true;
|
||||
}
|
||||
if (!mod) {
|
||||
return this;
|
||||
}
|
||||
return new BoundingBox(mnX, mnY, mnZ, mxX, mxY, mxZ);
|
||||
}
|
||||
|
||||
public AxisAlignedBB getAxisAlignedBB() {
|
||||
return AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Float.floatToIntBits(maxX);
|
||||
result = prime * result + Float.floatToIntBits(maxY);
|
||||
result = prime * result + Float.floatToIntBits(maxZ);
|
||||
result = prime * result + Float.floatToIntBits(minX);
|
||||
result = prime * result + Float.floatToIntBits(minY);
|
||||
result = prime * result + Float.floatToIntBits(minZ);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
BoundingBox other = (BoundingBox) obj;
|
||||
if (Float.floatToIntBits(maxX) != Float.floatToIntBits(other.maxX)) return false;
|
||||
if (Float.floatToIntBits(maxY) != Float.floatToIntBits(other.maxY)) return false;
|
||||
if (Float.floatToIntBits(maxZ) != Float.floatToIntBits(other.maxZ)) return false;
|
||||
if (Float.floatToIntBits(minX) != Float.floatToIntBits(other.minX)) return false;
|
||||
if (Float.floatToIntBits(minY) != Float.floatToIntBits(other.minY)) return false;
|
||||
if (Float.floatToIntBits(minZ) != Float.floatToIntBits(other.minZ)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -9,83 +9,82 @@ import com.enderio.core.common.vecmath.Vector4f;
|
||||
|
||||
public final class ColorUtil {
|
||||
|
||||
public static Vector4f toFloat(Color color) {
|
||||
float[] rgba = color.getComponents(null);
|
||||
return new Vector4f(rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||
}
|
||||
public static Vector4f toFloat(Color color) {
|
||||
float[] rgba = color.getComponents(null);
|
||||
return new Vector4f(rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||
}
|
||||
|
||||
public static Vector3f toFloat(int rgb) {
|
||||
int r = rgb >> 16 & 255;
|
||||
int g = rgb >> 8 & 255;
|
||||
int b = rgb & 255;
|
||||
return new Vector3f(r / 255F, g / 255F, b / 255F);
|
||||
}
|
||||
public static Vector3f toFloat(int rgb) {
|
||||
int r = rgb >> 16 & 255;
|
||||
int g = rgb >> 8 & 255;
|
||||
int b = rgb & 255;
|
||||
return new Vector3f(r / 255F, g / 255F, b / 255F);
|
||||
}
|
||||
|
||||
public static int getRGB(Color color) {
|
||||
return getRGB(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
public static int getRGB(Color color) {
|
||||
return getRGB(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
public static int getRGBA(Color color) {
|
||||
return getRGBA(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
||||
}
|
||||
public static int getRGBA(Color color) {
|
||||
return getRGBA(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
||||
}
|
||||
|
||||
public static int getARGB(Color color) {
|
||||
return getRGBA(color.getAlpha(), color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
public static int getARGB(Color color) {
|
||||
return getRGBA(color.getAlpha(), color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
public static int getRGB(Vector3f rgb) {
|
||||
return getRGB(rgb.x, rgb.y, rgb.z);
|
||||
}
|
||||
public static int getRGB(Vector3f rgb) {
|
||||
return getRGB(rgb.x, rgb.y, rgb.z);
|
||||
}
|
||||
|
||||
public static int getRGB(float r, float g, float b) {
|
||||
return getRGB((int) (r * 255), (int) (g * 255), (int) (b * 255));
|
||||
}
|
||||
public static int getRGB(float r, float g, float b) {
|
||||
return getRGB((int) (r * 255), (int) (g * 255), (int) (b * 255));
|
||||
}
|
||||
|
||||
public static int getRGBA(Vector4f col) {
|
||||
return getRGBA(col.x, col.y, col.z, col.w);
|
||||
}
|
||||
public static int getRGBA(Vector4f col) {
|
||||
return getRGBA(col.x, col.y, col.z, col.w);
|
||||
}
|
||||
|
||||
public static int getRGBA(float r, float g, float b, float a) {
|
||||
return getRGBA((int) (r * 255), (int) (g * 255), (int) (b * 255), (int) (a * 255));
|
||||
}
|
||||
public static int getRGBA(float r, float g, float b, float a) {
|
||||
return getRGBA((int) (r * 255), (int) (g * 255), (int) (b * 255), (int) (a * 255));
|
||||
}
|
||||
|
||||
public static int getARGB(float r, float g, float b, float a) {
|
||||
return getARGB((int) (a * 255), (int) (r * 255), (int) (g * 255), (int) (b * 255));
|
||||
}
|
||||
public static int getARGB(float r, float g, float b, float a) {
|
||||
return getARGB((int) (a * 255), (int) (r * 255), (int) (g * 255), (int) (b * 255));
|
||||
}
|
||||
|
||||
public static int getRGB(int r, int g, int b) {
|
||||
return (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
|
||||
}
|
||||
public static int getRGB(int r, int g, int b) {
|
||||
return (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
|
||||
}
|
||||
|
||||
public static int getARGB(int r, int g, int b, int a) {
|
||||
return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
|
||||
}
|
||||
public static int getARGB(int r, int g, int b, int a) {
|
||||
return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
|
||||
}
|
||||
|
||||
public static int getRGBA(int r, int g, int b, int a) {
|
||||
return (r & 0xFF) << 24 | (g & 0xFF) << 16 | (b & 0xFF) << 8 | (a & 0xFF);
|
||||
}
|
||||
public static int getRGBA(int r, int g, int b, int a) {
|
||||
return (r & 0xFF) << 24 | (g & 0xFF) << 16 | (b & 0xFF) << 8 | (a & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns an int into a glColor4f function
|
||||
*
|
||||
* @author Buildcraft team
|
||||
*/
|
||||
public static void setGLColorFromInt(int color) {
|
||||
float red = (color >> 16 & 255) / 255.0F;
|
||||
float green = (color >> 8 & 255) / 255.0F;
|
||||
float blue = (color & 255) / 255.0F;
|
||||
GL11.glColor4f(red, green, blue, 1.0F);
|
||||
}
|
||||
/**
|
||||
* Turns an int into a glColor4f function
|
||||
*
|
||||
* @author Buildcraft team
|
||||
*/
|
||||
public static void setGLColorFromInt(int color) {
|
||||
float red = (color >> 16 & 255) / 255.0F;
|
||||
float green = (color >> 8 & 255) / 255.0F;
|
||||
float blue = (color & 255) / 255.0F;
|
||||
GL11.glColor4f(red, green, blue, 1.0F);
|
||||
}
|
||||
|
||||
public static int toHex(int r, int g, int b) {
|
||||
int hex = 0;
|
||||
hex = hex | ((r) << 16);
|
||||
hex = hex | ((g) << 8);
|
||||
hex = hex | ((b));
|
||||
return hex;
|
||||
}
|
||||
public static int toHex(int r, int g, int b) {
|
||||
int hex = 0;
|
||||
hex = hex | ((r) << 16);
|
||||
hex = hex | ((g) << 8);
|
||||
hex = hex | ((b));
|
||||
return hex;
|
||||
}
|
||||
|
||||
private ColorUtil() {
|
||||
}
|
||||
private ColorUtil() {}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.enderio.core.api.client.render.IConnectedTextureRenderer;
|
||||
import com.enderio.core.api.client.render.IRenderFace;
|
||||
import com.enderio.core.common.util.BlockCoord;
|
||||
@@ -13,325 +19,322 @@ import com.enderio.core.common.vecmath.Vector3d;
|
||||
import com.enderio.core.common.vecmath.Vector4f;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class ConnectedTextureRenderer implements IRenderFace, IConnectedTextureRenderer {
|
||||
|
||||
public static interface TextureCallback {
|
||||
public IIcon getTextureForFace(ForgeDirection dir);
|
||||
}
|
||||
public static interface TextureCallback {
|
||||
|
||||
public static class DefaultTextureCallback implements TextureCallback {
|
||||
|
||||
private final IIcon tex;
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
|
||||
public DefaultTextureCallback(IIcon borderTex) {
|
||||
this.tex = borderTex;
|
||||
block = null;
|
||||
meta = 0;
|
||||
public IIcon getTextureForFace(ForgeDirection dir);
|
||||
}
|
||||
|
||||
public DefaultTextureCallback(Block block, int meta) {
|
||||
tex = null;
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
public static class DefaultTextureCallback implements TextureCallback {
|
||||
|
||||
private final IIcon tex;
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
|
||||
public DefaultTextureCallback(IIcon borderTex) {
|
||||
this.tex = borderTex;
|
||||
block = null;
|
||||
meta = 0;
|
||||
}
|
||||
|
||||
public DefaultTextureCallback(Block block, int meta) {
|
||||
tex = null;
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getTextureForFace(ForgeDirection dir) {
|
||||
if (tex != null) {
|
||||
return tex;
|
||||
}
|
||||
if (block != null) {
|
||||
return block.getIcon(dir.ordinal(), meta);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean forceAllEdges = false;
|
||||
|
||||
private TextureCallback edgeTexureCallback;
|
||||
|
||||
private boolean matchMetaData;
|
||||
|
||||
private EnumSet<ForgeDirection> sidesToRender = EnumSet.allOf(ForgeDirection.class);
|
||||
|
||||
public boolean isForceAllEdges() {
|
||||
return forceAllEdges;
|
||||
}
|
||||
|
||||
public void setForceAllEdges(boolean forceAllEdges) {
|
||||
this.forceAllEdges = forceAllEdges;
|
||||
}
|
||||
|
||||
public TextureCallback getEdgeTexureCallback() {
|
||||
return edgeTexureCallback;
|
||||
}
|
||||
|
||||
public void setEdgeTexureCallback(TextureCallback edgeTexureCallback) {
|
||||
this.edgeTexureCallback = edgeTexureCallback;
|
||||
}
|
||||
|
||||
public void setEdgeTexture(IIcon texture) {
|
||||
if (texture == null) {
|
||||
edgeTexureCallback = null;
|
||||
return;
|
||||
}
|
||||
edgeTexureCallback = new DefaultTextureCallback(texture);
|
||||
}
|
||||
|
||||
public void setMatchMeta(boolean matchMetaData) {
|
||||
this.matchMetaData = matchMetaData;
|
||||
}
|
||||
|
||||
public void setSidesToRender(EnumSet<ForgeDirection> sides) {
|
||||
sidesToRender = sides.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getTextureForFace(ForgeDirection dir) {
|
||||
if (tex != null) {
|
||||
return tex;
|
||||
}
|
||||
if (block != null) {
|
||||
return block.getIcon(dir.ordinal(), meta);
|
||||
}
|
||||
return null;
|
||||
public boolean matchesMetadata(int meta1, int meta2) {
|
||||
return !this.matchMetaData || meta1 == meta2;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void renderFace(CustomRenderBlocks rb, ForgeDirection face, Block par1Block, double x, double y, double z,
|
||||
IIcon texture, List<Vertex> refVertices, boolean translateToXYZ) {
|
||||
|
||||
private boolean forceAllEdges = false;
|
||||
|
||||
private TextureCallback edgeTexureCallback;
|
||||
|
||||
private boolean matchMetaData;
|
||||
|
||||
private EnumSet<ForgeDirection> sidesToRender = EnumSet.allOf(ForgeDirection.class);
|
||||
|
||||
public boolean isForceAllEdges() {
|
||||
return forceAllEdges;
|
||||
}
|
||||
|
||||
public void setForceAllEdges(boolean forceAllEdges) {
|
||||
this.forceAllEdges = forceAllEdges;
|
||||
}
|
||||
|
||||
public TextureCallback getEdgeTexureCallback() {
|
||||
return edgeTexureCallback;
|
||||
}
|
||||
|
||||
public void setEdgeTexureCallback(TextureCallback edgeTexureCallback) {
|
||||
this.edgeTexureCallback = edgeTexureCallback;
|
||||
}
|
||||
|
||||
public void setEdgeTexture(IIcon texture) {
|
||||
if (texture == null) {
|
||||
edgeTexureCallback = null;
|
||||
return;
|
||||
}
|
||||
edgeTexureCallback = new DefaultTextureCallback(texture);
|
||||
}
|
||||
|
||||
public void setMatchMeta(boolean matchMetaData) {
|
||||
this.matchMetaData = matchMetaData;
|
||||
}
|
||||
|
||||
public void setSidesToRender(EnumSet<ForgeDirection> sides) {
|
||||
sidesToRender = sides.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesMetadata(int meta1, int meta2) {
|
||||
return !this.matchMetaData || meta1 == meta2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFace(CustomRenderBlocks rb, ForgeDirection face, Block par1Block, double x, double y, double z, IIcon texture, List<Vertex> refVertices,
|
||||
boolean translateToXYZ) {
|
||||
|
||||
if (!sidesToRender.contains(face)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Vertex> finalVerts = new ArrayList<Vertex>();
|
||||
finalVerts.addAll(refVertices);
|
||||
|
||||
IIcon borderTex = edgeTexureCallback == null ? null : edgeTexureCallback.getTextureForFace(face);
|
||||
if (borderTex != null) {
|
||||
|
||||
texture = borderTex;
|
||||
List<ForgeDirection> edges;
|
||||
if (forceAllEdges) {
|
||||
edges = RenderUtil.getEdgesForFace(face);
|
||||
} else {
|
||||
edges = RenderUtil.getNonConectedEdgesForFace(rb.blockAccess, (int) x, (int) y, (int) z, face, this);
|
||||
}
|
||||
|
||||
List<ForgeDirection> allEdges = RenderUtil.getEdgesForFace(face);
|
||||
|
||||
float scaleFactor = 15f / 16f;
|
||||
Vector2f uv = new Vector2f();
|
||||
|
||||
//for each that needs a border, add a geom for the border and move in the 'centre' of the face
|
||||
//so there is no overlap
|
||||
for (ForgeDirection edge : edges) {
|
||||
|
||||
//We need to move the 'centre' of the face so it doesn't overlap with the border
|
||||
moveCorners(refVertices, edge, 1 - scaleFactor);
|
||||
|
||||
//Now create the geometry for this edge of the border
|
||||
float xLen = 1 - Math.abs(edge.offsetX) * scaleFactor;
|
||||
float yLen = 1 - Math.abs(edge.offsetY) * scaleFactor;
|
||||
float zLen = 1 - Math.abs(edge.offsetZ) * scaleFactor;
|
||||
|
||||
xLen -= 2 * (1 - par1Block.getBlockBoundsMaxX()) - par1Block.getBlockBoundsMinX();
|
||||
yLen -= 2 * (1 - par1Block.getBlockBoundsMaxY()) - par1Block.getBlockBoundsMinY();
|
||||
zLen -= 2 * (1 - par1Block.getBlockBoundsMaxZ()) - par1Block.getBlockBoundsMinZ();
|
||||
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE.scale(xLen, yLen, zLen);
|
||||
|
||||
List<Vector3d> corners = bb.getCornersForFaceD(face);
|
||||
for (Vector3d corner : corners) {
|
||||
if (translateToXYZ) {
|
||||
corner.x += x;
|
||||
corner.y += y;
|
||||
corner.z += z;
|
||||
}
|
||||
corner.x += (float) (edge.offsetX * 0.5) - Math.signum(edge.offsetX) * xLen / 2f;
|
||||
corner.y += (float) (edge.offsetY * 0.5) - Math.signum(edge.offsetY) * yLen / 2f;
|
||||
corner.z += (float) (edge.offsetZ * 0.5) - Math.signum(edge.offsetZ) * zLen / 2f;
|
||||
if (!sidesToRender.contains(face)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[] { 0, 1, 2, 3 };
|
||||
for (int index : indices) {
|
||||
Vector3d corner = corners.get(index);
|
||||
if (translateToXYZ) {
|
||||
RenderUtil.getUvForCorner(uv, corner, (int) x, (int) y, (int) z, face, texture);
|
||||
} else {
|
||||
RenderUtil.getUvForCorner(uv, corner, 0, 0, 0, face, texture);
|
||||
}
|
||||
Vertex vertex = new Vertex();
|
||||
vertex.xyz.set(corner);
|
||||
//vertex.xyz.add(ForgeDirectionOffsets.offsetScaled(face, 0.00005));
|
||||
vertex.uv = new Vector2f(uv);
|
||||
applyLighting(vertex, corner, refVertices);
|
||||
finalVerts.add(vertex);
|
||||
List<Vertex> finalVerts = new ArrayList<Vertex>();
|
||||
finalVerts.addAll(refVertices);
|
||||
|
||||
IIcon borderTex = edgeTexureCallback == null ? null : edgeTexureCallback.getTextureForFace(face);
|
||||
if (borderTex != null) {
|
||||
|
||||
texture = borderTex;
|
||||
List<ForgeDirection> edges;
|
||||
if (forceAllEdges) {
|
||||
edges = RenderUtil.getEdgesForFace(face);
|
||||
} else {
|
||||
edges = RenderUtil.getNonConectedEdgesForFace(rb.blockAccess, (int) x, (int) y, (int) z, face, this);
|
||||
}
|
||||
|
||||
List<ForgeDirection> allEdges = RenderUtil.getEdgesForFace(face);
|
||||
|
||||
float scaleFactor = 15f / 16f;
|
||||
Vector2f uv = new Vector2f();
|
||||
|
||||
// for each that needs a border, add a geom for the border and move in the 'centre' of the face
|
||||
// so there is no overlap
|
||||
for (ForgeDirection edge : edges) {
|
||||
|
||||
// We need to move the 'centre' of the face so it doesn't overlap with the border
|
||||
moveCorners(refVertices, edge, 1 - scaleFactor);
|
||||
|
||||
// Now create the geometry for this edge of the border
|
||||
float xLen = 1 - Math.abs(edge.offsetX) * scaleFactor;
|
||||
float yLen = 1 - Math.abs(edge.offsetY) * scaleFactor;
|
||||
float zLen = 1 - Math.abs(edge.offsetZ) * scaleFactor;
|
||||
|
||||
xLen -= 2 * (1 - par1Block.getBlockBoundsMaxX()) - par1Block.getBlockBoundsMinX();
|
||||
yLen -= 2 * (1 - par1Block.getBlockBoundsMaxY()) - par1Block.getBlockBoundsMinY();
|
||||
zLen -= 2 * (1 - par1Block.getBlockBoundsMaxZ()) - par1Block.getBlockBoundsMinZ();
|
||||
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE.scale(xLen, yLen, zLen);
|
||||
|
||||
List<Vector3d> corners = bb.getCornersForFaceD(face);
|
||||
for (Vector3d corner : corners) {
|
||||
if (translateToXYZ) {
|
||||
corner.x += x;
|
||||
corner.y += y;
|
||||
corner.z += z;
|
||||
}
|
||||
corner.x += (float) (edge.offsetX * 0.5) - Math.signum(edge.offsetX) * xLen / 2f;
|
||||
corner.y += (float) (edge.offsetY * 0.5) - Math.signum(edge.offsetY) * yLen / 2f;
|
||||
corner.z += (float) (edge.offsetZ * 0.5) - Math.signum(edge.offsetZ) * zLen / 2f;
|
||||
}
|
||||
|
||||
int[] indices = new int[] { 0, 1, 2, 3 };
|
||||
for (int index : indices) {
|
||||
Vector3d corner = corners.get(index);
|
||||
if (translateToXYZ) {
|
||||
RenderUtil.getUvForCorner(uv, corner, (int) x, (int) y, (int) z, face, texture);
|
||||
} else {
|
||||
RenderUtil.getUvForCorner(uv, corner, 0, 0, 0, face, texture);
|
||||
}
|
||||
Vertex vertex = new Vertex();
|
||||
vertex.xyz.set(corner);
|
||||
// vertex.xyz.add(ForgeDirectionOffsets.offsetScaled(face, 0.00005));
|
||||
vertex.uv = new Vector2f(uv);
|
||||
applyLighting(vertex, corner, refVertices);
|
||||
finalVerts.add(vertex);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < allEdges.size(); i++) {
|
||||
ForgeDirection dir = allEdges.get(i);
|
||||
ForgeDirection dir2 = i + 1 < allEdges.size() ? allEdges.get(i + 1) : allEdges.get(0);
|
||||
if (needsCorner(dir, dir2, edges, face, par1Block, x, y, z, rb.blockAccess)) {
|
||||
|
||||
Vertex v = new Vertex();
|
||||
v.uv = new Vector2f();
|
||||
v.xyz.set(ForgeDirectionOffsets.forDir(dir));
|
||||
v.xyz.add(ForgeDirectionOffsets.forDir(dir2));
|
||||
// TODO: dodgy hack to just move the corner forward a bit
|
||||
v.xyz.add(ForgeDirectionOffsets.offsetScaled(face, 0.001f));
|
||||
v.xyz.x = Math.max(-0.001, v.xyz.x);
|
||||
v.xyz.y = Math.max(-0.001, v.xyz.y);
|
||||
v.xyz.z = Math.max(-0.001, v.xyz.z);
|
||||
|
||||
v.xyz.x -= (1 - par1Block.getBlockBoundsMaxX()) - par1Block.getBlockBoundsMinX();
|
||||
v.xyz.y -= (1 - par1Block.getBlockBoundsMaxY()) - par1Block.getBlockBoundsMinY();
|
||||
v.xyz.z -= (1 - par1Block.getBlockBoundsMaxZ()) - par1Block.getBlockBoundsMinZ();
|
||||
|
||||
if (ForgeDirectionOffsets.isPositiveOffset(face)) {
|
||||
v.xyz.add(ForgeDirectionOffsets.forDir(face));
|
||||
}
|
||||
|
||||
if (translateToXYZ) {
|
||||
v.xyz.x += x;
|
||||
v.xyz.y += y;
|
||||
v.xyz.z += z;
|
||||
RenderUtil.getUvForCorner(v.uv, v.xyz, (int) x, (int) y, (int) z, face, texture);
|
||||
} else {
|
||||
RenderUtil.getUvForCorner(v.uv, v.xyz, 0, 0, 0, face, texture);
|
||||
}
|
||||
applyLighting(v, v.xyz, refVertices);
|
||||
|
||||
finalVerts.add(v);
|
||||
|
||||
Vector3d corner = new Vector3d(v.xyz);
|
||||
if (ForgeDirectionOffsets.isPositiveOffset(face)) {
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir2, null, corner);
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir, dir2, corner);
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir, null, corner);
|
||||
} else {
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir, null, corner);
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir, dir2, corner);
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir2, null, corner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < allEdges.size(); i++) {
|
||||
ForgeDirection dir = allEdges.get(i);
|
||||
ForgeDirection dir2 = i + 1 < allEdges.size() ? allEdges.get(i + 1) : allEdges.get(0);
|
||||
if (needsCorner(dir, dir2, edges, face, par1Block, x, y, z, rb.blockAccess)) {
|
||||
RenderUtil.addVerticesToTessellator(finalVerts, Tessellator.instance);
|
||||
}
|
||||
|
||||
Vertex v = new Vertex();
|
||||
v.uv = new Vector2f();
|
||||
v.xyz.set(ForgeDirectionOffsets.forDir(dir));
|
||||
v.xyz.add(ForgeDirectionOffsets.forDir(dir2));
|
||||
//TODO: dodgy hack to just move the corner forward a bit
|
||||
v.xyz.add(ForgeDirectionOffsets.offsetScaled(face, 0.001f));
|
||||
v.xyz.x = Math.max(-0.001, v.xyz.x);
|
||||
v.xyz.y = Math.max(-0.001, v.xyz.y);
|
||||
v.xyz.z = Math.max(-0.001, v.xyz.z);
|
||||
|
||||
v.xyz.x -= (1 - par1Block.getBlockBoundsMaxX()) - par1Block.getBlockBoundsMinX();
|
||||
v.xyz.y -= (1 - par1Block.getBlockBoundsMaxY()) - par1Block.getBlockBoundsMinY();
|
||||
v.xyz.z -= (1 - par1Block.getBlockBoundsMaxZ()) - par1Block.getBlockBoundsMinZ();
|
||||
|
||||
if (ForgeDirectionOffsets.isPositiveOffset(face)) {
|
||||
v.xyz.add(ForgeDirectionOffsets.forDir(face));
|
||||
}
|
||||
|
||||
if (translateToXYZ) {
|
||||
v.xyz.x += x;
|
||||
v.xyz.y += y;
|
||||
v.xyz.z += z;
|
||||
RenderUtil.getUvForCorner(v.uv, v.xyz, (int) x, (int) y, (int) z, face, texture);
|
||||
} else {
|
||||
RenderUtil.getUvForCorner(v.uv, v.xyz, 0, 0, 0, face, texture);
|
||||
}
|
||||
applyLighting(v, v.xyz, refVertices);
|
||||
|
||||
finalVerts.add(v);
|
||||
|
||||
Vector3d corner = new Vector3d(v.xyz);
|
||||
if (ForgeDirectionOffsets.isPositiveOffset(face)) {
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir2, null, corner);
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir, dir2, corner);
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir, null, corner);
|
||||
} else {
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir, null, corner);
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir, dir2, corner);
|
||||
addVertexForCorner(face, x, y, z, texture, translateToXYZ, finalVerts, dir2, null, corner);
|
||||
}
|
||||
private Vertex getClosestVertex(List<Vertex> vertices, Vector3d corner) {
|
||||
Vertex result = null;
|
||||
double d2 = Double.MAX_VALUE;
|
||||
for (Vertex v : vertices) {
|
||||
double tmp = corner.distanceSquared(v.xyz);
|
||||
if (tmp <= d2) {
|
||||
result = v;
|
||||
d2 = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
RenderUtil.addVerticesToTessellator(finalVerts, Tessellator.instance);
|
||||
}
|
||||
|
||||
private Vertex getClosestVertex(List<Vertex> vertices, Vector3d corner) {
|
||||
Vertex result = null;
|
||||
double d2 = Double.MAX_VALUE;
|
||||
for (Vertex v : vertices) {
|
||||
double tmp = corner.distanceSquared(v.xyz);
|
||||
if (tmp <= d2) {
|
||||
result = v;
|
||||
d2 = tmp;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addVertexForCorner(ForgeDirection face, double x, double y, double z, IIcon texture, boolean translateToXYZ, List<Vertex> vertices,
|
||||
ForgeDirection dir, ForgeDirection dir2, Vector3d corner) {
|
||||
float scale = 1 / 16f;
|
||||
Vertex vert = new Vertex();
|
||||
vert.uv = new Vector2f();
|
||||
vert.xyz.set(corner);
|
||||
vert.xyz.sub(ForgeDirectionOffsets.offsetScaled(dir, scale));
|
||||
if (dir2 != null) {
|
||||
vert.xyz.sub(ForgeDirectionOffsets.offsetScaled(dir2, scale));
|
||||
}
|
||||
if (translateToXYZ) {
|
||||
RenderUtil.getUvForCorner(vert.uv, vert.xyz, (int) x, (int) y, (int) z, face, texture);
|
||||
} else {
|
||||
RenderUtil.getUvForCorner(vert.uv, vert.xyz, 0, 0, 0, face, texture);
|
||||
}
|
||||
applyLighting(vert, corner, vertices);
|
||||
vertices.add(vert);
|
||||
}
|
||||
|
||||
private void applyLighting(Vertex vert, Vector3d samplePoint, List<Vertex> litVertices) {
|
||||
Vertex closest = getClosestVertex(litVertices, samplePoint);
|
||||
if (closest == null) {
|
||||
return;
|
||||
}
|
||||
vert.setBrightness(closest.brightness);
|
||||
Vector4f col = closest.getColor();
|
||||
if (col != null) {
|
||||
vert.setColor(col);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needsCorner(ForgeDirection dir, ForgeDirection dir2, List<ForgeDirection> edges, ForgeDirection face, Block par1Block, double x, double y,
|
||||
double z, IBlockAccess blockAccess) {
|
||||
|
||||
if (edges.contains(dir) || edges.contains(dir2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockCoord bc = new BlockCoord((int) x, (int) y, (int) z);
|
||||
BlockCoord testLoc = bc.getLocation(dir);
|
||||
if (RenderUtil.getNonConectedEdgesForFace(blockAccess, testLoc.x, testLoc.y, testLoc.z, face, this).contains(dir2)) {
|
||||
return true;
|
||||
}
|
||||
testLoc = bc.getLocation(dir2);
|
||||
if (RenderUtil.getNonConectedEdgesForFace(blockAccess, testLoc.x, testLoc.y, testLoc.z, face, this).contains(dir)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void moveCorners(List<Vertex> vertices, ForgeDirection edge, float scaleFactor) {
|
||||
int[] indices = getClosest(edge, vertices);
|
||||
if (indices[0] < 0) {
|
||||
return;
|
||||
}
|
||||
vertices.get(indices[0]).xyz.x -= scaleFactor * edge.offsetX;
|
||||
vertices.get(indices[1]).xyz.x -= scaleFactor * edge.offsetX;
|
||||
vertices.get(indices[0]).xyz.y -= scaleFactor * edge.offsetY;
|
||||
vertices.get(indices[1]).xyz.y -= scaleFactor * edge.offsetY;
|
||||
vertices.get(indices[0]).xyz.z -= scaleFactor * edge.offsetZ;
|
||||
vertices.get(indices[1]).xyz.z -= scaleFactor * edge.offsetZ;
|
||||
}
|
||||
|
||||
private int[] getClosest(ForgeDirection edge, List<Vertex> vertices) {
|
||||
int[] res = new int[] { -1, -1 };
|
||||
boolean highest = edge.offsetX > 0 || edge.offsetY > 0 || edge.offsetZ > 0;
|
||||
double minMax = highest ? -Double.MAX_VALUE : Double.MAX_VALUE;
|
||||
int index = 0;
|
||||
for (Vertex v : vertices) {
|
||||
double val = get(v.xyz, edge);
|
||||
if (highest ? val >= minMax : val <= minMax) {
|
||||
if (val != minMax) {
|
||||
res[0] = index;
|
||||
private void addVertexForCorner(ForgeDirection face, double x, double y, double z, IIcon texture,
|
||||
boolean translateToXYZ, List<Vertex> vertices, ForgeDirection dir, ForgeDirection dir2, Vector3d corner) {
|
||||
float scale = 1 / 16f;
|
||||
Vertex vert = new Vertex();
|
||||
vert.uv = new Vector2f();
|
||||
vert.xyz.set(corner);
|
||||
vert.xyz.sub(ForgeDirectionOffsets.offsetScaled(dir, scale));
|
||||
if (dir2 != null) {
|
||||
vert.xyz.sub(ForgeDirectionOffsets.offsetScaled(dir2, scale));
|
||||
}
|
||||
if (translateToXYZ) {
|
||||
RenderUtil.getUvForCorner(vert.uv, vert.xyz, (int) x, (int) y, (int) z, face, texture);
|
||||
} else {
|
||||
res[1] = index;
|
||||
RenderUtil.getUvForCorner(vert.uv, vert.xyz, 0, 0, 0, face, texture);
|
||||
}
|
||||
minMax = val;
|
||||
}
|
||||
index++;
|
||||
applyLighting(vert, corner, vertices);
|
||||
vertices.add(vert);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private double get(Vector3d xyz, ForgeDirection edge) {
|
||||
if (edge == ForgeDirection.EAST || edge == ForgeDirection.WEST) {
|
||||
return xyz.x;
|
||||
private void applyLighting(Vertex vert, Vector3d samplePoint, List<Vertex> litVertices) {
|
||||
Vertex closest = getClosestVertex(litVertices, samplePoint);
|
||||
if (closest == null) {
|
||||
return;
|
||||
}
|
||||
vert.setBrightness(closest.brightness);
|
||||
Vector4f col = closest.getColor();
|
||||
if (col != null) {
|
||||
vert.setColor(col);
|
||||
}
|
||||
}
|
||||
if (edge == ForgeDirection.UP || edge == ForgeDirection.DOWN) {
|
||||
return xyz.y;
|
||||
|
||||
private boolean needsCorner(ForgeDirection dir, ForgeDirection dir2, List<ForgeDirection> edges,
|
||||
ForgeDirection face, Block par1Block, double x, double y, double z, IBlockAccess blockAccess) {
|
||||
|
||||
if (edges.contains(dir) || edges.contains(dir2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockCoord bc = new BlockCoord((int) x, (int) y, (int) z);
|
||||
BlockCoord testLoc = bc.getLocation(dir);
|
||||
if (RenderUtil.getNonConectedEdgesForFace(blockAccess, testLoc.x, testLoc.y, testLoc.z, face, this)
|
||||
.contains(dir2)) {
|
||||
return true;
|
||||
}
|
||||
testLoc = bc.getLocation(dir2);
|
||||
if (RenderUtil.getNonConectedEdgesForFace(blockAccess, testLoc.x, testLoc.y, testLoc.z, face, this)
|
||||
.contains(dir)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void moveCorners(List<Vertex> vertices, ForgeDirection edge, float scaleFactor) {
|
||||
int[] indices = getClosest(edge, vertices);
|
||||
if (indices[0] < 0) {
|
||||
return;
|
||||
}
|
||||
vertices.get(indices[0]).xyz.x -= scaleFactor * edge.offsetX;
|
||||
vertices.get(indices[1]).xyz.x -= scaleFactor * edge.offsetX;
|
||||
vertices.get(indices[0]).xyz.y -= scaleFactor * edge.offsetY;
|
||||
vertices.get(indices[1]).xyz.y -= scaleFactor * edge.offsetY;
|
||||
vertices.get(indices[0]).xyz.z -= scaleFactor * edge.offsetZ;
|
||||
vertices.get(indices[1]).xyz.z -= scaleFactor * edge.offsetZ;
|
||||
}
|
||||
|
||||
private int[] getClosest(ForgeDirection edge, List<Vertex> vertices) {
|
||||
int[] res = new int[] { -1, -1 };
|
||||
boolean highest = edge.offsetX > 0 || edge.offsetY > 0 || edge.offsetZ > 0;
|
||||
double minMax = highest ? -Double.MAX_VALUE : Double.MAX_VALUE;
|
||||
int index = 0;
|
||||
for (Vertex v : vertices) {
|
||||
double val = get(v.xyz, edge);
|
||||
if (highest ? val >= minMax : val <= minMax) {
|
||||
if (val != minMax) {
|
||||
res[0] = index;
|
||||
} else {
|
||||
res[1] = index;
|
||||
}
|
||||
minMax = val;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private double get(Vector3d xyz, ForgeDirection edge) {
|
||||
if (edge == ForgeDirection.EAST || edge == ForgeDirection.WEST) {
|
||||
return xyz.x;
|
||||
}
|
||||
if (edge == ForgeDirection.UP || edge == ForgeDirection.DOWN) {
|
||||
return xyz.y;
|
||||
}
|
||||
return xyz.z;
|
||||
}
|
||||
return xyz.z;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,337 +1,341 @@
|
||||
package com.enderio.core.client.render;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
|
||||
public final class CubeRenderer {
|
||||
|
||||
public static final Vector3d[] verts = new Vector3d[8];
|
||||
static {
|
||||
for (int i = 0; i < verts.length; i++) {
|
||||
verts[i] = new Vector3d();
|
||||
}
|
||||
}
|
||||
|
||||
public static void render(Block block, int meta) {
|
||||
render(block, meta, null);
|
||||
}
|
||||
|
||||
public static void render(Block block, int meta, VertexTransform xForm) {
|
||||
IIcon[] icons = new IIcon[6];
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
icons[dir.ordinal()] = block.getIcon(dir.ordinal(), meta);
|
||||
}
|
||||
render(BoundingBox.UNIT_CUBE.translate(0, -0.1f, 0), icons, xForm, true);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon tex) {
|
||||
render(bb, tex, null, false);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon tex, boolean tintSides) {
|
||||
render(bb, tex, null, tintSides);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon tex, VertexTransform xForm) {
|
||||
render(bb, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), xForm, false);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon tex, VertexTransform xForm, float[] brightnessPerSide, boolean tintSides) {
|
||||
float minU = 0;
|
||||
float minV = 0;
|
||||
float maxU = 1;
|
||||
float maxV = 1;
|
||||
if (tex != null) {
|
||||
minU = tex.getMinU();
|
||||
minV = tex.getMinV();
|
||||
maxU = tex.getMaxU();
|
||||
maxV = tex.getMaxV();
|
||||
}
|
||||
render(bb, minU, maxU, minV, maxV, xForm, brightnessPerSide, tintSides);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon tex, VertexTransform xForm, boolean tintSides) {
|
||||
float minU = 0;
|
||||
float minV = 0;
|
||||
float maxU = 1;
|
||||
float maxV = 1;
|
||||
if (tex != null) {
|
||||
minU = tex.getMinU();
|
||||
minV = tex.getMinV();
|
||||
maxU = tex.getMaxU();
|
||||
maxV = tex.getMaxV();
|
||||
}
|
||||
render(bb, minU, maxU, minV, maxV, xForm, tintSides);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, boolean tintSides) {
|
||||
render(bb, minU, maxU, minV, maxV, null, tintSides);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV) {
|
||||
render(bb, minU, maxU, minV, maxV, null, false);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, VertexTransform xForm) {
|
||||
render(bb, minU, maxU, minV, maxV, xForm, false);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, VertexTransform xForm, boolean tintSides) {
|
||||
float[] brightnessPerSide = null;
|
||||
if (tintSides) {
|
||||
brightnessPerSide = new float[6];
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
brightnessPerSide[dir.ordinal()] = RenderUtil.getColorMultiplierForFace(dir);
|
||||
}
|
||||
}
|
||||
render(bb, minU, maxU, minV, maxV, xForm, brightnessPerSide);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, VertexTransform xForm, float[] brightnessPerSide, boolean tintSides) {
|
||||
|
||||
if (tintSides) {
|
||||
if (brightnessPerSide == null || brightnessPerSide.length != 6) {
|
||||
brightnessPerSide = new float[] { 1, 1, 1, 1, 1, 1 };
|
||||
}
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
brightnessPerSide[dir.ordinal()] = brightnessPerSide[dir.ordinal()] * RenderUtil.getColorMultiplierForFace(dir);
|
||||
}
|
||||
|
||||
}
|
||||
render(bb, minU, maxU, minV, maxV, xForm, brightnessPerSide);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, VertexTransform xForm, float[] brightnessPerSide) {
|
||||
|
||||
if (brightnessPerSide != null && brightnessPerSide.length != 6) {
|
||||
brightnessPerSide = null;
|
||||
public static final Vector3d[] verts = new Vector3d[8];
|
||||
static {
|
||||
for (int i = 0; i < verts.length; i++) {
|
||||
verts[i] = new Vector3d();
|
||||
}
|
||||
}
|
||||
|
||||
setupVertices(bb, xForm);
|
||||
|
||||
float tmp = minV;
|
||||
minV = maxV;
|
||||
maxV = tmp;
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.setNormal(0, 0, -1);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.NORTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[1], minU, minV);
|
||||
addVecWithUV(verts[0], maxU, minV);
|
||||
addVecWithUV(verts[3], maxU, maxV);
|
||||
addVecWithUV(verts[2], minU, maxV);
|
||||
|
||||
tessellator.setNormal(0, 0, 1);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.SOUTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[4], minU, minV);
|
||||
addVecWithUV(verts[5], maxU, minV);
|
||||
addVecWithUV(verts[6], maxU, maxV);
|
||||
addVecWithUV(verts[7], minU, maxV);
|
||||
|
||||
tessellator.setNormal(0, 1, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.UP.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[6], minU, minV);
|
||||
addVecWithUV(verts[2], minU, maxV);
|
||||
addVecWithUV(verts[3], maxU, maxV);
|
||||
addVecWithUV(verts[7], maxU, minV);
|
||||
|
||||
tessellator.setNormal(0, -1, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.DOWN.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[0], maxU, maxV);
|
||||
addVecWithUV(verts[1], minU, maxV);
|
||||
addVecWithUV(verts[5], minU, minV);
|
||||
addVecWithUV(verts[4], maxU, minV);
|
||||
|
||||
tessellator.setNormal(1, 0, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.EAST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[2], minU, maxV);
|
||||
addVecWithUV(verts[6], maxU, maxV);
|
||||
addVecWithUV(verts[5], maxU, minV);
|
||||
addVecWithUV(verts[1], minU, minV);
|
||||
|
||||
tessellator.setNormal(-1, 0, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.WEST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[0], minU, minV);
|
||||
addVecWithUV(verts[4], maxU, minV);
|
||||
addVecWithUV(verts[7], maxU, maxV);
|
||||
addVecWithUV(verts[3], minU, maxV);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon[] icons, boolean tintSides) {
|
||||
float[] brightnessPerSide = null;
|
||||
if (tintSides) {
|
||||
brightnessPerSide = new float[6];
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
brightnessPerSide[dir.ordinal()] = RenderUtil.getColorMultiplierForFace(dir);
|
||||
}
|
||||
}
|
||||
render(bb, icons, null, brightnessPerSide);
|
||||
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon[] icons, VertexTransform xForm, boolean tintSides) {
|
||||
float[] brightnessPerSide = null;
|
||||
if (tintSides) {
|
||||
brightnessPerSide = new float[6];
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
brightnessPerSide[dir.ordinal()] = RenderUtil.getColorMultiplierForFace(dir);
|
||||
}
|
||||
}
|
||||
render(bb, icons, xForm, brightnessPerSide);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon[] faceTextures, VertexTransform xForm, float[] brightnessPerSide) {
|
||||
setupVertices(bb, xForm);
|
||||
float minU;
|
||||
float maxU;
|
||||
float minV;
|
||||
float maxV;
|
||||
IIcon tex;
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.setNormal(0, 0, -1);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.NORTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
public static void render(Block block, int meta) {
|
||||
render(block, meta, null);
|
||||
}
|
||||
|
||||
tex = faceTextures[ForgeDirection.NORTH.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[1], minU, maxV);
|
||||
addVecWithUV(verts[0], maxU, maxV);
|
||||
addVecWithUV(verts[3], maxU, minV);
|
||||
addVecWithUV(verts[2], minU, minV);
|
||||
|
||||
tessellator.setNormal(0, 0, 1);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.SOUTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
public static void render(Block block, int meta, VertexTransform xForm) {
|
||||
IIcon[] icons = new IIcon[6];
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
icons[dir.ordinal()] = block.getIcon(dir.ordinal(), meta);
|
||||
}
|
||||
render(BoundingBox.UNIT_CUBE.translate(0, -0.1f, 0), icons, xForm, true);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.SOUTH.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[4], minU, maxV);
|
||||
addVecWithUV(verts[5], maxU, maxV);
|
||||
addVecWithUV(verts[6], maxU, minV);
|
||||
addVecWithUV(verts[7], minU, minV);
|
||||
|
||||
tessellator.setNormal(0, 1, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.UP.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
public static void render(BoundingBox bb, IIcon tex) {
|
||||
render(bb, tex, null, false);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.UP.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[6], minU, minV);
|
||||
addVecWithUV(verts[2], minU, maxV);
|
||||
addVecWithUV(verts[3], maxU, maxV);
|
||||
addVecWithUV(verts[7], maxU, minV);
|
||||
|
||||
tessellator.setNormal(0, -1, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.DOWN.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
public static void render(BoundingBox bb, IIcon tex, boolean tintSides) {
|
||||
render(bb, tex, null, tintSides);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.DOWN.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[0], maxU, maxV);
|
||||
addVecWithUV(verts[1], minU, maxV);
|
||||
addVecWithUV(verts[5], minU, minV);
|
||||
addVecWithUV(verts[4], maxU, minV);
|
||||
|
||||
tessellator.setNormal(1, 0, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.EAST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
public static void render(BoundingBox bb, IIcon tex, VertexTransform xForm) {
|
||||
render(bb, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), xForm, false);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.EAST.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[2], minU, minV);
|
||||
addVecWithUV(verts[6], maxU, minV);
|
||||
addVecWithUV(verts[5], maxU, maxV);
|
||||
addVecWithUV(verts[1], minU, maxV);
|
||||
|
||||
tessellator.setNormal(-1, 0, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.WEST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
public static void render(BoundingBox bb, IIcon tex, VertexTransform xForm, float[] brightnessPerSide,
|
||||
boolean tintSides) {
|
||||
float minU = 0;
|
||||
float minV = 0;
|
||||
float maxU = 1;
|
||||
float maxV = 1;
|
||||
if (tex != null) {
|
||||
minU = tex.getMinU();
|
||||
minV = tex.getMinV();
|
||||
maxU = tex.getMaxU();
|
||||
maxV = tex.getMaxV();
|
||||
}
|
||||
render(bb, minU, maxU, minV, maxV, xForm, brightnessPerSide, tintSides);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.WEST.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[0], minU, maxV);
|
||||
addVecWithUV(verts[4], maxU, maxV);
|
||||
addVecWithUV(verts[7], maxU, minV);
|
||||
addVecWithUV(verts[3], minU, minV);
|
||||
}
|
||||
|
||||
public static void setupVertices(BoundingBox bound) {
|
||||
setupVertices(bound, null);
|
||||
}
|
||||
|
||||
public static void setupVertices(BoundingBox bound, VertexTransform xForm) {
|
||||
verts[0].set(bound.minX, bound.minY, bound.minZ);
|
||||
verts[1].set(bound.maxX, bound.minY, bound.minZ);
|
||||
verts[2].set(bound.maxX, bound.maxY, bound.minZ);
|
||||
verts[3].set(bound.minX, bound.maxY, bound.minZ);
|
||||
verts[4].set(bound.minX, bound.minY, bound.maxZ);
|
||||
verts[5].set(bound.maxX, bound.minY, bound.maxZ);
|
||||
verts[6].set(bound.maxX, bound.maxY, bound.maxZ);
|
||||
verts[7].set(bound.minX, bound.maxY, bound.maxZ);
|
||||
|
||||
if (xForm != null) {
|
||||
for (Vector3d vec : verts) {
|
||||
xForm.apply(vec);
|
||||
}
|
||||
public static void render(BoundingBox bb, IIcon tex, VertexTransform xForm, boolean tintSides) {
|
||||
float minU = 0;
|
||||
float minV = 0;
|
||||
float maxU = 1;
|
||||
float maxV = 1;
|
||||
if (tex != null) {
|
||||
minU = tex.getMinU();
|
||||
minV = tex.getMinV();
|
||||
maxU = tex.getMaxU();
|
||||
maxV = tex.getMaxV();
|
||||
}
|
||||
render(bb, minU, maxU, minV, maxV, xForm, tintSides);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addVecWithUV(Vector3d vec, double u, double v) {
|
||||
Tessellator.instance.addVertexWithUV(vec.x, vec.y, vec.z, u, v);
|
||||
}
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, boolean tintSides) {
|
||||
render(bb, minU, maxU, minV, maxV, null, tintSides);
|
||||
}
|
||||
|
||||
private CubeRenderer() {
|
||||
}
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV) {
|
||||
render(bb, minU, maxU, minV, maxV, null, false);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, VertexTransform xForm) {
|
||||
render(bb, minU, maxU, minV, maxV, xForm, false);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, VertexTransform xForm,
|
||||
boolean tintSides) {
|
||||
float[] brightnessPerSide = null;
|
||||
if (tintSides) {
|
||||
brightnessPerSide = new float[6];
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
brightnessPerSide[dir.ordinal()] = RenderUtil.getColorMultiplierForFace(dir);
|
||||
}
|
||||
}
|
||||
render(bb, minU, maxU, minV, maxV, xForm, brightnessPerSide);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, VertexTransform xForm,
|
||||
float[] brightnessPerSide, boolean tintSides) {
|
||||
|
||||
if (tintSides) {
|
||||
if (brightnessPerSide == null || brightnessPerSide.length != 6) {
|
||||
brightnessPerSide = new float[] { 1, 1, 1, 1, 1, 1 };
|
||||
}
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
brightnessPerSide[dir.ordinal()] = brightnessPerSide[dir.ordinal()]
|
||||
* RenderUtil.getColorMultiplierForFace(dir);
|
||||
}
|
||||
|
||||
}
|
||||
render(bb, minU, maxU, minV, maxV, xForm, brightnessPerSide);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, float minU, float maxU, float minV, float maxV, VertexTransform xForm,
|
||||
float[] brightnessPerSide) {
|
||||
|
||||
if (brightnessPerSide != null && brightnessPerSide.length != 6) {
|
||||
brightnessPerSide = null;
|
||||
}
|
||||
|
||||
setupVertices(bb, xForm);
|
||||
|
||||
float tmp = minV;
|
||||
minV = maxV;
|
||||
maxV = tmp;
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.setNormal(0, 0, -1);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.NORTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[1], minU, minV);
|
||||
addVecWithUV(verts[0], maxU, minV);
|
||||
addVecWithUV(verts[3], maxU, maxV);
|
||||
addVecWithUV(verts[2], minU, maxV);
|
||||
|
||||
tessellator.setNormal(0, 0, 1);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.SOUTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[4], minU, minV);
|
||||
addVecWithUV(verts[5], maxU, minV);
|
||||
addVecWithUV(verts[6], maxU, maxV);
|
||||
addVecWithUV(verts[7], minU, maxV);
|
||||
|
||||
tessellator.setNormal(0, 1, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.UP.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[6], minU, minV);
|
||||
addVecWithUV(verts[2], minU, maxV);
|
||||
addVecWithUV(verts[3], maxU, maxV);
|
||||
addVecWithUV(verts[7], maxU, minV);
|
||||
|
||||
tessellator.setNormal(0, -1, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.DOWN.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[0], maxU, maxV);
|
||||
addVecWithUV(verts[1], minU, maxV);
|
||||
addVecWithUV(verts[5], minU, minV);
|
||||
addVecWithUV(verts[4], maxU, minV);
|
||||
|
||||
tessellator.setNormal(1, 0, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.EAST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[2], minU, maxV);
|
||||
addVecWithUV(verts[6], maxU, maxV);
|
||||
addVecWithUV(verts[5], maxU, minV);
|
||||
addVecWithUV(verts[1], minU, minV);
|
||||
|
||||
tessellator.setNormal(-1, 0, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.WEST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
addVecWithUV(verts[0], minU, minV);
|
||||
addVecWithUV(verts[4], maxU, minV);
|
||||
addVecWithUV(verts[7], maxU, maxV);
|
||||
addVecWithUV(verts[3], minU, maxV);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon[] icons, boolean tintSides) {
|
||||
float[] brightnessPerSide = null;
|
||||
if (tintSides) {
|
||||
brightnessPerSide = new float[6];
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
brightnessPerSide[dir.ordinal()] = RenderUtil.getColorMultiplierForFace(dir);
|
||||
}
|
||||
}
|
||||
render(bb, icons, null, brightnessPerSide);
|
||||
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon[] icons, VertexTransform xForm, boolean tintSides) {
|
||||
float[] brightnessPerSide = null;
|
||||
if (tintSides) {
|
||||
brightnessPerSide = new float[6];
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
brightnessPerSide[dir.ordinal()] = RenderUtil.getColorMultiplierForFace(dir);
|
||||
}
|
||||
}
|
||||
render(bb, icons, xForm, brightnessPerSide);
|
||||
}
|
||||
|
||||
public static void render(BoundingBox bb, IIcon[] faceTextures, VertexTransform xForm, float[] brightnessPerSide) {
|
||||
setupVertices(bb, xForm);
|
||||
float minU;
|
||||
float maxU;
|
||||
float minV;
|
||||
float maxV;
|
||||
IIcon tex;
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.setNormal(0, 0, -1);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.NORTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
|
||||
tex = faceTextures[ForgeDirection.NORTH.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[1], minU, maxV);
|
||||
addVecWithUV(verts[0], maxU, maxV);
|
||||
addVecWithUV(verts[3], maxU, minV);
|
||||
addVecWithUV(verts[2], minU, minV);
|
||||
|
||||
tessellator.setNormal(0, 0, 1);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.SOUTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.SOUTH.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[4], minU, maxV);
|
||||
addVecWithUV(verts[5], maxU, maxV);
|
||||
addVecWithUV(verts[6], maxU, minV);
|
||||
addVecWithUV(verts[7], minU, minV);
|
||||
|
||||
tessellator.setNormal(0, 1, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.UP.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.UP.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[6], minU, minV);
|
||||
addVecWithUV(verts[2], minU, maxV);
|
||||
addVecWithUV(verts[3], maxU, maxV);
|
||||
addVecWithUV(verts[7], maxU, minV);
|
||||
|
||||
tessellator.setNormal(0, -1, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.DOWN.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.DOWN.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[0], maxU, maxV);
|
||||
addVecWithUV(verts[1], minU, maxV);
|
||||
addVecWithUV(verts[5], minU, minV);
|
||||
addVecWithUV(verts[4], maxU, minV);
|
||||
|
||||
tessellator.setNormal(1, 0, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.EAST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.EAST.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[2], minU, minV);
|
||||
addVecWithUV(verts[6], maxU, minV);
|
||||
addVecWithUV(verts[5], maxU, maxV);
|
||||
addVecWithUV(verts[1], minU, maxV);
|
||||
|
||||
tessellator.setNormal(-1, 0, 0);
|
||||
if (brightnessPerSide != null) {
|
||||
float cm = brightnessPerSide[ForgeDirection.WEST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.WEST.ordinal()];
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
maxV = tex.getMaxV();
|
||||
addVecWithUV(verts[0], minU, maxV);
|
||||
addVecWithUV(verts[4], maxU, maxV);
|
||||
addVecWithUV(verts[7], maxU, minV);
|
||||
addVecWithUV(verts[3], minU, minV);
|
||||
}
|
||||
|
||||
public static void setupVertices(BoundingBox bound) {
|
||||
setupVertices(bound, null);
|
||||
}
|
||||
|
||||
public static void setupVertices(BoundingBox bound, VertexTransform xForm) {
|
||||
verts[0].set(bound.minX, bound.minY, bound.minZ);
|
||||
verts[1].set(bound.maxX, bound.minY, bound.minZ);
|
||||
verts[2].set(bound.maxX, bound.maxY, bound.minZ);
|
||||
verts[3].set(bound.minX, bound.maxY, bound.minZ);
|
||||
verts[4].set(bound.minX, bound.minY, bound.maxZ);
|
||||
verts[5].set(bound.maxX, bound.minY, bound.maxZ);
|
||||
verts[6].set(bound.maxX, bound.maxY, bound.maxZ);
|
||||
verts[7].set(bound.minX, bound.maxY, bound.maxZ);
|
||||
|
||||
if (xForm != null) {
|
||||
for (Vector3d vec : verts) {
|
||||
xForm.apply(vec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addVecWithUV(Vector3d vec, double u, double v) {
|
||||
Tessellator.instance.addVertexWithUV(vec.x, vec.y, vec.z, u, v);
|
||||
}
|
||||
|
||||
private CubeRenderer() {}
|
||||
|
||||
}
|
||||
@@ -2,61 +2,62 @@ package com.enderio.core.client.render;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.enderio.core.api.client.render.IRenderFace;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.enderio.core.api.client.render.IRenderFace;
|
||||
|
||||
public class CustomCubeRenderer {
|
||||
|
||||
public static final CustomCubeRenderer instance = new CustomCubeRenderer();
|
||||
public static final CustomCubeRenderer instance = new CustomCubeRenderer();
|
||||
|
||||
private CustomRenderBlocks rb = null;
|
||||
private CustomRenderBlocks rb = null;
|
||||
|
||||
private IIcon overrideTexture;
|
||||
private IIcon overrideTexture;
|
||||
|
||||
public void renderBlock(IBlockAccess ba, Block par1Block, int par2, int par3, int par4) {
|
||||
renderBlock(ba, par1Block, par2, par3, par4, (IRenderFace) null);
|
||||
}
|
||||
|
||||
public void renderBlock(IBlockAccess ba, Block par1Block, int par2, int par3, int par4, IRenderFace renderer) {
|
||||
if (rb == null) {
|
||||
rb = new CustomRenderBlocks(ba);
|
||||
public void renderBlock(IBlockAccess ba, Block par1Block, int par2, int par3, int par4) {
|
||||
renderBlock(ba, par1Block, par2, par3, par4, (IRenderFace) null);
|
||||
}
|
||||
rb.blockAccess = ba;
|
||||
rb.setOverrideTexture(getOverrideTexture());
|
||||
rb.setFaceRenderers(null);
|
||||
if (renderer != null) {
|
||||
rb.addFaceRenderer(renderer);
|
||||
|
||||
public void renderBlock(IBlockAccess ba, Block par1Block, int par2, int par3, int par4, IRenderFace renderer) {
|
||||
if (rb == null) {
|
||||
rb = new CustomRenderBlocks(ba);
|
||||
}
|
||||
rb.blockAccess = ba;
|
||||
rb.setOverrideTexture(getOverrideTexture());
|
||||
rb.setFaceRenderers(null);
|
||||
if (renderer != null) {
|
||||
rb.addFaceRenderer(renderer);
|
||||
}
|
||||
rb.setRenderBoundsFromBlock(par1Block);
|
||||
rb.renderStandardBlock(par1Block, par2, par3, par4);
|
||||
}
|
||||
rb.setRenderBoundsFromBlock(par1Block);
|
||||
rb.renderStandardBlock(par1Block, par2, par3, par4);
|
||||
}
|
||||
|
||||
public void renderBlock(IBlockAccess ba, Block par1Block, int par2, int par3, int par4, Collection<IRenderFace> renderers) {
|
||||
if (rb == null) {
|
||||
rb = new CustomRenderBlocks(ba);
|
||||
public void renderBlock(IBlockAccess ba, Block par1Block, int par2, int par3, int par4,
|
||||
Collection<IRenderFace> renderers) {
|
||||
if (rb == null) {
|
||||
rb = new CustomRenderBlocks(ba);
|
||||
}
|
||||
rb.blockAccess = ba;
|
||||
rb.setOverrideTexture(getOverrideTexture());
|
||||
rb.setFaceRenderers(renderers);
|
||||
rb.setRenderBoundsFromBlock(par1Block);
|
||||
rb.renderStandardBlock(par1Block, par2, par3, par4);
|
||||
}
|
||||
rb.blockAccess = ba;
|
||||
rb.setOverrideTexture(getOverrideTexture());
|
||||
rb.setFaceRenderers(renderers);
|
||||
rb.setRenderBoundsFromBlock(par1Block);
|
||||
rb.renderStandardBlock(par1Block, par2, par3, par4);
|
||||
}
|
||||
|
||||
public IIcon getOverrideTexture() {
|
||||
return overrideTexture;
|
||||
}
|
||||
|
||||
public void setOverrideTexture(IIcon overrideTexture) {
|
||||
this.overrideTexture = overrideTexture;
|
||||
}
|
||||
|
||||
public CustomRenderBlocks getCustomRenderBlocks() {
|
||||
if (rb == null) {
|
||||
rb = new CustomRenderBlocks();
|
||||
public IIcon getOverrideTexture() {
|
||||
return overrideTexture;
|
||||
}
|
||||
|
||||
public void setOverrideTexture(IIcon overrideTexture) {
|
||||
this.overrideTexture = overrideTexture;
|
||||
}
|
||||
|
||||
public CustomRenderBlocks getCustomRenderBlocks() {
|
||||
if (rb == null) {
|
||||
rb = new CustomRenderBlocks();
|
||||
}
|
||||
return rb;
|
||||
}
|
||||
return rb;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -5,51 +5,51 @@ import com.enderio.core.api.client.render.IWidgetMap;
|
||||
|
||||
public class CustomWidgetIcon implements IWidgetIcon {
|
||||
|
||||
private final int x, y, width, height;
|
||||
private final IWidgetMap map;
|
||||
private final int x, y, width, height;
|
||||
private final IWidgetMap map;
|
||||
|
||||
private IWidgetIcon overlay;
|
||||
private IWidgetIcon overlay;
|
||||
|
||||
public CustomWidgetIcon(int x, int y, int width, int height, IWidgetMap map, IWidgetIcon overlay) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.map = map;
|
||||
this.overlay = overlay;
|
||||
}
|
||||
public CustomWidgetIcon(int x, int y, int width, int height, IWidgetMap map, IWidgetIcon overlay) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.map = map;
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
public CustomWidgetIcon(int x, int y, int width, int height, IWidgetMap map) {
|
||||
this(x, y, width, height, map, null);
|
||||
}
|
||||
public CustomWidgetIcon(int x, int y, int width, int height, IWidgetMap map) {
|
||||
this(x, y, width, height, map, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
@Override
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidgetMap getMap() {
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
public IWidgetMap getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidgetIcon getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
@Override
|
||||
public IWidgetIcon getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
}
|
||||
@@ -20,121 +20,123 @@ import com.enderio.core.common.util.ItemUtil;
|
||||
* @author Garrett Spicer-Davis
|
||||
*/
|
||||
public class DirectionalModelRenderer<T extends TileEntity> extends TileEntitySpecialRenderer implements IItemRenderer {
|
||||
private IModelCustom model;
|
||||
private ResourceLocation texture;
|
||||
private IEnderModel modelSMT;
|
||||
|
||||
public DirectionalModelRenderer(ResourceLocation model, ResourceLocation texture) {
|
||||
this.model = AdvancedModelLoader.loadModel(model);
|
||||
this.texture = texture;
|
||||
}
|
||||
private IModelCustom model;
|
||||
private ResourceLocation texture;
|
||||
private IEnderModel modelSMT;
|
||||
|
||||
public DirectionalModelRenderer(IEnderModel model, ResourceLocation texture) {
|
||||
this.modelSMT = model;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
private void renderDirectionalTileEntityAt(T tile, double x, double y, double z, int metaOverride) {
|
||||
int meta = getMetadata(tile, metaOverride);
|
||||
setup(x, y, z, metaOverride);
|
||||
rotate(getRotation(tile, metaOverride));
|
||||
renderModel(tile, meta);
|
||||
}
|
||||
|
||||
protected final int getMetadata(T tile, int metaOverride) {
|
||||
return metaOverride >= 0 ? metaOverride : tile.getBlockMetadata();
|
||||
}
|
||||
|
||||
protected void setup(double x, double y, double z, int metaOverride) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) x + 0.5f, (float) y - (metaOverride >= 0 ? 0.1f : 0), (float) z + 0.5f);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
}
|
||||
|
||||
protected int getRotation(T tile, int metaOverride) {
|
||||
return getMetadata(tile, metaOverride);
|
||||
}
|
||||
|
||||
protected void rotate(int rotation) {
|
||||
switch (rotation) {
|
||||
case 1:
|
||||
GL11.glRotatef(180f, 0, 0, 1);
|
||||
GL11.glTranslatef(0, -1f, 0);
|
||||
break;
|
||||
case 2:
|
||||
GL11.glRotatef(90f, 1f, 0, 0);
|
||||
GL11.glTranslatef(0, -0.5f, -0.5f);
|
||||
break;
|
||||
case 3:
|
||||
GL11.glRotatef(90f, -1f, 0, 0);
|
||||
GL11.glTranslatef(0, -0.5f, 0.5f);
|
||||
break;
|
||||
case 4:
|
||||
GL11.glRotatef(90f, 0, 0, -1f);
|
||||
GL11.glTranslatef(-0.5f, -0.5f, 0);
|
||||
break;
|
||||
case 5:
|
||||
GL11.glRotatef(90f, 0, 0, 1f);
|
||||
GL11.glTranslatef(0.5f, -0.5f, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderModel(T tile, int meta) {
|
||||
if (model != null) {
|
||||
GL11.glScalef(0.5f, 0.5f, 0.5f);
|
||||
model.renderAll();
|
||||
} else {
|
||||
GL11.glTranslated(0, -0.5, 0);
|
||||
modelSMT.render(0.0625f);
|
||||
public DirectionalModelRenderer(ResourceLocation model, ResourceLocation texture) {
|
||||
this.model = AdvancedModelLoader.loadModel(model);
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float yaw) {
|
||||
renderDirectionalTileEntityAt((T) tile, x, y, z, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return helper == ItemRendererHelper.INVENTORY_BLOCK || helper == ItemRendererHelper.ENTITY_BOBBING || helper == ItemRendererHelper.ENTITY_ROTATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
switch (type) {
|
||||
case ENTITY:
|
||||
GL11.glTranslatef(-0.4f, 0.1f, -0.4f);
|
||||
GL11.glScalef(0.75f, 0.75f, 0.75f);
|
||||
break;
|
||||
case EQUIPPED:
|
||||
GL11.glScalef(0.75f, 0.75f, 0.75f);
|
||||
GL11.glTranslatef(-0.1f, 0.2f, 0.5f);
|
||||
GL11.glRotatef(-40, 1, 0, 0);
|
||||
GL11.glRotatef(45, 0, 1, 0);
|
||||
GL11.glRotatef(20, 0, 0, 1);
|
||||
break;
|
||||
case EQUIPPED_FIRST_PERSON:
|
||||
GL11.glScalef(0.75f, 0.75f, 0.75f);
|
||||
break;
|
||||
case FIRST_PERSON_MAP:
|
||||
break;
|
||||
case INVENTORY:
|
||||
break;
|
||||
public DirectionalModelRenderer(IEnderModel model, ResourceLocation texture) {
|
||||
this.modelSMT = model;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
renderDirectionalTileEntityAt(null, 0, 0, 0, ItemUtil.getNBTTag(item).getInteger("storedMetaData"));
|
||||
private void renderDirectionalTileEntityAt(T tile, double x, double y, double z, int metaOverride) {
|
||||
int meta = getMetadata(tile, metaOverride);
|
||||
setup(x, y, z, metaOverride);
|
||||
rotate(getRotation(tile, metaOverride));
|
||||
renderModel(tile, meta);
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
protected final int getMetadata(T tile, int metaOverride) {
|
||||
return metaOverride >= 0 ? metaOverride : tile.getBlockMetadata();
|
||||
}
|
||||
|
||||
protected void setup(double x, double y, double z, int metaOverride) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) x + 0.5f, (float) y - (metaOverride >= 0 ? 0.1f : 0), (float) z + 0.5f);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
}
|
||||
|
||||
protected int getRotation(T tile, int metaOverride) {
|
||||
return getMetadata(tile, metaOverride);
|
||||
}
|
||||
|
||||
protected void rotate(int rotation) {
|
||||
switch (rotation) {
|
||||
case 1:
|
||||
GL11.glRotatef(180f, 0, 0, 1);
|
||||
GL11.glTranslatef(0, -1f, 0);
|
||||
break;
|
||||
case 2:
|
||||
GL11.glRotatef(90f, 1f, 0, 0);
|
||||
GL11.glTranslatef(0, -0.5f, -0.5f);
|
||||
break;
|
||||
case 3:
|
||||
GL11.glRotatef(90f, -1f, 0, 0);
|
||||
GL11.glTranslatef(0, -0.5f, 0.5f);
|
||||
break;
|
||||
case 4:
|
||||
GL11.glRotatef(90f, 0, 0, -1f);
|
||||
GL11.glTranslatef(-0.5f, -0.5f, 0);
|
||||
break;
|
||||
case 5:
|
||||
GL11.glRotatef(90f, 0, 0, 1f);
|
||||
GL11.glTranslatef(0.5f, -0.5f, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderModel(T tile, int meta) {
|
||||
if (model != null) {
|
||||
GL11.glScalef(0.5f, 0.5f, 0.5f);
|
||||
model.renderAll();
|
||||
} else {
|
||||
GL11.glTranslated(0, -0.5, 0);
|
||||
modelSMT.render(0.0625f);
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float yaw) {
|
||||
renderDirectionalTileEntityAt((T) tile, x, y, z, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return helper == ItemRendererHelper.INVENTORY_BLOCK || helper == ItemRendererHelper.ENTITY_BOBBING
|
||||
|| helper == ItemRendererHelper.ENTITY_ROTATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
switch (type) {
|
||||
case ENTITY:
|
||||
GL11.glTranslatef(-0.4f, 0.1f, -0.4f);
|
||||
GL11.glScalef(0.75f, 0.75f, 0.75f);
|
||||
break;
|
||||
case EQUIPPED:
|
||||
GL11.glScalef(0.75f, 0.75f, 0.75f);
|
||||
GL11.glTranslatef(-0.1f, 0.2f, 0.5f);
|
||||
GL11.glRotatef(-40, 1, 0, 0);
|
||||
GL11.glRotatef(45, 0, 1, 0);
|
||||
GL11.glRotatef(20, 0, 0, 1);
|
||||
break;
|
||||
case EQUIPPED_FIRST_PERSON:
|
||||
GL11.glScalef(0.75f, 0.75f, 0.75f);
|
||||
break;
|
||||
case FIRST_PERSON_MAP:
|
||||
break;
|
||||
case INVENTORY:
|
||||
break;
|
||||
}
|
||||
|
||||
renderDirectionalTileEntityAt(null, 0, 0, 0, ItemUtil.getNBTTag(item).getInteger("storedMetaData"));
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
@@ -8,112 +8,112 @@ import com.enderio.core.api.client.render.IWidgetMap;
|
||||
|
||||
public enum EnderWidget implements IWidgetIcon {
|
||||
|
||||
BUTTON_BASE(0, 0),
|
||||
UP_ARROW_OFF(212, 64, 11, 8),
|
||||
UP_ARROW_ON(223, 64, 11, 8),
|
||||
UP_ARROW_HOVER_OFF(234, 64, 11, 8),
|
||||
UP_ARROW_HOVER_ON(245, 64, 11, 8),
|
||||
DOWN_ARROW_OFF(212, 72, 11, 8),
|
||||
DOWN_ARROW_ON(223, 72, 11, 8),
|
||||
DOWN_ARROW_HOVER_OFF(234, 72, 11, 8),
|
||||
DOWN_ARROW_HOVER_ON(245, 72, 11, 8),
|
||||
BUTTON_BASE(0, 0),
|
||||
UP_ARROW_OFF(212, 64, 11, 8),
|
||||
UP_ARROW_ON(223, 64, 11, 8),
|
||||
UP_ARROW_HOVER_OFF(234, 64, 11, 8),
|
||||
UP_ARROW_HOVER_ON(245, 64, 11, 8),
|
||||
DOWN_ARROW_OFF(212, 72, 11, 8),
|
||||
DOWN_ARROW_ON(223, 72, 11, 8),
|
||||
DOWN_ARROW_HOVER_OFF(234, 72, 11, 8),
|
||||
DOWN_ARROW_HOVER_ON(245, 72, 11, 8),
|
||||
|
||||
VSCROLL_THUMB_OFF(234, 80, 11, 8),
|
||||
VSCROLL_THUMB_HOVER_OFF(234, 88, 11, 8),
|
||||
VSCROLL_THUMB_ON(245, 80, 11, 8),
|
||||
VSCROLL_THUMB_HOVER_ON(245, 88, 11, 8),
|
||||
VSCROLL_THUMB_OFF(234, 80, 11, 8),
|
||||
VSCROLL_THUMB_HOVER_OFF(234, 88, 11, 8),
|
||||
VSCROLL_THUMB_ON(245, 80, 11, 8),
|
||||
VSCROLL_THUMB_HOVER_ON(245, 88, 11, 8),
|
||||
|
||||
BUTTON(0, 208),
|
||||
BUTTON_HIGHLIGHT(16, 208),
|
||||
BUTTON_DISABLED(32, 208),
|
||||
BUTTON_DOWN(48, 208),
|
||||
BUTTON_DOWN_HIGHLIGHT(64, 208),
|
||||
BUTTON_CHECKED(112, 208),
|
||||
BUTTON(0, 208),
|
||||
BUTTON_HIGHLIGHT(16, 208),
|
||||
BUTTON_DISABLED(32, 208),
|
||||
BUTTON_DOWN(48, 208),
|
||||
BUTTON_DOWN_HIGHLIGHT(64, 208),
|
||||
BUTTON_CHECKED(112, 208),
|
||||
|
||||
LEFT_ARROW(224, 32, 8, 16),
|
||||
LEFT_ARROW_PRESSED(240, 32, 8, 16),
|
||||
LEFT_ARROW_HOVER(224, 48, 8, 16),
|
||||
LEFT_ARROW_HOVER_PRESSED(240, 48, 8, 16),
|
||||
LEFT_ARROW(224, 32, 8, 16),
|
||||
LEFT_ARROW_PRESSED(240, 32, 8, 16),
|
||||
LEFT_ARROW_HOVER(224, 48, 8, 16),
|
||||
LEFT_ARROW_HOVER_PRESSED(240, 48, 8, 16),
|
||||
|
||||
RIGHT_ARROW(232, 32, 8, 16),
|
||||
RIGHT_ARROW_PRESSED(248, 32, 8, 16),
|
||||
RIGHT_ARROW_HOVER(232, 48, 8, 16),
|
||||
RIGHT_ARROW_HOVER_PRESSED(248, 48, 8, 16),
|
||||
RIGHT_ARROW(232, 32, 8, 16),
|
||||
RIGHT_ARROW_PRESSED(248, 32, 8, 16),
|
||||
RIGHT_ARROW_HOVER(232, 48, 8, 16),
|
||||
RIGHT_ARROW_HOVER_PRESSED(248, 48, 8, 16),
|
||||
|
||||
ADD_BUT(208, 32, 8, 8),
|
||||
ADD_BUT_PRESSED(216, 32, 8, 8),
|
||||
ADD_BUT_HOVER(208, 48, 8, 8),
|
||||
ADD_BUT_HOVER_PRESSED(216, 48, 8, 8),
|
||||
ADD_BUT(208, 32, 8, 8),
|
||||
ADD_BUT_PRESSED(216, 32, 8, 8),
|
||||
ADD_BUT_HOVER(208, 48, 8, 8),
|
||||
ADD_BUT_HOVER_PRESSED(216, 48, 8, 8),
|
||||
|
||||
MINUS_BUT(208, 40, 8, 8),
|
||||
MINUS_BUT_PRESSED(216, 40, 8, 8),
|
||||
MINUS_BUT_HOVER(208, 56, 8, 8),
|
||||
MINUS_BUT_HOVER_PRESSED(216, 56, 8, 8),
|
||||
MINUS_BUT(208, 40, 8, 8),
|
||||
MINUS_BUT_PRESSED(216, 40, 8, 8),
|
||||
MINUS_BUT_HOVER(208, 56, 8, 8),
|
||||
MINUS_BUT_HOVER_PRESSED(216, 56, 8, 8),
|
||||
|
||||
X_BUT(200, 32, 8, 8),
|
||||
X_BUT_PRESSED(200, 40, 8, 8),
|
||||
X_BUT_HOVER(200, 48, 8, 8),
|
||||
X_BUT_HOVER_PRESSED(200, 56, 8, 8),
|
||||
X_BUT(200, 32, 8, 8),
|
||||
X_BUT_PRESSED(200, 40, 8, 8),
|
||||
X_BUT_HOVER(200, 48, 8, 8),
|
||||
X_BUT_HOVER_PRESSED(200, 56, 8, 8),
|
||||
|
||||
NEUTRAL_SLOT_BACKGROUND(112, 176, 16, 16), ;
|
||||
NEUTRAL_SLOT_BACKGROUND(112, 176, 16, 16),;
|
||||
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation(EnderCore.MODID, "textures/gui/widgets.png");
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation(EnderCore.MODID, "textures/gui/widgets.png");
|
||||
|
||||
public static final IWidgetMap map = new IWidgetMap.WidgetMapImpl(256, TEXTURE);
|
||||
public static final IWidgetMap map = new IWidgetMap.WidgetMapImpl(256, TEXTURE);
|
||||
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int width;
|
||||
public final int height;
|
||||
public final IWidgetIcon overlay;
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int width;
|
||||
public final int height;
|
||||
public final IWidgetIcon overlay;
|
||||
|
||||
EnderWidget(int x, int y) {
|
||||
this(x, y, null);
|
||||
}
|
||||
EnderWidget(int x, int y) {
|
||||
this(x, y, null);
|
||||
}
|
||||
|
||||
EnderWidget(int x, int y, IWidgetIcon overlay) {
|
||||
this(x, y, 16, 16, overlay);
|
||||
}
|
||||
EnderWidget(int x, int y, IWidgetIcon overlay) {
|
||||
this(x, y, 16, 16, overlay);
|
||||
}
|
||||
|
||||
EnderWidget(int x, int y, int width, int height) {
|
||||
this(x, y, width, height, null);
|
||||
}
|
||||
|
||||
EnderWidget(int x, int y, int width, int height, IWidgetIcon overlay) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.overlay = overlay;
|
||||
}
|
||||
EnderWidget(int x, int y, int width, int height) {
|
||||
this(x, y, width, height, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
EnderWidget(int x, int y, int width, int height, IWidgetIcon overlay) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidgetIcon getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidgetMap getMap() {
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidgetIcon getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidgetMap getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -7,63 +7,64 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class IconUtil {
|
||||
|
||||
public static interface IIconProvider {
|
||||
public static interface IIconProvider {
|
||||
|
||||
public void registerIcons(IIconRegister register);
|
||||
public void registerIcons(IIconRegister register);
|
||||
|
||||
/** 0 = terrain.png, 1 = items.png */
|
||||
public int getTextureType();
|
||||
}
|
||||
|
||||
private static ArrayList<IIconProvider> iconProviders = new ArrayList<IIconProvider>();
|
||||
|
||||
public static IIcon whiteTexture;
|
||||
public static IIcon blankTexture;
|
||||
public static IIcon errorTexture;
|
||||
|
||||
static {
|
||||
MinecraftForge.EVENT_BUS.register(new IconUtil());
|
||||
addIconProvider(new IIconProvider() {
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister register) {
|
||||
whiteTexture = register.registerIcon("enderio:white");
|
||||
errorTexture = register.registerIcon("enderio:error");
|
||||
blankTexture = register.registerIcon("enderio:blank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureType() {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void addIconProvider(IIconProvider registrar) {
|
||||
iconProviders.add(registrar);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@SubscribeEvent
|
||||
public void onIconLoad(TextureStitchEvent.Pre event) {
|
||||
for (IIconProvider reg : iconProviders) {
|
||||
if (reg.getTextureType() == event.map.getTextureType()) {
|
||||
reg.registerIcons(event.map);
|
||||
}
|
||||
/** 0 = terrain.png, 1 = items.png */
|
||||
public int getTextureType();
|
||||
}
|
||||
}
|
||||
|
||||
public static IIcon getIconForItem(int itemId, int meta) {
|
||||
Item item = Item.getItemById(itemId);
|
||||
if (item == null) {
|
||||
return null;
|
||||
private static ArrayList<IIconProvider> iconProviders = new ArrayList<IIconProvider>();
|
||||
|
||||
public static IIcon whiteTexture;
|
||||
public static IIcon blankTexture;
|
||||
public static IIcon errorTexture;
|
||||
|
||||
static {
|
||||
MinecraftForge.EVENT_BUS.register(new IconUtil());
|
||||
addIconProvider(new IIconProvider() {
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister register) {
|
||||
whiteTexture = register.registerIcon("enderio:white");
|
||||
errorTexture = register.registerIcon("enderio:error");
|
||||
blankTexture = register.registerIcon("enderio:blank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureType() {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void addIconProvider(IIconProvider registrar) {
|
||||
iconProviders.add(registrar);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@SubscribeEvent
|
||||
public void onIconLoad(TextureStitchEvent.Pre event) {
|
||||
for (IIconProvider reg : iconProviders) {
|
||||
if (reg.getTextureType() == event.map.getTextureType()) {
|
||||
reg.registerIcons(event.map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IIcon getIconForItem(int itemId, int meta) {
|
||||
Item item = Item.getItemById(itemId);
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
return item.getIconFromDamage(meta);
|
||||
}
|
||||
return item.getIconFromDamage(meta);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,47 +6,50 @@ import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.model.obj.WavefrontObject;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
|
||||
public class SimpleModelRenderer implements ISimpleBlockRenderingHandler {
|
||||
private final Tessellator tes = Tessellator.instance;
|
||||
|
||||
private final WavefrontObject model;
|
||||
private final Tessellator tes = Tessellator.instance;
|
||||
|
||||
private final int renderId;
|
||||
|
||||
public SimpleModelRenderer(WavefrontObject model, int renderId) {
|
||||
this.model = model;
|
||||
this.renderId = renderId;
|
||||
}
|
||||
private final WavefrontObject model;
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return renderId;
|
||||
}
|
||||
private final int renderId;
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
TechneUtil.renderWithIcon(model, block.getIcon(0, metadata), tes);
|
||||
tes.draw();
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
public SimpleModelRenderer(WavefrontObject model, int renderId) {
|
||||
this.model = model;
|
||||
this.renderId = renderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + .5F, z + .5F);
|
||||
TechneUtil.renderWithIcon(model, block.getIcon(0, world.getBlockMetadata(x, y, z)), tes);
|
||||
tes.addTranslation(-x - .5F, -y - .5F, -z - .5F);
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return renderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
TechneUtil.renderWithIcon(model, block.getIcon(0, metadata), tes);
|
||||
tes.draw();
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
|
||||
RenderBlocks renderer) {
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + .5F, z + .5F);
|
||||
TechneUtil.renderWithIcon(model, block.getIcon(0, world.getBlockMetadata(x, y, z)), tes);
|
||||
tes.addTranslation(-x - .5F, -y - .5F, -z - .5F);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -10,69 +10,82 @@ import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.model.obj.GroupObject;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
|
||||
public class TechneModelRenderer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
protected Map<String, GroupObject> model;
|
||||
private int renderId;
|
||||
protected Map<String, GroupObject> model;
|
||||
private int renderId;
|
||||
|
||||
protected VertexTransform vt;
|
||||
protected VertexTransform vt;
|
||||
|
||||
public TechneModelRenderer(String modid, String modelPath, int renderId) {
|
||||
this(modid, modelPath, renderId, null);
|
||||
}
|
||||
public TechneModelRenderer(String modid, String modelPath, int renderId) {
|
||||
this(modid, modelPath, renderId, null);
|
||||
}
|
||||
|
||||
public TechneModelRenderer(String modid, String modelPath, int renderId, VertexTransform vt) {
|
||||
this(TechneUtil.getModel(modid, modelPath), renderId, vt);
|
||||
}
|
||||
public TechneModelRenderer(String modid, String modelPath, int renderId, VertexTransform vt) {
|
||||
this(TechneUtil.getModel(modid, modelPath), renderId, vt);
|
||||
}
|
||||
|
||||
public TechneModelRenderer(Map<String, GroupObject> model, int renderId) {
|
||||
this(model, renderId, null);
|
||||
}
|
||||
public TechneModelRenderer(Map<String, GroupObject> model, int renderId) {
|
||||
this(model, renderId, null);
|
||||
}
|
||||
|
||||
public TechneModelRenderer(Map<String, GroupObject> model, int renderId, VertexTransform vt) {
|
||||
this.model = model;
|
||||
this.renderId = renderId;
|
||||
this.vt = vt;
|
||||
}
|
||||
public TechneModelRenderer(Map<String, GroupObject> model, int renderId, VertexTransform vt) {
|
||||
this.model = model;
|
||||
this.renderId = renderId;
|
||||
this.vt = vt;
|
||||
}
|
||||
|
||||
protected Collection<GroupObject> getModel(Block block, int metadata) {
|
||||
return model.values();
|
||||
}
|
||||
protected Collection<GroupObject> getModel(Block block, int metadata) {
|
||||
return model.values();
|
||||
}
|
||||
|
||||
protected Collection<GroupObject> getModel(IBlockAccess world, int x, int y, int z) {
|
||||
return model.values();
|
||||
}
|
||||
protected Collection<GroupObject> getModel(IBlockAccess world, int x, int y, int z) {
|
||||
return model.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
TechneUtil.vt = this.vt;
|
||||
TechneUtil.renderInventoryBlock(getModel(block, metadata), getModelIcon(block, metadata), block, metadata, renderer);
|
||||
}
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
TechneUtil.vt = this.vt;
|
||||
TechneUtil.renderInventoryBlock(
|
||||
getModel(block, metadata),
|
||||
getModelIcon(block, metadata),
|
||||
block,
|
||||
metadata,
|
||||
renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
TechneUtil.vt = this.vt;
|
||||
return TechneUtil.renderWorldBlock(getModel(world, x, y, z), getModelIcon(world, x, y, z, block), world, x, y, z, block, renderer);
|
||||
}
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
|
||||
RenderBlocks renderer) {
|
||||
TechneUtil.vt = this.vt;
|
||||
return TechneUtil.renderWorldBlock(
|
||||
getModel(world, x, y, z),
|
||||
getModelIcon(world, x, y, z, block),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
block,
|
||||
renderer);
|
||||
}
|
||||
|
||||
protected IIcon getModelIcon(Block block, int metadata) {
|
||||
return block.getIcon(0, metadata);
|
||||
}
|
||||
protected IIcon getModelIcon(Block block, int metadata) {
|
||||
return block.getIcon(0, metadata);
|
||||
}
|
||||
|
||||
protected IIcon getModelIcon(IBlockAccess world, int x, int y, int z, Block block) {
|
||||
return block.getIcon(world, x, y, z, 0);
|
||||
}
|
||||
protected IIcon getModelIcon(IBlockAccess world, int x, int y, int z, Block block) {
|
||||
return block.getIcon(world, x, y, z, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return renderId;
|
||||
}
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return renderId;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,18 @@
|
||||
/*
|
||||
|
||||
Copyright © 2014 RainWarrior
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
4. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
* Copyright © 2014 RainWarrior Permission is granted to anyone to use this software for any purpose, including
|
||||
* commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The
|
||||
* origin of this software must not be misrepresented; you must not claim that you wrote the original software. 2.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided with the distribution. 3. Altered source versions
|
||||
* must be plainly marked as such, and must not be misrepresented as being the original software. 4. This notice may not
|
||||
* be removed or altered from any source distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.enderio.core.client.render;
|
||||
@@ -67,357 +50,368 @@ import org.lwjgl.util.vector.Vector4f;
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
/**
|
||||
* Slightly modified to fit the EnderIO source.
|
||||
*
|
||||
* @author Based on RainWarrior's code <a
|
||||
* href=https://gist.github.com/RainWarrior
|
||||
* /39794c3548de9dcc7303>here.</a>
|
||||
* @author Based on RainWarrior's code <a href=https://gist.github.com/RainWarrior /39794c3548de9dcc7303>here.</a>
|
||||
*/
|
||||
public class TechneUtil {
|
||||
|
||||
public static VertexTransform vt = null;
|
||||
public static VertexTransform vt = null;
|
||||
|
||||
private static final TechneModelLoader modelLoader = new TechneModelLoader();
|
||||
private static final TechneModelLoader modelLoader = new TechneModelLoader();
|
||||
|
||||
private static final Tessellator tes = Tessellator.instance;
|
||||
private static final Tessellator tes = Tessellator.instance;
|
||||
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel) {
|
||||
return bakeModel(model, supermodel, 1);
|
||||
}
|
||||
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale) {
|
||||
return bakeModel(model, supermodel, scale, new Matrix4f());
|
||||
}
|
||||
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale, Matrix4f matrix) {
|
||||
return bakeModel(model, supermodel, scale, matrix, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ModelRenderer to a list of GroupObjects, for ease of use in ISBRH
|
||||
* and other static contexts.
|
||||
*
|
||||
* @param scale
|
||||
* the scale factor, usually last argument to rendering methods
|
||||
* @param matrix
|
||||
* initial transformation matrix (replaces calling
|
||||
* glTranslate/glRotate/e.t.c. before rendering)
|
||||
* @param rotateYFirst
|
||||
* true, of the order of rotations be like in
|
||||
* ModelRenderer.renderWithRotation, false if like in
|
||||
* ModelRenderer.render
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale, Matrix4f matrix, boolean rotateYFirst) {
|
||||
|
||||
// Correction for the fact that TechneModel sets the texture size on the
|
||||
// ModelRenderer after the texture positions have been calculated. It also
|
||||
// never sets the size on the TechneModel, so we can use that value (which
|
||||
// is taken by the ModelRenderer for the calculations) to correct the
|
||||
// positions.
|
||||
|
||||
float uCorrection = ((int) model.textureWidth) / supermodel.textureWidth;
|
||||
float vCorrection = ((int) model.textureHeight) / supermodel.textureHeight;
|
||||
|
||||
Matrix4f m = new Matrix4f(matrix);
|
||||
|
||||
m.translate(new Vector3f(model.offsetX + model.rotationPointX * scale, model.offsetY + model.rotationPointY * scale, model.offsetZ + model.rotationPointZ
|
||||
* scale));
|
||||
|
||||
if (!rotateYFirst) {
|
||||
m.rotate(model.rotateAngleZ, new Vector3f(0, 0, 1));
|
||||
}
|
||||
m.rotate(model.rotateAngleY, new Vector3f(0, 1, 0));
|
||||
m.rotate(model.rotateAngleX, new Vector3f(1, 0, 0));
|
||||
|
||||
if (rotateYFirst) {
|
||||
m.rotate(model.rotateAngleZ, new Vector3f(0, 0, 1));
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel) {
|
||||
return bakeModel(model, supermodel, 1);
|
||||
}
|
||||
|
||||
Vector4f vec = new Vector4f();
|
||||
List<GroupObject> res = new ArrayList<GroupObject>();
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale) {
|
||||
return bakeModel(model, supermodel, scale, new Matrix4f());
|
||||
}
|
||||
|
||||
for (ModelBox box : (List<ModelBox>) model.cubeList) {
|
||||
GroupObject obj = new GroupObject("", GL11.GL_QUADS);
|
||||
TexturedQuad[] quads = (TexturedQuad[]) ObfuscationReflectionHelper.getPrivateValue(ModelBox.class, box, "quadList", "field_78254_i");
|
||||
for (int i = 0; i < quads.length; i++) {
|
||||
Face face = new Face();
|
||||
face.vertices = new Vertex[4];
|
||||
face.textureCoordinates = new TextureCoordinate[4];
|
||||
float minU = -1, minV = -1;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
PositionTextureVertex pv = quads[i].vertexPositions[j];
|
||||
if (minU < 0 || minU > pv.texturePositionX) {
|
||||
minU = pv.texturePositionX;
|
||||
}
|
||||
if (minV < 0 || minV > pv.texturePositionY) {
|
||||
minV = pv.texturePositionY;
|
||||
}
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale,
|
||||
Matrix4f matrix) {
|
||||
return bakeModel(model, supermodel, scale, matrix, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ModelRenderer to a list of GroupObjects, for ease of use in ISBRH and other static contexts.
|
||||
*
|
||||
* @param scale the scale factor, usually last argument to rendering methods
|
||||
* @param matrix initial transformation matrix (replaces calling glTranslate/glRotate/e.t.c. before rendering)
|
||||
* @param rotateYFirst true, of the order of rotations be like in ModelRenderer.renderWithRotation, false if like in
|
||||
* ModelRenderer.render
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale, Matrix4f matrix,
|
||||
boolean rotateYFirst) {
|
||||
|
||||
// Correction for the fact that TechneModel sets the texture size on the
|
||||
// ModelRenderer after the texture positions have been calculated. It also
|
||||
// never sets the size on the TechneModel, so we can use that value (which
|
||||
// is taken by the ModelRenderer for the calculations) to correct the
|
||||
// positions.
|
||||
|
||||
float uCorrection = ((int) model.textureWidth) / supermodel.textureWidth;
|
||||
float vCorrection = ((int) model.textureHeight) / supermodel.textureHeight;
|
||||
|
||||
Matrix4f m = new Matrix4f(matrix);
|
||||
|
||||
m.translate(
|
||||
new Vector3f(
|
||||
model.offsetX + model.rotationPointX * scale,
|
||||
model.offsetY + model.rotationPointY * scale,
|
||||
model.offsetZ + model.rotationPointZ * scale));
|
||||
|
||||
if (!rotateYFirst) {
|
||||
m.rotate(model.rotateAngleZ, new Vector3f(0, 0, 1));
|
||||
}
|
||||
for (int j = 0; j < 4; j++) {
|
||||
PositionTextureVertex pv = quads[i].vertexPositions[j];
|
||||
m.rotate(model.rotateAngleY, new Vector3f(0, 1, 0));
|
||||
m.rotate(model.rotateAngleX, new Vector3f(1, 0, 0));
|
||||
|
||||
vec.x = (float) pv.vector3D.xCoord * scale;
|
||||
vec.y = (float) pv.vector3D.yCoord * scale;
|
||||
vec.z = (float) pv.vector3D.zCoord * scale;
|
||||
vec.w = 1;
|
||||
|
||||
Matrix4f.transform(m, vec, vec);
|
||||
|
||||
face.vertices[j] = new Vertex(vec.x / vec.w, vec.y / vec.w, vec.z / vec.w);
|
||||
|
||||
// The small offset will reduce the amount of visible errors (white
|
||||
// pixels) at the edges of textures a lot. The introduced visible
|
||||
// offset is very small, about 1 screen pixel between a 1/16 block
|
||||
// wide element and a 1 block wide element when standing "on touch".
|
||||
float u;
|
||||
float v;
|
||||
if (pv.texturePositionX == minU) {
|
||||
u = pv.texturePositionX / uCorrection + 0.0001f;
|
||||
} else {
|
||||
u = pv.texturePositionX / uCorrection - 0.0001f;
|
||||
}
|
||||
if (pv.texturePositionY == minV) {
|
||||
v = pv.texturePositionY / vCorrection + 0.0001f;
|
||||
} else {
|
||||
v = pv.texturePositionY / vCorrection - 0.0001f;
|
||||
}
|
||||
face.textureCoordinates[j] = new TextureCoordinate(u, v);
|
||||
if (rotateYFirst) {
|
||||
m.rotate(model.rotateAngleZ, new Vector3f(0, 0, 1));
|
||||
}
|
||||
face.faceNormal = face.calculateFaceNormal();
|
||||
obj.faces.add(face);
|
||||
}
|
||||
res.add(obj);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
Vector4f vec = new Vector4f();
|
||||
List<GroupObject> res = new ArrayList<GroupObject>();
|
||||
|
||||
public static Map<String, GroupObject> bakeModel(TechneModel model) {
|
||||
return bakeModel(model, 1);
|
||||
}
|
||||
for (ModelBox box : (List<ModelBox>) model.cubeList) {
|
||||
GroupObject obj = new GroupObject("", GL11.GL_QUADS);
|
||||
TexturedQuad[] quads = (TexturedQuad[]) ObfuscationReflectionHelper
|
||||
.getPrivateValue(ModelBox.class, box, "quadList", "field_78254_i");
|
||||
for (int i = 0; i < quads.length; i++) {
|
||||
Face face = new Face();
|
||||
face.vertices = new Vertex[4];
|
||||
face.textureCoordinates = new TextureCoordinate[4];
|
||||
float minU = -1, minV = -1;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
PositionTextureVertex pv = quads[i].vertexPositions[j];
|
||||
if (minU < 0 || minU > pv.texturePositionX) {
|
||||
minU = pv.texturePositionX;
|
||||
}
|
||||
if (minV < 0 || minV > pv.texturePositionY) {
|
||||
minV = pv.texturePositionY;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < 4; j++) {
|
||||
PositionTextureVertex pv = quads[i].vertexPositions[j];
|
||||
|
||||
public static Map<String, GroupObject> bakeModel(TechneModel model, float scale) {
|
||||
return bakeModel(model, scale, new Matrix4f());
|
||||
}
|
||||
vec.x = (float) pv.vector3D.xCoord * scale;
|
||||
vec.y = (float) pv.vector3D.yCoord * scale;
|
||||
vec.z = (float) pv.vector3D.zCoord * scale;
|
||||
vec.w = 1;
|
||||
|
||||
public static Map<String, GroupObject> bakeModel(TechneModel model, float scale, Matrix4f m) {
|
||||
return bakeModel(model, scale, m, false);
|
||||
}
|
||||
Matrix4f.transform(m, vec, vec);
|
||||
|
||||
/**
|
||||
* Use this to convert TechneModel to it's static representation
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, GroupObject> bakeModel(TechneModel model, float scale, Matrix4f m, boolean rotateYFirst) {
|
||||
Map<String, ModelRenderer> parts = (Map<String, ModelRenderer>) ObfuscationReflectionHelper.getPrivateValue(TechneModel.class, model, "parts");
|
||||
Map<String, GroupObject> res = Maps.newHashMap();
|
||||
face.vertices[j] = new Vertex(vec.x / vec.w, vec.y / vec.w, vec.z / vec.w);
|
||||
|
||||
for (Map.Entry<String, ModelRenderer> e : parts.entrySet()) {
|
||||
GroupObject obj = bakeModel(e.getValue(), model, scale, m, rotateYFirst).get(0);
|
||||
res.put(e.getKey(), obj);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Map<String, GroupObject> getModel(String modid, String modelPath) {
|
||||
TechneModel tm = (TechneModel) modelLoader.loadInstance(new ResourceLocation(modid.toLowerCase(Locale.US), modelPath + ".tcn"));
|
||||
return TechneUtil.bakeModel(tm, 1f / 16, new Matrix4f().scale(new Vector3f(-1, -1, 1)));
|
||||
}
|
||||
|
||||
public static Collection<GroupObject> getModelAll(String modid, String modelPath) {
|
||||
TechneModel tm = (TechneModel) modelLoader.loadInstance(new ResourceLocation(modid.toLowerCase(Locale.US), modelPath + ".tcn"));
|
||||
return TechneUtil.bakeModel(tm, 1f / 16, new Matrix4f().scale(new Vector3f(-1, -1, 1))).values();
|
||||
}
|
||||
|
||||
public static void renderWithIcon(WavefrontObject model, IIcon icon, Tessellator tes) {
|
||||
renderWithIcon(model.groupObjects, icon, null, tes);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes) {
|
||||
renderWithIcon(model, icon, override, tes, null);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes, VertexTransform vt) {
|
||||
renderWithIcon(model, icon, override, tes, null, 0, 0, 0, vt);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world, int x, int y, int z) {
|
||||
renderWithIcon(model, icon, override, tes, world, x, y, z, null);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world, int x, int y, int z,
|
||||
VertexTransform vt) {
|
||||
renderWithIcon(model, icon, override, tes, world, x, y, z, vt, true);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world, int x, int y, int z,
|
||||
VertexTransform vt, boolean isbrh) {
|
||||
for (GroupObject go : model) {
|
||||
renderWithIcon(go, icon, override, tes, world, x, y, z, vt, isbrh);
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderWithIcon(GroupObject go, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world, int x, int y, int z, VertexTransform vt,
|
||||
boolean isbrh) {
|
||||
for (Face f : go.faces) {
|
||||
Vertex n = f.faceNormal;
|
||||
tes.setNormal(n.x, n.y, n.z);
|
||||
ForgeDirection normal = getNormalFor(n);
|
||||
ForgeDirection right = normal.getRotation(ForgeDirection.DOWN);
|
||||
if (normal == right) {
|
||||
right = ForgeDirection.EAST;
|
||||
}
|
||||
ForgeDirection down = normal.getRotation(right.getOpposite());
|
||||
|
||||
if (isbrh && world != null && world.getBlock(x, y, z).getLightOpacity() > 0) {
|
||||
int bx = x + normal.offsetX;
|
||||
int by = y + normal.offsetY;
|
||||
int bz = z + normal.offsetZ;
|
||||
tes.setBrightness(world.getBlock(bx, by, bz).getMixedBrightnessForBlock(world, bx, by, bz));
|
||||
}
|
||||
|
||||
for (int i = 0; i < f.vertices.length; i++) {
|
||||
Vertex vert = f.vertices[i];
|
||||
Vector3d v = new Vector3d(vert);
|
||||
Vector3d tv = new Vector3d(v);
|
||||
tv.add(0.5, 0, 0.5);
|
||||
if (vt != null) {
|
||||
vt.apply(v);
|
||||
// TODO BLECH
|
||||
if (vt instanceof VertexRotationFacing) {
|
||||
normal = ((VertexRotationFacing) vt).rotate(normal);
|
||||
}
|
||||
if (vt instanceof VertexTransformComposite) {
|
||||
for (VertexTransform xform : ((VertexTransformComposite) vt).xforms) {
|
||||
if (xform instanceof VertexRotationFacing) {
|
||||
normal = ((VertexRotationFacing) xform).rotate(normal);
|
||||
}
|
||||
// The small offset will reduce the amount of visible errors (white
|
||||
// pixels) at the edges of textures a lot. The introduced visible
|
||||
// offset is very small, about 1 screen pixel between a 1/16 block
|
||||
// wide element and a 1 block wide element when standing "on touch".
|
||||
float u;
|
||||
float v;
|
||||
if (pv.texturePositionX == minU) {
|
||||
u = pv.texturePositionX / uCorrection + 0.0001f;
|
||||
} else {
|
||||
u = pv.texturePositionX / uCorrection - 0.0001f;
|
||||
}
|
||||
if (pv.texturePositionY == minV) {
|
||||
v = pv.texturePositionY / vCorrection + 0.0001f;
|
||||
} else {
|
||||
v = pv.texturePositionY / vCorrection - 0.0001f;
|
||||
}
|
||||
face.textureCoordinates[j] = new TextureCoordinate(u, v);
|
||||
}
|
||||
face.faceNormal = face.calculateFaceNormal();
|
||||
obj.faces.add(face);
|
||||
}
|
||||
}
|
||||
res.add(obj);
|
||||
}
|
||||
|
||||
if (isbrh) {
|
||||
int c = (int) (0xFF * RenderUtil.getColorMultiplierForFace(normal));
|
||||
tes.setColorOpaque(c, c, c);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Map<String, GroupObject> bakeModel(TechneModel model) {
|
||||
return bakeModel(model, 1);
|
||||
}
|
||||
|
||||
public static Map<String, GroupObject> bakeModel(TechneModel model, float scale) {
|
||||
return bakeModel(model, scale, new Matrix4f());
|
||||
}
|
||||
|
||||
public static Map<String, GroupObject> bakeModel(TechneModel model, float scale, Matrix4f m) {
|
||||
return bakeModel(model, scale, m, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to convert TechneModel to it's static representation
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, GroupObject> bakeModel(TechneModel model, float scale, Matrix4f m, boolean rotateYFirst) {
|
||||
Map<String, ModelRenderer> parts = (Map<String, ModelRenderer>) ObfuscationReflectionHelper
|
||||
.getPrivateValue(TechneModel.class, model, "parts");
|
||||
Map<String, GroupObject> res = Maps.newHashMap();
|
||||
|
||||
for (Map.Entry<String, ModelRenderer> e : parts.entrySet()) {
|
||||
GroupObject obj = bakeModel(e.getValue(), model, scale, m, rotateYFirst).get(0);
|
||||
res.put(e.getKey(), obj);
|
||||
}
|
||||
|
||||
if (override != null) {
|
||||
return res;
|
||||
}
|
||||
|
||||
double interpX = Math.abs(tv.x * right.offsetX + tv.y * right.offsetY + tv.z * right.offsetZ);
|
||||
double interpY = Math.abs(tv.x * down.offsetX + tv.y * down.offsetY + tv.z * down.offsetZ);
|
||||
public static Map<String, GroupObject> getModel(String modid, String modelPath) {
|
||||
TechneModel tm = (TechneModel) modelLoader
|
||||
.loadInstance(new ResourceLocation(modid.toLowerCase(Locale.US), modelPath + ".tcn"));
|
||||
return TechneUtil.bakeModel(tm, 1f / 16, new Matrix4f().scale(new Vector3f(-1, -1, 1)));
|
||||
}
|
||||
|
||||
// Handles verts outside block bounds. Modulo fails at 1.0.
|
||||
while (interpX > 1) {
|
||||
interpX--;
|
||||
}
|
||||
while (interpY > 1) {
|
||||
interpY--;
|
||||
}
|
||||
public static Collection<GroupObject> getModelAll(String modid, String modelPath) {
|
||||
TechneModel tm = (TechneModel) modelLoader
|
||||
.loadInstance(new ResourceLocation(modid.toLowerCase(Locale.US), modelPath + ".tcn"));
|
||||
return TechneUtil.bakeModel(tm, 1f / 16, new Matrix4f().scale(new Vector3f(-1, -1, 1))).values();
|
||||
}
|
||||
|
||||
if (normal == ForgeDirection.SOUTH || normal == ForgeDirection.WEST) {
|
||||
interpX = 1 - interpX;
|
||||
}
|
||||
if (normal != ForgeDirection.UP && normal != ForgeDirection.DOWN) {
|
||||
interpY = 1 - interpY;
|
||||
}
|
||||
tes.addVertexWithUV(v.x, v.y, v.z, override.getInterpolatedU(interpX * 16), override.getInterpolatedV(interpY * 16));
|
||||
public static void renderWithIcon(WavefrontObject model, IIcon icon, Tessellator tes) {
|
||||
renderWithIcon(model.groupObjects, icon, null, tes);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes) {
|
||||
renderWithIcon(model, icon, override, tes, null);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes,
|
||||
VertexTransform vt) {
|
||||
renderWithIcon(model, icon, override, tes, null, 0, 0, 0, vt);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes,
|
||||
IBlockAccess world, int x, int y, int z) {
|
||||
renderWithIcon(model, icon, override, tes, world, x, y, z, null);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes,
|
||||
IBlockAccess world, int x, int y, int z, VertexTransform vt) {
|
||||
renderWithIcon(model, icon, override, tes, world, x, y, z, vt, true);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes,
|
||||
IBlockAccess world, int x, int y, int z, VertexTransform vt, boolean isbrh) {
|
||||
for (GroupObject go : model) {
|
||||
renderWithIcon(go, icon, override, tes, world, x, y, z, vt, isbrh);
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderWithIcon(GroupObject go, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world,
|
||||
int x, int y, int z, VertexTransform vt, boolean isbrh) {
|
||||
for (Face f : go.faces) {
|
||||
Vertex n = f.faceNormal;
|
||||
tes.setNormal(n.x, n.y, n.z);
|
||||
ForgeDirection normal = getNormalFor(n);
|
||||
ForgeDirection right = normal.getRotation(ForgeDirection.DOWN);
|
||||
if (normal == right) {
|
||||
right = ForgeDirection.EAST;
|
||||
}
|
||||
ForgeDirection down = normal.getRotation(right.getOpposite());
|
||||
|
||||
if (isbrh && world != null && world.getBlock(x, y, z).getLightOpacity() > 0) {
|
||||
int bx = x + normal.offsetX;
|
||||
int by = y + normal.offsetY;
|
||||
int bz = z + normal.offsetZ;
|
||||
tes.setBrightness(world.getBlock(bx, by, bz).getMixedBrightnessForBlock(world, bx, by, bz));
|
||||
}
|
||||
|
||||
for (int i = 0; i < f.vertices.length; i++) {
|
||||
Vertex vert = f.vertices[i];
|
||||
Vector3d v = new Vector3d(vert);
|
||||
Vector3d tv = new Vector3d(v);
|
||||
tv.add(0.5, 0, 0.5);
|
||||
if (vt != null) {
|
||||
vt.apply(v);
|
||||
// TODO BLECH
|
||||
if (vt instanceof VertexRotationFacing) {
|
||||
normal = ((VertexRotationFacing) vt).rotate(normal);
|
||||
}
|
||||
if (vt instanceof VertexTransformComposite) {
|
||||
for (VertexTransform xform : ((VertexTransformComposite) vt).xforms) {
|
||||
if (xform instanceof VertexRotationFacing) {
|
||||
normal = ((VertexRotationFacing) xform).rotate(normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isbrh) {
|
||||
int c = (int) (0xFF * RenderUtil.getColorMultiplierForFace(normal));
|
||||
tes.setColorOpaque(c, c, c);
|
||||
}
|
||||
|
||||
if (override != null) {
|
||||
|
||||
double interpX = Math.abs(tv.x * right.offsetX + tv.y * right.offsetY + tv.z * right.offsetZ);
|
||||
double interpY = Math.abs(tv.x * down.offsetX + tv.y * down.offsetY + tv.z * down.offsetZ);
|
||||
|
||||
// Handles verts outside block bounds. Modulo fails at 1.0.
|
||||
while (interpX > 1) {
|
||||
interpX--;
|
||||
}
|
||||
while (interpY > 1) {
|
||||
interpY--;
|
||||
}
|
||||
|
||||
if (normal == ForgeDirection.SOUTH || normal == ForgeDirection.WEST) {
|
||||
interpX = 1 - interpX;
|
||||
}
|
||||
if (normal != ForgeDirection.UP && normal != ForgeDirection.DOWN) {
|
||||
interpY = 1 - interpY;
|
||||
}
|
||||
tes.addVertexWithUV(
|
||||
v.x,
|
||||
v.y,
|
||||
v.z,
|
||||
override.getInterpolatedU(interpX * 16),
|
||||
override.getInterpolatedV(interpY * 16));
|
||||
} else {
|
||||
TextureCoordinate t = f.textureCoordinates[i];
|
||||
tes.addVertexWithUV(v.x, v.y, v.z, getInterpolatedU(icon, t.u), getInterpolatedV(icon, t.v));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reducing texture positioning error by working in double and not multiplying
|
||||
// and dividing by 16.
|
||||
public static double getInterpolatedV(IIcon icon, double offset) {
|
||||
return icon.getMinV() + (icon.getMaxV() - icon.getMinV()) * offset;
|
||||
}
|
||||
|
||||
public static double getInterpolatedU(IIcon icon, double offset) {
|
||||
return icon.getMinU() + (icon.getMaxU() - icon.getMinU()) * offset;
|
||||
}
|
||||
|
||||
private static ForgeDirection getNormalFor(Vertex n) {
|
||||
if (n.x != 0) {
|
||||
return n.x > 0 ? ForgeDirection.EAST : ForgeDirection.WEST;
|
||||
} else if (n.y != 0) {
|
||||
return n.y > 0 ? ForgeDirection.UP : ForgeDirection.DOWN;
|
||||
} else {
|
||||
TextureCoordinate t = f.textureCoordinates[i];
|
||||
tes.addVertexWithUV(v.x, v.y, v.z, getInterpolatedU(icon, t.u), getInterpolatedV(icon, t.v));
|
||||
return n.z > 0 ? ForgeDirection.SOUTH : ForgeDirection.NORTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reducing texture positioning error by working in double and not multiplying
|
||||
// and dividing by 16.
|
||||
public static double getInterpolatedV(IIcon icon, double offset) {
|
||||
return icon.getMinV() + (icon.getMaxV() - icon.getMinV()) * offset;
|
||||
}
|
||||
|
||||
public static double getInterpolatedU(IIcon icon, double offset) {
|
||||
return icon.getMinU() + (icon.getMaxU() - icon.getMinU()) * offset;
|
||||
}
|
||||
|
||||
private static ForgeDirection getNormalFor(Vertex n) {
|
||||
if (n.x != 0) {
|
||||
return n.x > 0 ? ForgeDirection.EAST : ForgeDirection.WEST;
|
||||
} else if (n.y != 0) {
|
||||
return n.y > 0 ? ForgeDirection.UP : ForgeDirection.DOWN;
|
||||
} else {
|
||||
return n.z > 0 ? ForgeDirection.SOUTH : ForgeDirection.NORTH;
|
||||
public static void renderInventoryBlock(Collection<GroupObject> model, Block block, int metadata, RenderBlocks rb) {
|
||||
renderInventoryBlock(model, getIconFor(block, metadata), block, metadata, rb);
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderInventoryBlock(Collection<GroupObject> model, Block block, int metadata, RenderBlocks rb) {
|
||||
renderInventoryBlock(model, getIconFor(block, metadata), block, metadata, rb);
|
||||
}
|
||||
|
||||
public static void renderInventoryBlock(Collection<GroupObject> model, IIcon icon, Block block, int metadata, RenderBlocks rb) {
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(0, -0.47f, 0);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, vt);
|
||||
tes.addTranslation(0, 0.47f, 0);
|
||||
tes.draw();
|
||||
resetVT();
|
||||
}
|
||||
|
||||
public static void renderInventoryBlock(GroupObject model, Block block, int metadata, RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, metadata);
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(0, -0.47f, 0);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, null, 0, 0, 0, vt, true);
|
||||
tes.addTranslation(0, 0.47f, 0);
|
||||
tes.draw();
|
||||
resetVT();
|
||||
}
|
||||
|
||||
public static boolean renderWorldBlock(Collection<GroupObject> model, IBlockAccess world, int x, int y, int z, Block block, RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, world, x, y, z);
|
||||
return renderWorldBlock(model, icon, world, x, y, z, block, rb);
|
||||
}
|
||||
|
||||
public static boolean renderWorldBlock(Collection<GroupObject> model, IIcon icon, IBlockAccess world, int x, int y, int z, Block block, RenderBlocks rb) {
|
||||
if (icon == null) {
|
||||
return false;
|
||||
public static void renderInventoryBlock(Collection<GroupObject> model, IIcon icon, Block block, int metadata,
|
||||
RenderBlocks rb) {
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(0, -0.47f, 0);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, vt);
|
||||
tes.addTranslation(0, 0.47f, 0);
|
||||
tes.draw();
|
||||
resetVT();
|
||||
}
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + 0.0375f, z + .5F);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, world, x, y, z, vt);
|
||||
tes.addTranslation(-x - .5F, -y - 0.0375f, -z - .5F);
|
||||
resetVT();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean renderWorldBlock(GroupObject model, IBlockAccess world, int x, int y, int z, Block block, RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, world, x, y, z);
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + 0.0375f, z + .5F);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, world, x, y, z, vt, true);
|
||||
tes.addTranslation(-x - .5F, -y - 0.0375f, -z - .5F);
|
||||
resetVT();
|
||||
return true;
|
||||
}
|
||||
public static void renderInventoryBlock(GroupObject model, Block block, int metadata, RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, metadata);
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(0, -0.47f, 0);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, null, 0, 0, 0, vt, true);
|
||||
tes.addTranslation(0, 0.47f, 0);
|
||||
tes.draw();
|
||||
resetVT();
|
||||
}
|
||||
|
||||
private static void resetVT() {
|
||||
vt = null;
|
||||
}
|
||||
public static boolean renderWorldBlock(Collection<GroupObject> model, IBlockAccess world, int x, int y, int z,
|
||||
Block block, RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, world, x, y, z);
|
||||
return renderWorldBlock(model, icon, world, x, y, z, block, rb);
|
||||
}
|
||||
|
||||
private static IIcon getIconFor(Block block, IBlockAccess world, int x, int y, int z) {
|
||||
return block.getIcon(world, x, y, z, 0);
|
||||
}
|
||||
public static boolean renderWorldBlock(Collection<GroupObject> model, IIcon icon, IBlockAccess world, int x, int y,
|
||||
int z, Block block, RenderBlocks rb) {
|
||||
if (icon == null) {
|
||||
return false;
|
||||
}
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + 0.0375f, z + .5F);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, world, x, y, z, vt);
|
||||
tes.addTranslation(-x - .5F, -y - 0.0375f, -z - .5F);
|
||||
resetVT();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IIcon getIconFor(Block block, int metadata) {
|
||||
return block.getIcon(0, metadata);
|
||||
}
|
||||
public static boolean renderWorldBlock(GroupObject model, IBlockAccess world, int x, int y, int z, Block block,
|
||||
RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, world, x, y, z);
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + 0.0375f, z + .5F);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, world, x, y, z, vt, true);
|
||||
tes.addTranslation(-x - .5F, -y - 0.0375f, -z - .5F);
|
||||
resetVT();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void resetVT() {
|
||||
vt = null;
|
||||
}
|
||||
|
||||
private static IIcon getIconFor(Block block, IBlockAccess world, int x, int y, int z) {
|
||||
return block.getIcon(world, x, y, z, 0);
|
||||
}
|
||||
|
||||
private static IIcon getIconFor(Block block, int metadata) {
|
||||
return block.getIcon(0, metadata);
|
||||
}
|
||||
}
|
||||
@@ -8,51 +8,51 @@ import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
public class VertexRotation implements VertexTransform {
|
||||
|
||||
private final Vector3d center;
|
||||
private Quat4d quat;
|
||||
private double angle;
|
||||
private final Vector3d axis;
|
||||
private final Vector3d center;
|
||||
private Quat4d quat;
|
||||
private double angle;
|
||||
private final Vector3d axis;
|
||||
|
||||
public VertexRotation(double angle, Vector3d axis, Vector3d center) {
|
||||
this.center = new Vector3d(center);
|
||||
this.axis = new Vector3d(axis);
|
||||
this.angle = angle;
|
||||
quat = Quat4d.makeRotate(angle, axis);
|
||||
}
|
||||
public VertexRotation(double angle, Vector3d axis, Vector3d center) {
|
||||
this.center = new Vector3d(center);
|
||||
this.axis = new Vector3d(axis);
|
||||
this.angle = angle;
|
||||
quat = Quat4d.makeRotate(angle, axis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Vertex vertex) {
|
||||
apply(vertex.xyz);
|
||||
}
|
||||
@Override
|
||||
public void apply(Vertex vertex) {
|
||||
apply(vertex.xyz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Vector3d vec) {
|
||||
vec.sub(center);
|
||||
quat.rotate(vec);
|
||||
vec.add(center);
|
||||
}
|
||||
@Override
|
||||
public void apply(Vector3d vec) {
|
||||
vec.sub(center);
|
||||
quat.rotate(vec);
|
||||
vec.add(center);
|
||||
}
|
||||
|
||||
public void setAngle(double angle) {
|
||||
this.angle = angle;
|
||||
quat = Quat4d.makeRotate(angle, axis);
|
||||
}
|
||||
public void setAngle(double angle) {
|
||||
this.angle = angle;
|
||||
quat = Quat4d.makeRotate(angle, axis);
|
||||
}
|
||||
|
||||
public double getAngle() {
|
||||
return angle;
|
||||
}
|
||||
public double getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
public void setAxis(Vector3d axis) {
|
||||
this.axis.set(axis);
|
||||
quat = Quat4d.makeRotate(angle, axis);
|
||||
}
|
||||
public void setAxis(Vector3d axis) {
|
||||
this.axis.set(axis);
|
||||
quat = Quat4d.makeRotate(angle, axis);
|
||||
}
|
||||
|
||||
public void setCenter(Vector3d cen) {
|
||||
center.set(cen);
|
||||
}
|
||||
public void setCenter(Vector3d cen) {
|
||||
center.set(cen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToNormal(Vector3f vec) {
|
||||
quat.rotate(vec);
|
||||
}
|
||||
@Override
|
||||
public void applyToNormal(Vector3f vec) {
|
||||
quat.rotate(vec);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +1,45 @@
|
||||
package com.enderio.core.client.render;
|
||||
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
|
||||
public class VertexRotationFacing extends VertexRotation {
|
||||
|
||||
private static final double ROTATION_AMOUNT = Math.PI / 2;
|
||||
private static final double ROTATION_AMOUNT = Math.PI / 2;
|
||||
|
||||
private ForgeDirection defaultDir;
|
||||
private ForgeDirection defaultDir;
|
||||
|
||||
public VertexRotationFacing(ForgeDirection defaultDir) {
|
||||
super(0, new Vector3d(0, 0.5, 0), new Vector3d(0, 0, 0));
|
||||
this.defaultDir = defaultDir;
|
||||
}
|
||||
public VertexRotationFacing(ForgeDirection defaultDir) {
|
||||
super(0, new Vector3d(0, 0.5, 0), new Vector3d(0, 0, 0));
|
||||
this.defaultDir = defaultDir;
|
||||
}
|
||||
|
||||
public void setRotation(ForgeDirection dir) {
|
||||
if (dir == defaultDir) {
|
||||
setAngle(0);
|
||||
} else if (dir == defaultDir.getOpposite()) {
|
||||
setAngle(ROTATION_AMOUNT * 2);
|
||||
} else if (dir == defaultDir.getRotation(ForgeDirection.DOWN)) {
|
||||
setAngle(ROTATION_AMOUNT);
|
||||
} else {
|
||||
setAngle(ROTATION_AMOUNT * 3);
|
||||
public void setRotation(ForgeDirection dir) {
|
||||
if (dir == defaultDir) {
|
||||
setAngle(0);
|
||||
} else if (dir == defaultDir.getOpposite()) {
|
||||
setAngle(ROTATION_AMOUNT * 2);
|
||||
} else if (dir == defaultDir.getRotation(ForgeDirection.DOWN)) {
|
||||
setAngle(ROTATION_AMOUNT);
|
||||
} else {
|
||||
setAngle(ROTATION_AMOUNT * 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ForgeDirection rotate(ForgeDirection dir) {
|
||||
if (dir.offsetY != 0) {
|
||||
return dir;
|
||||
public ForgeDirection rotate(ForgeDirection dir) {
|
||||
if (dir.offsetY != 0) {
|
||||
return dir;
|
||||
}
|
||||
if (getAngle() == ROTATION_AMOUNT) {
|
||||
return dir.getRotation(ForgeDirection.DOWN);
|
||||
}
|
||||
if (getAngle() == ROTATION_AMOUNT * 2) {
|
||||
return dir.getOpposite();
|
||||
}
|
||||
if (getAngle() == ROTATION_AMOUNT * 3) {
|
||||
return dir.getRotation(ForgeDirection.UP);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
if (getAngle() == ROTATION_AMOUNT) {
|
||||
return dir.getRotation(ForgeDirection.DOWN);
|
||||
}
|
||||
if (getAngle() == ROTATION_AMOUNT * 2) {
|
||||
return dir.getOpposite();
|
||||
}
|
||||
if (getAngle() == ROTATION_AMOUNT * 3) {
|
||||
return dir.getRotation(ForgeDirection.UP);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
@@ -9,40 +9,40 @@ import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
public class VertexTransformComposite implements VertexTransform {
|
||||
|
||||
public final VertexTransform[] xforms;
|
||||
public final VertexTransform[] xforms;
|
||||
|
||||
public VertexTransformComposite(VertexTransform... xforms) {
|
||||
this.xforms = xforms;
|
||||
}
|
||||
|
||||
VertexTransformComposite(Collection<VertexTransform> xformsIn) {
|
||||
xforms = new VertexTransform[xformsIn.size()];
|
||||
int i = 0;
|
||||
for (VertexTransform xform : xformsIn) {
|
||||
xforms[i] = xform;
|
||||
i++;
|
||||
public VertexTransformComposite(VertexTransform... xforms) {
|
||||
this.xforms = xforms;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Vertex vertex) {
|
||||
for (VertexTransform xform : xforms) {
|
||||
xform.apply(vertex);
|
||||
VertexTransformComposite(Collection<VertexTransform> xformsIn) {
|
||||
xforms = new VertexTransform[xformsIn.size()];
|
||||
int i = 0;
|
||||
for (VertexTransform xform : xformsIn) {
|
||||
xforms[i] = xform;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Vector3d vec) {
|
||||
for (VertexTransform xform : xforms) {
|
||||
xform.apply(vec);
|
||||
@Override
|
||||
public void apply(Vertex vertex) {
|
||||
for (VertexTransform xform : xforms) {
|
||||
xform.apply(vertex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToNormal(Vector3f vec) {
|
||||
for (VertexTransform xform : xforms) {
|
||||
xform.applyToNormal(vec);
|
||||
@Override
|
||||
public void apply(Vector3d vec) {
|
||||
for (VertexTransform xform : xforms) {
|
||||
xform.apply(vec);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToNormal(Vector3f vec) {
|
||||
for (VertexTransform xform : xforms) {
|
||||
xform.applyToNormal(vec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,55 +7,55 @@ import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
public class VertexTranslation implements VertexTransform {
|
||||
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
public VertexTranslation(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public VertexTranslation(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public VertexTranslation(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public VertexTranslation(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public VertexTranslation(Vector3d trans) {
|
||||
this(trans.x, trans.y, trans.z);
|
||||
}
|
||||
public VertexTranslation(Vector3d trans) {
|
||||
this(trans.x, trans.y, trans.z);
|
||||
}
|
||||
|
||||
public VertexTranslation(Vector3f trans) {
|
||||
this(trans.x, trans.y, trans.z);
|
||||
}
|
||||
public VertexTranslation(Vector3f trans) {
|
||||
this(trans.x, trans.y, trans.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Vertex vertex) {
|
||||
apply(vertex.xyz);
|
||||
}
|
||||
@Override
|
||||
public void apply(Vertex vertex) {
|
||||
apply(vertex.xyz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Vector3d vec) {
|
||||
vec.x += x;
|
||||
vec.y += y;
|
||||
vec.z += z;
|
||||
}
|
||||
@Override
|
||||
public void apply(Vector3d vec) {
|
||||
vec.x += x;
|
||||
vec.y += y;
|
||||
vec.z += z;
|
||||
}
|
||||
|
||||
public void set(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public void set(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void set(Vector3d trans) {
|
||||
set(trans.x, trans.y, trans.z);
|
||||
}
|
||||
public void set(Vector3d trans) {
|
||||
set(trans.x, trans.y, trans.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToNormal(Vector3f vec) {
|
||||
@Override
|
||||
public void applyToNormal(Vector3f vec) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,45 +6,45 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class BlockSound extends PositionedSound implements ITickableSound {
|
||||
|
||||
private boolean donePlaying = false;
|
||||
private boolean donePlaying = false;
|
||||
|
||||
public BlockSound(ResourceLocation p_i45103_1_) {
|
||||
super(p_i45103_1_);
|
||||
}
|
||||
public BlockSound(ResourceLocation p_i45103_1_) {
|
||||
super(p_i45103_1_);
|
||||
}
|
||||
|
||||
public boolean isDonePlaying() {
|
||||
return this.donePlaying;
|
||||
}
|
||||
public boolean isDonePlaying() {
|
||||
return this.donePlaying;
|
||||
}
|
||||
|
||||
public BlockSound setDonePlaying(boolean donePlaying) {
|
||||
this.donePlaying = donePlaying;
|
||||
return this;
|
||||
}
|
||||
public BlockSound setDonePlaying(boolean donePlaying) {
|
||||
this.donePlaying = donePlaying;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockSound setVolume(float vol) {
|
||||
this.volume = vol;
|
||||
return this;
|
||||
}
|
||||
public BlockSound setVolume(float vol) {
|
||||
this.volume = vol;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockSound setPitch(float pitch) {
|
||||
this.field_147663_c = pitch;
|
||||
return this;
|
||||
}
|
||||
public BlockSound setPitch(float pitch) {
|
||||
this.field_147663_c = pitch;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockSound setLocation(float x, float y, float z) {
|
||||
this.xPosF = x;
|
||||
this.yPosF = y;
|
||||
this.zPosF = z;
|
||||
return this;
|
||||
}
|
||||
public BlockSound setLocation(float x, float y, float z) {
|
||||
this.xPosF = x;
|
||||
this.yPosF = y;
|
||||
this.zPosF = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockSound setDoRepeat(boolean bool) {
|
||||
this.repeat = bool;
|
||||
return this;
|
||||
}
|
||||
public BlockSound setDoRepeat(boolean bool) {
|
||||
this.repeat = bool;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
;
|
||||
}
|
||||
@Override
|
||||
public void update() {
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -28,190 +28,192 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class BlockEnder extends Block {
|
||||
|
||||
protected final @Nullable Class<? extends TileEntityEnder> teClass;
|
||||
protected final String name;
|
||||
protected final boolean hasComparatorInputOverride;
|
||||
protected final @Nullable Class<? extends TileEntityEnder> teClass;
|
||||
protected final String name;
|
||||
protected final boolean hasComparatorInputOverride;
|
||||
|
||||
protected BlockEnder(String name, Class<? extends TileEntityEnder> teClass) {
|
||||
this(name, teClass, new Material(MapColor.ironColor));
|
||||
}
|
||||
|
||||
protected BlockEnder(String name, Class<? extends TileEntityEnder> teClass, Material mat) {
|
||||
super(mat);
|
||||
this.teClass = teClass;
|
||||
this.name = name;
|
||||
setHardness(0.5F);
|
||||
setBlockName(name);
|
||||
setStepSound(Block.soundTypeMetal);
|
||||
setHarvestLevel("pickaxe", 0);
|
||||
hasComparatorInputOverride = teClass != null && IComparatorOutput.class.isAssignableFrom(teClass);
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
GameRegistry.registerBlock(this, name);
|
||||
if (teClass != null) {
|
||||
GameRegistry.registerTileEntity(teClass, name + "TileEntity");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(int metadata) {
|
||||
return teClass != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
if (teClass != null) {
|
||||
try {
|
||||
TileEntityEnder te = teClass.newInstance();
|
||||
te.init();
|
||||
return te;
|
||||
} catch (Exception e) {
|
||||
Log.error("Could not create tile entity for block " + name + " for class " + teClass);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iIconRegister) {
|
||||
blockIcon = iIconRegister.registerIcon("enderio:" + name);
|
||||
}
|
||||
|
||||
/* Subclass Helpers */
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
|
||||
if (entityPlayer.isSneaking()) {
|
||||
return false;
|
||||
protected BlockEnder(String name, Class<? extends TileEntityEnder> teClass) {
|
||||
this(name, teClass, new Material(MapColor.ironColor));
|
||||
}
|
||||
|
||||
if (te instanceof ITankAccess) {
|
||||
if (FluidUtil.fillInternalTankFromPlayerHandItem(world, x, y, z, entityPlayer, (ITankAccess) te)) {
|
||||
protected BlockEnder(String name, Class<? extends TileEntityEnder> teClass, Material mat) {
|
||||
super(mat);
|
||||
this.teClass = teClass;
|
||||
this.name = name;
|
||||
setHardness(0.5F);
|
||||
setBlockName(name);
|
||||
setStepSound(Block.soundTypeMetal);
|
||||
setHarvestLevel("pickaxe", 0);
|
||||
hasComparatorInputOverride = teClass != null && IComparatorOutput.class.isAssignableFrom(teClass);
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
GameRegistry.registerBlock(this, name);
|
||||
if (teClass != null) {
|
||||
GameRegistry.registerTileEntity(teClass, name + "TileEntity");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(int metadata) {
|
||||
return teClass != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
if (teClass != null) {
|
||||
try {
|
||||
TileEntityEnder te = teClass.newInstance();
|
||||
te.init();
|
||||
return te;
|
||||
} catch (Exception e) {
|
||||
Log.error("Could not create tile entity for block " + name + " for class " + teClass);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iIconRegister) {
|
||||
blockIcon = iIconRegister.registerIcon("enderio:" + name);
|
||||
}
|
||||
|
||||
/* Subclass Helpers */
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7,
|
||||
float par8, float par9) {
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
|
||||
if (entityPlayer.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (te instanceof ITankAccess) {
|
||||
if (FluidUtil.fillInternalTankFromPlayerHandItem(world, x, y, z, entityPlayer, (ITankAccess) te)) {
|
||||
return true;
|
||||
}
|
||||
if (FluidUtil.fillPlayerHandItemFromInternalTank(world, x, y, z, entityPlayer, (ITankAccess) te)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return openGui(world, x, y, z, entityPlayer, side);
|
||||
}
|
||||
|
||||
protected boolean shouldWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
|
||||
return true;
|
||||
}
|
||||
if (FluidUtil.fillPlayerHandItemFromInternalTank(world, x, y, z, entityPlayer, (ITankAccess) te)) {
|
||||
}
|
||||
|
||||
protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean doNormalDrops(World world, int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return openGui(world, x, y, z, entityPlayer, side);
|
||||
}
|
||||
|
||||
protected boolean shouldWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean doNormalDrops(World world, int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
|
||||
if (willHarvest) {
|
||||
return true;
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
|
||||
if (willHarvest) {
|
||||
return true;
|
||||
}
|
||||
return super.removedByPlayer(world, player, x, y, z, willHarvest);
|
||||
}
|
||||
return super.removedByPlayer(world, player, x, y, z, willHarvest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) {
|
||||
super.harvestBlock(world, player, x, y, z, meta);
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
if (doNormalDrops(world, x, y, z)) {
|
||||
return super.getDrops(world, x, y, z, metadata, fortune);
|
||||
@Override
|
||||
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) {
|
||||
super.harvestBlock(world, player, x, y, z, meta);
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
return Lists.newArrayList(getNBTDrop(world, x, y, z, (TileEntityEnder) world.getTileEntity(x, y, z)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
|
||||
return getPickBlock(target, world, x, y, z, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, @Nullable EntityPlayer player) {
|
||||
return getNBTDrop(world, x, y, z, teClass != null ? getTileEntityEio(world, x, y, z) : null);
|
||||
}
|
||||
|
||||
public ItemStack getNBTDrop(World world, int x, int y, int z, @Nullable TileEntityEnder te) {
|
||||
int meta = te != null ? damageDropped(te.getBlockMetadata()) : world.getBlockMetadata(x, y, z);
|
||||
ItemStack itemStack = new ItemStack(this, 1, meta);
|
||||
processDrop(world, x, y, z, te, itemStack);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
protected void processDrop(World world, int x, int y, int z, @Nullable TileEntityEnder te, ItemStack drop) {
|
||||
}
|
||||
|
||||
@SuppressWarnings("null")
|
||||
protected @Nullable TileEntityEnder getTileEntityEio(IBlockAccess world, int x, int y, int z) {
|
||||
if (teClass != null) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (teClass.isInstance(te)) { // no need to null-check teClass here, it was checked 2 lines above and is *final*
|
||||
return (TileEntityEnder) te;
|
||||
}
|
||||
@Override
|
||||
public final ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
if (doNormalDrops(world, x, y, z)) {
|
||||
return super.getDrops(world, x, y, z, metadata, fortune);
|
||||
}
|
||||
return Lists.newArrayList(getNBTDrop(world, x, y, z, (TileEntityEnder) world.getTileEntity(x, y, z)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean shouldDoWorkThisTick(World world, int x, int y, int z, int interval) {
|
||||
TileEntityEnder te = getTileEntityEio(world, x, y, z);
|
||||
if (te == null) {
|
||||
return world.getTotalWorldTime() % interval == 0;
|
||||
} else {
|
||||
return te.shouldDoWorkThisTick(interval);
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
|
||||
return getPickBlock(target, world, x, y, z, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean shouldDoWorkThisTick(World world, int x, int y, int z, int interval, int offset) {
|
||||
TileEntityEnder te = getTileEntityEio(world, x, y, z);
|
||||
if (te == null) {
|
||||
return (world.getTotalWorldTime() + offset) % interval == 0;
|
||||
} else {
|
||||
return te.shouldDoWorkThisTick(interval, offset);
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z,
|
||||
@Nullable EntityPlayer player) {
|
||||
return getNBTDrop(world, x, y, z, teClass != null ? getTileEntityEio(world, x, y, z) : null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride() {
|
||||
return hasComparatorInputOverride;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(World w, int x, int y, int z, int side) {
|
||||
if (hasComparatorInputOverride) {
|
||||
TileEntityEnder te = getTileEntityEio(w, x, y, z);
|
||||
if (te != null) {
|
||||
return ((IComparatorOutput) te).getComparatorOutput();
|
||||
}
|
||||
public ItemStack getNBTDrop(World world, int x, int y, int z, @Nullable TileEntityEnder te) {
|
||||
int meta = te != null ? damageDropped(te.getBlockMetadata()) : world.getBlockMetadata(x, y, z);
|
||||
ItemStack itemStack = new ItemStack(this, 1, meta);
|
||||
processDrop(world, x, y, z, te, itemStack);
|
||||
return itemStack;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Because the vanilla method takes floats...
|
||||
public void setBlockBounds(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
|
||||
public void setBlockBounds(AxisAlignedBB bb) {
|
||||
setBlockBounds(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
||||
}
|
||||
protected void processDrop(World world, int x, int y, int z, @Nullable TileEntityEnder te, ItemStack drop) {}
|
||||
|
||||
@SuppressWarnings("null")
|
||||
protected @Nullable TileEntityEnder getTileEntityEio(IBlockAccess world, int x, int y, int z) {
|
||||
if (teClass != null) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (teClass.isInstance(te)) { // no need to null-check teClass here, it was checked 2 lines above and is
|
||||
// *final*
|
||||
return (TileEntityEnder) te;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean shouldDoWorkThisTick(World world, int x, int y, int z, int interval) {
|
||||
TileEntityEnder te = getTileEntityEio(world, x, y, z);
|
||||
if (te == null) {
|
||||
return world.getTotalWorldTime() % interval == 0;
|
||||
} else {
|
||||
return te.shouldDoWorkThisTick(interval);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean shouldDoWorkThisTick(World world, int x, int y, int z, int interval, int offset) {
|
||||
TileEntityEnder te = getTileEntityEio(world, x, y, z);
|
||||
if (te == null) {
|
||||
return (world.getTotalWorldTime() + offset) % interval == 0;
|
||||
} else {
|
||||
return te.shouldDoWorkThisTick(interval, offset);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride() {
|
||||
return hasComparatorInputOverride;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(World w, int x, int y, int z, int side) {
|
||||
if (hasComparatorInputOverride) {
|
||||
TileEntityEnder te = getTileEntityEio(w, x, y, z);
|
||||
if (te != null) {
|
||||
return ((IComparatorOutput) te).getComparatorOutput();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Because the vanilla method takes floats...
|
||||
public void setBlockBounds(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
|
||||
public void setBlockBounds(AxisAlignedBB bb) {
|
||||
setBlockBounds(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
||||
}
|
||||
}
|
||||
@@ -5,33 +5,33 @@ import net.minecraft.world.World;
|
||||
import com.enderio.core.common.util.Scheduler;
|
||||
|
||||
public class CommonProxy {
|
||||
protected Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* Returns a scheduler for the current side
|
||||
* <p>
|
||||
* For internal use only, please call {@link Scheduler#instance()} to obtain
|
||||
* an {@link Scheduler} instance.
|
||||
*/
|
||||
public Scheduler getScheduler() {
|
||||
if (scheduler == null) {
|
||||
scheduler = new Scheduler(true);
|
||||
protected Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* Returns a scheduler for the current side
|
||||
* <p>
|
||||
* For internal use only, please call {@link Scheduler#instance()} to obtain an {@link Scheduler} instance.
|
||||
*/
|
||||
public Scheduler getScheduler() {
|
||||
if (scheduler == null) {
|
||||
scheduler = new Scheduler(true);
|
||||
}
|
||||
return scheduler;
|
||||
}
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
public World getClientWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void throwModCompatibilityError(String... msgs) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String msg : msgs) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append("\n");
|
||||
}
|
||||
sb.append(msg);
|
||||
public World getClientWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void throwModCompatibilityError(String... msgs) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String msg : msgs) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append("\n");
|
||||
}
|
||||
sb.append(msg);
|
||||
}
|
||||
throw new RuntimeException(sb.toString());
|
||||
}
|
||||
throw new RuntimeException(sb.toString());
|
||||
}
|
||||
}
|
||||
@@ -16,187 +16,190 @@ import com.google.common.collect.Maps;
|
||||
|
||||
public class ContainerEnder<T extends IInventory> extends Container {
|
||||
|
||||
protected Map<Slot, Point> playerSlotLocations = Maps.newLinkedHashMap();
|
||||
protected Map<Slot, Point> playerSlotLocations = Maps.newLinkedHashMap();
|
||||
|
||||
protected final int startPlayerSlot;
|
||||
protected final int endPlayerSlot;
|
||||
protected final int startHotBarSlot;
|
||||
protected final int endHotBarSlot;
|
||||
protected final int startPlayerSlot;
|
||||
protected final int endPlayerSlot;
|
||||
protected final int startHotBarSlot;
|
||||
protected final int endHotBarSlot;
|
||||
|
||||
private final @Nonnull T inv;
|
||||
private final @Nonnull InventoryPlayer playerInv;
|
||||
private final @Nonnull T inv;
|
||||
private final @Nonnull InventoryPlayer playerInv;
|
||||
|
||||
@Nonnull
|
||||
private static <T> T checkNotNull(T reference) {
|
||||
if (reference == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return reference;
|
||||
}
|
||||
|
||||
public ContainerEnder(InventoryPlayer playerInv, T inv) {
|
||||
this.inv = checkNotNull(inv);
|
||||
this.playerInv = checkNotNull(playerInv);
|
||||
|
||||
addSlots(playerInv);
|
||||
|
||||
int x = getPlayerInventoryOffset().x;
|
||||
int y = getPlayerInventoryOffset().y;
|
||||
|
||||
// add players inventory
|
||||
startPlayerSlot = inventorySlots.size();
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
Point loc = new Point(x + j * 18, y + i * 18);
|
||||
Slot slot = new Slot(playerInv, j + i * 9 + 9, loc.x, loc.y);
|
||||
addSlotToContainer(slot);
|
||||
playerSlotLocations.put(slot, loc);
|
||||
}
|
||||
}
|
||||
endPlayerSlot = inventorySlots.size();
|
||||
|
||||
startHotBarSlot = inventorySlots.size();
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
Point loc = new Point(x + i * 18, y + 58);
|
||||
Slot slot = new Slot(playerInv, i, loc.x, loc.y);
|
||||
addSlotToContainer(slot);
|
||||
playerSlotLocations.put(slot, loc);
|
||||
}
|
||||
endHotBarSlot = inventorySlots.size();
|
||||
}
|
||||
|
||||
protected void addSlots(InventoryPlayer playerInv) {
|
||||
}
|
||||
|
||||
public Point getPlayerInventoryOffset() {
|
||||
return new Point(8, 84);
|
||||
}
|
||||
|
||||
public Point getUpgradeOffset() {
|
||||
return new Point(12, 60);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public T getInv() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return getInv().isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(p_82846_2_);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
int minPlayerSlot = inventorySlots.size() - playerInv.mainInventory.length;
|
||||
if (p_82846_2_ < minPlayerSlot) {
|
||||
if (!this.mergeItemStack(itemstack1, minPlayerSlot, this.inventorySlots.size(), true)) {
|
||||
return null;
|
||||
@Nonnull
|
||||
private static <T> T checkNotNull(T reference) {
|
||||
if (reference == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
} else if (!this.mergeItemStack(itemstack1, 0, minPlayerSlot, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
return reference;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
public ContainerEnder(InventoryPlayer playerInv, T inv) {
|
||||
this.inv = checkNotNull(inv);
|
||||
this.playerInv = checkNotNull(playerInv);
|
||||
|
||||
/**
|
||||
* Added validation of slot input
|
||||
*/
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
||||
addSlots(playerInv);
|
||||
|
||||
boolean result = false;
|
||||
int checkIndex = fromIndex;
|
||||
int x = getPlayerInventoryOffset().x;
|
||||
int y = getPlayerInventoryOffset().y;
|
||||
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
}
|
||||
|
||||
Slot slot;
|
||||
ItemStack itemstack1;
|
||||
|
||||
if (par1ItemStack.isStackable()) {
|
||||
|
||||
while (par1ItemStack.stackSize > 0 && (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex)) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem()
|
||||
&& (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage())
|
||||
&& ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1) && slot.isItemValid(par1ItemStack) && par1ItemStack != itemstack1) {
|
||||
|
||||
int mergedSize = itemstack1.stackSize + par1ItemStack.stackSize;
|
||||
int maxStackSize = Math.min(par1ItemStack.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (mergedSize <= maxStackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
itemstack1.stackSize = mergedSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
} else if (itemstack1.stackSize < maxStackSize) {
|
||||
par1ItemStack.stackSize -= maxStackSize - itemstack1.stackSize;
|
||||
itemstack1.stackSize = maxStackSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
}
|
||||
// add players inventory
|
||||
startPlayerSlot = inventorySlots.size();
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
Point loc = new Point(x + j * 18, y + i * 18);
|
||||
Slot slot = new Slot(playerInv, j + i * 9 + 9, loc.x, loc.y);
|
||||
addSlotToContainer(slot);
|
||||
playerSlotLocations.put(slot, loc);
|
||||
}
|
||||
}
|
||||
endPlayerSlot = inventorySlots.size();
|
||||
|
||||
startHotBarSlot = inventorySlots.size();
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
Point loc = new Point(x + i * 18, y + 58);
|
||||
Slot slot = new Slot(playerInv, i, loc.x, loc.y);
|
||||
addSlotToContainer(slot);
|
||||
playerSlotLocations.put(slot, loc);
|
||||
}
|
||||
endHotBarSlot = inventorySlots.size();
|
||||
}
|
||||
|
||||
protected void addSlots(InventoryPlayer playerInv) {}
|
||||
|
||||
public Point getPlayerInventoryOffset() {
|
||||
return new Point(8, 84);
|
||||
}
|
||||
|
||||
public Point getUpgradeOffset() {
|
||||
return new Point(12, 60);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public T getInv() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return getInv().isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(p_82846_2_);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
int minPlayerSlot = inventorySlots.size() - playerInv.mainInventory.length;
|
||||
if (p_82846_2_ < minPlayerSlot) {
|
||||
if (!this.mergeItemStack(itemstack1, minPlayerSlot, this.inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
} else if (!this.mergeItemStack(itemstack1, 0, minPlayerSlot, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Added validation of slot input
|
||||
*/
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
||||
|
||||
boolean result = false;
|
||||
int checkIndex = fromIndex;
|
||||
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
checkIndex = toIndex - 1;
|
||||
}
|
||||
}
|
||||
|
||||
Slot slot;
|
||||
ItemStack itemstack1;
|
||||
|
||||
if (par1ItemStack.isStackable()) {
|
||||
|
||||
while (par1ItemStack.stackSize > 0
|
||||
&& (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex)) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem()
|
||||
&& (!par1ItemStack.getHasSubtypes()
|
||||
|| par1ItemStack.getItemDamage() == itemstack1.getItemDamage())
|
||||
&& ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1)
|
||||
&& slot.isItemValid(par1ItemStack)
|
||||
&& par1ItemStack != itemstack1) {
|
||||
|
||||
int mergedSize = itemstack1.stackSize + par1ItemStack.stackSize;
|
||||
int maxStackSize = Math.min(par1ItemStack.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (mergedSize <= maxStackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
itemstack1.stackSize = mergedSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
} else if (itemstack1.stackSize < maxStackSize) {
|
||||
par1ItemStack.stackSize -= maxStackSize - itemstack1.stackSize;
|
||||
itemstack1.stackSize = maxStackSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (par1ItemStack.stackSize > 0) {
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
} else {
|
||||
checkIndex = fromIndex;
|
||||
}
|
||||
|
||||
while (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 == null && slot.isItemValid(par1ItemStack)) {
|
||||
ItemStack in = par1ItemStack.copy();
|
||||
in.stackSize = Math.min(in.stackSize, slot.getSlotStackLimit());
|
||||
|
||||
slot.putStack(in);
|
||||
slot.onSlotChanged();
|
||||
if (in.stackSize >= par1ItemStack.stackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
} else {
|
||||
par1ItemStack.stackSize -= in.stackSize;
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (par1ItemStack.stackSize > 0) {
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
} else {
|
||||
checkIndex = fromIndex;
|
||||
}
|
||||
|
||||
while (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 == null && slot.isItemValid(par1ItemStack)) {
|
||||
ItemStack in = par1ItemStack.copy();
|
||||
in.stackSize = Math.min(in.stackSize, slot.getSlotStackLimit());
|
||||
|
||||
slot.putStack(in);
|
||||
slot.onSlotChanged();
|
||||
if (in.stackSize >= par1ItemStack.stackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
} else {
|
||||
par1ItemStack.stackSize -= in.stackSize;
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.enderio.core.common;
|
||||
|
||||
import static com.enderio.core.common.Handlers.Handler.Inst.*;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -32,336 +34,331 @@ import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import static com.enderio.core.common.Handlers.Handler.Inst.*;
|
||||
|
||||
public class Handlers {
|
||||
|
||||
/**
|
||||
* New enum to represent handler types. Possible to use to figure out what
|
||||
* type a method is without direct info.
|
||||
*
|
||||
* The order of the constants is the order they are tried. This is VERY
|
||||
* important!
|
||||
*/
|
||||
public enum HandlerType {
|
||||
|
||||
/**
|
||||
* Represents the {@link MinecraftForge#ORE_GEN_BUS}
|
||||
* New enum to represent handler types. Possible to use to figure out what type a method is without direct info.
|
||||
*
|
||||
* The order of the constants is the order they are tried. This is VERY important!
|
||||
*/
|
||||
FORGE_OREGEN("net.minecraftforge.event.terraingen.OreGenEvent", MinecraftForge.ORE_GEN_BUS),
|
||||
|
||||
/**
|
||||
* Represents the {@link MinecraftForge#TERRAIN_GEN_BUS}
|
||||
*/
|
||||
FORGE_TERRAIN("net.minecraftforge.event.terraingen", MinecraftForge.TERRAIN_GEN_BUS),
|
||||
|
||||
/**
|
||||
* Represents the {@link MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
FORGE("net.minecraftforge", MinecraftForge.EVENT_BUS),
|
||||
|
||||
/**
|
||||
* Represents the {@link FMLCommonHandler#bus()}
|
||||
*/
|
||||
FML("cpw.mods.fml", FMLCommonHandler.instance().bus());
|
||||
|
||||
private HandlerType(String eventIdentifier, EventBus bus) {
|
||||
this.eventIdentifier = eventIdentifier;
|
||||
this.bus = bus;
|
||||
}
|
||||
|
||||
public final String eventIdentifier;
|
||||
public final EventBus bus;
|
||||
}
|
||||
|
||||
/**
|
||||
* To be put on classes that are Forge/FML event handlers. EnderCore will
|
||||
* automatically figure out what busses it needs to be registered to.
|
||||
* <p>
|
||||
* It can get the instance of the handler in a few ways: <br>
|
||||
* A public no args constructor (or lombok {@link NoArgsConstructor})
|
||||
* <b>OR</b><br>
|
||||
* A static singleton object with field name {@code INSTANCE} (public or
|
||||
* private). <b>OR</b><br>
|
||||
* A static method with name <code>instance()</code> (public or private)
|
||||
* <p>
|
||||
* This can also be explicitly set using {@link #getInstFrom()} to avoid
|
||||
* invoking code that may cause issues.
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Handler {
|
||||
@Deprecated
|
||||
public enum HandlerType {
|
||||
/**
|
||||
* Represents the {@link MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
FORGE,
|
||||
|
||||
/**
|
||||
* Represents the {@link FMLCommonHandler#bus()}
|
||||
*/
|
||||
FML
|
||||
}
|
||||
/**
|
||||
* Represents the {@link MinecraftForge#ORE_GEN_BUS}
|
||||
*/
|
||||
FORGE_OREGEN("net.minecraftforge.event.terraingen.OreGenEvent", MinecraftForge.ORE_GEN_BUS),
|
||||
|
||||
public enum Inst {
|
||||
/**
|
||||
* The default, will try all three methods, in the order
|
||||
* {@link Inst#CONSTRUCTOR}, {@link Inst#FIELD}, {@link Inst#METHOD}
|
||||
*/
|
||||
AUTO,
|
||||
/**
|
||||
* Represents the {@link MinecraftForge#TERRAIN_GEN_BUS}
|
||||
*/
|
||||
FORGE_TERRAIN("net.minecraftforge.event.terraingen", MinecraftForge.TERRAIN_GEN_BUS),
|
||||
|
||||
/**
|
||||
* The handler should be constructed from the default constructor of the
|
||||
* class
|
||||
*/
|
||||
CONSTRUCTOR,
|
||||
/**
|
||||
* Represents the {@link MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
FORGE("net.minecraftforge", MinecraftForge.EVENT_BUS),
|
||||
|
||||
/**
|
||||
* The handler should be grabbed from the static {@code INSTANCE} field of
|
||||
* the class
|
||||
*/
|
||||
FIELD,
|
||||
/**
|
||||
* Represents the {@link FMLCommonHandler#bus()}
|
||||
*/
|
||||
FML("cpw.mods.fml", FMLCommonHandler.instance().bus());
|
||||
|
||||
/**
|
||||
* The handler should be grabbed from the static {@code instance()} method
|
||||
* of the class
|
||||
*/
|
||||
METHOD,
|
||||
|
||||
/**
|
||||
* Added for scala compat, not necessary to set explicitly ({@link #AUTO}
|
||||
* will find this).
|
||||
*/
|
||||
SCALA_OBJECT;
|
||||
|
||||
boolean matches(Inst other) {
|
||||
return this == AUTO || other == AUTO || other == this;
|
||||
}
|
||||
}
|
||||
|
||||
public enum HandlerSide {
|
||||
|
||||
/**
|
||||
* Whether to load this handler or not will be determined by the package
|
||||
* name. If it contains "client" it will only load clientside. The default
|
||||
* value.
|
||||
*/
|
||||
AUTO,
|
||||
|
||||
/**
|
||||
* Will load on both sides.
|
||||
*/
|
||||
COMMON,
|
||||
|
||||
/**
|
||||
* Will load only clientside.
|
||||
*/
|
||||
CLIENT,
|
||||
|
||||
/**
|
||||
* Will load only serverside.
|
||||
*/
|
||||
SERVER;
|
||||
|
||||
public boolean equals(Side other) {
|
||||
if (this == COMMON) {
|
||||
return true;
|
||||
} else {
|
||||
return this == CLIENT ? other == Side.CLIENT : other == Side.SERVER;
|
||||
private HandlerType(String eventIdentifier, EventBus bus) {
|
||||
this.eventIdentifier = eventIdentifier;
|
||||
this.bus = bus;
|
||||
}
|
||||
}
|
||||
|
||||
public final String eventIdentifier;
|
||||
public final EventBus bus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of buses to register this handler to. Leave blank for all.
|
||||
* To be put on classes that are Forge/FML event handlers. EnderCore will automatically figure out what busses it
|
||||
* needs to be registered to.
|
||||
* <p>
|
||||
* It can get the instance of the handler in a few ways: <br>
|
||||
* A public no args constructor (or lombok {@link NoArgsConstructor}) <b>OR</b><br>
|
||||
* A static singleton object with field name {@code INSTANCE} (public or private). <b>OR</b><br>
|
||||
* A static method with name <code>instance()</code> (public or private)
|
||||
* <p>
|
||||
* This can also be explicitly set using {@link #getInstFrom()} to avoid invoking code that may cause issues.
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Handler {
|
||||
|
||||
@Deprecated
|
||||
public enum HandlerType {
|
||||
/**
|
||||
* Represents the {@link MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
FORGE,
|
||||
|
||||
/**
|
||||
* Represents the {@link FMLCommonHandler#bus()}
|
||||
*/
|
||||
FML
|
||||
}
|
||||
|
||||
public enum Inst {
|
||||
|
||||
/**
|
||||
* The default, will try all three methods, in the order {@link Inst#CONSTRUCTOR}, {@link Inst#FIELD},
|
||||
* {@link Inst#METHOD}
|
||||
*/
|
||||
AUTO,
|
||||
|
||||
/**
|
||||
* The handler should be constructed from the default constructor of the class
|
||||
*/
|
||||
CONSTRUCTOR,
|
||||
|
||||
/**
|
||||
* The handler should be grabbed from the static {@code INSTANCE} field of the class
|
||||
*/
|
||||
FIELD,
|
||||
|
||||
/**
|
||||
* The handler should be grabbed from the static {@code instance()} method of the class
|
||||
*/
|
||||
METHOD,
|
||||
|
||||
/**
|
||||
* Added for scala compat, not necessary to set explicitly ({@link #AUTO} will find this).
|
||||
*/
|
||||
SCALA_OBJECT;
|
||||
|
||||
boolean matches(Inst other) {
|
||||
return this == AUTO || other == AUTO || other == this;
|
||||
}
|
||||
}
|
||||
|
||||
public enum HandlerSide {
|
||||
|
||||
/**
|
||||
* Whether to load this handler or not will be determined by the package name. If it contains "client" it
|
||||
* will only load clientside. The default value.
|
||||
*/
|
||||
AUTO,
|
||||
|
||||
/**
|
||||
* Will load on both sides.
|
||||
*/
|
||||
COMMON,
|
||||
|
||||
/**
|
||||
* Will load only clientside.
|
||||
*/
|
||||
CLIENT,
|
||||
|
||||
/**
|
||||
* Will load only serverside.
|
||||
*/
|
||||
SERVER;
|
||||
|
||||
public boolean equals(Side other) {
|
||||
if (this == COMMON) {
|
||||
return true;
|
||||
} else {
|
||||
return this == CLIENT ? other == Side.CLIENT : other == Side.SERVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of buses to register this handler to. Leave blank for all.
|
||||
*/
|
||||
@Deprecated
|
||||
HandlerType[] value() default { HandlerType.FORGE, HandlerType.FML };
|
||||
|
||||
/**
|
||||
* The method of getting your handler's instance. Defaults to {@link Inst#AUTO}
|
||||
*/
|
||||
Inst getInstFrom() default AUTO;
|
||||
|
||||
/**
|
||||
* The side to load this handler on. Defaults to {@link HandlerSide#AUTO}
|
||||
*/
|
||||
HandlerSide side() default HandlerSide.AUTO;
|
||||
}
|
||||
|
||||
private static final Set<String> packageSet = new HashSet<String>();
|
||||
|
||||
private static Set<ASMData> annotations;
|
||||
|
||||
public static void preInit(FMLPreInitializationEvent event) {
|
||||
annotations = event.getAsmData().getAll(Handler.class.getName());
|
||||
}
|
||||
|
||||
// private String getEnclosingPackage(Object obj) {
|
||||
// Class<?> modClass = obj.getClass();
|
||||
//
|
||||
// while (modClass.getComponentType() != null) {
|
||||
// modClass = modClass.getComponentType();
|
||||
// }
|
||||
//
|
||||
// while (modClass.getEnclosingClass() != null) {
|
||||
// modClass = modClass.getEnclosingClass();
|
||||
// }
|
||||
//
|
||||
// String name = modClass.getName();
|
||||
// int lastDot = name.lastIndexOf('.');
|
||||
//
|
||||
// return lastDot == -1 ? name : name.substring(0, lastDot);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Registers a top level package to be searched for {@link Handler} classes. Not needed if your {@code @Mod} class
|
||||
* implements {@link IEnderMod}
|
||||
*
|
||||
* @param packageName
|
||||
* @deprecated This is not needed, period.
|
||||
*/
|
||||
@Deprecated
|
||||
HandlerType[] value() default { HandlerType.FORGE, HandlerType.FML };
|
||||
|
||||
/**
|
||||
* The method of getting your handler's instance. Defaults to
|
||||
* {@link Inst#AUTO}
|
||||
*/
|
||||
Inst getInstFrom() default AUTO;
|
||||
|
||||
/**
|
||||
* The side to load this handler on. Defaults to {@link HandlerSide#AUTO}
|
||||
*/
|
||||
HandlerSide side() default HandlerSide.AUTO;
|
||||
}
|
||||
|
||||
private static final Set<String> packageSet = new HashSet<String>();
|
||||
|
||||
private static Set<ASMData> annotations;
|
||||
|
||||
public static void preInit(FMLPreInitializationEvent event) {
|
||||
annotations = event.getAsmData().getAll(Handler.class.getName());
|
||||
}
|
||||
|
||||
// private String getEnclosingPackage(Object obj) {
|
||||
// Class<?> modClass = obj.getClass();
|
||||
//
|
||||
// while (modClass.getComponentType() != null) {
|
||||
// modClass = modClass.getComponentType();
|
||||
// }
|
||||
//
|
||||
// while (modClass.getEnclosingClass() != null) {
|
||||
// modClass = modClass.getEnclosingClass();
|
||||
// }
|
||||
//
|
||||
// String name = modClass.getName();
|
||||
// int lastDot = name.lastIndexOf('.');
|
||||
//
|
||||
// return lastDot == -1 ? name : name.substring(0, lastDot);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Registers a top level package to be searched for {@link Handler} classes.
|
||||
* Not needed if your {@code @Mod} class implements {@link IEnderMod}
|
||||
*
|
||||
* @param packageName
|
||||
* @deprecated This is not needed, period.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void addPackage(String packageName) {
|
||||
if (Loader.instance().hasReachedState(LoaderState.INITIALIZATION)) {
|
||||
throw new RuntimeException("This method must only be called in preinit");
|
||||
}
|
||||
|
||||
EnderCore.logger.info("Adding package " + packageName + " to handler search.");
|
||||
packageSet.add(packageName);
|
||||
}
|
||||
|
||||
private static boolean registered = false;
|
||||
|
||||
/**
|
||||
* For internal use only. Do not call. Callers will be sacked.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public static void register(FMLInitializationEvent event) {
|
||||
if (registered) {
|
||||
throw new IllegalStateException("I warned you!");
|
||||
}
|
||||
|
||||
for (ASMData data : annotations) {
|
||||
String className = data.getClassName();
|
||||
// if not client handler, or we are on client, continue
|
||||
if (shouldLoad(data)) {
|
||||
try {
|
||||
Class<?> c = Class.forName(className);
|
||||
Annotation a = c.getAnnotation(Handler.class);
|
||||
if (a != null) {
|
||||
registerHandler(c, data, (Handler) a);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
EnderCore.logger.error(String.format("[Handlers] %s threw an error on load, skipping...", className));
|
||||
t.printStackTrace();
|
||||
public static void addPackage(String packageName) {
|
||||
if (Loader.instance().hasReachedState(LoaderState.INITIALIZATION)) {
|
||||
throw new RuntimeException("This method must only be called in preinit");
|
||||
}
|
||||
} else {
|
||||
EnderCore.logger.info(String.format("[Handlers] Skipping class %s, it is not loaded on this side.", className));
|
||||
}
|
||||
|
||||
EnderCore.logger.info("Adding package " + packageName + " to handler search.");
|
||||
packageSet.add(packageName);
|
||||
}
|
||||
|
||||
registered = true;
|
||||
}
|
||||
private static boolean registered = false;
|
||||
|
||||
private static final Field _value = ReflectionHelper.findField(EnumHolder.class, "value");
|
||||
/**
|
||||
* For internal use only. Do not call. Callers will be sacked.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public static void register(FMLInitializationEvent event) {
|
||||
if (registered) {
|
||||
throw new IllegalStateException("I warned you!");
|
||||
}
|
||||
|
||||
private static boolean shouldLoad(ASMData data) {
|
||||
EnumHolder holder = (EnumHolder) data.getAnnotationInfo().get("side");
|
||||
HandlerSide side;
|
||||
try {
|
||||
if (holder == null) {
|
||||
side = HandlerSide.AUTO;
|
||||
} else {
|
||||
side = HandlerSide.valueOf((String) _value.get(holder));
|
||||
}
|
||||
Side currentSide = FMLCommonHandler.instance().getEffectiveSide();
|
||||
|
||||
if (side == null || side == HandlerSide.AUTO) {
|
||||
return !data.getClassName().contains("client") || currentSide.isClient();
|
||||
} else {
|
||||
return side.equals(currentSide);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void registerHandler(Class<?> c, ASMData data, Handler handler) throws InstantiationException, IllegalAccessException {
|
||||
EnderCore.logger.info(String.format("[Handlers] Registering handler %s to busses: %s", c.getSimpleName(), Arrays.deepToString(handler.value())));
|
||||
|
||||
Object inst = tryInit(handler, c);
|
||||
|
||||
Method[] methods = c.getDeclaredMethods();
|
||||
EnumSet<HandlerType> types = EnumSet.noneOf(HandlerType.class);
|
||||
|
||||
// Iterate over all methods to find those with @SubscribeEvent, then figure out what type that method is
|
||||
for (Method m : methods) {
|
||||
if (m.isAnnotationPresent(SubscribeEvent.class)) {
|
||||
Class<?>[] params = m.getParameterTypes();
|
||||
if (params.length >= 1) {
|
||||
Class<?> param = params[0];
|
||||
l: while (param != Event.class && param != null && param != Object.class) {
|
||||
for (HandlerType type : HandlerType.values()) {
|
||||
if (param.getName().contains(type.eventIdentifier)) {
|
||||
types.add(type);
|
||||
break l;
|
||||
}
|
||||
for (ASMData data : annotations) {
|
||||
String className = data.getClassName();
|
||||
// if not client handler, or we are on client, continue
|
||||
if (shouldLoad(data)) {
|
||||
try {
|
||||
Class<?> c = Class.forName(className);
|
||||
Annotation a = c.getAnnotation(Handler.class);
|
||||
if (a != null) {
|
||||
registerHandler(c, data, (Handler) a);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
EnderCore.logger
|
||||
.error(String.format("[Handlers] %s threw an error on load, skipping...", className));
|
||||
t.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
EnderCore.logger
|
||||
.info(String.format("[Handlers] Skipping class %s, it is not loaded on this side.", className));
|
||||
}
|
||||
param = param.getSuperclass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registered = true;
|
||||
}
|
||||
|
||||
for (HandlerType type : types) {
|
||||
type.bus.register(inst);
|
||||
}
|
||||
}
|
||||
private static final Field _value = ReflectionHelper.findField(EnumHolder.class, "value");
|
||||
|
||||
private static Object tryInit(Handler annot, Class<?> c) {
|
||||
Inst pref = annot.getInstFrom();
|
||||
private static boolean shouldLoad(ASMData data) {
|
||||
EnumHolder holder = (EnumHolder) data.getAnnotationInfo().get("side");
|
||||
HandlerSide side;
|
||||
try {
|
||||
if (holder == null) {
|
||||
side = HandlerSide.AUTO;
|
||||
} else {
|
||||
side = HandlerSide.valueOf((String) _value.get(holder));
|
||||
}
|
||||
Side currentSide = FMLCommonHandler.instance().getEffectiveSide();
|
||||
|
||||
// Silence all exceptions to trickle down to next if statement.
|
||||
// If all three fail, RuntimeException is thrown.
|
||||
if (pref.matches(CONSTRUCTOR)) {
|
||||
try {
|
||||
return c.newInstance();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (side == null || side == HandlerSide.AUTO) {
|
||||
return !data.getClassName().contains("client") || currentSide.isClient();
|
||||
} else {
|
||||
return side.equals(currentSide);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pref.matches(FIELD)) {
|
||||
try {
|
||||
Field inst = c.getDeclaredField("INSTANCE");
|
||||
inst.setAccessible(true);
|
||||
return inst.get(null);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
private static void registerHandler(Class<?> c, ASMData data, Handler handler)
|
||||
throws InstantiationException, IllegalAccessException {
|
||||
EnderCore.logger.info(
|
||||
String.format(
|
||||
"[Handlers] Registering handler %s to busses: %s",
|
||||
c.getSimpleName(),
|
||||
Arrays.deepToString(handler.value())));
|
||||
|
||||
Object inst = tryInit(handler, c);
|
||||
|
||||
Method[] methods = c.getDeclaredMethods();
|
||||
EnumSet<HandlerType> types = EnumSet.noneOf(HandlerType.class);
|
||||
|
||||
// Iterate over all methods to find those with @SubscribeEvent, then figure out what type that method is
|
||||
for (Method m : methods) {
|
||||
if (m.isAnnotationPresent(SubscribeEvent.class)) {
|
||||
Class<?>[] params = m.getParameterTypes();
|
||||
if (params.length >= 1) {
|
||||
Class<?> param = params[0];
|
||||
l: while (param != Event.class && param != null && param != Object.class) {
|
||||
for (HandlerType type : HandlerType.values()) {
|
||||
if (param.getName().contains(type.eventIdentifier)) {
|
||||
types.add(type);
|
||||
break l;
|
||||
}
|
||||
}
|
||||
param = param.getSuperclass();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (HandlerType type : types) {
|
||||
type.bus.register(inst);
|
||||
}
|
||||
}
|
||||
|
||||
if (pref.matches(METHOD)) {
|
||||
try {
|
||||
Method inst = c.getDeclaredMethod("instance");
|
||||
inst.setAccessible(true);
|
||||
return inst.invoke(null);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
private static Object tryInit(Handler annot, Class<?> c) {
|
||||
Inst pref = annot.getInstFrom();
|
||||
|
||||
if (pref.matches(SCALA_OBJECT)) {
|
||||
try {
|
||||
Field inst = Class.forName(c.getName() + "$").getDeclaredField("MODULE$");
|
||||
inst.setAccessible(true);
|
||||
return inst.get(null);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
// Silence all exceptions to trickle down to next if statement.
|
||||
// If all three fail, RuntimeException is thrown.
|
||||
if (pref.matches(CONSTRUCTOR)) {
|
||||
try {
|
||||
return c.newInstance();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Could not instantiate @Handler class " + c.getName() + " or access INSTANCE field or instance() method.");
|
||||
}
|
||||
if (pref.matches(FIELD)) {
|
||||
try {
|
||||
Field inst = c.getDeclaredField("INSTANCE");
|
||||
inst.setAccessible(true);
|
||||
return inst.get(null);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
if (pref.matches(METHOD)) {
|
||||
try {
|
||||
Method inst = c.getDeclaredMethod("instance");
|
||||
inst.setAccessible(true);
|
||||
return inst.invoke(null);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
if (pref.matches(SCALA_OBJECT)) {
|
||||
try {
|
||||
Field inst = Class.forName(c.getName() + "$").getDeclaredField("MODULE$");
|
||||
inst.setAccessible(true);
|
||||
return inst.get(null);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
throw new RuntimeException(
|
||||
"Could not instantiate @Handler class " + c.getName()
|
||||
+ " or access INSTANCE field or instance() method.");
|
||||
}
|
||||
}
|
||||
@@ -8,180 +8,159 @@ import com.google.common.collect.Lists;
|
||||
|
||||
public class Lang {
|
||||
|
||||
private static final String REGEX = "\\" + '|';
|
||||
public static final char CHAR = '|';
|
||||
private static final String REGEX = "\\" + '|';
|
||||
public static final char CHAR = '|';
|
||||
|
||||
private final String prefix;
|
||||
private final String prefix;
|
||||
|
||||
public Lang(String locKey) {
|
||||
this.prefix = locKey.concat(".");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The prefix assigned to this Lang object.
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the stored prefix to this string, separating with a period. Using this
|
||||
* method returns the string that is used for localizing if you passed this
|
||||
* arg into {@link #localize(String, Object...)}.
|
||||
*
|
||||
* @param suffix
|
||||
* The suffix string
|
||||
* @return The full string
|
||||
*/
|
||||
public String addPrefix(String suffix) {
|
||||
return prefix.concat(suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the string passed, first appending the prefix stored in this
|
||||
* instance of the class.
|
||||
*
|
||||
* @param unloc
|
||||
* The unlocalized string.
|
||||
* @param args
|
||||
* The args to format the localized text with.
|
||||
*
|
||||
* @return A localized string.
|
||||
*/
|
||||
public String localize(String unloc, Object... args) {
|
||||
return localizeExact(addPrefix(unloc), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the string passed, first appending the prefix stored in this
|
||||
* instance of the class.
|
||||
*
|
||||
* @param unloc
|
||||
* The unlocalized string.
|
||||
*
|
||||
* @return A localized string.
|
||||
*/
|
||||
public String localize(String unloc) {
|
||||
return localizeExact(addPrefix(unloc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores the prefix stored in this instance of the class and localizes the
|
||||
* raw string passed.
|
||||
*
|
||||
* @param unloc
|
||||
* The unlocalized string.
|
||||
* @param args
|
||||
* The args to format the localized text with.
|
||||
*
|
||||
* @return A localized string.
|
||||
*/
|
||||
public String localizeExact(String unloc, Object... args) {
|
||||
return StatCollector.translateToLocalFormatted(unloc, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores the prefix stored in this instance of the class and localizes the
|
||||
* raw string passed.
|
||||
*
|
||||
* @param unloc
|
||||
* The unlocalized string.
|
||||
*
|
||||
* @return A localized string.
|
||||
*/
|
||||
public String localizeExact(String unloc) {
|
||||
return StatCollector.translateToLocal(unloc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the localized text on "|" into a String[].
|
||||
*
|
||||
* @param unloc
|
||||
* The unlocalized string.
|
||||
* @param args
|
||||
* The args to format the localized text with.
|
||||
* @return A localized list of strings.
|
||||
*/
|
||||
public String[] localizeList(String unloc, String... args) {
|
||||
return splitList(localize(unloc, (Object[]) args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the localized text on "|" into a String[].
|
||||
*
|
||||
* @param unloc
|
||||
* The unlocalized string.
|
||||
* @return A localized list of strings.
|
||||
*/
|
||||
public String[] localizeList(String unloc) {
|
||||
return splitList(localize(unloc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes all strings in a list, using the prefix.
|
||||
*
|
||||
* @param unloc
|
||||
* The list of unlocalized strings.
|
||||
* @return A list of localized versions of the passed strings.
|
||||
*/
|
||||
public List<String> localizeAll(List<String> unloc) {
|
||||
List<String> ret = Lists.newArrayList();
|
||||
for (String s : unloc) {
|
||||
ret.add(localize(s));
|
||||
public Lang(String locKey) {
|
||||
this.prefix = locKey.concat(".");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes all strings in an array, using the prefix.
|
||||
*
|
||||
* @param unloc
|
||||
* The array of unlocalized strings.
|
||||
* @return An array of localized versions of the passed strings.
|
||||
*/
|
||||
public String[] localizeAll(Lang lang, String... unloc) {
|
||||
String[] ret = new String[unloc.length];
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
ret[i] = lang.localize(unloc[i]);
|
||||
/**
|
||||
* @return The prefix assigned to this Lang object.
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a list of strings based on {@value #CHAR}
|
||||
*
|
||||
* @param list
|
||||
* The list of strings to split
|
||||
* @return An array of strings split on {@value #CHAR}
|
||||
*/
|
||||
public String[] splitList(String list) {
|
||||
return list.split(REGEX);
|
||||
}
|
||||
/**
|
||||
* Adds the stored prefix to this string, separating with a period. Using this method returns the string that is
|
||||
* used for localizing if you passed this arg into {@link #localize(String, Object...)}.
|
||||
*
|
||||
* @param suffix The suffix string
|
||||
* @return The full string
|
||||
*/
|
||||
public String addPrefix(String suffix) {
|
||||
return prefix.concat(suffix);
|
||||
}
|
||||
|
||||
public String[] splitList(String list, String split) {
|
||||
return list.split(split);
|
||||
}
|
||||
/**
|
||||
* Localizes the string passed, first appending the prefix stored in this instance of the class.
|
||||
*
|
||||
* @param unloc The unlocalized string.
|
||||
* @param args The args to format the localized text with.
|
||||
*
|
||||
* @return A localized string.
|
||||
*/
|
||||
public String localize(String unloc, Object... args) {
|
||||
return localizeExact(addPrefix(unloc), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the passed string (plus the prefix) has a localization mapped.
|
||||
*
|
||||
* @param unloc
|
||||
* The unlocalized suffix
|
||||
* @return True if there is a localization mapped, false otherwise.
|
||||
*/
|
||||
public boolean canLocalize(String unloc) {
|
||||
return canLocalizeExact(addPrefix(unloc));
|
||||
}
|
||||
/**
|
||||
* Localizes the string passed, first appending the prefix stored in this instance of the class.
|
||||
*
|
||||
* @param unloc The unlocalized string.
|
||||
*
|
||||
* @return A localized string.
|
||||
*/
|
||||
public String localize(String unloc) {
|
||||
return localizeExact(addPrefix(unloc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the passed string has a localization mapped. Does not use the
|
||||
* prefix.
|
||||
*
|
||||
* @param unloc
|
||||
* The unlocalized string
|
||||
* @return True if there is a localization mapped, false otherwise.
|
||||
*/
|
||||
public boolean canLocalizeExact(String unloc) {
|
||||
return StatCollector.canTranslate(unloc);
|
||||
}
|
||||
/**
|
||||
* Ignores the prefix stored in this instance of the class and localizes the raw string passed.
|
||||
*
|
||||
* @param unloc The unlocalized string.
|
||||
* @param args The args to format the localized text with.
|
||||
*
|
||||
* @return A localized string.
|
||||
*/
|
||||
public String localizeExact(String unloc, Object... args) {
|
||||
return StatCollector.translateToLocalFormatted(unloc, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores the prefix stored in this instance of the class and localizes the raw string passed.
|
||||
*
|
||||
* @param unloc The unlocalized string.
|
||||
*
|
||||
* @return A localized string.
|
||||
*/
|
||||
public String localizeExact(String unloc) {
|
||||
return StatCollector.translateToLocal(unloc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the localized text on "|" into a String[].
|
||||
*
|
||||
* @param unloc The unlocalized string.
|
||||
* @param args The args to format the localized text with.
|
||||
* @return A localized list of strings.
|
||||
*/
|
||||
public String[] localizeList(String unloc, String... args) {
|
||||
return splitList(localize(unloc, (Object[]) args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the localized text on "|" into a String[].
|
||||
*
|
||||
* @param unloc The unlocalized string.
|
||||
* @return A localized list of strings.
|
||||
*/
|
||||
public String[] localizeList(String unloc) {
|
||||
return splitList(localize(unloc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes all strings in a list, using the prefix.
|
||||
*
|
||||
* @param unloc The list of unlocalized strings.
|
||||
* @return A list of localized versions of the passed strings.
|
||||
*/
|
||||
public List<String> localizeAll(List<String> unloc) {
|
||||
List<String> ret = Lists.newArrayList();
|
||||
for (String s : unloc) {
|
||||
ret.add(localize(s));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes all strings in an array, using the prefix.
|
||||
*
|
||||
* @param unloc The array of unlocalized strings.
|
||||
* @return An array of localized versions of the passed strings.
|
||||
*/
|
||||
public String[] localizeAll(Lang lang, String... unloc) {
|
||||
String[] ret = new String[unloc.length];
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
ret[i] = lang.localize(unloc[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a list of strings based on {@value #CHAR}
|
||||
*
|
||||
* @param list The list of strings to split
|
||||
* @return An array of strings split on {@value #CHAR}
|
||||
*/
|
||||
public String[] splitList(String list) {
|
||||
return list.split(REGEX);
|
||||
}
|
||||
|
||||
public String[] splitList(String list, String split) {
|
||||
return list.split(split);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the passed string (plus the prefix) has a localization mapped.
|
||||
*
|
||||
* @param unloc The unlocalized suffix
|
||||
* @return True if there is a localization mapped, false otherwise.
|
||||
*/
|
||||
public boolean canLocalize(String unloc) {
|
||||
return canLocalizeExact(addPrefix(unloc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the passed string has a localization mapped. Does not use the prefix.
|
||||
*
|
||||
* @param unloc The unlocalized string
|
||||
* @return True if there is a localization mapped, false otherwise.
|
||||
*/
|
||||
public boolean canLocalizeExact(String unloc) {
|
||||
return StatCollector.canTranslate(unloc);
|
||||
}
|
||||
}
|
||||
@@ -11,62 +11,64 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public final class OreDict {
|
||||
|
||||
public static void registerVanilla() {
|
||||
safeRegister("barsIron", Blocks.iron_bars);
|
||||
safeRegister("blockHopper", Blocks.hopper);
|
||||
safeRegister("blockObsidian", Blocks.obsidian);
|
||||
safeRegister("itemNetherStar", Items.nether_star);
|
||||
safeRegister("gravel", Blocks.gravel);
|
||||
safeRegister("chestWood", Blocks.chest);
|
||||
safeRegister("craftingTableWood", Blocks.crafting_table);
|
||||
safeRegister("itemCoal", Items.coal);
|
||||
safeRegister("itemCharcoal", new ItemStack(Items.coal, 1, 1));
|
||||
safeRegister("pearlEnder", Items.ender_pearl);
|
||||
safeRegister("pearlEnderEye", Items.ender_eye);
|
||||
safeRegister("itemBlazeRod", Items.blaze_rod);
|
||||
safeRegister("itemBlazePowder", Items.blaze_powder);
|
||||
safeRegister("itemClay", Items.clay_ball);
|
||||
safeRegister("itemFlint", Items.flint);
|
||||
safeRegister("itemGhastTear", Items.ghast_tear);
|
||||
safeRegister("dustGunpowder", Items.gunpowder);
|
||||
safeRegister("itemLeather", Items.leather);
|
||||
safeRegister("slabWoodOak", new ItemStack(Blocks.wooden_slab, 1, 0));
|
||||
safeRegister("slabWoodSpruce", new ItemStack(Blocks.wooden_slab, 1, 1));
|
||||
safeRegister("slabWoodBirch", new ItemStack(Blocks.wooden_slab, 1, 2));
|
||||
safeRegister("slabWoodJungle", new ItemStack(Blocks.wooden_slab, 1, 3));
|
||||
safeRegister("slabWoodAcacia", new ItemStack(Blocks.wooden_slab, 1, 4));
|
||||
safeRegister("slabWoodDarkOak", new ItemStack(Blocks.wooden_slab, 1, 5));
|
||||
safeRegister("slabStone", new ItemStack(Blocks.stone_slab, 1, 0));
|
||||
safeRegister("slabSandstone", new ItemStack(Blocks.stone_slab, 1, 1));
|
||||
safeRegister("slabCobblestone", new ItemStack(Blocks.stone_slab, 1, 3));
|
||||
safeRegister("slabBricks", new ItemStack(Blocks.stone_slab, 1, 4));
|
||||
safeRegister("slabStoneBricks", new ItemStack(Blocks.stone_slab, 1, 5));
|
||||
safeRegister("slabNetherBrick", new ItemStack(Blocks.stone_slab, 1, 6));
|
||||
safeRegister("slabQuartz", new ItemStack(Blocks.stone_slab, 1, 7));
|
||||
}
|
||||
|
||||
public static void safeRegister(String name, Block block) {
|
||||
safeRegister(name, Item.getItemFromBlock(block));
|
||||
}
|
||||
|
||||
public static void safeRegister(String name, Item item) {
|
||||
safeRegister(name, new ItemStack(item));
|
||||
}
|
||||
|
||||
public static void safeRegister(String name, ItemStack stack) {
|
||||
if (!isRegistered(stack, OreDictionary.getOres(name))) OreDictionary.registerOre(name, stack);
|
||||
}
|
||||
|
||||
private static boolean isRegistered(ItemStack stack, ArrayList<ItemStack> toCheck) {
|
||||
for (ItemStack check : toCheck) {
|
||||
if (stack != null && stack.getItem() == check.getItem() && (stack.getItemDamage() == check.getItemDamage() || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
return true;
|
||||
}
|
||||
public static void registerVanilla() {
|
||||
safeRegister("barsIron", Blocks.iron_bars);
|
||||
safeRegister("blockHopper", Blocks.hopper);
|
||||
safeRegister("blockObsidian", Blocks.obsidian);
|
||||
safeRegister("itemNetherStar", Items.nether_star);
|
||||
safeRegister("gravel", Blocks.gravel);
|
||||
safeRegister("chestWood", Blocks.chest);
|
||||
safeRegister("craftingTableWood", Blocks.crafting_table);
|
||||
safeRegister("itemCoal", Items.coal);
|
||||
safeRegister("itemCharcoal", new ItemStack(Items.coal, 1, 1));
|
||||
safeRegister("pearlEnder", Items.ender_pearl);
|
||||
safeRegister("pearlEnderEye", Items.ender_eye);
|
||||
safeRegister("itemBlazeRod", Items.blaze_rod);
|
||||
safeRegister("itemBlazePowder", Items.blaze_powder);
|
||||
safeRegister("itemClay", Items.clay_ball);
|
||||
safeRegister("itemFlint", Items.flint);
|
||||
safeRegister("itemGhastTear", Items.ghast_tear);
|
||||
safeRegister("dustGunpowder", Items.gunpowder);
|
||||
safeRegister("itemLeather", Items.leather);
|
||||
safeRegister("slabWoodOak", new ItemStack(Blocks.wooden_slab, 1, 0));
|
||||
safeRegister("slabWoodSpruce", new ItemStack(Blocks.wooden_slab, 1, 1));
|
||||
safeRegister("slabWoodBirch", new ItemStack(Blocks.wooden_slab, 1, 2));
|
||||
safeRegister("slabWoodJungle", new ItemStack(Blocks.wooden_slab, 1, 3));
|
||||
safeRegister("slabWoodAcacia", new ItemStack(Blocks.wooden_slab, 1, 4));
|
||||
safeRegister("slabWoodDarkOak", new ItemStack(Blocks.wooden_slab, 1, 5));
|
||||
safeRegister("slabStone", new ItemStack(Blocks.stone_slab, 1, 0));
|
||||
safeRegister("slabSandstone", new ItemStack(Blocks.stone_slab, 1, 1));
|
||||
safeRegister("slabCobblestone", new ItemStack(Blocks.stone_slab, 1, 3));
|
||||
safeRegister("slabBricks", new ItemStack(Blocks.stone_slab, 1, 4));
|
||||
safeRegister("slabStoneBricks", new ItemStack(Blocks.stone_slab, 1, 5));
|
||||
safeRegister("slabNetherBrick", new ItemStack(Blocks.stone_slab, 1, 6));
|
||||
safeRegister("slabQuartz", new ItemStack(Blocks.stone_slab, 1, 7));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private OreDict() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
}
|
||||
public static void safeRegister(String name, Block block) {
|
||||
safeRegister(name, Item.getItemFromBlock(block));
|
||||
}
|
||||
|
||||
public static void safeRegister(String name, Item item) {
|
||||
safeRegister(name, new ItemStack(item));
|
||||
}
|
||||
|
||||
public static void safeRegister(String name, ItemStack stack) {
|
||||
if (!isRegistered(stack, OreDictionary.getOres(name))) OreDictionary.registerOre(name, stack);
|
||||
}
|
||||
|
||||
private static boolean isRegistered(ItemStack stack, ArrayList<ItemStack> toCheck) {
|
||||
for (ItemStack check : toCheck) {
|
||||
if (stack != null && stack.getItem() == check.getItem()
|
||||
&& (stack.getItemDamage() == check.getItemDamage()
|
||||
|| stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private OreDict() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
}
|
||||
@@ -17,158 +17,152 @@ import com.enderio.core.common.util.Util;
|
||||
|
||||
public abstract class TileEntityEnder extends TileEntity {
|
||||
|
||||
private final int checkOffset = (int) (Math.random() * 20);
|
||||
protected final boolean isProgressTile;
|
||||
private final int checkOffset = (int) (Math.random() * 20);
|
||||
protected final boolean isProgressTile;
|
||||
|
||||
protected int lastProgressScaled = -1;
|
||||
protected int ticksSinceLastProgressUpdate;
|
||||
protected int lastProgressScaled = -1;
|
||||
protected int ticksSinceLastProgressUpdate;
|
||||
|
||||
public TileEntityEnder() {
|
||||
isProgressTile = this instanceof IProgressTile;
|
||||
}
|
||||
public TileEntityEnder() {
|
||||
isProgressTile = this instanceof IProgressTile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean canUpdate() {
|
||||
return shouldUpdate() || isProgressTile;
|
||||
}
|
||||
@Override
|
||||
public final boolean canUpdate() {
|
||||
return shouldUpdate() || isProgressTile;
|
||||
}
|
||||
|
||||
protected boolean shouldUpdate() {
|
||||
return true;
|
||||
}
|
||||
protected boolean shouldUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private long lastUpdate = 0;
|
||||
private long lastUpdate = 0;
|
||||
|
||||
@Override
|
||||
public final void updateEntity() {
|
||||
if (ConfigHandler.allowExternalTickSpeedup || worldObj.getTotalWorldTime() != lastUpdate) {
|
||||
lastUpdate = worldObj.getTotalWorldTime();
|
||||
doUpdate();
|
||||
if (isProgressTile && !worldObj.isRemote) {
|
||||
int curScaled = getProgressScaled(16);
|
||||
if (++ticksSinceLastProgressUpdate >= getProgressUpdateFreq() || curScaled != lastProgressScaled) {
|
||||
sendTaskProgressPacket();
|
||||
lastProgressScaled = curScaled;
|
||||
@Override
|
||||
public final void updateEntity() {
|
||||
if (ConfigHandler.allowExternalTickSpeedup || worldObj.getTotalWorldTime() != lastUpdate) {
|
||||
lastUpdate = worldObj.getTotalWorldTime();
|
||||
doUpdate();
|
||||
if (isProgressTile && !worldObj.isRemote) {
|
||||
int curScaled = getProgressScaled(16);
|
||||
if (++ticksSinceLastProgressUpdate >= getProgressUpdateFreq() || curScaled != lastProgressScaled) {
|
||||
sendTaskProgressPacket();
|
||||
lastProgressScaled = curScaled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final int getProgressScaled(int scale) {
|
||||
if (isProgressTile) {
|
||||
return Util.getProgressScaled(scale, (IProgressTile) this);
|
||||
public final int getProgressScaled(int scale) {
|
||||
if (isProgressTile) {
|
||||
return Util.getProgressScaled(scale, (IProgressTile) this);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected void doUpdate() {
|
||||
protected void doUpdate() {
|
||||
|
||||
}
|
||||
|
||||
protected void sendTaskProgressPacket() {
|
||||
if (isProgressTile) {
|
||||
EnderPacketHandler.sendToAllAround(new PacketProgress((IProgressTile) this), this);
|
||||
}
|
||||
ticksSinceLastProgressUpdate = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls how often progress updates. Has no effect if your TE is not
|
||||
* {@link IProgressTile}.
|
||||
*/
|
||||
protected int getProgressUpdateFreq() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readFromNBT(NBTTagCompound root) {
|
||||
super.readFromNBT(root);
|
||||
readCustomNBT(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void writeToNBT(NBTTagCompound root) {
|
||||
super.writeToNBT(root);
|
||||
writeCustomNBT(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeCustomNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
readCustomNBT(pkt.func_148857_g());
|
||||
}
|
||||
|
||||
public boolean canPlayerAccess(EntityPlayer player) {
|
||||
return !isInvalid() && player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64D;
|
||||
}
|
||||
|
||||
protected abstract void writeCustomNBT(NBTTagCompound root);
|
||||
|
||||
protected abstract void readCustomNBT(NBTTagCompound root);
|
||||
|
||||
protected void updateBlock() {
|
||||
if (worldObj != null) {
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
protected void sendTaskProgressPacket() {
|
||||
if (isProgressTile) {
|
||||
EnderPacketHandler.sendToAllAround(new PacketProgress((IProgressTile) this), this);
|
||||
}
|
||||
ticksSinceLastProgressUpdate = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isPoweredRedstone() {
|
||||
return worldObj.blockExists(xCoord, yCoord, zCoord) ? worldObj.getStrongestIndirectPower(xCoord, yCoord, zCoord) > 0 : false;
|
||||
}
|
||||
/**
|
||||
* Controls how often progress updates. Has no effect if your TE is not {@link IProgressTile}.
|
||||
*/
|
||||
protected int getProgressUpdateFreq() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called directly after the TE is constructed. This is the place to call
|
||||
* non-final methods.
|
||||
*
|
||||
* Note: This will not be called when the TE is loaded from the save. Hook
|
||||
* into the nbt methods for that.
|
||||
*/
|
||||
public void init() {
|
||||
}
|
||||
@Override
|
||||
public final void readFromNBT(NBTTagCompound root) {
|
||||
super.readFromNBT(root);
|
||||
readCustomNBT(root);
|
||||
}
|
||||
|
||||
private BlockCoord cachedLocation = null;
|
||||
@Override
|
||||
public final void writeToNBT(NBTTagCompound root) {
|
||||
super.writeToNBT(root);
|
||||
writeCustomNBT(root);
|
||||
}
|
||||
|
||||
public BlockCoord getLocation() {
|
||||
return cachedLocation == null || !cachedLocation.equals(xCoord, yCoord, zCoord) ? (cachedLocation = new BlockCoord(this)) : cachedLocation;
|
||||
}
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeCustomNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this with an interval (in ticks) to find out if the current tick is
|
||||
* the one you want to do some work. This is staggered so the work of
|
||||
* different TEs is stretched out over time.
|
||||
*
|
||||
* @see #shouldDoWorkThisTick(int, int) If you need to offset work ticks
|
||||
*/
|
||||
protected boolean shouldDoWorkThisTick(int interval) {
|
||||
return shouldDoWorkThisTick(interval, 0);
|
||||
}
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
readCustomNBT(pkt.func_148857_g());
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this with an interval (in ticks) to find out if the current tick is
|
||||
* the one you want to do some work. This is staggered so the work of
|
||||
* different TEs is stretched out over time.
|
||||
*
|
||||
* If you have different work items in your TE, use this variant to stagger
|
||||
* your work.
|
||||
*/
|
||||
protected boolean shouldDoWorkThisTick(int interval, int offset) {
|
||||
return (worldObj.getTotalWorldTime() + checkOffset + offset) % interval == 0;
|
||||
}
|
||||
public boolean canPlayerAccess(EntityPlayer player) {
|
||||
return !isInvalid() && player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called server-side when a GhostSlot is changed. Check that the given slot
|
||||
* number really is a ghost slot before storing the given stack.
|
||||
*
|
||||
* @param slot
|
||||
* The slot number that was given to the ghost slot
|
||||
* @param stack
|
||||
* The stack that should be placed, null to clear
|
||||
*/
|
||||
public void setGhostSlotContents(int slot, ItemStack stack) {
|
||||
}
|
||||
protected abstract void writeCustomNBT(NBTTagCompound root);
|
||||
|
||||
protected abstract void readCustomNBT(NBTTagCompound root);
|
||||
|
||||
protected void updateBlock() {
|
||||
if (worldObj != null) {
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isPoweredRedstone() {
|
||||
return worldObj.blockExists(xCoord, yCoord, zCoord)
|
||||
? worldObj.getStrongestIndirectPower(xCoord, yCoord, zCoord) > 0
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called directly after the TE is constructed. This is the place to call non-final methods.
|
||||
*
|
||||
* Note: This will not be called when the TE is loaded from the save. Hook into the nbt methods for that.
|
||||
*/
|
||||
public void init() {}
|
||||
|
||||
private BlockCoord cachedLocation = null;
|
||||
|
||||
public BlockCoord getLocation() {
|
||||
return cachedLocation == null || !cachedLocation.equals(xCoord, yCoord, zCoord)
|
||||
? (cachedLocation = new BlockCoord(this))
|
||||
: cachedLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this with an interval (in ticks) to find out if the current tick is the one you want to do some work. This
|
||||
* is staggered so the work of different TEs is stretched out over time.
|
||||
*
|
||||
* @see #shouldDoWorkThisTick(int, int) If you need to offset work ticks
|
||||
*/
|
||||
protected boolean shouldDoWorkThisTick(int interval) {
|
||||
return shouldDoWorkThisTick(interval, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this with an interval (in ticks) to find out if the current tick is the one you want to do some work. This
|
||||
* is staggered so the work of different TEs is stretched out over time.
|
||||
*
|
||||
* If you have different work items in your TE, use this variant to stagger your work.
|
||||
*/
|
||||
protected boolean shouldDoWorkThisTick(int interval, int offset) {
|
||||
return (worldObj.getTotalWorldTime() + checkOffset + offset) % interval == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called server-side when a GhostSlot is changed. Check that the given slot number really is a ghost slot before
|
||||
* storing the given stack.
|
||||
*
|
||||
* @param slot The slot number that was given to the ghost slot
|
||||
* @param stack The stack that should be placed, null to clear
|
||||
*/
|
||||
public void setGhostSlotContents(int slot, ItemStack stack) {}
|
||||
}
|
||||
@@ -18,93 +18,93 @@ import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class CommandReloadConfigs extends CommandBase {
|
||||
public static final CommandReloadConfigs SERVER = new CommandReloadConfigs(Side.SERVER);
|
||||
public static final CommandReloadConfigs CLIENT = new CommandReloadConfigs(Side.CLIENT);
|
||||
|
||||
private static List<String> validModIDs = new ArrayList<String>();
|
||||
public static final CommandReloadConfigs SERVER = new CommandReloadConfigs(Side.SERVER);
|
||||
public static final CommandReloadConfigs CLIENT = new CommandReloadConfigs(Side.CLIENT);
|
||||
|
||||
private final Side side;
|
||||
private static List<String> validModIDs = new ArrayList<String>();
|
||||
|
||||
static {
|
||||
EnderCore.logger.info("Sending dummy event to all mods");
|
||||
private final Side side;
|
||||
|
||||
for (ModContainer mod : Loader.instance().getActiveModList()) {
|
||||
ConfigFileChangedEvent event = new ConfigFileChangedEvent(mod.getModId());
|
||||
FMLCommonHandler.instance().bus().post(event);
|
||||
static {
|
||||
EnderCore.logger.info("Sending dummy event to all mods");
|
||||
|
||||
if (event.isSuccessful()) {
|
||||
validModIDs.add(mod.getModId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private CommandReloadConfigs(Side side) {
|
||||
this.side = side;
|
||||
}
|
||||
for (ModContainer mod : Loader.instance().getActiveModList()) {
|
||||
ConfigFileChangedEvent event = new ConfigFileChangedEvent(mod.getModId());
|
||||
FMLCommonHandler.instance().bus().post(event);
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return side == Side.SERVER ? "reloadServerConfigs" : "reloadConfigs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_) {
|
||||
return "/" + getCommandName() + " <modid> (<modid2> <modid3> ...)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender player) {
|
||||
return player.getEntityWorld().isRemote || super.canCommandSenderUseCommand(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender player, String[] args) {
|
||||
if (args.length >= 1) {
|
||||
String[] avail = validModIDs.toArray(new String[validModIDs.size()]);
|
||||
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
avail = ArrayUtils.removeElement(avail, args[i]);
|
||||
}
|
||||
|
||||
return getListOfStringsMatchingLastWord(args, avail);
|
||||
if (event.isSuccessful()) {
|
||||
validModIDs.add(mod.getModId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private CommandReloadConfigs(Side side) {
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender player, String[] args) {
|
||||
if (side == Side.CLIENT == player.getEntityWorld().isRemote)
|
||||
for (String s : args) {
|
||||
boolean validModid = false;
|
||||
for (ModContainer mod : Loader.instance().getModObjectList().keySet()) {
|
||||
if (mod.getModId().equals(s)) {
|
||||
validModid = true;
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return side == Side.SERVER ? "reloadServerConfigs" : "reloadConfigs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_) {
|
||||
return "/" + getCommandName() + " <modid> (<modid2> <modid3> ...)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender player) {
|
||||
return player.getEntityWorld().isRemote || super.canCommandSenderUseCommand(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender player, String[] args) {
|
||||
if (args.length >= 1) {
|
||||
String[] avail = validModIDs.toArray(new String[validModIDs.size()]);
|
||||
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
avail = ArrayUtils.removeElement(avail, args[i]);
|
||||
}
|
||||
|
||||
return getListOfStringsMatchingLastWord(args, avail);
|
||||
}
|
||||
|
||||
if (validModid) {
|
||||
ConfigFileChangedEvent event = new ConfigFileChangedEvent(s);
|
||||
FMLCommonHandler.instance().bus().post(event);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (event.isSuccessful()) {
|
||||
sendResult(player, s, "success");
|
||||
} else {
|
||||
sendResult(player, s, "fail");
|
||||
}
|
||||
} else {
|
||||
sendResult(player, s, "invalid");
|
||||
@Override
|
||||
public void processCommand(ICommandSender player, String[] args) {
|
||||
if (side == Side.CLIENT == player.getEntityWorld().isRemote) for (String s : args) {
|
||||
boolean validModid = false;
|
||||
for (ModContainer mod : Loader.instance().getModObjectList().keySet()) {
|
||||
if (mod.getModId().equals(s)) {
|
||||
validModid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (validModid) {
|
||||
ConfigFileChangedEvent event = new ConfigFileChangedEvent(s);
|
||||
FMLCommonHandler.instance().bus().post(event);
|
||||
|
||||
if (event.isSuccessful()) {
|
||||
sendResult(player, s, "success");
|
||||
} else {
|
||||
sendResult(player, s, "fail");
|
||||
}
|
||||
} else {
|
||||
sendResult(player, s, "invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendResult(ICommandSender player, String modid, String result) {
|
||||
player.addChatMessage(new ChatComponentText(EnderCore.lang.localize("command.config.result." + result, modid)));
|
||||
}
|
||||
private void sendResult(ICommandSender player, String modid, String result) {
|
||||
player.addChatMessage(new ChatComponentText(EnderCore.lang.localize("command.config.result." + result, modid)));
|
||||
}
|
||||
}
|
||||
@@ -14,74 +14,78 @@ import net.minecraft.scoreboard.Scoreboard;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
|
||||
public class CommandScoreboardInfo extends CommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "scoreboardinfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_) {
|
||||
return "/scoreboardinfo <board> <name>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender p_71519_1_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void processCommand(ICommandSender player, String[] args) {
|
||||
if (args.length < 2) {
|
||||
throw new WrongUsageException("This command requires 2 args: <board> <name>");
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "scoreboardinfo";
|
||||
}
|
||||
|
||||
Scoreboard board = player.getEntityWorld().getScoreboard();
|
||||
|
||||
ScoreObjective obj = board.getObjective(args[0]);
|
||||
|
||||
if (obj == null) {
|
||||
player.addChatMessage(new ChatComponentText("No such board " + args[0]));
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_) {
|
||||
return "/scoreboardinfo <board> <name>";
|
||||
}
|
||||
|
||||
Collection<Score> collection = board.func_96534_i(obj);
|
||||
|
||||
for (Score score : collection) {
|
||||
if (score.getPlayerName().equals(args[1])) {
|
||||
player.addChatMessage(new ChatComponentText(args[1] + "'s score on board \"" + args[0] + "\": " + score.getScorePoints()));
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
player.addChatMessage(new ChatComponentText("No score for " + args[1] + " on board \"" + args[0] + "\""));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
List<String> boards = new ArrayList<String>();
|
||||
for (ScoreObjective obj : (Collection<ScoreObjective>) player.getEntityWorld().getScoreboard().getScoreObjectives()) {
|
||||
boards.add(obj.getName());
|
||||
}
|
||||
|
||||
return getListOfStringsFromIterableMatchingLastWord(args, boards);
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender p_71519_1_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 2) {
|
||||
List<String> players = new ArrayList<String>();
|
||||
for (EntityPlayer p : (List<EntityPlayer>) player.getEntityWorld().playerEntities) {
|
||||
players.add(p.getCommandSenderName());
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void processCommand(ICommandSender player, String[] args) {
|
||||
if (args.length < 2) {
|
||||
throw new WrongUsageException("This command requires 2 args: <board> <name>");
|
||||
}
|
||||
|
||||
return getListOfStringsFromIterableMatchingLastWord(args, players);
|
||||
Scoreboard board = player.getEntityWorld().getScoreboard();
|
||||
|
||||
ScoreObjective obj = board.getObjective(args[0]);
|
||||
|
||||
if (obj == null) {
|
||||
player.addChatMessage(new ChatComponentText("No such board " + args[0]));
|
||||
}
|
||||
|
||||
Collection<Score> collection = board.func_96534_i(obj);
|
||||
|
||||
for (Score score : collection) {
|
||||
if (score.getPlayerName().equals(args[1])) {
|
||||
player.addChatMessage(
|
||||
new ChatComponentText(
|
||||
args[1] + "'s score on board \"" + args[0] + "\": " + score.getScorePoints()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
player.addChatMessage(new ChatComponentText("No score for " + args[1] + " on board \"" + args[0] + "\""));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
List<String> boards = new ArrayList<String>();
|
||||
for (ScoreObjective obj : (Collection<ScoreObjective>) player.getEntityWorld().getScoreboard()
|
||||
.getScoreObjectives()) {
|
||||
boards.add(obj.getName());
|
||||
}
|
||||
|
||||
return getListOfStringsFromIterableMatchingLastWord(args, boards);
|
||||
}
|
||||
|
||||
if (args.length == 2) {
|
||||
List<String> players = new ArrayList<String>();
|
||||
for (EntityPlayer p : (List<EntityPlayer>) player.getEntityWorld().playerEntities) {
|
||||
players.add(p.getCommandSenderName());
|
||||
}
|
||||
|
||||
return getListOfStringsFromIterableMatchingLastWord(args, players);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -16,120 +16,127 @@ import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.event.FMLStateEvent;
|
||||
|
||||
public enum CompatRegistry {
|
||||
INSTANCE;
|
||||
|
||||
private static class Registration {
|
||||
private final String[] modids;
|
||||
private final RegisterTime[] times;
|
||||
INSTANCE;
|
||||
|
||||
private Registration(RegisterTime time, String... modids) {
|
||||
this.modids = modids;
|
||||
this.times = new RegisterTime[] { time };
|
||||
private static class Registration {
|
||||
|
||||
private final String[] modids;
|
||||
private final RegisterTime[] times;
|
||||
|
||||
private Registration(RegisterTime time, String... modids) {
|
||||
this.modids = modids;
|
||||
this.times = new RegisterTime[] { time };
|
||||
}
|
||||
|
||||
private Registration(RegisterTime[] times, String... modids) {
|
||||
this.modids = modids;
|
||||
this.times = times;
|
||||
}
|
||||
|
||||
public String[] getModids() {
|
||||
return this.modids;
|
||||
}
|
||||
|
||||
public RegisterTime[] getTimes() {
|
||||
return this.times;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Generated("lombok")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof CompatRegistry.Registration)) return false;
|
||||
final Registration other = (Registration) o;
|
||||
if (!java.util.Arrays.deepEquals(this.getModids(), other.getModids())) return false;
|
||||
if (!java.util.Arrays.deepEquals(this.getTimes(), other.getTimes())) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Generated("lombok")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + java.util.Arrays.deepHashCode(this.getModids());
|
||||
result = result * PRIME + java.util.Arrays.deepHashCode(this.getTimes());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Generated("lombok")
|
||||
public java.lang.String toString() {
|
||||
return "CompatRegistry.Registration(modids=" + java.util.Arrays.deepToString(this.getModids())
|
||||
+ ", times="
|
||||
+ java.util.Arrays.deepToString(this.getTimes())
|
||||
+ ")";
|
||||
}
|
||||
}
|
||||
|
||||
private Registration(RegisterTime[] times, String... modids) {
|
||||
this.modids = modids;
|
||||
this.times = times;
|
||||
}
|
||||
|
||||
public String[] getModids() {
|
||||
return this.modids;
|
||||
private Map<Registration, String> compatMap = new HashMap<Registration, String>();
|
||||
|
||||
private RegisterTime state = null;
|
||||
|
||||
private CompatRegistry() {}
|
||||
|
||||
public RegisterTime getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public RegisterTime[] getTimes() {
|
||||
return this.times;
|
||||
public void registerCompat(RegisterTime time, String clazz, String... modids) {
|
||||
compatMap.put(new Registration(time, modids), clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Generated("lombok")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof CompatRegistry.Registration)) return false;
|
||||
final Registration other = (Registration)o;
|
||||
if (!java.util.Arrays.deepEquals(this.getModids(), other.getModids())) return false;
|
||||
if (!java.util.Arrays.deepEquals(this.getTimes(), other.getTimes())) return false;
|
||||
return true;
|
||||
public void registerCompat(RegisterTime[] times, String clazz, String... modids) {
|
||||
compatMap.put(new Registration(times, modids), clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Generated("lombok")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + java.util.Arrays.deepHashCode(this.getModids());
|
||||
result = result * PRIME + java.util.Arrays.deepHashCode(this.getTimes());
|
||||
return result;
|
||||
public void handle(FMLStateEvent event) {
|
||||
RegisterTime time = RegisterTime.timeFor(event);
|
||||
state = time;
|
||||
for (Registration r : compatMap.keySet()) {
|
||||
if (ArrayUtils.contains(r.times, time) && allModsLoaded(r.modids)) {
|
||||
doLoad(compatMap.get(r));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Generated("lombok")
|
||||
public java.lang.String toString() {
|
||||
return "CompatRegistry.Registration(modids=" + java.util.Arrays.deepToString(this.getModids()) + ", times=" + java.util.Arrays.deepToString(this.getTimes()) + ")";
|
||||
private boolean allModsLoaded(String[] modids) {
|
||||
for (String s : modids) {
|
||||
if (!Loader.isModLoaded(s)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Registration, String> compatMap = new HashMap<Registration, String>();
|
||||
|
||||
private RegisterTime state = null;
|
||||
|
||||
private CompatRegistry() {
|
||||
}
|
||||
|
||||
public RegisterTime getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void registerCompat(RegisterTime time, String clazz, String... modids) {
|
||||
compatMap.put(new Registration(time, modids), clazz);
|
||||
}
|
||||
|
||||
public void registerCompat(RegisterTime[] times, String clazz, String... modids) {
|
||||
compatMap.put(new Registration(times, modids), clazz);
|
||||
}
|
||||
|
||||
public void handle(FMLStateEvent event) {
|
||||
RegisterTime time = RegisterTime.timeFor(event);
|
||||
state = time;
|
||||
for (Registration r : compatMap.keySet()) {
|
||||
if (ArrayUtils.contains(r.times, time) && allModsLoaded(r.modids)) {
|
||||
doLoad(compatMap.get(r));
|
||||
}
|
||||
public void forceLoad(String clazz) {
|
||||
Iterator<Registration> iter = compatMap.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Registration r = iter.next();
|
||||
String s = compatMap.get(r);
|
||||
if (s.equals(clazz)) {
|
||||
doLoad(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allModsLoaded(String[] modids) {
|
||||
for (String s : modids) {
|
||||
if (!Loader.isModLoaded(s)) {
|
||||
return false;
|
||||
}
|
||||
private void doLoad(String clazz) {
|
||||
try {
|
||||
EnderCore.logger.info("[Compat] Loading compatability class " + clazz);
|
||||
Class<?> compat = Class.forName(clazz);
|
||||
compat.getDeclaredMethod(ICompat.METHOD_NAME).invoke(null);
|
||||
} catch (NoSuchMethodException e) {
|
||||
EnderCore.logger.error(
|
||||
"[Compat] ICompatability class {} did not contain static method {}!",
|
||||
clazz,
|
||||
ICompat.METHOD_NAME);
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException("Error in compatability class " + clazz, e.getTargetException());
|
||||
} catch (Throwable e) {
|
||||
EnderCore.logger.error("[Compat] An unknown error was thrown loading class {}.", clazz);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void forceLoad(String clazz) {
|
||||
Iterator<Registration> iter = compatMap.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Registration r = iter.next();
|
||||
String s = compatMap.get(r);
|
||||
if (s.equals(clazz)) {
|
||||
doLoad(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doLoad(String clazz) {
|
||||
try {
|
||||
EnderCore.logger.info("[Compat] Loading compatability class " + clazz);
|
||||
Class<?> compat = Class.forName(clazz);
|
||||
compat.getDeclaredMethod(ICompat.METHOD_NAME).invoke(null);
|
||||
} catch (NoSuchMethodException e) {
|
||||
EnderCore.logger.error("[Compat] ICompatability class {} did not contain static method {}!", clazz, ICompat.METHOD_NAME);
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException("Error in compatability class " + clazz, e.getTargetException());
|
||||
} catch (Throwable e) {
|
||||
EnderCore.logger.error("[Compat] An unknown error was thrown loading class {}.", clazz);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.enderio.core.common.compat;
|
||||
|
||||
/**
|
||||
* By implementing this marker interface the class must have a static method by
|
||||
* the name of the constant contained within this interface
|
||||
* By implementing this marker interface the class must have a static method by the name of the constant contained
|
||||
* within this interface
|
||||
*/
|
||||
public interface ICompat {
|
||||
public static final String METHOD_NAME = "load";
|
||||
|
||||
public static final String METHOD_NAME = "load";
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -2,31 +2,32 @@ package com.enderio.core.common.config;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.enderio.core.client.config.BaseConfigGui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.enderio.core.client.config.BaseConfigGui;
|
||||
import cpw.mods.fml.client.IModGuiFactory;
|
||||
|
||||
public class BaseConfigFactory implements IModGuiFactory {
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance) {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return BaseConfigGui.class;
|
||||
}
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance) {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return BaseConfigGui.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,149 +19,157 @@ import com.enderio.core.common.tweaks.Tweak;
|
||||
import com.enderio.core.common.tweaks.Tweaks;
|
||||
|
||||
public class ConfigHandler extends AbstractConfigHandler implements ITweakConfigHandler, IReloadCallback {
|
||||
private static final String sectionGeneral = Configuration.CATEGORY_GENERAL;
|
||||
private static final String sectionEnchants = "enchants";
|
||||
|
||||
@Config
|
||||
@Comment({ "Show oredictionary names of every item in its tooltip.", "0 - Off", "1 - Always on", "2 - Only with shift", "3 - Only in debug mode" })
|
||||
@Range(min = 0, max = 3)
|
||||
@NoSync
|
||||
public static int showOredictTooltips = 2;
|
||||
private static final String sectionGeneral = Configuration.CATEGORY_GENERAL;
|
||||
private static final String sectionEnchants = "enchants";
|
||||
|
||||
@Config
|
||||
@Comment({ "Show item registry names in tooltips.", "0 - Off", "1 - Always on", "2 - Only with shift", "3 - Only in debug mode" })
|
||||
@Range(min = 0, max = 3)
|
||||
@NoSync
|
||||
public static int showRegistryNameTooltips = 3;
|
||||
@Config
|
||||
@Comment({ "Show oredictionary names of every item in its tooltip.", "0 - Off", "1 - Always on",
|
||||
"2 - Only with shift", "3 - Only in debug mode" })
|
||||
@Range(min = 0, max = 3)
|
||||
@NoSync
|
||||
public static int showOredictTooltips = 2;
|
||||
|
||||
@Config
|
||||
@Comment({ "Show durability on item tooltips.", "0 - Off", "1 - Always on", "2 - Only with shift", "3 - Only in debug mode" })
|
||||
@Range(min = 0, max = 3)
|
||||
@NoSync
|
||||
public static int showDurabilityTooltips = 1;
|
||||
@Config
|
||||
@Comment({ "Show item registry names in tooltips.", "0 - Off", "1 - Always on", "2 - Only with shift",
|
||||
"3 - Only in debug mode" })
|
||||
@Range(min = 0, max = 3)
|
||||
@NoSync
|
||||
public static int showRegistryNameTooltips = 3;
|
||||
|
||||
@Config
|
||||
@Comment({ "Removes all void fog.", "0 = off", "1 = DEFAULT worldtype only", "2 = all world types" })
|
||||
@NoSync
|
||||
@Range(min = 0, max = 2)
|
||||
public static int disableVoidFog = 1;
|
||||
@Config
|
||||
@Comment({ "Show durability on item tooltips.", "0 - Off", "1 - Always on", "2 - Only with shift",
|
||||
"3 - Only in debug mode" })
|
||||
@Range(min = 0, max = 3)
|
||||
@NoSync
|
||||
public static int showDurabilityTooltips = 1;
|
||||
|
||||
@Config
|
||||
@Comment("The max amount of XP levels an anvil recipe can use.")
|
||||
public static int anvilMaxLevel = 40;
|
||||
@Config
|
||||
@Comment({ "Removes all void fog.", "0 = off", "1 = DEFAULT worldtype only", "2 = all world types" })
|
||||
@NoSync
|
||||
@Range(min = 0, max = 2)
|
||||
public static int disableVoidFog = 1;
|
||||
|
||||
@Config
|
||||
@Comment("The way the game should have been made (Yes this is the fireworks thing).")
|
||||
public static boolean betterAchievements = true;
|
||||
@Config
|
||||
@Comment("The max amount of XP levels an anvil recipe can use.")
|
||||
public static int anvilMaxLevel = 40;
|
||||
|
||||
@Config
|
||||
@Comment("Disabling this option will prevent any crops added to the config json from being right clickable.")
|
||||
public static boolean allowCropRC = true;
|
||||
@Config
|
||||
@Comment("The way the game should have been made (Yes this is the fireworks thing).")
|
||||
public static boolean betterAchievements = true;
|
||||
|
||||
@Config
|
||||
@Comment("Prevent tick speedup (i.e. torcherino) on any TE that uses the base TE class from EnderCore")
|
||||
public static boolean allowExternalTickSpeedup = false;
|
||||
@Config
|
||||
@Comment("Disabling this option will prevent any crops added to the config json from being right clickable.")
|
||||
public static boolean allowCropRC = true;
|
||||
|
||||
@Config
|
||||
@Comment({ "0 - Do nothing", "1 - Remove stacktraces, leave 1-line missing texture errors", "2 - Remove all missing texture errors completely." })
|
||||
@NoSync
|
||||
@Range(min = 0, max = 2)
|
||||
public static int textureErrorRemover = 1;
|
||||
@Config
|
||||
@Comment("Prevent tick speedup (i.e. torcherino) on any TE that uses the base TE class from EnderCore")
|
||||
public static boolean allowExternalTickSpeedup = false;
|
||||
|
||||
@Config
|
||||
@Comment({ "Controls the default sorting on the mod list GUI.", "0 - Default sort (load order)", "1 - A to Z sort", "2 - Z to A sort" })
|
||||
@NoSync
|
||||
@Range(min = 0, max = 2)
|
||||
public static int defaultModSort = 1;
|
||||
@Config
|
||||
@Comment({ "0 - Do nothing", "1 - Remove stacktraces, leave 1-line missing texture errors",
|
||||
"2 - Remove all missing texture errors completely." })
|
||||
@NoSync
|
||||
@Range(min = 0, max = 2)
|
||||
public static int textureErrorRemover = 1;
|
||||
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Enchant ID for the XP boost enchant.")
|
||||
@RestartReq(RestartReqs.REQUIRES_MC_RESTART)
|
||||
@Range(min = 0, max = 255)
|
||||
public static int enchantIDXPBoost = 45;
|
||||
@Config
|
||||
@Comment({ "Controls the default sorting on the mod list GUI.", "0 - Default sort (load order)", "1 - A to Z sort",
|
||||
"2 - Z to A sort" })
|
||||
@NoSync
|
||||
@Range(min = 0, max = 2)
|
||||
public static int defaultModSort = 1;
|
||||
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Allow the XP Boost enchant to be registered.")
|
||||
@RestartReq(RestartReqs.REQUIRES_MC_RESTART)
|
||||
public static boolean allowXPBoost = true;
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Enchant ID for the XP boost enchant.")
|
||||
@RestartReq(RestartReqs.REQUIRES_MC_RESTART)
|
||||
@Range(min = 0, max = 255)
|
||||
public static int enchantIDXPBoost = 45;
|
||||
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Enchant ID for the Auto Smelt enchant.")
|
||||
@RestartReq(RestartReqs.REQUIRES_MC_RESTART)
|
||||
@Range(min = 0, max = 255)
|
||||
public static int enchantIDAutoSmelt = 46;
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Allow the XP Boost enchant to be registered.")
|
||||
@RestartReq(RestartReqs.REQUIRES_MC_RESTART)
|
||||
public static boolean allowXPBoost = true;
|
||||
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Allow the Auto Smelt enchant to be registered.")
|
||||
@RestartReq(RestartReqs.REQUIRES_MC_RESTART)
|
||||
public static boolean allowAutoSmelt = true;
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Enchant ID for the Auto Smelt enchant.")
|
||||
@RestartReq(RestartReqs.REQUIRES_MC_RESTART)
|
||||
@Range(min = 0, max = 255)
|
||||
public static int enchantIDAutoSmelt = 46;
|
||||
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Allow the Auto Smelt enchant to work with Fortune.")
|
||||
public static boolean allowAutoSmeltWithFortune = true;
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Allow the Auto Smelt enchant to be registered.")
|
||||
@RestartReq(RestartReqs.REQUIRES_MC_RESTART)
|
||||
public static boolean allowAutoSmelt = true;
|
||||
|
||||
// @Config("test")
|
||||
// public static List<Integer> test1 = Lists.newArrayList(1, 2, 3);
|
||||
// @Config("test")
|
||||
// public static List<Double> test2 = Lists.newArrayList(0.1, 0.2, 0.3);
|
||||
// @Config("test")
|
||||
// public static List<Boolean> test3 = Lists.newArrayList(true, false, true);
|
||||
// @Config("test")
|
||||
// public static List<String> test4 = Lists.newArrayList("test1", "test2", "test3");
|
||||
@Config(sectionEnchants)
|
||||
@Comment("Allow the Auto Smelt enchant to work with Fortune.")
|
||||
public static boolean allowAutoSmeltWithFortune = true;
|
||||
|
||||
private static ConfigHandler INSTANCE;
|
||||
// @Config("test")
|
||||
// public static List<Integer> test1 = Lists.newArrayList(1, 2, 3);
|
||||
// @Config("test")
|
||||
// public static List<Double> test2 = Lists.newArrayList(0.1, 0.2, 0.3);
|
||||
// @Config("test")
|
||||
// public static List<Boolean> test3 = Lists.newArrayList(true, false, true);
|
||||
// @Config("test")
|
||||
// public static List<String> test4 = Lists.newArrayList("test1", "test2", "test3");
|
||||
|
||||
public static File configFolder, enderConfigFolder;
|
||||
public static File configFile;
|
||||
public static ConfigProcessor processor;
|
||||
private static ConfigHandler INSTANCE;
|
||||
|
||||
public static ConfigHandler instance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ConfigHandler();
|
||||
public static File configFolder, enderConfigFolder;
|
||||
public static File configFile;
|
||||
public static ConfigProcessor processor;
|
||||
|
||||
public static ConfigHandler instance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ConfigHandler();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
protected ConfigHandler() {
|
||||
super(EnderCore.MODID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addSection(sectionGeneral);
|
||||
addSection(sectionEnchants);
|
||||
addSection("tweaks");
|
||||
processor = new ConfigProcessor(getClass(), this, this);
|
||||
processor.process(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reloadIngameConfigs() {
|
||||
Tweaks.loadIngameTweaks();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reloadNonIngameConfigs() {
|
||||
Tweaks.loadNonIngameTweaks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callback(ConfigProcessor inst) {
|
||||
Tweaks.loadIngameTweaks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addBooleanFor(Tweak tweak) {
|
||||
activateSection("tweaks");
|
||||
return getValue(tweak.getName(), tweak.getComment(), true);
|
||||
}
|
||||
|
||||
public void loadRightClickCrops() {
|
||||
JsonConfigReader<PlantInfo> reader = new JsonConfigReader<PlantInfo>(new ModToken(EnderCore.class, EnderCore.MODID.toLowerCase(Locale.US) + "/config"),
|
||||
enderConfigFolder.getAbsolutePath() + "/cropConfig.json", PlantInfo.class);
|
||||
for (PlantInfo i : reader) {
|
||||
i.init();
|
||||
RightClickCropHandler.INSTANCE.addCrop(i);
|
||||
protected ConfigHandler() {
|
||||
super(EnderCore.MODID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addSection(sectionGeneral);
|
||||
addSection(sectionEnchants);
|
||||
addSection("tweaks");
|
||||
processor = new ConfigProcessor(getClass(), this, this);
|
||||
processor.process(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reloadIngameConfigs() {
|
||||
Tweaks.loadIngameTweaks();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reloadNonIngameConfigs() {
|
||||
Tweaks.loadNonIngameTweaks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callback(ConfigProcessor inst) {
|
||||
Tweaks.loadIngameTweaks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addBooleanFor(Tweak tweak) {
|
||||
activateSection("tweaks");
|
||||
return getValue(tweak.getName(), tweak.getComment(), true);
|
||||
}
|
||||
|
||||
public void loadRightClickCrops() {
|
||||
JsonConfigReader<PlantInfo> reader = new JsonConfigReader<PlantInfo>(
|
||||
new ModToken(EnderCore.class, EnderCore.MODID.toLowerCase(Locale.US) + "/config"),
|
||||
enderConfigFolder.getAbsolutePath() + "/cropConfig.json",
|
||||
PlantInfo.class);
|
||||
for (PlantInfo i : reader) {
|
||||
i.init();
|
||||
RightClickCropHandler.INSTANCE.addCrop(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,13 @@ import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.common.config.AbstractConfigHandler.RestartReqs;
|
||||
import com.enderio.core.common.config.annot.Comment;
|
||||
@@ -38,359 +38,356 @@ import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent;
|
||||
|
||||
/**
|
||||
* This class can be used to automatically process {@link Config} annotations on
|
||||
* fields, and sync the data in those fields to clients. It will also
|
||||
* automatically respond to all config changed events and handle them
|
||||
* appropriately.
|
||||
* This class can be used to automatically process {@link Config} annotations on fields, and sync the data in those
|
||||
* fields to clients. It will also automatically respond to all config changed events and handle them appropriately.
|
||||
*
|
||||
* @see #process(boolean)
|
||||
*/
|
||||
public class ConfigProcessor {
|
||||
public interface IReloadCallback {
|
||||
void callback(ConfigProcessor inst);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple adapter for reading custom config types.
|
||||
*
|
||||
* @param <BASE>
|
||||
* Must be a possible class that can be used in configs. This
|
||||
* consists of:
|
||||
* <ul>
|
||||
* <code>
|
||||
* <li>Boolean</li>
|
||||
* <li>Integer</li>
|
||||
* <li>Double</li>
|
||||
* <li>String</li>
|
||||
* <li>boolean[]</li>
|
||||
* <li>int[]</li>
|
||||
* <li>double[]</li>
|
||||
* <li>String[]</li>
|
||||
* </code>
|
||||
* </ul>
|
||||
* @param <ACTUAL>
|
||||
* The actual type of this adapter. This is what the field type must
|
||||
* be for this adapter to be applied.
|
||||
*/
|
||||
public interface ITypeAdapter<ACTUAL, BASE> {
|
||||
TypeToken<ACTUAL> getActualType();
|
||||
public interface IReloadCallback {
|
||||
|
||||
Property.Type getType();
|
||||
void callback(ConfigProcessor inst);
|
||||
}
|
||||
|
||||
/**
|
||||
* If this binds to a primitive type, return it here (e.g. int.class).
|
||||
* Otherwise, return null.
|
||||
*
|
||||
* @return The class for this ITypeAdapter's primitive type.
|
||||
* A simple adapter for reading custom config types.
|
||||
*
|
||||
* @param <BASE> Must be a possible class that can be used in configs. This consists of:
|
||||
* <ul>
|
||||
* <code>
|
||||
* <li>Boolean</li>
|
||||
* <li>Integer</li>
|
||||
* <li>Double</li>
|
||||
* <li>String</li>
|
||||
* <li>boolean[]</li>
|
||||
* <li>int[]</li>
|
||||
* <li>double[]</li>
|
||||
* <li>String[]</li>
|
||||
* </code>
|
||||
* </ul>
|
||||
* @param <ACTUAL> The actual type of this adapter. This is what the field type must be for this adapter to be
|
||||
* applied.
|
||||
*/
|
||||
@Nullable
|
||||
Class<?> getPrimitiveType();
|
||||
public interface ITypeAdapter<ACTUAL, BASE> {
|
||||
|
||||
ACTUAL createActualType(BASE base);
|
||||
TypeToken<ACTUAL> getActualType();
|
||||
|
||||
BASE createBaseType(ACTUAL actual);
|
||||
}
|
||||
Property.Type getType();
|
||||
|
||||
static final Map<String, ConfigProcessor> processorMap = Maps.newHashMap();
|
||||
/**
|
||||
* If this binds to a primitive type, return it here (e.g. int.class). Otherwise, return null.
|
||||
*
|
||||
* @return The class for this ITypeAdapter's primitive type.
|
||||
*/
|
||||
@Nullable
|
||||
Class<?> getPrimitiveType();
|
||||
|
||||
private final List<ITypeAdapter<?, ?>> adapters = Lists.newArrayList();
|
||||
ACTUAL createActualType(BASE base);
|
||||
|
||||
final String modid;
|
||||
|
||||
private final Class<?> configs;
|
||||
private final Configuration configFile;
|
||||
private final IReloadCallback callback;
|
||||
|
||||
Map<String, Object> configValues = Maps.newHashMap();
|
||||
Map<String, Object> defaultValues = Maps.newHashMap();
|
||||
Map<String, Object> originalValues = Maps.newHashMap();
|
||||
|
||||
private Set<String> sections = Sets.newHashSet();
|
||||
|
||||
/**
|
||||
* This constructor omits the callback arg.
|
||||
*
|
||||
* @see #ConfigProcessor(Class, File, String, IReloadCallback)
|
||||
*/
|
||||
public ConfigProcessor(Class<?> configs, File configFile, String modid) {
|
||||
this(configs, configFile, modid, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProcessor to read and set {@link Config} values.
|
||||
*
|
||||
* @param configs
|
||||
* The class which contains your {@link Config} annotations
|
||||
* @param configFile
|
||||
* The file to use as the configuration file
|
||||
* @param modid
|
||||
* The modid of the owner mod
|
||||
* @param callback
|
||||
* an {@link IReloadCallback} object which will be called whenever
|
||||
* config values are edited.
|
||||
*/
|
||||
public ConfigProcessor(Class<?> configs, File configFile, String modid, IReloadCallback callback) {
|
||||
this(configs, new Configuration(configFile), modid, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor if you are using a {@code ConfigProcessor} alongside
|
||||
* an {@link AbstractConfigHandler}. Do not pass a handler that has not been
|
||||
* {@link AbstractConfigHandler#initialize(File) initialized}!
|
||||
*
|
||||
* @param configs
|
||||
* The class which contains your {@link Config} annotations
|
||||
* (typically same class as your {@link AbstractConfigHandler
|
||||
* handler})
|
||||
* @param handler
|
||||
* Your {@link AbstractConfigHandler}
|
||||
*/
|
||||
public ConfigProcessor(Class<?> configs, AbstractConfigHandler handler) {
|
||||
this(configs, handler, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor if you are using a {@code ConfigProcessor} alongside
|
||||
* an {@link AbstractConfigHandler}. Do not pass a handler that has not been
|
||||
* {@link AbstractConfigHandler#initialize(File) initialized}!
|
||||
*
|
||||
* @param configs
|
||||
* The class which contains your {@link Config} annotations
|
||||
* (typically same class as your {@link AbstractConfigHandler
|
||||
* handler})
|
||||
* @param handler
|
||||
* Your {@link AbstractConfigHandler}
|
||||
* @param callback
|
||||
* an {@link IReloadCallback} object which will be called whenever
|
||||
* config values are edited.
|
||||
*/
|
||||
public ConfigProcessor(Class<?> configs, AbstractConfigHandler handler, IReloadCallback callback) {
|
||||
this(configs, handler.config, handler.modid, callback);
|
||||
}
|
||||
|
||||
private ConfigProcessor(Class<?> configs, Configuration configFile, String modid, IReloadCallback callback) {
|
||||
this.configs = configs;
|
||||
this.configFile = configFile;
|
||||
this.modid = modid;
|
||||
this.callback = callback;
|
||||
processorMap.put(modid, this);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
adapters.addAll(TypeAdapterBase.all);
|
||||
}
|
||||
|
||||
public <ACTUAL, BASE> ConfigProcessor addAdapter(ITypeAdapter<ACTUAL, BASE> adapter) {
|
||||
adapters.add(adapter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <ACTUAL, BASE> ConfigProcessor addAdapters(ITypeAdapter<ACTUAL, BASE>... adapters) {
|
||||
for (ITypeAdapter<ACTUAL, BASE> adapter : adapters) {
|
||||
addAdapter(adapter);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes all the configs in this processors class, optionally loading them
|
||||
* from file first.
|
||||
*
|
||||
* @param load
|
||||
* If true, the values from the file will be loaded. Otherwise, the
|
||||
* values existing in memory will be used.
|
||||
*/
|
||||
public void process(boolean load) {
|
||||
if (load) {
|
||||
configFile.load();
|
||||
BASE createBaseType(ACTUAL actual);
|
||||
}
|
||||
|
||||
try {
|
||||
for (Field f : configs.getDeclaredFields()) {
|
||||
processField(f);
|
||||
}
|
||||
if (callback != null) {
|
||||
callback.callback(this);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
static final Map<String, ConfigProcessor> processorMap = Maps.newHashMap();
|
||||
|
||||
private final List<ITypeAdapter<?, ?>> adapters = Lists.newArrayList();
|
||||
|
||||
final String modid;
|
||||
|
||||
private final Class<?> configs;
|
||||
private final Configuration configFile;
|
||||
private final IReloadCallback callback;
|
||||
|
||||
Map<String, Object> configValues = Maps.newHashMap();
|
||||
Map<String, Object> defaultValues = Maps.newHashMap();
|
||||
Map<String, Object> originalValues = Maps.newHashMap();
|
||||
|
||||
private Set<String> sections = Sets.newHashSet();
|
||||
|
||||
/**
|
||||
* This constructor omits the callback arg.
|
||||
*
|
||||
* @see #ConfigProcessor(Class, File, String, IReloadCallback)
|
||||
*/
|
||||
public ConfigProcessor(Class<?> configs, File configFile, String modid) {
|
||||
this(configs, configFile, modid, null);
|
||||
}
|
||||
|
||||
configFile.save();
|
||||
}
|
||||
|
||||
// returns true if the config value changed
|
||||
private boolean processField(Field f) throws Exception {
|
||||
Config cfg = f.getAnnotation(Config.class);
|
||||
if (cfg == null) {
|
||||
return false;
|
||||
}
|
||||
String name = f.getName();
|
||||
Object value = defaultValues.get(name);
|
||||
if (value == null) {
|
||||
value = f.get(null);
|
||||
defaultValues.put(name, value);
|
||||
/**
|
||||
* Constructs a new ConfigProcessor to read and set {@link Config} values.
|
||||
*
|
||||
* @param configs The class which contains your {@link Config} annotations
|
||||
* @param configFile The file to use as the configuration file
|
||||
* @param modid The modid of the owner mod
|
||||
* @param callback an {@link IReloadCallback} object which will be called whenever config values are edited.
|
||||
*/
|
||||
public ConfigProcessor(Class<?> configs, File configFile, String modid, IReloadCallback callback) {
|
||||
this(configs, new Configuration(configFile), modid, callback);
|
||||
}
|
||||
|
||||
Object newValue = getConfigValue(cfg.value(), getComment(f), f, value);
|
||||
/**
|
||||
* Use this constructor if you are using a {@code ConfigProcessor} alongside an {@link AbstractConfigHandler}. Do
|
||||
* not pass a handler that has not been {@link AbstractConfigHandler#initialize(File) initialized}!
|
||||
*
|
||||
* @param configs The class which contains your {@link Config} annotations (typically same class as your
|
||||
* {@link AbstractConfigHandler handler})
|
||||
* @param handler Your {@link AbstractConfigHandler}
|
||||
*/
|
||||
public ConfigProcessor(Class<?> configs, AbstractConfigHandler handler) {
|
||||
this(configs, handler, null);
|
||||
}
|
||||
|
||||
configValues.put(f.getName(), newValue);
|
||||
originalValues.put(f.getName(), newValue);
|
||||
f.set(null, newValue);
|
||||
/**
|
||||
* Use this constructor if you are using a {@code ConfigProcessor} alongside an {@link AbstractConfigHandler}. Do
|
||||
* not pass a handler that has not been {@link AbstractConfigHandler#initialize(File) initialized}!
|
||||
*
|
||||
* @param configs The class which contains your {@link Config} annotations (typically same class as your
|
||||
* {@link AbstractConfigHandler handler})
|
||||
* @param handler Your {@link AbstractConfigHandler}
|
||||
* @param callback an {@link IReloadCallback} object which will be called whenever config values are edited.
|
||||
*/
|
||||
public ConfigProcessor(Class<?> configs, AbstractConfigHandler handler, IReloadCallback callback) {
|
||||
this(configs, handler.config, handler.modid, callback);
|
||||
}
|
||||
|
||||
sections.add(cfg.value());
|
||||
private ConfigProcessor(Class<?> configs, Configuration configFile, String modid, IReloadCallback callback) {
|
||||
this.configs = configs;
|
||||
this.configFile = configFile;
|
||||
this.modid = modid;
|
||||
this.callback = callback;
|
||||
processorMap.put(modid, this);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
adapters.addAll(TypeAdapterBase.all);
|
||||
}
|
||||
|
||||
return !value.equals(newValue);
|
||||
}
|
||||
public <ACTUAL, BASE> ConfigProcessor addAdapter(ITypeAdapter<ACTUAL, BASE> adapter) {
|
||||
adapters.add(adapter);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private Object getConfigValue(String section, String[] commentLines, Field f, Object defVal) {
|
||||
Property prop = null;
|
||||
Object res = null;
|
||||
Bound<Double> bound = getBound(f);
|
||||
ITypeAdapter adapter = getAdapterFor(f);
|
||||
String comment = StringUtils.join(commentLines, "\n");
|
||||
if (adapter != null) {
|
||||
defVal = adapter.createBaseType(defVal);
|
||||
switch (adapter.getType()) {
|
||||
case BOOLEAN:
|
||||
if (defVal.getClass().isArray()) {
|
||||
prop = configFile.get(section, f.getName(), (boolean[]) defVal, comment);
|
||||
res = prop.getBooleanList();
|
||||
} else {
|
||||
prop = configFile.get(section, f.getName(), (Boolean) defVal, comment);
|
||||
res = prop.getBoolean();
|
||||
public <ACTUAL, BASE> ConfigProcessor addAdapters(ITypeAdapter<ACTUAL, BASE>... adapters) {
|
||||
for (ITypeAdapter<ACTUAL, BASE> adapter : adapters) {
|
||||
addAdapter(adapter);
|
||||
}
|
||||
break;
|
||||
case DOUBLE:
|
||||
if (defVal.getClass().isArray()) {
|
||||
prop = configFile.get(section, f.getName(), (double[]) defVal, comment);
|
||||
res = AbstractConfigHandler.boundDoubleArr(prop, Bound.of(bound.min.doubleValue(), bound.max.doubleValue()));
|
||||
} else {
|
||||
prop = configFile.get(section, f.getName(), (Double) defVal, comment);
|
||||
res = AbstractConfigHandler.boundValue(prop, Bound.of(bound.min.doubleValue(), bound.max.doubleValue()), (Double) defVal);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes all the configs in this processors class, optionally loading them from file first.
|
||||
*
|
||||
* @param load If true, the values from the file will be loaded. Otherwise, the values existing in memory will be
|
||||
* used.
|
||||
*/
|
||||
public void process(boolean load) {
|
||||
if (load) {
|
||||
configFile.load();
|
||||
}
|
||||
break;
|
||||
case INTEGER:
|
||||
if (defVal.getClass().isArray()) {
|
||||
prop = configFile.get(section, f.getName(), (int[]) defVal, comment);
|
||||
res = AbstractConfigHandler.boundIntArr(prop, Bound.of(bound.min.intValue(), bound.max.intValue()));
|
||||
} else {
|
||||
prop = configFile.get(section, f.getName(), (Integer) defVal, comment);
|
||||
res = AbstractConfigHandler.boundValue(prop, Bound.of(bound.min.intValue(), bound.max.intValue()), (Integer) defVal);
|
||||
|
||||
try {
|
||||
for (Field f : configs.getDeclaredFields()) {
|
||||
processField(f);
|
||||
}
|
||||
if (callback != null) {
|
||||
callback.callback(this);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
if (defVal.getClass().isArray()) {
|
||||
prop = configFile.get(section, f.getName(), (String[]) defVal, comment);
|
||||
res = prop.getStringList();
|
||||
} else {
|
||||
prop = configFile.get(section, f.getName(), (String) defVal, comment);
|
||||
res = prop.getString();
|
||||
|
||||
configFile.save();
|
||||
}
|
||||
|
||||
// returns true if the config value changed
|
||||
private boolean processField(Field f) throws Exception {
|
||||
Config cfg = f.getAnnotation(Config.class);
|
||||
if (cfg == null) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (res != null) {
|
||||
AbstractConfigHandler.setBounds(prop, bound);
|
||||
AbstractConfigHandler.addCommentDetails(prop, bound);
|
||||
getRestartReq(f).apply(prop);
|
||||
return adapter.createActualType(res);
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(String.format("No adapter for type %s in class %s, field %s", f.getGenericType(), configs, f));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private ITypeAdapter getAdapterFor(Field f) {
|
||||
TypeToken<?> t = TypeToken.of(f.getGenericType());
|
||||
Class<?> c = f.getType();
|
||||
for (ITypeAdapter adapter : adapters) {
|
||||
if ((c.isPrimitive() && c == adapter.getPrimitiveType()) || adapter.getActualType().isAssignableFrom(t)) {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImmutableSet<String> sections() {
|
||||
return ImmutableSet.copyOf(sections);
|
||||
}
|
||||
|
||||
public ConfigCategory getCategory(String category) {
|
||||
return configFile.getCategory(category);
|
||||
}
|
||||
|
||||
public void syncTo(Map<String, Object> values) {
|
||||
this.configValues = values;
|
||||
for (String s : configValues.keySet()) {
|
||||
try {
|
||||
Field f = configs.getDeclaredField(s);
|
||||
Config annot = f.getAnnotation(Config.class);
|
||||
if (annot != null && !getNoSync(f)) {
|
||||
Object newVal = configValues.get(s);
|
||||
Object oldVal = f.get(null);
|
||||
boolean changed = false;
|
||||
if (!oldVal.equals(newVal)) {
|
||||
EnderCore.logger.debug("Config {}.{} differs from new data. Changing from {} to {}", configs.getName(), f.getName(), oldVal, newVal);
|
||||
f.set(null, newVal);
|
||||
changed = true;
|
||||
}
|
||||
if (changed && callback != null) {
|
||||
callback.callback(this);
|
||||
}
|
||||
} else if (annot != null) {
|
||||
EnderCore.logger.debug("Skipping syncing field {}.{} as it was marked NoSync", configs.getName(), f.getName());
|
||||
String name = f.getName();
|
||||
Object value = defaultValues.get(name);
|
||||
if (value == null) {
|
||||
value = f.get(null);
|
||||
defaultValues.put(name, value);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Object newValue = getConfigValue(cfg.value(), getComment(f), f, value);
|
||||
|
||||
configValues.put(f.getName(), newValue);
|
||||
originalValues.put(f.getName(), newValue);
|
||||
f.set(null, newValue);
|
||||
|
||||
sections.add(cfg.value());
|
||||
|
||||
return !value.equals(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getComment(Field f) {
|
||||
Comment c = f.getAnnotation(Comment.class);
|
||||
return c == null ? new String[0] : c.value();
|
||||
}
|
||||
|
||||
private Bound<Double> getBound(Field f) {
|
||||
Range r = f.getAnnotation(Range.class);
|
||||
return r == null ? Bound.MAX_BOUND : Bound.of(r.min(), r.max());
|
||||
}
|
||||
|
||||
private boolean getNoSync(Field f) {
|
||||
return f.getAnnotation(NoSync.class) != null;
|
||||
}
|
||||
|
||||
private RestartReqs getRestartReq(Field f) {
|
||||
RestartReq r = f.getAnnotation(RestartReq.class);
|
||||
return r == null ? RestartReqs.NONE : r.value();
|
||||
}
|
||||
|
||||
/* Event Handling */
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
EnderCore.logger.info("Sending server configs to client for {}", configs.getName());
|
||||
EnderPacketHandler.INSTANCE.sendTo(new PacketConfigSync(this), (EntityPlayerMP) event.player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLogout(ClientDisconnectionFromServerEvent event) {
|
||||
syncTo(originalValues);
|
||||
EnderCore.logger.info("Reset configs to client values for {}", configs.getName());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
|
||||
if (event.modID.equals(modid)) {
|
||||
process(false);
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private Object getConfigValue(String section, String[] commentLines, Field f, Object defVal) {
|
||||
Property prop = null;
|
||||
Object res = null;
|
||||
Bound<Double> bound = getBound(f);
|
||||
ITypeAdapter adapter = getAdapterFor(f);
|
||||
String comment = StringUtils.join(commentLines, "\n");
|
||||
if (adapter != null) {
|
||||
defVal = adapter.createBaseType(defVal);
|
||||
switch (adapter.getType()) {
|
||||
case BOOLEAN:
|
||||
if (defVal.getClass().isArray()) {
|
||||
prop = configFile.get(section, f.getName(), (boolean[]) defVal, comment);
|
||||
res = prop.getBooleanList();
|
||||
} else {
|
||||
prop = configFile.get(section, f.getName(), (Boolean) defVal, comment);
|
||||
res = prop.getBoolean();
|
||||
}
|
||||
break;
|
||||
case DOUBLE:
|
||||
if (defVal.getClass().isArray()) {
|
||||
prop = configFile.get(section, f.getName(), (double[]) defVal, comment);
|
||||
res = AbstractConfigHandler
|
||||
.boundDoubleArr(prop, Bound.of(bound.min.doubleValue(), bound.max.doubleValue()));
|
||||
} else {
|
||||
prop = configFile.get(section, f.getName(), (Double) defVal, comment);
|
||||
res = AbstractConfigHandler.boundValue(
|
||||
prop,
|
||||
Bound.of(bound.min.doubleValue(), bound.max.doubleValue()),
|
||||
(Double) defVal);
|
||||
}
|
||||
break;
|
||||
case INTEGER:
|
||||
if (defVal.getClass().isArray()) {
|
||||
prop = configFile.get(section, f.getName(), (int[]) defVal, comment);
|
||||
res = AbstractConfigHandler
|
||||
.boundIntArr(prop, Bound.of(bound.min.intValue(), bound.max.intValue()));
|
||||
} else {
|
||||
prop = configFile.get(section, f.getName(), (Integer) defVal, comment);
|
||||
res = AbstractConfigHandler.boundValue(
|
||||
prop,
|
||||
Bound.of(bound.min.intValue(), bound.max.intValue()),
|
||||
(Integer) defVal);
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
if (defVal.getClass().isArray()) {
|
||||
prop = configFile.get(section, f.getName(), (String[]) defVal, comment);
|
||||
res = prop.getStringList();
|
||||
} else {
|
||||
prop = configFile.get(section, f.getName(), (String) defVal, comment);
|
||||
res = prop.getString();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (res != null) {
|
||||
AbstractConfigHandler.setBounds(prop, bound);
|
||||
AbstractConfigHandler.addCommentDetails(prop, bound);
|
||||
getRestartReq(f).apply(prop);
|
||||
return adapter.createActualType(res);
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
String.format("No adapter for type %s in class %s, field %s", f.getGenericType(), configs, f));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConfigFileChanged(ConfigFileChangedEvent event) {
|
||||
if (event.modID.equals(modid)) {
|
||||
process(true);
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private ITypeAdapter getAdapterFor(Field f) {
|
||||
TypeToken<?> t = TypeToken.of(f.getGenericType());
|
||||
Class<?> c = f.getType();
|
||||
for (ITypeAdapter adapter : adapters) {
|
||||
if ((c.isPrimitive() && c == adapter.getPrimitiveType()) || adapter.getActualType().isAssignableFrom(t)) {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImmutableSet<String> sections() {
|
||||
return ImmutableSet.copyOf(sections);
|
||||
}
|
||||
|
||||
public ConfigCategory getCategory(String category) {
|
||||
return configFile.getCategory(category);
|
||||
}
|
||||
|
||||
public void syncTo(Map<String, Object> values) {
|
||||
this.configValues = values;
|
||||
for (String s : configValues.keySet()) {
|
||||
try {
|
||||
Field f = configs.getDeclaredField(s);
|
||||
Config annot = f.getAnnotation(Config.class);
|
||||
if (annot != null && !getNoSync(f)) {
|
||||
Object newVal = configValues.get(s);
|
||||
Object oldVal = f.get(null);
|
||||
boolean changed = false;
|
||||
if (!oldVal.equals(newVal)) {
|
||||
EnderCore.logger.debug(
|
||||
"Config {}.{} differs from new data. Changing from {} to {}",
|
||||
configs.getName(),
|
||||
f.getName(),
|
||||
oldVal,
|
||||
newVal);
|
||||
f.set(null, newVal);
|
||||
changed = true;
|
||||
}
|
||||
if (changed && callback != null) {
|
||||
callback.callback(this);
|
||||
}
|
||||
} else if (annot != null) {
|
||||
EnderCore.logger.debug(
|
||||
"Skipping syncing field {}.{} as it was marked NoSync",
|
||||
configs.getName(),
|
||||
f.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getComment(Field f) {
|
||||
Comment c = f.getAnnotation(Comment.class);
|
||||
return c == null ? new String[0] : c.value();
|
||||
}
|
||||
|
||||
private Bound<Double> getBound(Field f) {
|
||||
Range r = f.getAnnotation(Range.class);
|
||||
return r == null ? Bound.MAX_BOUND : Bound.of(r.min(), r.max());
|
||||
}
|
||||
|
||||
private boolean getNoSync(Field f) {
|
||||
return f.getAnnotation(NoSync.class) != null;
|
||||
}
|
||||
|
||||
private RestartReqs getRestartReq(Field f) {
|
||||
RestartReq r = f.getAnnotation(RestartReq.class);
|
||||
return r == null ? RestartReqs.NONE : r.value();
|
||||
}
|
||||
|
||||
/* Event Handling */
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
EnderCore.logger.info("Sending server configs to client for {}", configs.getName());
|
||||
EnderPacketHandler.INSTANCE.sendTo(new PacketConfigSync(this), (EntityPlayerMP) event.player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLogout(ClientDisconnectionFromServerEvent event) {
|
||||
syncTo(originalValues);
|
||||
EnderCore.logger.info("Reset configs to client values for {}", configs.getName());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
|
||||
if (event.modID.equals(modid)) {
|
||||
process(false);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConfigFileChanged(ConfigFileChangedEvent event) {
|
||||
if (event.modID.equals(modid)) {
|
||||
process(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,6 @@ package com.enderio.core.common.config;
|
||||
import com.enderio.core.common.tweaks.Tweak;
|
||||
|
||||
public interface ITweakConfigHandler {
|
||||
public boolean addBooleanFor(Tweak tweak);
|
||||
|
||||
public boolean addBooleanFor(Tweak tweak);
|
||||
}
|
||||
@@ -28,233 +28,207 @@ import com.google.gson.reflect.TypeToken;
|
||||
* <p>
|
||||
* Where the objects go inbetween the brackets ( [] )
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the object to be read in. If this type is generic in
|
||||
* itself (ex. {@code HashMap}) you should use one of the TypeToken
|
||||
* constructors.
|
||||
* @param <T> The type of the object to be read in. If this type is generic in itself (ex. {@code HashMap}) you should
|
||||
* use one of the TypeToken constructors.
|
||||
*/
|
||||
public class JsonConfigReader<T> implements Iterable<T> {
|
||||
/**
|
||||
* A class representing some info about your mod.
|
||||
* <p>
|
||||
* <b>mainClass</b> is a class in your mod so that files can be copied out of
|
||||
* your jar.<br>
|
||||
* <b>assetPath</b> is the path to your default json file. This includes the
|
||||
* /modid part and whatever subfolders follow.
|
||||
*/
|
||||
public static class ModToken {
|
||||
private Class<?> mainClass;
|
||||
private String assetPath;
|
||||
|
||||
public ModToken(Class<?> mainClass, String assetPath) {
|
||||
this.mainClass = mainClass;
|
||||
this.assetPath = assetPath;
|
||||
}
|
||||
|
||||
public Class<?> getMainClass() {
|
||||
return mainClass;
|
||||
}
|
||||
|
||||
public String getAssetPath() {
|
||||
return assetPath;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A class representing some info about your mod.
|
||||
* <p>
|
||||
* <b>mainClass</b> is a class in your mod so that files can be copied out of your jar.<br>
|
||||
* <b>assetPath</b> is the path to your default json file. This includes the /modid part and whatever subfolders
|
||||
* follow.
|
||||
*/
|
||||
public static class ModToken {
|
||||
|
||||
/**
|
||||
* The default key for the json data. This is what is used when calling
|
||||
* {@link #getElements()}.
|
||||
*/
|
||||
public static final String DEFAULT_KEY = "data";
|
||||
private static final JsonParser parser = new JsonParser();
|
||||
private Class<?> mainClass;
|
||||
private String assetPath;
|
||||
|
||||
private final GsonBuilder builder = new GsonBuilder();
|
||||
public ModToken(Class<?> mainClass, String assetPath) {
|
||||
this.mainClass = mainClass;
|
||||
this.assetPath = assetPath;
|
||||
}
|
||||
|
||||
private File file;
|
||||
private JsonObject root;
|
||||
public Class<?> getMainClass() {
|
||||
return mainClass;
|
||||
}
|
||||
|
||||
private Class<T> type = null;
|
||||
private TypeToken<T> typeToken = null;
|
||||
|
||||
/**
|
||||
* An easy way to read in config files in JSON format
|
||||
*
|
||||
* @param mod
|
||||
* A {@link ModToken} object to hold data about your mod. This is
|
||||
* used to automatically copy the file from your jar if it does not
|
||||
* exist in the config folder
|
||||
* @param fullFileName
|
||||
* The full file path and name of your JSON config. Can be relative
|
||||
* to the working directory or absolute.
|
||||
* @param objClass
|
||||
* The type of the object being deserialized. Must be of the same
|
||||
* type as the generic type of this class.
|
||||
*/
|
||||
public JsonConfigReader(ModToken mod, String fullFileName, Class<T> objClass) {
|
||||
this(mod, new File(fullFileName), objClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* An easy way to read in config files in JSON format
|
||||
*
|
||||
* @param mod
|
||||
* A {@link ModToken} object to hold data about your mod. This is
|
||||
* used to automatically copy the file from your jar if it does not
|
||||
* exist in the config folder
|
||||
* @param file
|
||||
* The {@link File} representing your JSON config.
|
||||
* @param objClass
|
||||
* The type of the object being deserialized. Must be of the same
|
||||
* type as the generic type of this class.
|
||||
*/
|
||||
public JsonConfigReader(ModToken mod, File file, Class<T> objClass) {
|
||||
this.type = objClass;
|
||||
initialize(mod, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* An easy way to read in config files in JSON format. Use this constructor if
|
||||
* the type of this class is generic in itself. (ex. {@code HashMap<K, V>})
|
||||
*
|
||||
* @param mod
|
||||
* A {@link ModToken} object to hold data about your mod. This is
|
||||
* used to automatically copy the file from your jar if it does not
|
||||
* exist in the config folder
|
||||
* @param fullFileName
|
||||
* The full file path and name of your JSON config. Can be relative
|
||||
* to the working directory or absolute.
|
||||
* @param objType
|
||||
* A {@link TypeToken} representing the type of the object to be
|
||||
* deserialized. Must be of the same type as the generic type of this
|
||||
* class.
|
||||
*/
|
||||
public JsonConfigReader(ModToken mod, String fullFileName, TypeToken<T> objType) {
|
||||
this(mod, new File(fullFileName), objType);
|
||||
}
|
||||
|
||||
/**
|
||||
* An easy way to read in config files in JSON format. Use this constructor if
|
||||
* the type of this class is generic in itself. (ex. {@code HashMap<K, V>})
|
||||
*
|
||||
* @param mod
|
||||
* A {@link ModToken} object to hold data about your mod. This is
|
||||
* used to automatically copy the file from your jar if it does not
|
||||
* exist in the config folder
|
||||
* @param file
|
||||
* The {@link File} representing your JSON config.
|
||||
* @param objType
|
||||
* A {@link TypeToken} representing the type of the object to be
|
||||
* deserialized. Must be of the same type as the generic type of this
|
||||
* class.
|
||||
*/
|
||||
public JsonConfigReader(ModToken mod, File file, TypeToken<T> objType) {
|
||||
this.typeToken = objType;
|
||||
initialize(mod, file);
|
||||
}
|
||||
|
||||
private void initialize(ModToken mod, File file) {
|
||||
this.file = file;
|
||||
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
String assetPath = mod.getAssetPath();
|
||||
if (!assetPath.endsWith("/")) {
|
||||
assetPath = assetPath + "/";
|
||||
}
|
||||
|
||||
EnderFileUtils.copyFromJar(mod.getMainClass(), assetPath + file.getName(), file);
|
||||
public String getAssetPath() {
|
||||
return assetPath;
|
||||
}
|
||||
}
|
||||
|
||||
refresh();
|
||||
}
|
||||
/**
|
||||
* The default key for the json data. This is what is used when calling {@link #getElements()}.
|
||||
*/
|
||||
public static final String DEFAULT_KEY = "data";
|
||||
private static final JsonParser parser = new JsonParser();
|
||||
|
||||
/**
|
||||
* Reparses the config file.
|
||||
*
|
||||
* @return The {@link JsonObject} read.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* If there is an exception while reading the file.
|
||||
*/
|
||||
public JsonObject parseFile() {
|
||||
try {
|
||||
return parser.parse(new FileReader(file)).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
private final GsonBuilder builder = new GsonBuilder();
|
||||
|
||||
/**
|
||||
* Reparses the config file and stores the result in this class. Use this if
|
||||
* your JSON config was edited and you want to reload from disk.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* If there is an exception while reading the file.
|
||||
*/
|
||||
public void refresh() {
|
||||
this.root = parseFile();
|
||||
}
|
||||
private File file;
|
||||
private JsonObject root;
|
||||
|
||||
/**
|
||||
* If this key exists in the current JSON data.
|
||||
*
|
||||
* @param key
|
||||
* The String key
|
||||
* @return True if this JSON has the given key. False otherwise.
|
||||
*/
|
||||
public boolean hasKey(String key) {
|
||||
return root.get(key) != null;
|
||||
}
|
||||
private Class<T> type = null;
|
||||
private TypeToken<T> typeToken = null;
|
||||
|
||||
/**
|
||||
* Gives this reader's {@link GsonBuilder} object so that you may configure
|
||||
* type adapters and other settings.
|
||||
*/
|
||||
public GsonBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads from the {@link JsonObject} linked to the {@link String key} and
|
||||
* returns a List of all the elements contained in its array.
|
||||
*
|
||||
* @return A list of the generic type of this class containing the
|
||||
* deserialized elements from the passed key.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<T> getElements(String key) {
|
||||
if (!hasKey(key)) {
|
||||
return Lists.newArrayList();
|
||||
/**
|
||||
* An easy way to read in config files in JSON format
|
||||
*
|
||||
* @param mod A {@link ModToken} object to hold data about your mod. This is used to automatically copy the
|
||||
* file from your jar if it does not exist in the config folder
|
||||
* @param fullFileName The full file path and name of your JSON config. Can be relative to the working directory or
|
||||
* absolute.
|
||||
* @param objClass The type of the object being deserialized. Must be of the same type as the generic type of
|
||||
* this class.
|
||||
*/
|
||||
public JsonConfigReader(ModToken mod, String fullFileName, Class<T> objClass) {
|
||||
this(mod, new File(fullFileName), objClass);
|
||||
}
|
||||
|
||||
Gson gson = builder.create();
|
||||
JsonArray elements = root.get(key).getAsJsonArray();
|
||||
List<T> list = new ArrayList<T>();
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
if (type == null) {
|
||||
list.add((T) gson.fromJson(elements.get(i), typeToken.getType()));
|
||||
} else {
|
||||
list.add(gson.fromJson(elements.get(i), type));
|
||||
}
|
||||
/**
|
||||
* An easy way to read in config files in JSON format
|
||||
*
|
||||
* @param mod A {@link ModToken} object to hold data about your mod. This is used to automatically copy the
|
||||
* file from your jar if it does not exist in the config folder
|
||||
* @param file The {@link File} representing your JSON config.
|
||||
* @param objClass The type of the object being deserialized. Must be of the same type as the generic type of this
|
||||
* class.
|
||||
*/
|
||||
public JsonConfigReader(ModToken mod, File file, Class<T> objClass) {
|
||||
this.type = objClass;
|
||||
initialize(mod, file);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the default (defined by {@value #DEFAULT_KEY}) cached JsonObject in
|
||||
* this class and returns a List of all the elements contained in its array.
|
||||
* <p>
|
||||
* {@link #getElements(String)} should be used if your config has multiple
|
||||
* keys.
|
||||
*
|
||||
* @return A list of the generic type of this class containing the
|
||||
* deserialized elements from your JSON config's default key.
|
||||
*/
|
||||
public List<T> getElements() {
|
||||
return getElements(DEFAULT_KEY);
|
||||
}
|
||||
/**
|
||||
* An easy way to read in config files in JSON format. Use this constructor if the type of this class is generic in
|
||||
* itself. (ex. {@code HashMap<K, V>})
|
||||
*
|
||||
* @param mod A {@link ModToken} object to hold data about your mod. This is used to automatically copy the
|
||||
* file from your jar if it does not exist in the config folder
|
||||
* @param fullFileName The full file path and name of your JSON config. Can be relative to the working directory or
|
||||
* absolute.
|
||||
* @param objType A {@link TypeToken} representing the type of the object to be deserialized. Must be of the
|
||||
* same type as the generic type of this class.
|
||||
*/
|
||||
public JsonConfigReader(ModToken mod, String fullFileName, TypeToken<T> objType) {
|
||||
this(mod, new File(fullFileName), objType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return getElements().iterator();
|
||||
}
|
||||
/**
|
||||
* An easy way to read in config files in JSON format. Use this constructor if the type of this class is generic in
|
||||
* itself. (ex. {@code HashMap<K, V>})
|
||||
*
|
||||
* @param mod A {@link ModToken} object to hold data about your mod. This is used to automatically copy the file
|
||||
* from your jar if it does not exist in the config folder
|
||||
* @param file The {@link File} representing your JSON config.
|
||||
* @param objType A {@link TypeToken} representing the type of the object to be deserialized. Must be of the same
|
||||
* type as the generic type of this class.
|
||||
*/
|
||||
public JsonConfigReader(ModToken mod, File file, TypeToken<T> objType) {
|
||||
this.typeToken = objType;
|
||||
initialize(mod, file);
|
||||
}
|
||||
|
||||
private void initialize(ModToken mod, File file) {
|
||||
this.file = file;
|
||||
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
String assetPath = mod.getAssetPath();
|
||||
if (!assetPath.endsWith("/")) {
|
||||
assetPath = assetPath + "/";
|
||||
}
|
||||
|
||||
EnderFileUtils.copyFromJar(mod.getMainClass(), assetPath + file.getName(), file);
|
||||
}
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reparses the config file.
|
||||
*
|
||||
* @return The {@link JsonObject} read.
|
||||
*
|
||||
* @throws RuntimeException If there is an exception while reading the file.
|
||||
*/
|
||||
public JsonObject parseFile() {
|
||||
try {
|
||||
return parser.parse(new FileReader(file)).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reparses the config file and stores the result in this class. Use this if your JSON config was edited and you
|
||||
* want to reload from disk.
|
||||
*
|
||||
* @throws RuntimeException If there is an exception while reading the file.
|
||||
*/
|
||||
public void refresh() {
|
||||
this.root = parseFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* If this key exists in the current JSON data.
|
||||
*
|
||||
* @param key The String key
|
||||
* @return True if this JSON has the given key. False otherwise.
|
||||
*/
|
||||
public boolean hasKey(String key) {
|
||||
return root.get(key) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives this reader's {@link GsonBuilder} object so that you may configure type adapters and other settings.
|
||||
*/
|
||||
public GsonBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads from the {@link JsonObject} linked to the {@link String key} and returns a List of all the elements
|
||||
* contained in its array.
|
||||
*
|
||||
* @return A list of the generic type of this class containing the deserialized elements from the passed key.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<T> getElements(String key) {
|
||||
if (!hasKey(key)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
Gson gson = builder.create();
|
||||
JsonArray elements = root.get(key).getAsJsonArray();
|
||||
List<T> list = new ArrayList<T>();
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
if (type == null) {
|
||||
list.add((T) gson.fromJson(elements.get(i), typeToken.getType()));
|
||||
} else {
|
||||
list.add(gson.fromJson(elements.get(i), type));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the default (defined by {@value #DEFAULT_KEY}) cached JsonObject in this class and returns a List of all
|
||||
* the elements contained in its array.
|
||||
* <p>
|
||||
* {@link #getElements(String)} should be used if your config has multiple keys.
|
||||
*
|
||||
* @return A list of the generic type of this class containing the deserialized elements from your JSON config's
|
||||
* default key.
|
||||
*/
|
||||
public List<T> getElements() {
|
||||
return getElements(DEFAULT_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return getElements().iterator();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.enderio.core.common.config;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -15,80 +11,82 @@ import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class PacketConfigSync implements IMessage {
|
||||
|
||||
public PacketConfigSync() {
|
||||
}
|
||||
public PacketConfigSync() {}
|
||||
|
||||
private Map<String, Object> configValues;
|
||||
private String modid;
|
||||
private Map<String, Object> configValues;
|
||||
private String modid;
|
||||
|
||||
public PacketConfigSync(ConfigProcessor toSync) {
|
||||
this.configValues = toSync.configValues;
|
||||
this.modid = toSync.modid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteArrayOutputStream obj = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(obj);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(gzip);
|
||||
objStream.writeObject(configValues);
|
||||
objStream.close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
public PacketConfigSync(ConfigProcessor toSync) {
|
||||
this.configValues = toSync.configValues;
|
||||
this.modid = toSync.modid;
|
||||
}
|
||||
|
||||
buf.writeShort(obj.size());
|
||||
buf.writeBytes(obj.toByteArray());
|
||||
|
||||
ByteBufUtils.writeUTF8String(buf, modid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pa4ok
|
||||
* you can trick forge network system & send client packet to server
|
||||
* and then use different hacks with serialization of untrusted data
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
return;
|
||||
}
|
||||
|
||||
short len = buf.readShort();
|
||||
byte[] compressedBody = new byte[len];
|
||||
|
||||
for (short i = 0; i < len; i++)
|
||||
compressedBody[i] = buf.readByte();
|
||||
|
||||
try {
|
||||
ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
|
||||
configValues = (Map<String, Object>) obj.readObject();
|
||||
obj.close();
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
|
||||
modid = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PacketConfigSync, PacketConfigSync> {
|
||||
@Override
|
||||
public PacketConfigSync onMessage(PacketConfigSync message, MessageContext ctx) {
|
||||
ConfigProcessor processor = ConfigProcessor.processorMap.get(message.modid);
|
||||
if (processor != null) {
|
||||
processor.syncTo(message.configValues);
|
||||
}
|
||||
return null;
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteArrayOutputStream obj = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(obj);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(gzip);
|
||||
objStream.writeObject(configValues);
|
||||
objStream.close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
|
||||
buf.writeShort(obj.size());
|
||||
buf.writeBytes(obj.toByteArray());
|
||||
|
||||
ByteBufUtils.writeUTF8String(buf, modid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pa4ok you can trick forge network system & send client packet to server and then use different hacks with
|
||||
* serialization of untrusted data
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
return;
|
||||
}
|
||||
|
||||
short len = buf.readShort();
|
||||
byte[] compressedBody = new byte[len];
|
||||
|
||||
for (short i = 0; i < len; i++) compressedBody[i] = buf.readByte();
|
||||
|
||||
try {
|
||||
ObjectInputStream obj = new ObjectInputStream(
|
||||
new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
|
||||
configValues = (Map<String, Object>) obj.readObject();
|
||||
obj.close();
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
|
||||
modid = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PacketConfigSync, PacketConfigSync> {
|
||||
|
||||
@Override
|
||||
public PacketConfigSync onMessage(PacketConfigSync message, MessageContext ctx) {
|
||||
ConfigProcessor processor = ConfigProcessor.processorMap.get(message.modid);
|
||||
if (processor != null) {
|
||||
processor.syncTo(message.configValues);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,54 +15,56 @@ import com.google.common.reflect.TypeToken;
|
||||
|
||||
@SuppressWarnings({ "serial", "unchecked" })
|
||||
public abstract class TypeAdapterBase<ACTUAL, BASE> implements ITypeAdapter<ACTUAL, BASE> {
|
||||
private final TypeToken<ACTUAL> actualType;
|
||||
private final Property.Type type;
|
||||
private final Class<?> primitiveType;
|
||||
|
||||
public TypeAdapterBase(TypeToken<ACTUAL> actualType, Property.Type type, Class<?> primitiveType) {
|
||||
this.actualType = actualType;
|
||||
this.type = type;
|
||||
this.primitiveType = primitiveType;
|
||||
}
|
||||
private final TypeToken<ACTUAL> actualType;
|
||||
private final Property.Type type;
|
||||
private final Class<?> primitiveType;
|
||||
|
||||
public TypeAdapterBase(TypeToken<ACTUAL> actualType, Property.Type baseType) {
|
||||
this(actualType, baseType, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<ACTUAL> getActualType() {
|
||||
return actualType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getPrimitiveType() {
|
||||
return primitiveType;
|
||||
}
|
||||
|
||||
public static final class TypeAdapterSame<TYPE> extends TypeAdapterBase<TYPE, TYPE> {
|
||||
public TypeAdapterSame(TypeToken<TYPE> actual, Property.Type base) {
|
||||
super(actual, base);
|
||||
public TypeAdapterBase(TypeToken<ACTUAL> actualType, Property.Type type, Class<?> primitiveType) {
|
||||
this.actualType = actualType;
|
||||
this.type = type;
|
||||
this.primitiveType = primitiveType;
|
||||
}
|
||||
|
||||
public TypeAdapterSame(TypeToken<TYPE> actual, Property.Type base, Class<?> primitiveType) {
|
||||
super(actual, base, primitiveType);
|
||||
public TypeAdapterBase(TypeToken<ACTUAL> actualType, Property.Type baseType) {
|
||||
this(actualType, baseType, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TYPE createActualType(TYPE base) {
|
||||
return base;
|
||||
public TypeToken<ACTUAL> getActualType() {
|
||||
return actualType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TYPE createBaseType(TYPE actual) {
|
||||
return actual;
|
||||
public Property.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getPrimitiveType() {
|
||||
return primitiveType;
|
||||
}
|
||||
|
||||
public static final class TypeAdapterSame<TYPE> extends TypeAdapterBase<TYPE, TYPE> {
|
||||
|
||||
public TypeAdapterSame(TypeToken<TYPE> actual, Property.Type base) {
|
||||
super(actual, base);
|
||||
}
|
||||
|
||||
public TypeAdapterSame(TypeToken<TYPE> actual, Property.Type base, Class<?> primitiveType) {
|
||||
super(actual, base, primitiveType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TYPE createActualType(TYPE base) {
|
||||
return base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TYPE createBaseType(TYPE actual) {
|
||||
return actual;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @formatter:off
|
||||
public static final TypeAdapterSame<Integer> INTEGER = new TypeAdapterSame<Integer>(TypeToken.of(Integer.class), Type.INTEGER, int.class);
|
||||
|
||||
@@ -7,16 +7,15 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Contains the comment for a config option. Has no effect is this field is not
|
||||
* also annotated with {@link Config}.
|
||||
* Contains the comment for a config option. Has no effect is this field is not also annotated with {@link Config}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Documented
|
||||
public @interface Comment {
|
||||
/**
|
||||
* The comment for the config option. Multiple strings will be split into
|
||||
* lines.
|
||||
*/
|
||||
String[] value() default "";
|
||||
|
||||
/**
|
||||
* The comment for the config option. Multiple strings will be split into lines.
|
||||
*/
|
||||
String[] value() default "";
|
||||
}
|
||||
@@ -6,24 +6,25 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.enderio.core.common.config.ConfigProcessor;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import com.enderio.core.common.config.ConfigProcessor;
|
||||
|
||||
/**
|
||||
* Used to mark a {@code static} field as a config option. Has no effect if the
|
||||
* class is not processed with a {@link ConfigProcessor}
|
||||
* Used to mark a {@code static} field as a config option. Has no effect if the class is not processed with a
|
||||
* {@link ConfigProcessor}
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Documented
|
||||
public @interface Config {
|
||||
/**
|
||||
* The section of the config option.
|
||||
*
|
||||
* (AKA Category)
|
||||
*
|
||||
* @return A string section name.
|
||||
*/
|
||||
String value() default Configuration.CATEGORY_GENERAL;
|
||||
|
||||
/**
|
||||
* The section of the config option.
|
||||
*
|
||||
* (AKA Category)
|
||||
*
|
||||
* @return A string section name.
|
||||
*/
|
||||
String value() default Configuration.CATEGORY_GENERAL;
|
||||
}
|
||||
@@ -7,12 +7,10 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* If annotation exists, this config will not be synced to the client upon
|
||||
* connection to a server. Has no effect is this field is not also annotated
|
||||
* with {@link Config}.
|
||||
* If annotation exists, this config will not be synced to the client upon connection to a server. Has no effect is this
|
||||
* field is not also annotated with {@link Config}.
|
||||
* <p>
|
||||
* This is useful for configs that have no need to be the same between client
|
||||
* and server (or are purely client-sided).
|
||||
* This is useful for configs that have no need to be the same between client and server (or are purely client-sided).
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
|
||||
@@ -7,33 +7,30 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Represents the range a config value can be, i.e. a minimum and maximum value.
|
||||
* This is applied forcefully, any value past one of the extremes will be
|
||||
* clamped inside this range. Has no effect is this field is not also annotated
|
||||
* with {@link Config}.
|
||||
* Represents the range a config value can be, i.e. a minimum and maximum value. This is applied forcefully, any value
|
||||
* past one of the extremes will be clamped inside this range. Has no effect is this field is not also annotated with
|
||||
* {@link Config}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Documented
|
||||
public @interface Range {
|
||||
|
||||
/**
|
||||
* The min value of the config.
|
||||
* <p>
|
||||
* For non-numeric values, or if there is no min value, this should remain
|
||||
* unset.
|
||||
*
|
||||
* @return A double minimum value for the config.
|
||||
*/
|
||||
double min() default Double.MIN_VALUE;
|
||||
/**
|
||||
* The min value of the config.
|
||||
* <p>
|
||||
* For non-numeric values, or if there is no min value, this should remain unset.
|
||||
*
|
||||
* @return A double minimum value for the config.
|
||||
*/
|
||||
double min() default Double.MIN_VALUE;
|
||||
|
||||
/**
|
||||
* The max value of the config.
|
||||
* <p>
|
||||
* For non-numeric values, or if there is no max value, this should remain
|
||||
* unset.
|
||||
*
|
||||
* @return A double maximum value for the config.
|
||||
*/
|
||||
double max() default Double.MAX_VALUE;
|
||||
/**
|
||||
* The max value of the config.
|
||||
* <p>
|
||||
* For non-numeric values, or if there is no max value, this should remain unset.
|
||||
*
|
||||
* @return A double maximum value for the config.
|
||||
*/
|
||||
double max() default Double.MAX_VALUE;
|
||||
}
|
||||
@@ -9,20 +9,20 @@ import java.lang.annotation.Target;
|
||||
import com.enderio.core.common.config.AbstractConfigHandler.RestartReqs;
|
||||
|
||||
/**
|
||||
* Represents the restart requirements of a config value. Use this if your
|
||||
* config will have no effect if changed while the game is running. Has no
|
||||
* effect is this field is not also annotated with {@link Config}.
|
||||
* Represents the restart requirements of a config value. Use this if your config will have no effect if changed while
|
||||
* the game is running. Has no effect is this field is not also annotated with {@link Config}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Documented
|
||||
public @interface RestartReq {
|
||||
/**
|
||||
* What requirements this config has for restarting the game.
|
||||
*
|
||||
* @see RestartReqs#NONE
|
||||
* @see RestartReqs#REQUIRES_WORLD_RESTART
|
||||
* @see RestartReqs#REQUIRES_MC_RESTART
|
||||
*/
|
||||
RestartReqs value() default RestartReqs.NONE;
|
||||
|
||||
/**
|
||||
* What requirements this config has for restarting the game.
|
||||
*
|
||||
* @see RestartReqs#NONE
|
||||
* @see RestartReqs#REQUIRES_WORLD_RESTART
|
||||
* @see RestartReqs#REQUIRES_MC_RESTART
|
||||
*/
|
||||
RestartReqs value() default RestartReqs.NONE;
|
||||
}
|
||||
@@ -1,69 +1,72 @@
|
||||
package com.enderio.core.common.enchant;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.api.common.enchant.IAdvancedEnchant;
|
||||
import com.enderio.core.common.config.ConfigHandler;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLInterModComms;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnumEnchantmentType;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.api.common.enchant.IAdvancedEnchant;
|
||||
import com.enderio.core.common.config.ConfigHandler;
|
||||
import cpw.mods.fml.common.event.FMLInterModComms;
|
||||
|
||||
public class EnchantAutoSmelt extends Enchantment implements IAdvancedEnchant {
|
||||
public static final EnchantAutoSmelt INSTANCE = new EnchantAutoSmelt(ConfigHandler.enchantIDAutoSmelt);
|
||||
|
||||
private EnchantAutoSmelt(int id) {
|
||||
super(id, 2, EnumEnchantmentType.breakable);
|
||||
}
|
||||
public static final EnchantAutoSmelt INSTANCE = new EnchantAutoSmelt(ConfigHandler.enchantIDAutoSmelt);
|
||||
|
||||
@Override
|
||||
public int getMaxEnchantability(int level) {
|
||||
return super.getMaxEnchantability(level) + 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinEnchantability(int level) {
|
||||
return super.getMinEnchantability(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApply(ItemStack stack) {
|
||||
return type.canEnchantItem(stack.getItem()) && !(stack.getItem() instanceof ItemArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "enchantment.autosmelt";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks() {
|
||||
return ConfigHandler.allowAutoSmelt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTooltipDetails(ItemStack stack) {
|
||||
return new String[] { EnderCore.lang.localize("enchantment.autosmelt.tooltip", false) };
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (ConfigHandler.allowAutoSmelt) {
|
||||
FMLInterModComms.sendMessage("EnderIO", "recipe:enchanter",
|
||||
"<enchantment name=\"enchantment.autosmelt\" costPerLevel=\"30\">\n<itemStack oreDictionary=\"blockCoal\" number=\"32\"/>\n</enchantment>");
|
||||
} else {
|
||||
Enchantment.enchantmentsList[this.effectId] = null;
|
||||
private EnchantAutoSmelt(int id) {
|
||||
super(id, 2, EnumEnchantmentType.breakable);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canApplyTogether(Enchantment ench) {
|
||||
return super.canApplyTogether(ench) && ench.effectId != silkTouch.effectId
|
||||
&& ((ench.effectId != fortune.effectId) || ConfigHandler.allowAutoSmeltWithFortune);
|
||||
}
|
||||
@Override
|
||||
public int getMaxEnchantability(int level) {
|
||||
return super.getMaxEnchantability(level) + 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinEnchantability(int level) {
|
||||
return super.getMinEnchantability(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApply(ItemStack stack) {
|
||||
return type.canEnchantItem(stack.getItem()) && !(stack.getItem() instanceof ItemArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "enchantment.autosmelt";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks() {
|
||||
return ConfigHandler.allowAutoSmelt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTooltipDetails(ItemStack stack) {
|
||||
return new String[] { EnderCore.lang.localize("enchantment.autosmelt.tooltip", false) };
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (ConfigHandler.allowAutoSmelt) {
|
||||
FMLInterModComms.sendMessage(
|
||||
"EnderIO",
|
||||
"recipe:enchanter",
|
||||
"<enchantment name=\"enchantment.autosmelt\" costPerLevel=\"30\">\n<itemStack oreDictionary=\"blockCoal\" number=\"32\"/>\n</enchantment>");
|
||||
} else {
|
||||
Enchantment.enchantmentsList[this.effectId] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canApplyTogether(Enchantment ench) {
|
||||
return super.canApplyTogether(ench) && ench.effectId != silkTouch.effectId
|
||||
&& ((ench.effectId != fortune.effectId) || ConfigHandler.allowAutoSmeltWithFortune);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +1,66 @@
|
||||
package com.enderio.core.common.enchant;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.api.common.enchant.IAdvancedEnchant;
|
||||
import com.enderio.core.common.config.ConfigHandler;
|
||||
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnumEnchantmentType;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.api.common.enchant.IAdvancedEnchant;
|
||||
import com.enderio.core.common.config.ConfigHandler;
|
||||
import cpw.mods.fml.common.event.FMLInterModComms;
|
||||
|
||||
public class EnchantXPBoost extends Enchantment implements IAdvancedEnchant {
|
||||
public static final EnchantXPBoost INSTANCE = new EnchantXPBoost(ConfigHandler.enchantIDXPBoost);
|
||||
|
||||
private EnchantXPBoost(int id) {
|
||||
super(id, 2, EnumEnchantmentType.breakable);
|
||||
}
|
||||
public static final EnchantXPBoost INSTANCE = new EnchantXPBoost(ConfigHandler.enchantIDXPBoost);
|
||||
|
||||
@Override
|
||||
public int getMaxEnchantability(int level) {
|
||||
return super.getMaxEnchantability(level) + 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinEnchantability(int level) {
|
||||
return super.getMinEnchantability(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApply(ItemStack stack) {
|
||||
return type.canEnchantItem(stack.getItem()) && !(stack.getItem() instanceof ItemArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "enchantment.xpboost";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks() {
|
||||
return ConfigHandler.allowXPBoost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTooltipDetails(ItemStack stack) {
|
||||
return new String[] { EnderCore.lang.localize("enchantment.xpboost.tooltip", false) };
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (ConfigHandler.allowXPBoost) {
|
||||
FMLInterModComms.sendMessage("EnderIO", "recipe:enchanter",
|
||||
"<enchantment name=\"enchantment.xpboost\" costPerLevel=\"4\">\n<itemStack oreDictionary=\"ingotGold\" number=\"16\"/>\n</enchantment>");
|
||||
} else {
|
||||
Enchantment.enchantmentsList[this.effectId] = null;
|
||||
private EnchantXPBoost(int id) {
|
||||
super(id, 2, EnumEnchantmentType.breakable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnchantability(int level) {
|
||||
return super.getMaxEnchantability(level) + 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinEnchantability(int level) {
|
||||
return super.getMinEnchantability(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApply(ItemStack stack) {
|
||||
return type.canEnchantItem(stack.getItem()) && !(stack.getItem() instanceof ItemArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "enchantment.xpboost";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks() {
|
||||
return ConfigHandler.allowXPBoost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTooltipDetails(ItemStack stack) {
|
||||
return new String[] { EnderCore.lang.localize("enchantment.xpboost.tooltip", false) };
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (ConfigHandler.allowXPBoost) {
|
||||
FMLInterModComms.sendMessage(
|
||||
"EnderIO",
|
||||
"recipe:enchanter",
|
||||
"<enchantment name=\"enchantment.xpboost\" costPerLevel=\"4\">\n<itemStack oreDictionary=\"ingotGold\" number=\"16\"/>\n</enchantment>");
|
||||
} else {
|
||||
Enchantment.enchantmentsList[this.effectId] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.enderio.core.common.event;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
|
||||
/**
|
||||
@@ -16,7 +17,8 @@ import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public class ArrowUpdateEvent extends EntityEvent {
|
||||
public ArrowUpdateEvent(Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
public ArrowUpdateEvent(Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 168 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user