mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 23:13:21 +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
@@ -15,6 +15,7 @@ Changes
|
||||
- Added tool blacklist to prevent broken spawners dropping when using those tools
|
||||
- Allow dark pick to work on glass material blocks such as glowstone (tterrag)
|
||||
- Add comparator support to tanks and capacitor banks (tterrag)
|
||||
- Ender Rail dependence on Railcraft API removed. RC API no longer distributed EIO
|
||||
- Added support for Ender Zoo enchants to Enchanter
|
||||
- #1188 Updated zh_CN.lang (Mrkwtkr)
|
||||
- #1199 Create Korean translation (puyo061)
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user