API and other consistency fixes

This commit is contained in:
Ben Spiers committed 2016-01-25 04:35:25 +00:00
1 parent 8af7ec270a
commit 3126f144d2
32 files changed
+100 -170

No files matched your search

@@ -12,6 +12,7 @@ import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
/**
@@ -29,6 +30,12 @@ public class BlockIndex implements Comparable<BlockIndex> {
/**
* Creates an index for a block located on x, y. z
*/
public BlockIndex(BlockPos pos) {
this.x = pos.getX();
this.y = pos.getY();
this.z = pos.getZ();
}
public BlockIndex(int x, int y, int z) {
this.x = x;
this.y = y;
@@ -48,7 +55,7 @@ public class BlockIndex implements Comparable<BlockIndex> {
}
public BlockIndex(TileEntity entity) {
this(entity.xCoord, entity.yCoord, entity.zCoord);
this(entity.getPos());
}
/**
@@ -80,7 +87,7 @@ public class BlockIndex implements Comparable<BlockIndex> {
}
public Block getBlock(World world) {
return world.getBlock(x, y, z);
return world.getBlockState(new BlockPos(x, y, z)).getBlock();
}
@Override
@@ -11,10 +11,7 @@ package buildcraft.api.core;
import java.util.Locale;
import java.util.Random;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public enum EnumColor {
@@ -105,8 +102,6 @@ public enum EnumColor {
0xEA7835,
0xe4e4e4};
@SideOnly(Side.CLIENT)
private static IIcon[] brushIcons;
public int getDarkHex() {
return DARK_HEX[ordinal()];
@@ -189,13 +184,4 @@ public enum EnumColor {
}
return b.toString().trim();
}
public static void setIconArray(IIcon[] icons) {
brushIcons = icons;
}
@SideOnly(Side.CLIENT)
public IIcon getIcon() {
return brushIcons [ordinal()];
}
}
@@ -8,24 +8,10 @@
*/
package buildcraft.api.core;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public interface IIconProvider {
/**
* @param iconIndex
*/
@SideOnly(Side.CLIENT)
IIcon getIcon(int iconIndex);
/**
* A call for the provider to register its Icons. This may be called multiple times but should only be executed once per provider
* @param iconRegister
*/
@SideOnly(Side.CLIENT)
void registerIcons(IIconRegister iconRegister);
}
+13 -13
View File
@@ -16,30 +16,30 @@ import net.minecraft.util.EnumFacing;
public class Position implements ISerializable {
public double x, y, z;
public ForgeDirection orientation;
public EnumFacing orientation;
public Position() {
x = 0;
y = 0;
z = 0;
orientation = ForgeDirection.UNKNOWN;
orientation = null;
}
public Position(double ci, double cj, double ck) {
x = ci;
y = cj;
z = ck;
orientation = ForgeDirection.UNKNOWN;
orientation = null;
}
public Position(double ci, double cj, double ck, ForgeDirection corientation) {
public Position(double ci, double cj, double ck, EnumFacing corientation) {
x = ci;
y = cj;
z = ck;
orientation = corientation;
if (orientation == null) {
orientation = ForgeDirection.UNKNOWN;
orientation = null;
}
}
@@ -55,17 +55,17 @@ public class Position implements ISerializable {
}
public Position(TileEntity tile) {
x = tile.xCoord;
y = tile.yCoord;
z = tile.zCoord;
orientation = ForgeDirection.UNKNOWN;
x = tile.getPos().getX();
y = tile.getPos().getY();
z = tile.getPos().getZ();
orientation = null;
}
public Position(BlockIndex index) {
x = index.x;
y = index.y;
z = index.z;
orientation = ForgeDirection.UNKNOWN;
orientation = null;
}
public void moveRight(double step) {
@@ -137,7 +137,7 @@ public class Position implements ISerializable {
public void writeToNBT(NBTTagCompound nbttagcompound) {
if (orientation == null) {
orientation = ForgeDirection.UNKNOWN;
orientation = null;
}
nbttagcompound.setDouble("i", x);
@@ -150,7 +150,7 @@ public class Position implements ISerializable {
x = nbttagcompound.getDouble("i");
y = nbttagcompound.getDouble("j");
z = nbttagcompound.getDouble("k");
orientation = ForgeDirection.values() [nbttagcompound.getByte("orientation")];
orientation = EnumFacing.VALUES [nbttagcompound.getByte("orientation")];
}
@Override
@@ -181,7 +181,7 @@ public class Position implements ISerializable {
x = stream.readDouble();
y = stream.readDouble();
z = stream.readDouble();
orientation = ForgeDirection.getOrientation(stream.readByte());
orientation = EnumFacing.getFront(stream.readByte());
}
@Override
@@ -21,7 +21,7 @@ public interface ICullable {
//They are used to effectively cull obstructed sides while processing facades.
//Make sure your implementation is correct otherwise expect FPS drop
void setRenderSide(ForgeDirection side, boolean render);
void setRenderSide(EnumFacing side, boolean render);
void setRenderAllSides();
@@ -1,7 +0,0 @@
package buildcraft.api.core.render;
import net.minecraft.util.IIcon;
public interface ITextureStateManager {
void set(IIcon icon);
}
@@ -9,14 +9,9 @@
package buildcraft.api.core.render;
import net.minecraft.block.Block;
import net.minecraft.util.IIcon;
public interface ITextureStates extends ICullable {
ITextureStateManager getTextureState();
IIcon getIcon(int side, int meta);
Block getBlock();
}
@@ -26,7 +26,7 @@ public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
* @return Amount of energy that was (or would have been, if simulated) received.
*/
@Override
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate);
/**
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
@@ -40,19 +40,19 @@ public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
* @return Amount of energy that was (or would have been, if simulated) extracted.
*/
@Override
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
int extractEnergy(EnumFacing from, int maxExtract, boolean simulate);
/**
* Returns the amount of energy currently stored.
*/
@Override
int getEnergyStored(ForgeDirection from);
int getEnergyStored(EnumFacing from);
/**
* Returns the maximum amount of energy that can be stored.
*/
@Override
int getMaxEnergyStored(ForgeDirection from);
int getMaxEnergyStored(EnumFacing from);
}
@@ -23,16 +23,16 @@ public interface IEnergyProvider extends IEnergyConnection {
* If TRUE, the extraction will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) extracted.
*/
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
int extractEnergy(EnumFacing from, int maxExtract, boolean simulate);
/**
* Returns the amount of energy currently stored.
*/
int getEnergyStored(ForgeDirection from);
int getEnergyStored(EnumFacing from);
/**
* Returns the maximum amount of energy that can be stored.
*/
int getMaxEnergyStored(ForgeDirection from);
int getMaxEnergyStored(EnumFacing from);
}
@@ -63,15 +63,15 @@ public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
if (container.stackTagCompound == null) {
container.stackTagCompound = new NBTTagCompound();
if (container.getTagCompound() == null) {
container.setTagCompound(new NBTTagCompound());
}
int energy = container.stackTagCompound.getInteger("Energy");
int energy = container.getTagCompound().getInteger("Energy");
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
if (!simulate) {
energy += energyReceived;
container.stackTagCompound.setInteger("Energy", energy);
container.getTagCompound().setInteger("Energy", energy);
}
return energyReceived;
}
@@ -79,15 +79,15 @@ public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) {
return 0;
}
int energy = container.stackTagCompound.getInteger("Energy");
int energy = container.getTagCompound().getInteger("Energy");
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
if (!simulate) {
energy -= energyExtracted;
container.stackTagCompound.setInteger("Energy", energy);
container.getTagCompound().setInteger("Energy", energy);
}
return energyExtracted;
}
@@ -95,10 +95,10 @@ public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
@Override
public int getEnergyStored(ItemStack container) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) {
return 0;
}
return container.stackTagCompound.getInteger("Energy");
return container.getTagCompound().getInteger("Energy");
}
@Override
@@ -30,34 +30,34 @@ public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
/* IEnergyConnection */
@Override
public boolean canConnectEnergy(ForgeDirection from) {
public boolean canConnectEnergy(EnumFacing from) {
return true;
}
/* IEnergyReceiver */
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
return storage.receiveEnergy(maxReceive, simulate);
}
/* IEnergyProvider */
@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
return storage.extractEnergy(maxExtract, simulate);
}
/* IEnergyReceiver and IEnergyProvider */
@Override
public int getEnergyStored(ForgeDirection from) {
public int getEnergyStored(EnumFacing from) {
return storage.getEnergyStored();
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
public int getMaxEnergyStored(EnumFacing from) {
return storage.getMaxEnergyStored();
}
@@ -11,7 +11,7 @@ import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
@@ -31,7 +31,7 @@ public interface ITurtleAccess
* Returns a vector containing the integer co-ordinates at which the turtle resides.
* @return a vector containing the integer co-ordinates at which the turtle resides.
*/
public ChunkCoordinates getPosition();
public BlockPos getPosition();
/**
* TODO: Document me
@@ -7,8 +7,9 @@
package dan200.computercraft.api.turtle;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
/**
* The primary interface for defining an turtle for Turtles. A turtle turtle
@@ -85,7 +86,7 @@ public interface ITurtleUpgrade
* @param side Which side of the turtle (left or right) the peripheral resides on.
* @return The IIcon that you wish to be used to render your turtle peripheral.
*/
public IIcon getIcon( ITurtleAccess turtle, TurtleSide side );
public TextureAtlasSprite getIcon(ITurtleAccess turtle, TurtleSide side );
/**
* TODO: Document me
+9 -10
View File
@@ -1,6 +1,7 @@
package ic2.api;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.util.EnumFacing;
@@ -40,8 +41,8 @@ public enum Direction {
return directions[(side + 2) % 6];
}
public static Direction fromForgeDirection(ForgeDirection dir) {
if (dir == ForgeDirection.UNKNOWN) return null;
public static Direction fromEnumFacing(EnumFacing dir) {
if (dir == null) return null;
return fromSideValue(dir.ordinal());
}
@@ -53,7 +54,7 @@ public enum Direction {
* @return Adjacent tile entity or null if none exists
*/
public TileEntity applyToTileEntity(TileEntity te) {
return applyTo(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
return applyTo(te.getWorld(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
}
/**
@@ -65,14 +66,12 @@ public enum Direction {
* @param z Z coordinate to check from
* @return Adjacent tile entity or null if none exists
*/
public TileEntity applyTo(World world, int x, int y, int z) {
int coords[] = { x, y, z };
public TileEntity applyTo(World world, BlockPos pos) {
coords[ordinal() / 2] += getSign();
if (world != null && world.blockExists(coords[0], coords[1], coords[2])) {
if (world != null && world.blockExists(pos)) {
try {
return world.getTileEntity(coords[0], coords[1], coords[2]);
return world.getTileEntity(pos);
} catch (Exception e) {
throw new RuntimeException("error getting TileEntity at dim "+world.provider.dimensionId+" "+coords[0]+"/"+coords[1]+"/"+coords[2]);
}
@@ -108,8 +107,8 @@ public enum Direction {
return (ordinal() % 2) * 2 - 1;
}
public ForgeDirection toForgeDirection() {
return ForgeDirection.getOrientation(toSideValue());
public EnumFacing toEnumFacing() {
return EnumFacing.getOrientation(toSideValue());
}
public static final Direction[] directions = Direction.values();
-36
View File
@@ -1,11 +1,9 @@
package ic2.api.crops;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
@@ -143,37 +141,6 @@ public abstract class CropCard {
*/
public abstract int maxSize();
/**
* Instantiate your Icons here.
*
* This method will get called by IC2, don't call it yourself.
*
* It's highly recommended to use your own assert domain here, e.g. yourmod:crop/* instead of
* ic2:crop/*, which will then read assets/yourmod/textures/blocks/crop/*.png.
*/
@SideOnly(Side.CLIENT)
public void registerSprites(IIconRegister iconRegister) {
textures = new IIcon[maxSize()];
for (int i = 1; i <= textures.length; i++) {
// ic2:crop/blockCrop.NAME.n is the legacy name for backwards compatiblity
textures[i - 1] = iconRegister.registerIcon("ic2:crop/blockCrop."+name()+"."+i);
}
}
/**
* Sprite the crop is meant to be rendered with.
*
* @param crop reference to ICropTile
* @return 0-255, representing the sprite index on the crop's spritesheet.
*/
@SideOnly(Side.CLIENT)
public IIcon getSprite(ICropTile crop) {
if (crop.getSize() <= 0 || crop.getSize() > textures.length) return null;
return textures[crop.getSize() - 1];
}
/**
* Amount of growth points needed to increase the plant's size.
* Default is 200 * tier.
@@ -426,8 +393,5 @@ public abstract class CropCard {
}
}
@SideOnly(Side.CLIENT)
protected IIcon textures[];
private final String modId; // TODO: make owner abstract, remove modId auto detection
}
-9
View File
@@ -2,7 +2,6 @@ package ic2.api.crops;
import java.util.Collection;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.BiomeGenBase;
@@ -131,14 +130,6 @@ public abstract class Crops {
*/
public abstract BaseSeed getBaseSeed(ItemStack stack);
/**
* Execute registerSprites for all registered crop cards.
*
* This method will get called by IC2, don't call it yourself.
*/
@SideOnly(Side.CLIENT)
public abstract void startSpriteRegistration(IIconRegister iconRegister);
/**
* Returns the ID for the given crop.
*
+2 -2
View File
@@ -3,7 +3,7 @@ package ic2.api.crops;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
/**
@@ -207,7 +207,7 @@ public interface ICropTile {
*
* @return Crop location
*/
public ChunkCoordinates getLocation();
public BlockPos getLocation();
/**
* Get the crop's light level.
+3 -2
View File
@@ -1,6 +1,7 @@
package ic2.api.energy;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.util.EnumFacing;
@@ -25,7 +26,7 @@ public interface IEnergyNet {
* @param z z-coordinate
* @return tile entity registered to the energy net or null if none is registered
*/
TileEntity getTileEntity(World world, int x, int y, int z);
TileEntity getTileEntity(World world, BlockPos pos);
/**
* Get the EnergyNet-registered neighbor tile entity at the specified position.
@@ -34,7 +35,7 @@ public interface IEnergyNet {
* @param dir direction the neighbor is to be found
* @return neighbor tile entity registered to the energy net or null if none is registered
*/
TileEntity getNeighbor(TileEntity te, ForgeDirection dir);
TileEntity getNeighbor(TileEntity te, EnumFacing dir);
/**
* determine how much energy has been emitted by the EnergyEmitter specified
@@ -15,7 +15,7 @@ public class EnergyTileEvent extends WorldEvent {
public final IEnergyTile energyTile;
public EnergyTileEvent(IEnergyTile energyTile1) {
super(((TileEntity) energyTile1).getWorldObj());
super(((TileEntity) energyTile1).getWorld());
if (world == null) throw new NullPointerException("world is null");
@@ -340,7 +340,7 @@ public class BasicSink extends TileEntity implements IEnergySink {
// energy net interface >>
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
public boolean acceptsEnergyFrom(TileEntity emitter, EnumFacing direction) {
return true;
}
@@ -350,7 +350,7 @@ public class BasicSink extends TileEntity implements IEnergySink {
}
@Override
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) {
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
energyStored += amount;
return 0;
@@ -343,7 +343,7 @@ public class BasicSource extends TileEntity implements IEnergySource {
// energy net interface >>
@Override
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) {
public boolean emitsEnergyTo(TileEntity receiver, EnumFacing direction) {
return true;
}
@@ -7,7 +7,7 @@ public interface IHeatSource {
/*
* Return max heat transmission peer Tick (only theoretical bandwidth not available amount)
*/
int maxrequestHeatTick(ForgeDirection directionFrom);
int maxrequestHeatTick(EnumFacing directionFrom);
/*
* @param requested amount of heat to transfer
@@ -19,5 +19,5 @@ public interface IHeatSource {
* requestHeat(100) : return 50 : so 50 units of heat remove from HeatSource
*/
int requestHeat(ForgeDirection directionFrom, int requestheat);
int requestHeat(EnumFacing directionFrom, int requestheat);
}
@@ -6,7 +6,7 @@ public interface IKineticSource {
/*
* Return max kinetic energy transmission peer Tick (only theoretical bandwidth not available amount)
*/
int maxrequestkineticenergyTick(ForgeDirection directionFrom);
int maxrequestkineticenergyTick(EnumFacing directionFrom);
/*
* @param requested amount of kinetic energy to transfer
@@ -18,5 +18,5 @@ public interface IKineticSource {
* requestkineticenergy(100) : return 50 : so 50 units of kinetic energy remove from KineticSource
*/
int requestkineticenergy(ForgeDirection directionFrom, int requestkineticenergy);
int requestkineticenergy(EnumFacing directionFrom, int requestkineticenergy);
}
@@ -57,5 +57,5 @@ public interface IEnergyStorage {
* @param side side the teleporter is draining energy from
* @return Whether the block is teleporter compatible
*/
public boolean isTeleporterCompatible(ForgeDirection side);
public boolean isTeleporterCompatible(EnumFacing side);
}