Ender Rail dependence on Railcraft API removed. RC API no longer distributed EIO

This commit is contained in:
CrazyPants committed 2014-11-10 20:16:26 +08:00
1 parent d742d961c6
commit 1972e6a80e
17 files changed
+255 -163

No files matched your search

@@ -129,6 +129,7 @@ public class BlockEnderRail extends BlockRail implements IResourceTooltipProvide
return super.removedByPlayer(world, player, x, y, z, willHarvest);
}
@Override
public int getBasicRailMetadata(IBlockAccess world, EntityMinecart cart, int x, int y, int z) {
//Ignore turning bit, used for receive direction
return world.getBlockMetadata(x, y, z) & 7;
@@ -144,6 +145,7 @@ public class BlockEnderRail extends BlockRail implements IResourceTooltipProvide
return canPlaceBlockAt(world, x, y, z);
}
@Override
public boolean isFlexibleRail(IBlockAccess world, int y, int x, int z) {
return false;
}
@@ -153,6 +155,7 @@ public class BlockEnderRail extends BlockRail implements IResourceTooltipProvide
return getUnlocalizedName();
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
if(world.isRemote) {
return;
@@ -173,6 +176,7 @@ public class BlockEnderRail extends BlockRail implements IResourceTooltipProvide
}
@Override
public void onMinecartPass(World world, EntityMinecart cart, int x, int y, int z) {
if(world.isRemote) {
return;
@@ -240,7 +244,7 @@ public class BlockEnderRail extends BlockRail implements IResourceTooltipProvide
private int getPowerRequired(EntityMinecart cart, TileTransceiver sender, TileTransceiver reciever) {
int powerPerCart = getPowerRequiredForSingleCart(sender, reciever);
int numCarts = CartLinkUtil.getNumberOfCartsInTrain(cart);
int numCarts = CartLinkUtil.instance.getNumberOfCartsInTrain(cart);
return powerPerCart * numCarts;
}
@@ -259,9 +263,9 @@ public class BlockEnderRail extends BlockRail implements IResourceTooltipProvide
private boolean teleportCart(World world, EntityMinecart cart, TileTransceiver sender, TileTransceiver reciever) {
List<EntityMinecart> allCarts = CartLinkUtil.getCartsInTrain(cart);
List<EntityMinecart> allCarts = CartLinkUtil.instance.getCartsInTrain(cart);
if(allCarts.size() > 1) {
CartLinkUtil.updateCartLinks(world, cart);
CartLinkUtil.instance.updateCartLinks(world, cart);
}
List<List<Entity>> toTeleport = new ArrayList<List<Entity>>(allCarts.size());
@@ -1,187 +1,60 @@
package crazypants.enderio.rail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import mods.railcraft.api.carts.CartTools;
import mods.railcraft.api.carts.ILinkageManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import crazypants.vecmath.Vector3d;
import cpw.mods.fml.common.Loader;
public class CartLinkUtil {
public class CartLinkUtil implements ICartLinkUtil {
public static final ICartLinkUtil instance;
static {
ICartLinkUtil daInstance;
if(Loader.isModLoaded("Railcraft")) {
try {
daInstance = new RailcraftLinkUtil();
} catch (Exception e) {
daInstance = new CartLinkUtil();
}
} else {
daInstance = new CartLinkUtil();
}
instance = daInstance;
}
private CartLinkUtil() {
}
public static void breakLinks(World world, Entity cart) {
if(cart instanceof EntityMinecart) {
breakLinks(world, (EntityMinecart) cart);
}
}
public static void breakLinks(World world, EntityMinecart cart) {
if(world == null || cart == null) {
return;
}
ILinkageManager linkMan = CartTools.getLinkageManager(world);
if(linkMan == null) {
return;
}
linkMan.breakLinks(cart);
}
public static void recreateLink(EntityMinecart existingCart, EntityMinecart newCart) {
if(existingCart == null || newCart == null) {
return;
}
ILinkageManager linkMan = CartTools.getLinkageManager(existingCart.worldObj);
if(linkMan == null) {
return;
}
UUID linkA = getLinkA(newCart);
if(linkA != null && linkA.equals(existingCart.getPersistentID())) {
if(!linkMan.areLinked(existingCart, newCart)) {
boolean res = linkMan.createLink(existingCart, newCart);
}
return;
}
UUID linkB = getLinkB(newCart);
if(linkB != null && linkB.equals(existingCart.getPersistentID())) {
if(!linkMan.areLinked(existingCart, newCart)) {
boolean res = linkMan.createLink(existingCart, newCart);
}
return;
}
}
public static void updateCartLinks(World world, EntityMinecart cart) {
ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
if(linkMan == null || linkMan.countCartsInTrain(cart) <= 1) {
return;
}
Iterable<EntityMinecart> allCarts = linkMan.getCartsInTrain(cart);
for (EntityMinecart aCart : allCarts) {
if(aCart != null) {
updateLink("a", aCart, linkMan.getLinkedCartA(aCart));
updateLink("b", aCart, linkMan.getLinkedCartB(aCart));
}
}
}
private static void updateLink(String prefix, EntityMinecart cart, EntityMinecart linkedCart) {
NBTTagCompound data = cart.getEntityData();
long lastUpdateTime = -1;
String timeKey = prefix + "UpdateTime";
if(data.hasKey(timeKey)) {
lastUpdateTime = data.getLong(timeKey);
}
long curTime = cart.worldObj.getTotalWorldTime();
if(lastUpdateTime > 0 && curTime - lastUpdateTime < 100) {
return;
}
data.setLong(timeKey, curTime);
data.setString(prefix + "Link", linkedCart == null ? "null" : linkedCart.getPersistentID().toString());
}
public static UUID getLinkA(EntityMinecart cart) {
return getLink("a", cart);
}
public static UUID getLinkB(EntityMinecart cart) {
return getLink("b", cart);
}
private static UUID getLink(String prefix, EntityMinecart cart) {
NBTTagCompound data = cart.getEntityData();
String uuidStr = data.getString(prefix + "Link");
if(uuidStr == null || uuidStr.trim().isEmpty() || "null".equals(uuidStr)) {
return null;
}
return UUID.fromString(uuidStr);
}
public static int getNumberOfCartsInTrain(EntityMinecart cart) {
@Override
public int getNumberOfCartsInTrain(EntityMinecart cart) {
if(cart == null) {
return 0;
}
ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
if(linkMan == null) {
return 1;
}
return linkMan.countCartsInTrain(cart);
return 1;
}
public static List<EntityMinecart> getCartsInTrain(EntityMinecart cart) {
@Override
public List<EntityMinecart> getCartsInTrain(EntityMinecart cart) {
if(cart == null) {
Collections.emptyList();
return Collections.emptyList();
}
List<EntityMinecart> result = new ArrayList<EntityMinecart>();
ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
if(linkMan == null) {
result.add(cart);
return result;
}
Iterable<EntityMinecart> iter = linkMan.getCartsInTrain(cart);
for (EntityMinecart cartInTrain : iter) {
if(cartInTrain != null) {
result.add(cartInTrain);
}
}
Collections.sort(result, new TrainOrderComparator(cart));
return result;
return Collections.singletonList(cart);
}
public static void recreateLinks(EntityMinecart cart) {
ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
if(linkMan == null) {
return;
}
recreateLink(cart, linkMan, getLinkA(cart));
recreateLink(cart, linkMan, getLinkB(cart));
@Override
public void updateCartLinks(World world, EntityMinecart cart) {
}
private static void recreateLink(EntityMinecart cart, ILinkageManager linkMan, UUID uuid) {
if(uuid != null) {
EntityMinecart linkTo = linkMan.getCartFromUUID(uuid);
if(!linkMan.areLinked(cart, linkTo)) {
linkMan.createLink(cart, linkTo);
}
}
@Override
public void recreateLinks(EntityMinecart cart) {
}
private static class TrainOrderComparator implements Comparator<EntityMinecart> {
private final Vector3d refPoint = new Vector3d();
private final Vector3d loc1 = new Vector3d();
private final Vector3d loc2 = new Vector3d();
private double d1;
private double d2;
TrainOrderComparator(EntityMinecart head) {
set(refPoint, head);
}
@Override
public int compare(EntityMinecart o1, EntityMinecart o2) {
set(loc1, o1);
set(loc2, o2);
d1 = refPoint.distanceSquared(loc1);
d2 = refPoint.distanceSquared(loc2);
return Double.compare(d1, d2);
}
private void set(Vector3d point, EntityMinecart cart) {
point.set(cart.posX, cart.posY, cart.posZ);
}
@Override
public void breakLinks(World worldObj, Entity entity) {
}
}
@@ -118,7 +118,7 @@ public class EnderRailController {
TeleportUtil.spawn(transciever.getWorldObj(), ent);
if(cart != null) {
newlySpawnedCarts.add(cart.getPersistentID());
CartLinkUtil.recreateLinks(cart);
CartLinkUtil.instance.recreateLinks(cart);
}
}
}
@@ -282,7 +282,7 @@ public class EnderRailController {
}
private void resetForRandomRandomSpawn(Entity entity) {
CartLinkUtil.breakLinks(transciever.getWorldObj(), entity);
CartLinkUtil.instance.breakLinks(transciever.getWorldObj(), entity);
entity.riddenByEntity = null;
entity.ridingEntity = null;
entity.motionX = 0;
@@ -0,0 +1,21 @@
package crazypants.enderio.rail;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.world.World;
public interface ICartLinkUtil {
int getNumberOfCartsInTrain(EntityMinecart cart);
List<EntityMinecart> getCartsInTrain(EntityMinecart cart);
void updateCartLinks(World world, EntityMinecart cart);
void recreateLinks(EntityMinecart cart);
void breakLinks(World worldObj, Entity entity);
}
@@ -0,0 +1,193 @@
package crazypants.enderio.rail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import mods.railcraft.api.carts.CartTools;
import mods.railcraft.api.carts.ILinkageManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import crazypants.vecmath.Vector3d;
public class RailcraftLinkUtil implements ICartLinkUtil {
public RailcraftLinkUtil() throws Exception {
//Make sure the class we actually want to use exists, just in case the API changes
Class.forName("mods.railcraft.api.carts.CartTools");
}
@Override
public void breakLinks(World world, Entity cart) {
if(cart instanceof EntityMinecart) {
breakLinks(world, (EntityMinecart) cart);
}
}
public void breakLinks(World world, EntityMinecart cart) {
if(world == null || cart == null) {
return;
}
ILinkageManager linkMan = CartTools.getLinkageManager(world);
if(linkMan == null) {
return;
}
linkMan.breakLinks(cart);
}
public void recreateLink(EntityMinecart existingCart, EntityMinecart newCart) {
if(existingCart == null || newCart == null) {
return;
}
ILinkageManager linkMan = CartTools.getLinkageManager(existingCart.worldObj);
if(linkMan == null) {
return;
}
UUID linkA = getLinkA(newCart);
if(linkA != null && linkA.equals(existingCart.getPersistentID())) {
if(!linkMan.areLinked(existingCart, newCart)) {
boolean res = linkMan.createLink(existingCart, newCart);
}
return;
}
UUID linkB = getLinkB(newCart);
if(linkB != null && linkB.equals(existingCart.getPersistentID())) {
if(!linkMan.areLinked(existingCart, newCart)) {
boolean res = linkMan.createLink(existingCart, newCart);
}
return;
}
}
@Override
public void updateCartLinks(World world, EntityMinecart cart) {
ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
if(linkMan == null || linkMan.countCartsInTrain(cart) <= 1) {
return;
}
Iterable<EntityMinecart> allCarts = linkMan.getCartsInTrain(cart);
for (EntityMinecart aCart : allCarts) {
if(aCart != null) {
updateLink("a", aCart, linkMan.getLinkedCartA(aCart));
updateLink("b", aCart, linkMan.getLinkedCartB(aCart));
}
}
}
private void updateLink(String prefix, EntityMinecart cart, EntityMinecart linkedCart) {
NBTTagCompound data = cart.getEntityData();
long lastUpdateTime = -1;
String timeKey = prefix + "UpdateTime";
if(data.hasKey(timeKey)) {
lastUpdateTime = data.getLong(timeKey);
}
long curTime = cart.worldObj.getTotalWorldTime();
if(lastUpdateTime > 0 && curTime - lastUpdateTime < 100) {
return;
}
data.setLong(timeKey, curTime);
data.setString(prefix + "Link", linkedCart == null ? "null" : linkedCart.getPersistentID().toString());
}
public UUID getLinkA(EntityMinecart cart) {
return getLink("a", cart);
}
public UUID getLinkB(EntityMinecart cart) {
return getLink("b", cart);
}
private UUID getLink(String prefix, EntityMinecart cart) {
NBTTagCompound data = cart.getEntityData();
String uuidStr = data.getString(prefix + "Link");
if(uuidStr == null || uuidStr.trim().isEmpty() || "null".equals(uuidStr)) {
return null;
}
return UUID.fromString(uuidStr);
}
@Override
public int getNumberOfCartsInTrain(EntityMinecart cart) {
if(cart == null) {
return 0;
}
ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
if(linkMan == null) {
return 1;
}
return linkMan.countCartsInTrain(cart);
}
@Override
public List<EntityMinecart> getCartsInTrain(EntityMinecart cart) {
if(cart == null) {
Collections.emptyList();
}
List<EntityMinecart> result = new ArrayList<EntityMinecart>();
ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
if(linkMan == null) {
result.add(cart);
return result;
}
Iterable<EntityMinecart> iter = linkMan.getCartsInTrain(cart);
for (EntityMinecart cartInTrain : iter) {
if(cartInTrain != null) {
result.add(cartInTrain);
}
}
Collections.sort(result, new TrainOrderComparator(cart));
return result;
}
@Override
public void recreateLinks(EntityMinecart cart) {
ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
if(linkMan == null) {
return;
}
recreateLink(cart, linkMan, getLinkA(cart));
recreateLink(cart, linkMan, getLinkB(cart));
}
private void recreateLink(EntityMinecart cart, ILinkageManager linkMan, UUID uuid) {
if(uuid != null) {
EntityMinecart linkTo = linkMan.getCartFromUUID(uuid);
if(!linkMan.areLinked(cart, linkTo)) {
linkMan.createLink(cart, linkTo);
}
}
}
private static class TrainOrderComparator implements Comparator<EntityMinecart> {
private final Vector3d refPoint = new Vector3d();
private final Vector3d loc1 = new Vector3d();
private final Vector3d loc2 = new Vector3d();
private double d1;
private double d2;
TrainOrderComparator(EntityMinecart head) {
set(refPoint, head);
}
@Override
public int compare(EntityMinecart o1, EntityMinecart o2) {
set(loc1, o1);
set(loc2, o2);
d1 = refPoint.distanceSquared(loc1);
d2 = refPoint.distanceSquared(loc2);
return Double.compare(d1, d2);
}
private void set(Vector3d point, EntityMinecart cart) {
point.set(cart.posX, cart.posY, cart.posZ);
}
}
}
@@ -1,342 +0,0 @@
package mods.railcraft.api.carts;
import com.mojang.authlib.GameProfile;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemMinecart;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import mods.railcraft.api.core.items.IMinecartItem;
import net.minecraft.block.BlockRailBase;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayerFactory;
public abstract class CartTools {
private static final GameProfile railcraftProfile = new GameProfile(UUID.nameUUIDFromBytes("[Railcraft]".getBytes()), "[Railcraft]");
public static ILinkageManager linkageManager;
/**
* Returns an instance of ILinkageManager.
*
* Will return null if Railcraft is not installed.
*
* @param world The World, may be required in the future
* @return an instance of ILinkageManager
*/
public static ILinkageManager getLinkageManager(World world) {
return linkageManager;
}
/**
* Sets a carts owner.
*
* The is really only needed by the bukkit ports.
*
* @param cart
* @param owner
*/
public static void setCartOwner(EntityMinecart cart, EntityPlayer owner) {
setCartOwner(cart, owner.getGameProfile());
}
/**
* Sets a carts owner.
*
* The is really only needed by the bukkit ports.
*
* @param cart
* @param owner
*/
public static void setCartOwner(EntityMinecart cart, GameProfile owner) {
if (!cart.worldObj.isRemote) {
NBTTagCompound data = cart.getEntityData();
if (owner.getName() != null)
data.setString("owner", owner.getName());
if (owner.getId() != null)
data.setString("ownerId", owner.getId().toString());
}
}
/**
* Gets a carts owner. (player.username)
*
* The is really only needed by the bukkit ports.
*
* @param cart
* @return
*/
public static GameProfile getCartOwner(EntityMinecart cart) {
NBTTagCompound data = cart.getEntityData();
String ownerName = "[Unknown]";
if (data.hasKey("owner"))
ownerName = data.getString("owner");
UUID ownerId = null;
if (data.hasKey("ownerId"))
ownerId = UUID.fromString(data.getString("ownerId"));
return new GameProfile(ownerId, ownerName);
}
/**
* Does the cart have a owner?
*
* The is really only needed by the bukkit ports.
*
* @param cart
* @return
*/
public static boolean doesCartHaveOwner(EntityMinecart cart) {
NBTTagCompound data = cart.getEntityData();
return data.hasKey("owner");
}
/**
* Spawns a new cart entity using the provided item.
*
* The backing item must implement <code>IMinecartItem</code> and/or extend
* <code>ItemMinecart</code>.
*
* Generally Forge requires all cart items to extend ItemMinecart.
*
* @param owner The player name that should used as the owner
* @param cart An ItemStack containing a cart item, will not be changed by
* the function
* @param world The World object
* @param x x-Coord
* @param y y-Coord
* @param z z-Coord
* @return the cart placed or null if failed
* @see IMinecartItem, ItemMinecart
*/
public static EntityMinecart placeCart(GameProfile owner, ItemStack cart, WorldServer world, int x, int y, int z) {
if (cart == null)
return null;
cart = cart.copy();
if (cart.getItem() instanceof IMinecartItem) {
IMinecartItem mi = (IMinecartItem) cart.getItem();
return mi.placeCart(owner, cart, world, x, y, z);
} else if (cart.getItem() instanceof ItemMinecart)
try {
boolean placed = cart.getItem().onItemUse(cart, FakePlayerFactory.get(world, railcraftProfile),world, x, y, z
, 0, 0, 0, 0);
if (placed) {
List<EntityMinecart> carts = getMinecartsAt(world, x, y, z, 0.3f);
if (carts.size() > 0) {
setCartOwner(carts.get(0), owner);
return carts.get(0);
}
}
} catch (Exception e) {
return null;
}
return null;
}
/**
* Offers an item stack to linked carts or drops it if no one wants it.
*
* @param cart
* @param stack
*/
public static void offerOrDropItem(EntityMinecart cart, ItemStack stack) {
EntityMinecart link_A = getLinkageManager(cart.worldObj).getLinkedCartA(cart);
EntityMinecart link_B = getLinkageManager(cart.worldObj).getLinkedCartB(cart);
if (stack != null && stack.stackSize > 0 && link_A instanceof IItemTransfer)
stack = ((IItemTransfer) link_A).offerItem(cart, stack);
if (stack != null && stack.stackSize > 0 && link_B instanceof IItemTransfer)
stack = ((IItemTransfer) link_B).offerItem(cart, stack);
if (stack != null && stack.stackSize > 0)
cart.entityDropItem(stack, 1);
}
public static boolean isMinecartOnRailAt(World world, int i, int j, int k, float sensitivity) {
return isMinecartOnRailAt(world, i, j, k, sensitivity, null, true);
}
public static boolean isMinecartOnRailAt(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
if (BlockRailBase.func_150049_b_(world, i, j, k))
return isMinecartAt(world, i, j, k, sensitivity, type, subclass);
return false;
}
public static boolean isMinecartOnAnySide(World world, int i, int j, int k, float sensitivity) {
return isMinecartOnAnySide(world, i, j, k, sensitivity, null, true);
}
public static boolean isMinecartOnAnySide(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
List<EntityMinecart> list = new ArrayList<EntityMinecart>();
for (int side = 0; side < 6; side++) {
list.addAll(getMinecartsOnSide(world, i, j, k, sensitivity, ForgeDirection.getOrientation(side)));
}
if (type == null)
return !list.isEmpty();
else
for (EntityMinecart cart : list) {
if ((subclass && type.isInstance(cart)) || cart.getClass() == type)
return true;
}
return false;
}
public static boolean isMinecartAt(World world, int i, int j, int k, float sensitivity) {
return isMinecartAt(world, i, j, k, sensitivity, null, true);
}
public static boolean isMinecartAt(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
List<EntityMinecart> list = getMinecartsAt(world, i, j, k, sensitivity);
if (type == null)
return !list.isEmpty();
else
for (EntityMinecart cart : list) {
if ((subclass && type.isInstance(cart)) || cart.getClass() == type)
return true;
}
return false;
}
public static List<EntityMinecart> getMinecartsOnAllSides(World world, int i, int j, int k, float sensitivity) {
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
for (int side = 0; side < 6; side++) {
carts.addAll(getMinecartsOnSide(world, i, j, k, sensitivity, ForgeDirection.getOrientation(side)));
}
return carts;
}
public static List<EntityMinecart> getMinecartsOnAllSides(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
List<EntityMinecart> list = new ArrayList<EntityMinecart>();
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
for (int side = 0; side < 6; side++) {
list.addAll(getMinecartsOnSide(world, i, j, k, sensitivity, ForgeDirection.getOrientation(side)));
}
for (EntityMinecart cart : list) {
if ((subclass && type.isInstance(cart)) || cart.getClass() == type)
carts.add(cart);
}
return carts;
}
private static int getYOnSide(int y, ForgeDirection side) {
switch (side) {
case UP:
return y + 1;
case DOWN:
return y - 1;
default:
return y;
}
}
private static int getXOnSide(int x, ForgeDirection side) {
switch (side) {
case EAST:
return x + 1;
case WEST:
return x - 1;
default:
return x;
}
}
private static int getZOnSide(int z, ForgeDirection side) {
switch (side) {
case NORTH:
return z - 1;
case SOUTH:
return z + 1;
default:
return z;
}
}
public static List<EntityMinecart> getMinecartsOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side) {
return getMinecartsAt(world, getXOnSide(i, side), getYOnSide(j, side), getZOnSide(k, side), sensitivity);
}
public static boolean isMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side) {
return getMinecartOnSide(world, i, j, k, sensitivity, side) != null;
}
public static EntityMinecart getMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side) {
for (EntityMinecart cart : getMinecartsOnSide(world, i, j, k, sensitivity, side)) {
return cart;
}
return null;
}
public static boolean isMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side, Class<? extends EntityMinecart> type, boolean subclass) {
return getMinecartOnSide(world, i, j, k, sensitivity, side, type, subclass) != null;
}
public static <T extends EntityMinecart> T getMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side, Class<T> type, boolean subclass) {
for (EntityMinecart cart : getMinecartsOnSide(world, i, j, k, sensitivity, side)) {
if (type == null || (subclass && type.isInstance(cart)) || cart.getClass() == type)
return (T) cart;
}
return null;
}
/**
*
* @param world
* @param i
* @param j
* @param k
* @param sensitivity Controls the size of the search box, ranges from
* (-inf, 0.49].
* @return
*/
public static List<EntityMinecart> getMinecartsAt(World world, int i, int j, int k, float sensitivity) {
sensitivity = Math.min(sensitivity, 0.49f);
List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(i + sensitivity, j + sensitivity, k + sensitivity, i + 1 - sensitivity, j + 1 - sensitivity, k + 1 - sensitivity));
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
for (Object o : entities) {
EntityMinecart cart = (EntityMinecart) o;
if (!cart.isDead)
carts.add((EntityMinecart) o);
}
return carts;
}
public static List<EntityMinecart> getMinecartsIn(World world, int i1, int j1, int k1, int i2, int j2, int k2) {
List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(i1, j1, k1, i2, j2, k2));
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
for (Object o : entities) {
EntityMinecart cart = (EntityMinecart) o;
if (!cart.isDead)
carts.add((EntityMinecart) o);
}
return carts;
}
/**
* Returns the cart's "speed". It is not capped by the carts max speed, it
* instead returns the cart's "potential" speed. Used by collision and
* linkage logic. Do not use this to determine how fast a cart is currently
* moving.
*
* @param cart
* @return speed
*/
public static double getCartSpeedUncapped(EntityMinecart cart) {
return Math.sqrt(cart.motionX * cart.motionX + cart.motionZ * cart.motionZ);
}
public static boolean cartVelocityIsLessThan(EntityMinecart cart, float vel) {
return Math.abs(cart.motionX) < vel && Math.abs(cart.motionZ) < vel;
}
}
@@ -1,65 +0,0 @@
package mods.railcraft.api.carts;
import net.minecraft.item.ItemStack;
import mods.railcraft.api.core.items.IStackFilter;
/**
* This interface allows items to be passed around with out needing
* to know anything about the underlying implementation of the inventories.
*
* @author CovertJaguar <http://www.railcraft.info>
*/
public interface IItemTransfer
{
/**
* Offers an ItemStack to the object implementing this interface.
* This function will return null if the item is accepted in full,
* otherwise it will return whatever is rejected.
*
* @param source The Object offering the item
* @param offer The ItemStack being offered
* @return Unused or unwanted portions of offer
*/
public ItemStack offerItem(Object source, ItemStack offer);
/**
* Requests an ItemStack from the object implementing this interface.
* It is up to the object implementing this interface to determine which
* ItemStack to return, or none at all.
*
* @param source The Object submitting the request
* @return An ItemStack to fulfill the request or null if refused.
*/
public ItemStack requestItem(Object source);
/**
* Requests an ItemStack from the object implementing this interface
* that matches the request parameter.
* It is up to the object implementing this interface to
* determine which ItemStack to return, or none at all.
* However, if the return value is not null
* it should fulfill the following condition:<br/>
* InvTools.isItemEqual(it.requestItem(this,request), request) == true
*
* @param source The Object submitting the request
* @param request The type of item requested
* @return An ItemStack to fulfill the request or null if refused.
*/
public ItemStack requestItem(Object source, ItemStack request);
/**
* Requests an ItemStack from the object implementing this interface
* that matches the request parameter.
* It is up to the object implementing this interface to
* determine which ItemStack to return, or none at all.
* However, if the return value is not null
* it should fulfill the following condition:<br/>
* IStackFilter.matches(it.requestItem(this,request), request) == true
*
* @param source The Object submitting the request
* @param request The type of item requested
* @return An ItemStack to fulfill the request or null if refused.
*/
public ItemStack requestItem(Object source, IStackFilter request);
}
@@ -1,77 +0,0 @@
package mods.railcraft.api.carts;
import net.minecraft.entity.item.EntityMinecart;
/**
* This interface should be implemented by any minecart that wishes
* to change the default linkage behavior.
* It is NOT required to be able to link a cart,
* it merely gives you more control over the process.
* @author CovertJaguar <http://www.railcraft.info>
*/
public interface ILinkableCart
{
/**
* To disable linking altogether, return false here.
* @return True if this cart is linkable.
*/
public boolean isLinkable();
/**
* Check called when attempting to link carts.
* @param cart The cart that we are attempting to link with.
* @return True if we can link with this cart.
*/
public boolean canLinkWithCart(EntityMinecart cart);
/**
* Returns true if this cart has two links
* or false if it can only link with one cart.
* @return True if two links
*/
public boolean hasTwoLinks();
/**
* Gets the distance at which this cart can be linked.
* This is called on both carts and added together to determine
* how close two carts need to be for a successful link.
* Default = LinkageManager.LINKAGE_DISTANCE
* @param cart The cart that you are attempting to link with.
* @return The linkage distance
*/
public float getLinkageDistance(EntityMinecart cart);
/**
* Gets the optimal distance between linked carts.
* This is called on both carts and added together to determine
* the optimal rest distance between linked carts.
* The LinkageManager will attempt to maintain this distance
* between linked carts at all times.
* Default = LinkageManager.OPTIMAL_DISTANCE
* @param cart The cart that you are linked with.
* @return The optimal rest distance
*/
public float getOptimalDistance(EntityMinecart cart);
/**
* Return false if linked carts have no effect on the velocity of this cart.
* Use carefully, if you link two carts that can't be adjusted,
* it will behave as if they are not linked.
* @param cart The cart doing the adjusting.
* @return Whether the cart can have its velocity adjusted.
*/
public boolean canBeAdjusted(EntityMinecart cart);
/**
* Called upon successful link creation.
* @param cart The cart we linked with.
*/
public void onLinkCreated(EntityMinecart cart);
/**
* Called when a link is broken (usually).
* @param cart The cart we were linked with.
*/
public void onLinkBroken(EntityMinecart cart);
}
@@ -1,120 +0,0 @@
package mods.railcraft.api.carts;
import java.util.UUID;
import net.minecraft.entity.item.EntityMinecart;
/**
* The LinkageManager contains all the functions needed to link and interact
* with linked carts.
*
* To obtain an instance of this interface, call CartTools.getLinkageManager().
*
* Each cart can up to two links. They are called Link A and Link B. Some carts
* will have only Link A, for example the Tunnel Bore.
*
* @author CovertJaguar <http://www.railcraft.info>
* @see CartTools, ILinkableCart
*/
public interface ILinkageManager {
/**
* The default max distance at which carts can be linked, divided by 2.
*/
public static final float LINKAGE_DISTANCE = 1.25f;
/**
* The default distance at which linked carts are maintained, divided by 2.
*/
public static final float OPTIMAL_DISTANCE = 0.78f;
/**
* Creates a link between two carts, but only if there is nothing preventing
* such a link.
*
* @param cart1
* @param cart2
* @return True if the link succeeded.
*/
boolean createLink(EntityMinecart cart1, EntityMinecart cart2);
/**
* Returns the cart linked to Link A or null if nothing is currently
* occupying Link A.
*
* @param cart The cart for which to get the link
* @return The linked cart or null
*/
EntityMinecart getLinkedCartA(EntityMinecart cart);
/**
* Returns the cart linked to Link B or null if nothing is currently
* occupying Link B.
*
* @param cart The cart for which to get the link
* @return The linked cart or null
*/
EntityMinecart getLinkedCartB(EntityMinecart cart);
/**
* Returns true if the two carts are linked to each other.
*
* @param cart1
* @param cart2
* @return True if linked
*/
boolean areLinked(EntityMinecart cart1, EntityMinecart cart2);
/**
* Breaks a link between two carts, if any link exists.
*
* @param cart1
* @param cart2
*/
void breakLink(EntityMinecart cart1, EntityMinecart cart2);
/**
* Breaks all links the cart has.
*
* @param cart
*/
void breakLinks(EntityMinecart cart);
/**
* Break only link A.
*
* @param cart
*/
void breakLinkA(EntityMinecart cart);
/**
* Break only link B.
*
* @param cart
*/
void breakLinkB(EntityMinecart cart);
/**
* Counts how many carts are in the train.
*
* @param cart Any cart in the train
* @return The number of carts in the train
*/
int countCartsInTrain(EntityMinecart cart);
Iterable<EntityMinecart> getCartsInTrain(EntityMinecart cart);
/**
* Given a persistent Entity UUID, it will return a matching minecart,
* assuming one is loaded in the world.
*
* The Mapping is stored in a Map<UUID, EntityMinecart> so its fairly fast.
*
* This would probably be better in CartTools, but
* Railcraft really only uses it for linking and this was the
* easiest way to expose it.
*
* @param id Persistent Entity UUID
* @return A Minecart
*/
EntityMinecart getCartFromUUID(UUID id);
}
@@ -1,26 +0,0 @@
package mods.railcraft.api.carts;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.item.ItemStack;
/**
* Some helper functions to make interacting with carts simpler.
*
* This interface is implemented by CartBase.
*
* @author CovertJaguar <http://www.railcraft.info>
* @see CartBase
*/
public interface IMinecart {
/**
* Returns true if the Minecart matches the item provided. Generally just
* stack.isItemEqual(cart.getCartItem()), but some carts may need more
* control (the Tank Cart for example).
*
* @param stack the Filter
* @param cart the Cart
* @return true if the item matches the cart
*/
public boolean doesCartMatchFilter(ItemStack stack, EntityMinecart cart);
}
@@ -1,8 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 CovertJaguar
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@API(apiVersion="1.3.0", owner="RailcraftAPI|core", provides="RailcraftAPI|carts")
package mods.railcraft.api.carts;
import cpw.mods.fml.common.API;
@@ -1,41 +0,0 @@
package mods.railcraft.api.core.items;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* This interface should be implemented by any cart item,
* but it is generally optional.
*
* @author CovertJaguar <http://www.railcraft.info>
*/
public interface IMinecartItem
{
/**
* Controls whether this cart item can be placed by the Cart and Train Dispensers.
*
* Generally, you can ignore the placeCart() function if this returns false.
*
* @param cart
* @return true if it can be placed, false otherwise
*/
public boolean canBePlacedByNonPlayer(ItemStack cart);
/**
* Places a cart at the specified location.
*
* Implementing this function is optional.
*
* @param owner the name of the player placing the cart or "[MyMod]" with the brackets
* @param cart An ItemStack that contains the cart
* @param world The World
* @param i x-Coord
* @param j y-Coord
* @param k z-Coord
* @return the cart placed or null if failed
*/
public EntityMinecart placeCart(GameProfile owner, ItemStack cart, World world, int i, int j, int k);
}
@@ -1,23 +0,0 @@
package mods.railcraft.api.core.items;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.item.ItemStack;
/**
* This interface is used with several of the functions in IItemTransfer
* to provide a convenient means of dealing with entire classes of items without
* having to specify each item individually.
* @author CovertJaguar <http://www.railcraft.info>
*/
public interface IStackFilter
{
/**
* Railcraft adds the following IItemTypes during preInit: ALL, FUEL, TRACK, MINECART, BALLAST, FEED
*
* Feel free to grab them from here or define your own.
*/
public static final Map<String, IStackFilter> filters = new HashMap<String, IStackFilter>();
public boolean matches(ItemStack stack);
}
@@ -1,8 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 CovertJaguar
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@API(apiVersion="1.0", owner="Railcraft", provides="RailcraftAPI|core")
package mods.railcraft.api.core.items;
import cpw.mods.fml.common.API;
@@ -1,8 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 CovertJaguar
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@API(apiVersion="1.1", owner="Railcraft", provides="RailcraftAPI|core")
package mods.railcraft.api.core;
import cpw.mods.fml.common.API;
@@ -1,8 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 CovertJaguar
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@API(apiVersion="1.0", owner="Railcraft", provides="RailcraftAPI|core")
package mods.railcraft.api;
import cpw.mods.fml.common.API;