mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
Started work on ender rail.
This commit is contained in:
commit
0d4c84c995
18 files changed
+430
-10
No files matched your search
@@ -142,6 +142,7 @@ import crazypants.enderio.material.ItemPowderIngot;
|
||||
import crazypants.enderio.material.MaterialRecipes;
|
||||
import crazypants.enderio.network.MessageTileNBT;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.rail.BlockEnderRail;
|
||||
import crazypants.enderio.teleport.BlockTravelAnchor;
|
||||
import crazypants.enderio.teleport.ItemTravelStaff;
|
||||
import crazypants.enderio.teleport.TeleportRecipes;
|
||||
@@ -244,6 +245,8 @@ public class EnderIO {
|
||||
public static BlockDarkSteelPressurePlate blockDarkSteelPressurePlate;
|
||||
public static BlockEndermanSkull blockEndermanSkull;
|
||||
public static BlockReinforcedObsidian blockReinforcedObsidian;
|
||||
|
||||
public static BlockEnderRail blockEnderRail;
|
||||
|
||||
//Fluids
|
||||
public static Fluid fluidNutrientDistillation;
|
||||
@@ -286,6 +289,8 @@ public class EnderIO {
|
||||
public static ItemGliderWing itemGliderWing;
|
||||
|
||||
public static ItemSpawnEgg itemSpawnEgg;
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
@@ -349,6 +354,8 @@ public class EnderIO {
|
||||
blockFusedQuartz = BlockFusedQuartz.create();
|
||||
itemFusedQuartzFrame = ItemFusedQuartzFrame.create();
|
||||
|
||||
blockEnderRail = BlockEnderRail.create();
|
||||
|
||||
blockConduitBundle = BlockConduitBundle.create();
|
||||
blockConduitFacade = BlockConduitFacade.create();
|
||||
itemConduitFacade = ItemConduitFacade.create();
|
||||
|
||||
@@ -93,7 +93,9 @@ public enum ModObject {
|
||||
itemGliderWing,
|
||||
blockEndermanSkull,
|
||||
itemSoulVessel,
|
||||
itemFrankenSkull;
|
||||
itemFrankenSkull,
|
||||
|
||||
blockEnderRail;
|
||||
|
||||
public final String unlocalisedName;
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ public final class Config {
|
||||
public static final Section sectionAttarctor = new Section("Mob Attractor Settings", "attractor");
|
||||
public static final Section sectionLootConfig = new Section("Loot Config", "lootconfig");
|
||||
public static final Section sectionMobConfig = new Section("Mob Config", "mobconfig");
|
||||
public static final Section sectionRailConfig = new Section("Rail", "railconfig");
|
||||
|
||||
public static final double DEFAULT_CONDUIT_SCALE = 0.6;
|
||||
|
||||
@@ -366,9 +367,11 @@ public final class Config {
|
||||
|
||||
public static boolean dumpMobNames = false;
|
||||
|
||||
|
||||
public static boolean enderRailEnabled = true;
|
||||
public static int enderRailPowerRequireCrossDimensions = 10000;
|
||||
public static int enderRailPowerRequiredBase = 100;
|
||||
public static int enderRailPowerRequiredPerBlock = 10;
|
||||
|
||||
|
||||
|
||||
public static void load(FMLPreInitializationEvent event) {
|
||||
|
||||
@@ -972,6 +975,14 @@ public final class Config {
|
||||
enderCreeperExplosionRange = config.get(sectionMobConfig.name, "enderCreeperExplosionRange", enderCreeperExplosionRange,
|
||||
"The range of the 'teleport explosion'").getInt(enderCreeperExplosionRange);
|
||||
|
||||
enderRailEnabled = config.getBoolean("enderRailEnabled", sectionRailConfig.name, enderRailEnabled, "Wether Ender Rails are enabled");
|
||||
enderRailPowerRequireCrossDimensions = config.get(sectionRailConfig.name, "enderRailPowerRequireCrossDimensions", enderRailPowerRequireCrossDimensions,
|
||||
"The amount of power required to transpoer a cart accross dimensions").getInt(enderRailPowerRequireCrossDimensions);
|
||||
enderRailPowerRequiredBase = config.get(sectionRailConfig.name, "enderRailPowerRequiredBase", enderRailPowerRequiredBase,
|
||||
"The minimum amout of power required to teleport a cart in the same dimension").getInt(enderRailPowerRequiredBase);
|
||||
enderRailPowerRequiredPerBlock = config.get(sectionRailConfig.name, "enderRailPowerRequiredPerBlock", enderRailPowerRequiredPerBlock,
|
||||
"The amout of power required to teleport a cart per block in the same dimension").getInt(enderRailPowerRequiredPerBlock);
|
||||
|
||||
|
||||
dumpMobNames = config.getBoolean("dumpMobNames", sectionMobConfig.name, dumpMobNames,
|
||||
"When set to true a list of all registered mobs will be dumped to config/enderio/mobTypes.txt The names are in the format required by EIOs mob blacklists.");
|
||||
|
||||
@@ -109,6 +109,8 @@ public final class IconEIO {
|
||||
public static final IconEIO SINGLE_MINUS = new IconEIO(206, 116);
|
||||
public static final IconEIO DOUBLE_MINUS = new IconEIO(190, 116);
|
||||
public static final IconEIO TRIPLE_MINUS = new IconEIO(174, 116);
|
||||
|
||||
public static final IconEIO ENDER_RAIL = new IconEIO(235,175);
|
||||
|
||||
private static final int TEX_SIZE = 256;
|
||||
private static final double PIX_SIZE = 1d / TEX_SIZE;
|
||||
|
||||
@@ -235,6 +235,11 @@ public class MachineRecipes {
|
||||
ClearConfigRecipe inst = new ClearConfigRecipe();
|
||||
MinecraftForge.EVENT_BUS.register(inst);
|
||||
GameRegistry.addRecipe(inst);
|
||||
|
||||
//Ender Rail
|
||||
if(Config.enderRailEnabled) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void addOreDictionaryRecipes() {
|
||||
|
||||
@@ -4,7 +4,8 @@ public enum ChannelType {
|
||||
|
||||
POWER,
|
||||
ITEM,
|
||||
FLUID;
|
||||
FLUID,
|
||||
RAIL;
|
||||
|
||||
public static final ChannelType[] VALUES = values();
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class ServerChannelRegister extends ChannelRegister {
|
||||
iterators.remove(channel);
|
||||
}
|
||||
|
||||
private RoundRobinIterator<TileTransceiver> getIterator(Channel channel) {
|
||||
public RoundRobinIterator<TileTransceiver> getIterator(Channel channel) {
|
||||
RoundRobinIterator<TileTransceiver> res = iterators.get(channel);
|
||||
if(res == null) {
|
||||
res = new RoundRobinIterator<TileTransceiver>(transceivers);
|
||||
@@ -141,7 +141,7 @@ public class ServerChannelRegister extends ChannelRegister {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Fluid
|
||||
|
||||
|
||||
@@ -60,6 +60,11 @@ public class TileTransceiver extends AbstractPoweredTaskEntity implements IFluid
|
||||
recieveChannels.put(type, new ArrayList<Channel>());
|
||||
}
|
||||
currentTask = new ContinuousTask(Config.transceiverUpkeepCostRF);
|
||||
|
||||
}
|
||||
|
||||
public boolean isRedstoneChecksPassed() {
|
||||
return redstoneCheckPassed;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -162,6 +162,9 @@ public class ChannelTab implements ITabPanel {
|
||||
case ITEM:
|
||||
return IconEIO.WRENCH_OVERLAY_ITEM;
|
||||
case POWER:
|
||||
return IconEIO.WRENCH_OVERLAY_POWER;
|
||||
case RAIL:
|
||||
return IconEIO.ENDER_RAIL;
|
||||
default:
|
||||
return IconEIO.WRENCH_OVERLAY_POWER;
|
||||
}
|
||||
@@ -205,7 +208,7 @@ public class ChannelTab implements ITabPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private void receiveTogglePressed() {
|
||||
protected void receiveTogglePressed() {
|
||||
Channel c = channelList.getSelectedElement();
|
||||
if(c != null && !transceiver.getRecieveChannels(type).contains(c)) {
|
||||
transceiver.addRecieveChanel(c);
|
||||
@@ -219,7 +222,7 @@ public class ChannelTab implements ITabPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendTogglePressed() {
|
||||
protected void sendTogglePressed() {
|
||||
Channel c = channelList.getSelectedElement();
|
||||
if(c != null && !transceiver.getSendChannels(type).contains(c)) {
|
||||
transceiver.addSendChanel(c);
|
||||
|
||||
@@ -49,7 +49,10 @@ public class GuiTransceiver extends GuiMachineBase {
|
||||
tabs.add(generalTab);
|
||||
tabs.add(new ChannelTab(this, ChannelType.POWER));
|
||||
tabs.add(new ChannelTab(this, ChannelType.ITEM));
|
||||
tabs.add(new ChannelTab(this, ChannelType.FLUID));
|
||||
tabs.add(new ChannelTab(this, ChannelType.FLUID));
|
||||
if(Config.enderRailEnabled) {
|
||||
tabs.add(new ChannelTab(this, ChannelType.RAIL));
|
||||
}
|
||||
}
|
||||
|
||||
protected void updatePowerBarTooltip(List<String> text) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package crazypants.enderio.machine.transceiver.gui;
|
||||
|
||||
import crazypants.enderio.machine.transceiver.ChannelType;
|
||||
|
||||
public class RailTab extends ChannelTab {
|
||||
|
||||
public RailTab(GuiTransceiver guiTransceiver, ChannelType type) {
|
||||
super(guiTransceiver, type);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,7 +50,12 @@ public class NEIEnderIOConfig implements IConfigureNEI {
|
||||
if(!Config.reinforcedObsidianEnabled) {
|
||||
API.hideItem(new ItemStack(EnderIO.blockReinforcedObsidian));
|
||||
}
|
||||
|
||||
if(!Config.enderRailEnabled) {
|
||||
API.hideItem(new ItemStack(EnderIO.blockEnderRail));
|
||||
}
|
||||
if(!Config.reservoirEnabled) {
|
||||
API.hideItem(new ItemStack(EnderIO.blockReservoir));
|
||||
}
|
||||
if(!GasUtil.isGasConduitEnabled()) {
|
||||
API.hideItem(new ItemStack(EnderIO.itemGasConduit));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package crazypants.enderio.rail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRail;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.transceiver.Channel;
|
||||
import crazypants.enderio.machine.transceiver.ChannelType;
|
||||
import crazypants.enderio.machine.transceiver.ServerChannelRegister;
|
||||
import crazypants.enderio.machine.transceiver.TileTransceiver;
|
||||
import crazypants.util.RoundRobinIterator;
|
||||
|
||||
public class BlockEnderRail extends BlockRail {
|
||||
|
||||
public static BlockEnderRail create() {
|
||||
BlockEnderRail res = new BlockEnderRail();
|
||||
res.init();
|
||||
return res;
|
||||
}
|
||||
|
||||
protected BlockEnderRail() {
|
||||
setBlockName(ModObject.blockEnderRail.unlocalisedName);
|
||||
setStepSound(Block.soundTypeMetal);
|
||||
if(Config.enderRailEnabled) {
|
||||
setCreativeTab(EnderIOTab.tabEnderIO);
|
||||
}
|
||||
setBlockTextureName("enderio:blockEnderRail");
|
||||
}
|
||||
|
||||
private void init() {
|
||||
GameRegistry.registerBlock(this, ModObject.blockEnderRail.unlocalisedName);
|
||||
GameRegistry.registerTileEntity(TileEnderRail.class, ModObject.blockEnderRail.unlocalisedName + "TileEntity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(int metadata) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
return new TileEnderRail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlockAt(World world, int x, int y, int z) {
|
||||
return world.getBlock(x, y - 1, z) == EnderIO.blockTransceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBlockStay(World world, int x, int y, int z) {
|
||||
return canPlaceBlockAt(world, x, y, z);
|
||||
}
|
||||
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
int origMeta = world.getBlockMetadata(x, y, z);
|
||||
int newMeta = origMeta;
|
||||
if(field_150053_a) {
|
||||
newMeta = origMeta & 7;
|
||||
}
|
||||
|
||||
if(!canBlockStay(world, x, y, z)) {
|
||||
dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
|
||||
world.setBlockToAir(x, y, z);
|
||||
} else {
|
||||
func_150048_a(world, x, y, z, origMeta, newMeta, block);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onMinecartPass(World world, EntityMinecart cart, int x, int y, int z) {
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
// NBTTagCompound nbt = cart.getEntityData();
|
||||
// if(nbt.hasKey("lastTeleportedTime")) {
|
||||
// long lastTime = nbt.getLong("lastTeleportedTime");
|
||||
// if(world.getTotalWorldTime() - lastTime < 40) {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(! (te instanceof TileEnderRail)) {
|
||||
return;
|
||||
}
|
||||
TileEnderRail ter = (TileEnderRail)te;
|
||||
if(ter.isRecievedCart(cart)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tryTeleport(world, cart, x, y, z);
|
||||
}
|
||||
|
||||
private void tryTeleport(World world, EntityMinecart cart, int x, int y, int z) {
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y - 1, z);
|
||||
if(!(te instanceof TileTransceiver)) {
|
||||
return;
|
||||
}
|
||||
TileTransceiver sender = (TileTransceiver) te;
|
||||
if(!sender.isRedstoneChecksPassed()) {
|
||||
return;
|
||||
}
|
||||
if(!sender.hasPower()) {
|
||||
return;
|
||||
}
|
||||
List<Channel> sendChannels = sender.getSendChannels(ChannelType.RAIL);
|
||||
for (Channel channel : sendChannels) {
|
||||
RoundRobinIterator<TileTransceiver> iter = ServerChannelRegister.instance.getIterator(channel);
|
||||
for (TileTransceiver reciever : iter) {
|
||||
if(isValidDestination(sender, channel, reciever)) {
|
||||
int requiredPower = getPowerRequired(cart, sender, reciever);
|
||||
if(sender.getEnergyStored() >= requiredPower) {
|
||||
sender.usePower(requiredPower);
|
||||
teleportCart(world, cart, reciever);//reciever.xCoord, reciever.yCoord + 1, reciever.zCoord, reciever.getWorldObj().provider.dimensionId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidDestination(TileTransceiver sender, Channel channel, TileTransceiver reciever) {
|
||||
if(reciever == sender) {
|
||||
return false;
|
||||
}
|
||||
if(!reciever.getRecieveChannels(ChannelType.RAIL).contains(channel)) {
|
||||
return false;
|
||||
}
|
||||
if(!reciever.isRedstoneChecksPassed() || !sender.isRedstoneChecksPassed()) {
|
||||
return false;
|
||||
}
|
||||
if(!reciever.hasPower()) {
|
||||
return false;
|
||||
}
|
||||
TileEntity te = reciever.getWorldObj().getTileEntity(reciever.xCoord, reciever.yCoord + 1, reciever.zCoord);
|
||||
if(! (te instanceof TileEnderRail)) {
|
||||
return false;
|
||||
}
|
||||
TileEnderRail railTE = (TileEnderRail)te;
|
||||
return railTE.isClear();
|
||||
}
|
||||
|
||||
private int getPowerRequired(EntityMinecart cart, TileTransceiver sender, TileTransceiver reciever) {
|
||||
int powerPerCart = getPowerRequiredForSingleCart(sender, reciever);
|
||||
// ILinkageManager linkMan = CartTools.getLinkageManager(sender.getWorldObj());
|
||||
// if(linkMan == null) {
|
||||
return powerPerCart;
|
||||
// }
|
||||
// int numInLink = linkMan.countCartsInTrain(cart);
|
||||
// if(numInLink <= 1) {
|
||||
// return powerPerCart;
|
||||
// }
|
||||
// return numInLink * powerPerCart;
|
||||
}
|
||||
|
||||
private int getPowerRequiredForSingleCart(TileTransceiver sender, TileTransceiver reciever) {
|
||||
int powerRequired;
|
||||
if(sender.getWorldObj().provider.dimensionId != reciever.getWorldObj().provider.dimensionId) {
|
||||
powerRequired = Config.enderRailPowerRequireCrossDimensions;
|
||||
} else {
|
||||
powerRequired = Config.enderRailPowerRequiredBase;
|
||||
powerRequired += sender.getLocation().distance(reciever.getLocation()) * Config.enderRailPowerRequiredPerBlock;
|
||||
}
|
||||
return powerRequired;
|
||||
}
|
||||
|
||||
private void teleportCart(World world, EntityMinecart cart, TileTransceiver reciever) {//int toX, int toY, int toZ, int toDimension) {
|
||||
// ILinkageManager linkMan = CartTools.getLinkageManager(cart.worldObj);
|
||||
// if(linkMan == null || linkMan.countCartsInTrain(cart) <= 1) {
|
||||
teleportSingleCart(world, cart, reciever);//toX, toY, toZ, toDimension);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Iterable<EntityMinecart> allCarts = linkMan.getCartsInTrain(cart);
|
||||
// for(EntityMinecart aCart : allCarts) {
|
||||
// teleportSingleCart(world, aCart, reciever);//toX, toY, toZ, toDimension);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void teleportSingleCart(World world, EntityMinecart cart, TileTransceiver reciever) {//int toX, int toY, int toZ, int toDimension) {
|
||||
|
||||
int toDimension = reciever.getWorldObj().provider.dimensionId;
|
||||
int toX = reciever.xCoord;
|
||||
int toY = reciever.yCoord + 1;
|
||||
int toZ = reciever.zCoord;
|
||||
|
||||
TileEntity te = reciever.getWorldObj().getTileEntity(toX, toY, toZ);
|
||||
if(! (te instanceof TileEnderRail)) {
|
||||
return;
|
||||
}
|
||||
TileEnderRail ter = (TileEnderRail)te;
|
||||
|
||||
MinecraftServer minecraftserver = MinecraftServer.getServer();
|
||||
int j = cart.dimension;
|
||||
WorldServer worldserver = minecraftserver.worldServerForDimension(j);
|
||||
WorldServer worldserver1 = minecraftserver.worldServerForDimension(toDimension);
|
||||
cart.dimension = toDimension;
|
||||
|
||||
if(j == 1 && toDimension == 1) {
|
||||
worldserver1 = minecraftserver.worldServerForDimension(0);
|
||||
cart.dimension = 0;
|
||||
}
|
||||
|
||||
Entity passenger = cart.riddenByEntity;
|
||||
if(passenger != null) {
|
||||
worldserver.removeEntity(passenger);
|
||||
passenger.isDead = true;
|
||||
}
|
||||
|
||||
ItemStack[] stacks = null;
|
||||
if(cart instanceof IInventory) {
|
||||
IInventory cont = (IInventory) cart;
|
||||
stacks = new ItemStack[cont.getSizeInventory()];
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
stacks[i] = cont.getStackInSlot(i);
|
||||
cont.setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
worldserver.removeEntity(cart);
|
||||
cart.isDead = false;
|
||||
|
||||
Entity entity = EntityList.createEntityByName(EntityList.getEntityString(cart), worldserver1);
|
||||
if(entity != null) {
|
||||
|
||||
// entity.copyDataFrom(cart, true);
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
cart.writeToNBT(nbttagcompound);
|
||||
entity.readFromNBT(nbttagcompound);
|
||||
|
||||
entity.setLocationAndAngles(toX + 0.5, toY, toZ + 0.5, cart.rotationYaw, cart.rotationPitch);
|
||||
// NBTTagCompound nbt = entity.getEntityData();
|
||||
// long time = worldserver1.getTotalWorldTime();
|
||||
// nbt.setLong("lastTeleportedTime", time);
|
||||
|
||||
if(stacks != null && entity instanceof IInventory) {
|
||||
IInventory cont = (IInventory) entity;
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
cont.setInventorySlotContents(i, stacks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(passenger != null) {
|
||||
Entity newPas = EntityList.createEntityByName(EntityList.getEntityString(passenger), worldserver1);
|
||||
newPas.copyDataFrom(passenger, true);
|
||||
newPas.setLocationAndAngles(toX + 0.5, toY, toZ + 0.5, cart.rotationYaw, cart.rotationPitch);
|
||||
entity.riddenByEntity = newPas;
|
||||
newPas.ridingEntity = entity;
|
||||
worldserver1.spawnEntityInWorld(newPas);
|
||||
}
|
||||
|
||||
ter.addRecievedCart((EntityMinecart)entity);
|
||||
|
||||
worldserver1.spawnEntityInWorld(entity);
|
||||
|
||||
}
|
||||
cart.isDead = true;
|
||||
}
|
||||
|
||||
public boolean isFlexibleRail(IBlockAccess world, int y, int x, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package crazypants.enderio.rail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileEnderRail extends TileEntity {
|
||||
|
||||
private List<EntityMinecart> recievedCarts = new ArrayList<EntityMinecart>();
|
||||
|
||||
//private List<EntityMinecart> cartsOnTrack = new ArrayList<EntityMinecart>();
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
List<EntityMinecart> carts = getMinecartsAt(getWorldObj(), xCoord, yCoord, zCoord);
|
||||
List<EntityMinecart> toRemove = new ArrayList<EntityMinecart>();
|
||||
for(EntityMinecart recievedCart : recievedCarts) {
|
||||
if(!carts.contains(recievedCart)) {
|
||||
//recievedCarts.remove(recievedCart);
|
||||
toRemove.add(recievedCart);
|
||||
}
|
||||
}
|
||||
for(EntityMinecart recievedCart : toRemove) {
|
||||
recievedCarts.remove(recievedCart);
|
||||
}
|
||||
}
|
||||
|
||||
public void addRecievedCart(EntityMinecart mc) {
|
||||
recievedCarts.add(mc);
|
||||
}
|
||||
|
||||
public boolean isRecievedCart(EntityMinecart mc) {
|
||||
return recievedCarts.contains(mc);
|
||||
}
|
||||
|
||||
public boolean isClear() {
|
||||
List res = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord + 1, zCoord, xCoord + 1, yCoord + 2, zCoord + 1));
|
||||
return res == null || res.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
}
|
||||
|
||||
public List<EntityMinecart> getCartsOnTrack() {
|
||||
return getMinecartsAt(getWorldObj(), xCoord, yCoord + 1, zCoord);
|
||||
}
|
||||
|
||||
public static List<EntityMinecart> getMinecartsAt(World world, int x, int y, int z) {
|
||||
List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1));
|
||||
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
|
||||
for (Object o : entities) {
|
||||
EntityMinecart cart = (EntityMinecart) o;
|
||||
if (!cart.isDead) {
|
||||
carts.add((EntityMinecart) o);
|
||||
}
|
||||
}
|
||||
return carts;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -22,6 +22,10 @@ public final class BoundingBox {
|
||||
public final float maxY;
|
||||
public final float maxZ;
|
||||
|
||||
public BoundingBox(AxisAlignedBB bb) {
|
||||
this(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
||||
}
|
||||
|
||||
public BoundingBox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
|
||||
@@ -36,6 +36,11 @@ public final class BlockCoord {
|
||||
dz = z - other.z;
|
||||
return (dx * dx + dy * dy + dz * dz);
|
||||
}
|
||||
|
||||
public int distance(BlockCoord other) {
|
||||
double dsq = distanceSquared(other);
|
||||
return (int)Math.ceil(Math.sqrt(dsq));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
Reference in new issue
Block a user