mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-18 11:39:14 +00:00
Some class renaming, move TextureSubmap to API and improve its methods
This commit is contained in:
1 parent
c2fa40d57e
commit
d50f2c9da5
36 files changed
+373
-294
No files matched your search
@@ -6,8 +6,16 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import static net.minecraftforge.common.util.ForgeDirection.*;
|
||||
|
||||
/**
|
||||
* Think of this class as a "Two dimensional ForgeDirection, with diagonals".
|
||||
* <p>
|
||||
* It represents the eight different directions a face of a block can connect with CTM, and contains the logic for determining if a block is indeed connected in that direction.
|
||||
* <p>
|
||||
* Note that, for example, {@link #TOP_RIGHT} does not mean connected to the {@link #TOP} and {@link #RIGHT}, but connected in the diagonal direction represented by {@link #TOP_RIGHT}. This is used
|
||||
* for inner corner rendering.
|
||||
*/
|
||||
public enum Dir {
|
||||
|
||||
// @formatter:off
|
||||
TOP(UP),
|
||||
TOP_RIGHT(UP, EAST),
|
||||
RIGHT(EAST),
|
||||
@@ -18,8 +26,11 @@ public enum Dir {
|
||||
TOP_LEFT(UP, WEST);
|
||||
// @formatter:on
|
||||
|
||||
private static final ForgeDirection NORMAL = SOUTH;
|
||||
/**
|
||||
* All values of this enum, used to prevent unnecessary allocation via {@link #values()}.
|
||||
*/
|
||||
public static final Dir[] VALUES = values();
|
||||
private static final ForgeDirection NORMAL = SOUTH;
|
||||
|
||||
private ForgeDirection[] dirs;
|
||||
|
||||
@@ -27,6 +38,27 @@ public enum Dir {
|
||||
this.dirs = dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds if this block is connected for the given side in this Dir.
|
||||
*
|
||||
* @param inst
|
||||
* The CTM instance to use for logic.
|
||||
* @param world
|
||||
* The world the block is in.
|
||||
* @param x
|
||||
* The x coordinate of your block.
|
||||
* @param y
|
||||
* The y coordinate of your block.
|
||||
* @param z
|
||||
* The z coordinate of your block.
|
||||
* @param sideIdx
|
||||
* The side index of the current face. This equivalent to {@link ForgeDirection#ordinal()}
|
||||
* @param block
|
||||
* The block being rendered.
|
||||
* @param meta
|
||||
* The metadata of the block.
|
||||
* @return True if the block is connected in the given Dir, false otherwise.
|
||||
*/
|
||||
public boolean isConnected(CTM inst, IBlockAccess world, int x, int y, int z, int sideIdx, Block block, int meta) {
|
||||
ForgeDirection side = getOrientation(sideIdx);
|
||||
ForgeDirection[] dirs = getNormalizedDirs(side);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.cricketcraft.chisel.api.client;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public interface ISubmapManager {
|
||||
|
||||
/**
|
||||
* Gets the icon for item rendering, based on side and item metadata.
|
||||
*
|
||||
* @param side
|
||||
* Side of the ItemBlock.
|
||||
* @param meta
|
||||
* Metadata of the ItemBlock.
|
||||
* @return The IIcon for rendering.
|
||||
*/
|
||||
IIcon getIcon(int side, int meta);
|
||||
|
||||
/**
|
||||
* Gets the icon for world rendering, based on world position and side.
|
||||
*/
|
||||
IIcon getIcon(IBlockAccess world, int x, int y, int z, int side);
|
||||
|
||||
/**
|
||||
* Hook for registering any custom icons you might need in this class. Will be called during the normal block method.
|
||||
*
|
||||
* @param modName
|
||||
* The mod ID this submap was registered to.
|
||||
* @param block
|
||||
* The block being registered for.
|
||||
* @param register
|
||||
* The IIconRegister instance.
|
||||
*/
|
||||
void registerIcons(String modName, Block block, IIconRegister register);
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.cricketcraft.chisel.api.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* This class is used to split up a large IIcon into smaller "submapped" icons used for CTM and other texture manipulation.
|
||||
*/
|
||||
public class TextureSubmap {
|
||||
|
||||
private static List<TextureSubmap> submaps = Lists.newArrayList();
|
||||
private static TextureSubmap dummy = new TextureSubmap(null, 0, 0);
|
||||
static {
|
||||
MinecraftForge.EVENT_BUS.register(dummy);
|
||||
}
|
||||
|
||||
private int width, height;
|
||||
private IIcon baseIcon;
|
||||
private IIcon[][] icons;
|
||||
|
||||
/**
|
||||
* Construct a new submap. A submap is not required to be square, but it is required to be rectangular.
|
||||
*
|
||||
* @param baseIcon
|
||||
* The IIcon to submap.
|
||||
* @param width
|
||||
* The width of the map, in icons.
|
||||
* @param height
|
||||
* The height of the map, in icons.
|
||||
*/
|
||||
public TextureSubmap(IIcon baseIcon, int width, int height) {
|
||||
this.baseIcon = baseIcon;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.icons = new IIcon[width][height];
|
||||
submaps.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* The width, in icons, of the submap.
|
||||
*/
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* The height, in icons, of the submap.
|
||||
*/
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* The large "base" icon used for the submap.
|
||||
*/
|
||||
public IIcon getBaseIcon() {
|
||||
return baseIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and returns the sub-icon at the given coordinates. For example, if you have a 3 by 3 submap, calling {@code getSubIcon(1, 1)} will return the center subicon.
|
||||
*/
|
||||
public IIcon getSubIcon(int x, int y) {
|
||||
x = x % icons.length;
|
||||
return icons[x][y % icons[x].length];
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only, this is used to create the virtual "subicons" used in the map.
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public final void TexturesStitched(TextureStitchEvent.Post event) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
icons[x][y] = new TextureVirtual(getBaseIcon(), width, height, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TextureVirtual implements IIcon {
|
||||
|
||||
private int width, height;
|
||||
private float umin, umax, vmin, vmax;
|
||||
private String name;
|
||||
private IIcon parentIcon;
|
||||
|
||||
private TextureVirtual(IIcon parent, int w, int h, int x, int y) {
|
||||
parentIcon = parent;
|
||||
|
||||
umin = parentIcon.getInterpolatedU(16.0 * (x) / w);
|
||||
umax = parentIcon.getInterpolatedU(16.0 * (x + 1) / w);
|
||||
vmin = parentIcon.getInterpolatedV(16.0 * (y) / h);
|
||||
vmax = parentIcon.getInterpolatedV(16.0 * (y + 1) / h);
|
||||
|
||||
name = parentIcon.getIconName() + "|" + x + "." + y;
|
||||
|
||||
width = parentIcon.getIconWidth();
|
||||
height = parentIcon.getIconHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMinU() {
|
||||
return umin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMaxU() {
|
||||
return umax;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getInterpolatedU(double d0) {
|
||||
return (float) (umin + (umax - umin) * d0 / 16.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMinV() {
|
||||
return vmin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMaxV() {
|
||||
return vmax;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getInterpolatedV(double d0) {
|
||||
return (float) (vmin + (vmax - vmin) * d0 / 16.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getIconName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getIconWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getIconHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user