mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 19:59:58 +00:00
Ender Rail dependence on Railcraft API removed. RC API no longer distributed EIO
This commit is contained in:
1 parent
d742d961c6
commit
1972e6a80e
17 files changed
+255
-163
No files matched your search
@@ -0,0 +1,342 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
@@ -0,0 +1,41 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
@@ -0,0 +1,8 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
@@ -0,0 +1,8 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
Reference in new issue
Block a user