Merge branch '6.3.x' of github.com:BuildCraft/BuildCraft into 6.3.x
This commit is contained in:
commit
6fd9f36775
5 changed files with 47 additions and 0 deletions
|
@ -68,4 +68,6 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory
|
|||
public abstract IRobotRegistry getRegistry();
|
||||
|
||||
public abstract void releaseResources();
|
||||
|
||||
public abstract void onChunkUnload();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ public interface IRobotRegistry {
|
|||
|
||||
void killRobot(EntityRobotBase robot);
|
||||
|
||||
void unloadRobot(EntityRobotBase robot);
|
||||
|
||||
EntityRobotBase getLoadedRobot(long id);
|
||||
|
||||
boolean isTaken(ResourceId resourceId);
|
||||
|
|
|
@ -94,6 +94,10 @@ public class DockingStation implements IDockingStation {
|
|||
return robotTaking;
|
||||
}
|
||||
|
||||
public void invalidateRobotTakingEntity() {
|
||||
robotTaking = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long linkedId() {
|
||||
return robotTakingId;
|
||||
|
|
|
@ -945,6 +945,11 @@ public class EntityRobot extends EntityRobotBase implements
|
|||
super.setDead();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
getRegistry().unloadRobot(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePushed() {
|
||||
return false;
|
||||
|
@ -1079,4 +1084,5 @@ public class EntityRobot extends EntityRobotBase implements
|
|||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return new FluidTankInfo[] {new FluidTankInfo(tank, maxFluid)};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package buildcraft.core.robots;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -19,8 +20,11 @@ import net.minecraft.nbt.NBTTagList;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.api.robots.IDockingStation;
|
||||
|
@ -74,6 +78,14 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
|
|||
robotsLoaded.remove(robot.getRobotId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadRobot(EntityRobotBase robot) {
|
||||
markDirty();
|
||||
|
||||
releaseResources(robot, false, true);
|
||||
robotsLoaded.remove(robot.getRobotId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityRobot getLoadedRobot(long id) {
|
||||
if (robotsLoaded.containsKey(id)) {
|
||||
|
@ -172,6 +184,10 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
|
|||
}
|
||||
|
||||
private synchronized void releaseResources(EntityRobotBase robot, boolean forceAll) {
|
||||
releaseResources(robot, forceAll, false);
|
||||
}
|
||||
|
||||
private synchronized void releaseResources(EntityRobotBase robot, boolean forceAll, boolean resetMainLink) {
|
||||
markDirty();
|
||||
|
||||
if (resourcesTakenByRobot.containsKey(robot.getRobotId())) {
|
||||
|
@ -196,6 +212,9 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
|
|||
if (forceAll) {
|
||||
d.unsafeRelease(robot);
|
||||
}
|
||||
else if (resetMainLink && d.isMainStation() && d.robotIdTaking() == robot.getRobotId()) {
|
||||
d.invalidateRobotTakingEntity();
|
||||
}
|
||||
} else {
|
||||
d.unsafeRelease(robot);
|
||||
}
|
||||
|
@ -284,6 +303,8 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
|
|||
((DockingStation) d).world = world;
|
||||
}
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(newRegistry);
|
||||
|
||||
registries.put(world.provider.dimensionId, newRegistry);
|
||||
|
||||
return newRegistry;
|
||||
|
@ -349,4 +370,16 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChunkUnload(ChunkEvent.Unload e)
|
||||
{
|
||||
if(e.world == this.world)
|
||||
{
|
||||
for (EntityRobot robot : new ArrayList<EntityRobot>(robotsLoaded.values())) {
|
||||
if(!e.world.loadedEntityList.contains(robot))
|
||||
robot.onChunkUnload();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue