mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-26 14:53:21 +00:00
- TC Eldritch Challenge: <init>
This commit is contained in:
1 parent
d2c432404b
commit
acb2f07f45
11 files changed
+240
-38
No files matched your search
@@ -70,7 +70,9 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_GOLEM);
|
||||
FMLCommonHandler.instance().bus().register(new EventHandlerNetwork());
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandlerWorld());
|
||||
EventHandlerWorld worldEventHandler = new EventHandlerWorld();
|
||||
MinecraftForge.EVENT_BUS.register(worldEventHandler);
|
||||
FMLCommonHandler.instance().bus().register(worldEventHandler);
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandlerEntity());
|
||||
|
||||
RegisteredRecipes.init();
|
||||
|
||||
@@ -82,7 +82,8 @@ public class BlockNodeManipulator extends BlockStoneDevice {
|
||||
} else if(!world.isRemote && heldItem != null && heldItem.getItem() instanceof ItemWandCasting) {
|
||||
tile.checkMultiblock();
|
||||
if (tile.isMultiblockStructurePresent()) {
|
||||
if(!ResearchManager.isResearchComplete(player.getCommandSenderName(), Gadomancy.MODID.toUpperCase() + ".NODE_MANIPULATOR")) return false;
|
||||
String research = tile.getMultiblockType().getResearchNeeded();
|
||||
if(!ResearchManager.isResearchComplete(player.getCommandSenderName(), research)) return false;
|
||||
if (ThaumcraftApiHelper.consumeVisFromWandCrafting(player.getCurrentEquippedItem(), player, RegisteredRecipes.costsNodeManipulatorMultiblock, true)) {
|
||||
tile.formMultiblock();
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package makeo.gadomancy.common.blocks.tiles;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
|
||||
import makeo.gadomancy.common.network.packets.PacketTCNodeBolt;
|
||||
@@ -10,11 +11,13 @@ import makeo.gadomancy.common.node.NodeManipulatorResultHandler;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
import makeo.gadomancy.common.registration.RegisteredMultiblocks;
|
||||
import makeo.gadomancy.common.utils.MultiblockHelper;
|
||||
import makeo.gadomancy.common.utils.world.TCMazeHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
@@ -44,10 +47,10 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
|
||||
private static final int NODE_MANIPULATION_POSSIBLE_WORK_START = 70;
|
||||
private static final int NODE_MANIPULATION_WORK_ASPECT_CAP = 150;
|
||||
|
||||
private static final int ELDRITCH_PORTAL_CREATOR_WORK_START = 120;
|
||||
private static final int ELDRITCH_PORTAL_CREATOR_WORK_START = 5;
|
||||
private static final int ELDRITCH_PORTAL_CREATOR_ASPECT_CAP = 150;
|
||||
|
||||
//Already set when only multiblock would be present.
|
||||
//Already set when only multiblock would be present. aka is set, if 'isMultiblockPresent()' returns true.
|
||||
private MultiblockType multiblockType = null;
|
||||
private boolean multiblockStructurePresent = false;
|
||||
private boolean isMultiblock = false;
|
||||
@@ -92,7 +95,7 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
|
||||
private void eldritchPortalCreationTick() {
|
||||
|
||||
workTick++;
|
||||
if(workTick < 400) {
|
||||
if(workTick < 10) {
|
||||
if(workTick % 16 == 0) {
|
||||
PacketStartAnimation packet = new PacketStartAnimation(PacketStartAnimation.ID_RUNES, xCoord, yCoord, zCoord, (byte) 1);
|
||||
PacketHandler.INSTANCE.sendToAllAround(packet, getTargetPoint(32));
|
||||
@@ -116,7 +119,11 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
|
||||
if(te == null || !(te instanceof TileExtendedNode)) return;
|
||||
TileExtendedNode node = (TileExtendedNode) te;
|
||||
|
||||
System.out.println("portal creation?");
|
||||
List players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(15, 15, 15));
|
||||
if(!players.isEmpty()) {
|
||||
EntityPlayer player = (EntityPlayer) players.get(0);
|
||||
TCMazeHandler.createSessionAndTeleport(player, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
}
|
||||
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord + 2, zCoord);
|
||||
@@ -490,8 +497,18 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
|
||||
|
||||
public static enum MultiblockType {
|
||||
|
||||
NODE_MANIPULATOR,
|
||||
E_PORTAL_CREATOR
|
||||
NODE_MANIPULATOR(Gadomancy.MODID.toUpperCase() + ".NODE_MANIPULATOR"),
|
||||
E_PORTAL_CREATOR(Gadomancy.MODID.toUpperCase() + ".NODE_MANIPULATOR"); //Change sometime.
|
||||
|
||||
private String research;
|
||||
|
||||
private MultiblockType(String research) {
|
||||
this.research = research;
|
||||
}
|
||||
|
||||
public String getResearchNeeded() {
|
||||
return research;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,12 @@ package makeo.gadomancy.common.events;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController;
|
||||
import makeo.gadomancy.common.utils.world.TCMazeHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
@@ -31,4 +34,11 @@ public class EventHandlerEntity {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void on(LivingDeathEvent event) {
|
||||
if(!event.entity.worldObj.isRemote && event.entityLiving instanceof EntityPlayer) {
|
||||
TCMazeHandler.closeSession((EntityPlayer) event.entityLiving, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,6 +35,6 @@ public class EventHandlerNetwork {
|
||||
EntityPlayer player = e.player;
|
||||
Gadomancy.proxy.familiarHandler.notifyUnequip(player.worldObj, player);
|
||||
|
||||
TCMazeHandler.closeSession(e.player);
|
||||
TCMazeHandler.closeSession(e.player, true);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileNodeManipulator;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.utils.GolemEnumHelper;
|
||||
@@ -16,6 +17,8 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
@@ -59,8 +62,11 @@ public class EventHandlerWorld {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void on(TickEvent.WorldTickEvent event) {
|
||||
if (!event.world.isRemote && event.world.provider.dimensionId == 0) {
|
||||
public void on(TickEvent.ServerTickEvent event) {
|
||||
if(event.phase != TickEvent.Phase.END) return;
|
||||
WorldServer worldServer = DimensionManager.getWorld(ModConfig.dimOuterId);
|
||||
if(worldServer == null) return;
|
||||
if (!worldServer.isRemote && (worldServer.provider.dimensionId == 0 || worldServer.provider.dimensionId == ModConfig.dimOuterId)) {
|
||||
TCMazeHandler.tick();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package makeo.gadomancy.common.utils.world;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.util.IProgressUpdate;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 06.11.2015 23:39
|
||||
*/
|
||||
public class ChunkProviderTCOuter implements IChunkProvider {
|
||||
|
||||
private Random rand;
|
||||
private World worldObj;
|
||||
private WorldType worldType;
|
||||
private BiomeGenBase[] biomesForGeneration;
|
||||
|
||||
public ChunkProviderTCOuter(World p_i2006_1_, long p_i2006_2_, boolean p_i2006_4_) {
|
||||
this.worldObj = p_i2006_1_;
|
||||
this.worldType = p_i2006_1_.getWorldInfo().getTerrainType();
|
||||
this.rand = new Random(p_i2006_2_);
|
||||
}
|
||||
|
||||
public Chunk loadChunk(int p_73158_1_, int p_73158_2_) {
|
||||
return provideChunk(p_73158_1_, p_73158_2_);
|
||||
}
|
||||
|
||||
public Chunk provideChunk(int p_73154_1_, int p_73154_2_) {
|
||||
this.rand.setSeed(p_73154_1_ * 341873128712L + p_73154_2_ * 132897987541L);
|
||||
Block[] ablock = new Block[32768];
|
||||
byte[] meta = new byte[ablock.length];
|
||||
for (int k = 0; k < 16; k++) {
|
||||
for (int l = 0; l < 16; l++) {
|
||||
for (int j1 = 127; j1 >= 0; j1--) {
|
||||
int k1 = (l * 16 + k) * 128 + j1;
|
||||
ablock[k1] = null;
|
||||
meta[k1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.biomesForGeneration = this.worldObj.getWorldChunkManager().loadBlockGeneratorData(this.biomesForGeneration, p_73154_1_ * 16, p_73154_2_ * 16, 16, 16);
|
||||
|
||||
Chunk chunk = new Chunk(this.worldObj, ablock, meta, p_73154_1_, p_73154_2_);
|
||||
byte[] abyte = chunk.getBiomeArray();
|
||||
for (int k = 0; k < abyte.length; k++) {
|
||||
abyte[k] = ((byte) this.biomesForGeneration[k].biomeID);
|
||||
}
|
||||
chunk.generateSkylightMap();
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public boolean chunkExists(int p_73149_1_, int p_73149_2_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void populate(IChunkProvider p_73153_1_, int p_73153_2_, int p_73153_3_) {
|
||||
net.minecraft.block.BlockFalling.fallInstantly = true;
|
||||
MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(p_73153_1_, this.worldObj, this.worldObj.rand, p_73153_2_, p_73153_3_, false));
|
||||
|
||||
int k = p_73153_2_ * 16;
|
||||
int l = p_73153_3_ * 16;
|
||||
BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(k + 16, l + 16);
|
||||
biomegenbase.decorate(this.worldObj, this.worldObj.rand, k, l);
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(p_73153_1_, this.worldObj, this.worldObj.rand, p_73153_2_, p_73153_3_, false));
|
||||
net.minecraft.block.BlockFalling.fallInstantly = false;
|
||||
}
|
||||
|
||||
public boolean saveChunks(boolean p_73151_1_, IProgressUpdate p_73151_2_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveExtraData() {}
|
||||
|
||||
public boolean unloadQueuedChunks() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canSave() {
|
||||
System.out.println("canSave?");
|
||||
StackTraceElement[] currentStack = Thread.currentThread().getStackTrace();
|
||||
for(StackTraceElement element : currentStack) {
|
||||
System.out.println(element.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String makeString() {
|
||||
return "RandomLevelSource";
|
||||
}
|
||||
|
||||
public List getPossibleCreatures(EnumCreatureType p_73155_1_, int p_73155_2_, int p_73155_3_, int p_73155_4_) {
|
||||
BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(p_73155_2_, p_73155_4_);
|
||||
return biomegenbase.getSpawnableList(p_73155_1_);
|
||||
}
|
||||
|
||||
public ChunkPosition func_147416_a(World p_147416_1_, String p_147416_2_, int p_147416_3_, int p_147416_4_, int p_147416_5_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getLoadedChunkCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void recreateStructures(int p_82695_1_, int p_82695_2_) {
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,18 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.LongHashMap;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
|
||||
import net.minecraft.world.gen.ChunkProviderServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import thaumcraft.common.config.ConfigBlocks;
|
||||
import thaumcraft.common.lib.world.dim.Cell;
|
||||
import thaumcraft.common.lib.world.dim.CellLoc;
|
||||
@@ -18,6 +25,7 @@ import thaumcraft.common.lib.world.dim.MazeThread;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -39,13 +47,13 @@ public class TCMazeHandler {
|
||||
|
||||
//Our map to work with.
|
||||
public static ConcurrentHashMap<CellLoc, Short> labyrinthCopy = new ConcurrentHashMap<CellLoc, Short>();
|
||||
public static final int TELEPORT_LAYER_Y = 53;
|
||||
public static final int TELEPORT_LAYER_Y = 55;
|
||||
|
||||
private static Map<EntityPlayer, TCMazeSession> runningSessions = new HashMap<EntityPlayer, TCMazeSession>();
|
||||
|
||||
public static void closeAllSessionsAndCleanup() {
|
||||
for (EntityPlayer pl : runningSessions.keySet()) {
|
||||
runningSessions.get(pl).closeSession();
|
||||
runningSessions.get(pl).closeSession(false);
|
||||
}
|
||||
init();
|
||||
}
|
||||
@@ -53,9 +61,13 @@ public class TCMazeHandler {
|
||||
public static void tick() {
|
||||
WorldServer w = DimensionManager.getWorld(ModConfig.dimOuterId);
|
||||
if(w != null) {
|
||||
if(!w.levelSaving) w.levelSaving = true;
|
||||
//Chunks still get saved...
|
||||
|
||||
WorldServer out = MinecraftServer.getServer().worldServerForDimension(0);
|
||||
for(Object playerObj : w.playerEntities) {
|
||||
EntityPlayer player = (EntityPlayer) playerObj;
|
||||
List playerObjects = w.playerEntities;
|
||||
for (int i = 0; i < playerObjects.size(); i++) {
|
||||
EntityPlayer player = (EntityPlayer) playerObjects.get(i);
|
||||
if(!hasOpenSession(player)) {
|
||||
WorldUtil.tryTeleportBack((EntityPlayerMP) player, 0);
|
||||
ChunkCoordinates cc = out.getSpawnPoint();
|
||||
@@ -64,18 +76,19 @@ public class TCMazeHandler {
|
||||
}
|
||||
for(EntityPlayer player : runningSessions.keySet()) {
|
||||
if(player.worldObj.provider.dimensionId != ModConfig.dimOuterId) { //If the player left our dim, but he should still be in the session, ...
|
||||
closeSession(player);
|
||||
closeSession(player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Coordinates wanted here are the absolute Portal coordinates.
|
||||
* Coordinates wanted here are the absolute Portal coordinates.
|
||||
*/
|
||||
public static boolean createSessionAndTeleport(EntityPlayer player, int pX, int pY, int pZ) {
|
||||
if(hasOpenSession(player) || !hasFreeSessionSpace()) return false;
|
||||
Map<CellLoc, Short> chunksAffected = setupChunks(player.worldObj, pX, pZ);
|
||||
WorldServer w = MinecraftServer.getServer().worldServerForDimension(ModConfig.dimOuterId);
|
||||
Map<CellLoc, Short> chunksAffected = setupChunks(w, pX, pZ);
|
||||
Vec3 currentPos = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
|
||||
int originDim = player.worldObj.provider.dimensionId;
|
||||
TCMazeSession session = new TCMazeSession(player, chunksAffected, originDim, currentPos);
|
||||
@@ -86,7 +99,7 @@ public class TCMazeHandler {
|
||||
|
||||
private static Map<CellLoc, Short> setupChunks(World world, int pX, int pZ) {
|
||||
ConcurrentHashMap<CellLoc, Short> oldDat = MazeHandler.labyrinth;
|
||||
ConcurrentHashMap<CellLoc, Short> bufferOld = labyrinthCopy;
|
||||
ConcurrentHashMap<CellLoc, Short> bufferOld = new ConcurrentHashMap<CellLoc, Short>(labyrinthCopy);
|
||||
MazeHandler.labyrinth = labyrinthCopy;
|
||||
int chX = pX >> 4;
|
||||
int chZ = pZ >> 4;
|
||||
@@ -110,7 +123,10 @@ public class TCMazeHandler {
|
||||
world.captureBlockSnapshots = oldFlag;
|
||||
ArrayList<BlockSnapshot> snapshots = world.capturedBlockSnapshots;
|
||||
for(BlockSnapshot sn : snapshots) {
|
||||
if(sn.getCurrentBlock() == ConfigBlocks.blockEldritch && (sn.world.getBlockMetadata(sn.x, sn.y, sn.z) == 1 || sn.world.getBlockMetadata(sn.x, sn.y, sn.z) == 2)) {
|
||||
if(sn.getCurrentBlock() == ConfigBlocks.blockEldritch && (sn.world.getBlockMetadata(sn.x, sn.y, sn.z) == 1 || sn.world.getBlockMetadata(sn.x, sn.y, sn.z) == 2 || sn.world.getBlockMetadata(sn.x, sn.y, sn.z) == 3)) {
|
||||
sn.world.setBlockToAir(sn.x, sn.y, sn.z);
|
||||
}
|
||||
if(sn.getCurrentBlock() == ConfigBlocks.blockEldritchPortal) {
|
||||
sn.world.setBlockToAir(sn.x, sn.y, sn.z);
|
||||
}
|
||||
}
|
||||
@@ -123,13 +139,13 @@ public class TCMazeHandler {
|
||||
|
||||
private static Map<CellLoc, Short> calculateDifferences(ConcurrentHashMap<CellLoc, Short> bufferOld) {
|
||||
ConcurrentHashMap<CellLoc, Short> newDat = MazeHandler.labyrinth; //Only the new data has data, the old one doesn't have.
|
||||
Map<CellLoc, Short> list = new HashMap<CellLoc, Short>();
|
||||
Map<CellLoc, Short> newlyEvaluatedMaze = new HashMap<CellLoc, Short>();
|
||||
for(CellLoc loc : newDat.keySet()) {
|
||||
if(!bufferOld.containsKey(loc)) {
|
||||
list.put(loc, newDat.get(loc));
|
||||
newlyEvaluatedMaze.put(loc, newDat.get(loc));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return newlyEvaluatedMaze;
|
||||
}
|
||||
|
||||
private static boolean hasFreeSessionSpace() {
|
||||
@@ -148,18 +164,47 @@ public class TCMazeHandler {
|
||||
return !player.worldObj.isRemote && runningSessions.get(player) != null;
|
||||
}
|
||||
|
||||
public static void closeSession(EntityPlayer player) {
|
||||
public static void closeSession(EntityPlayer player, boolean teleport) {
|
||||
if(player.worldObj.isRemote) return;
|
||||
|
||||
if(runningSessions.containsKey(player)) {
|
||||
runningSessions.get(player).closeSession();
|
||||
runningSessions.get(player).closeSession(teleport);
|
||||
runningSessions.remove(player);
|
||||
}
|
||||
if(runningSessions.size() == 0) {
|
||||
forceWorldUnloading(ModConfig.dimOuterId);
|
||||
}
|
||||
}
|
||||
|
||||
public static void free(Map<CellLoc, Short> locations) {
|
||||
WorldServer ws = DimensionManager.getWorld(ModConfig.dimOuterId);
|
||||
for(CellLoc loc : locations.keySet()) {
|
||||
labyrinthCopy.remove(loc);
|
||||
forceChunkUnloading(ws, loc.x, loc.z);
|
||||
}
|
||||
}
|
||||
|
||||
private static void forceChunkUnloading(WorldServer ws, int chX, int chZ) {
|
||||
if(ws == null) return;
|
||||
long chunkPair = ChunkCoordIntPair.chunkXZ2Int(chX, chZ);
|
||||
ChunkProviderServer serverChProvider = ws.theChunkProviderServer;
|
||||
LongHashMap chunks = serverChProvider.loadedChunkHashMap;
|
||||
Chunk c = (Chunk) chunks.getValueByKey(chunkPair);
|
||||
|
||||
serverChProvider.loadedChunkHashMap.remove(chunkPair);
|
||||
if(c != null) serverChProvider.loadedChunks.remove(c);
|
||||
|
||||
if(serverChProvider.loadedChunks.size() == 0) {
|
||||
forceWorldUnloading(ws.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
|
||||
private static void forceWorldUnloading(int dimId) {
|
||||
WorldServer ws = DimensionManager.getWorld(dimId);
|
||||
if(ws != null) {
|
||||
MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(ws));
|
||||
ws.flush();
|
||||
DimensionManager.setWorld(dimId, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,22 +47,24 @@ class TCMazeSession {
|
||||
return null;
|
||||
}
|
||||
|
||||
final void closeSession() {
|
||||
final void closeSession(boolean teleport) {
|
||||
TCMazeHandler.free(chunksAffected);
|
||||
WorldUtil.tryTeleportBack(player, originDimId);
|
||||
player.setPosition(originLocation.xCoord, originLocation.yCoord, originLocation.zCoord);
|
||||
if(teleport) {
|
||||
WorldUtil.tryTeleportBack(player, originDimId);
|
||||
player.setPosition(originLocation.xCoord, originLocation.yCoord, originLocation.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
final void startSession() {
|
||||
if(portalCell == null) {
|
||||
LogManager.getLogger().error("Thaumcraft didn't generate a portal! Stopping instance!", new IllegalStateException());
|
||||
closeSession();
|
||||
closeSession(false);
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Thaumcraft didn't generate a portal in the Eldritch dimension. Sorry, we can't teleport you.."));
|
||||
} else {
|
||||
WorldUtil.teleportToFakeOuter(player);
|
||||
int x = portalCell.x * 16 + 7;
|
||||
int z = portalCell.z * 16 + 7;
|
||||
player.setPosition(x, TCMazeHandler.TELEPORT_LAYER_Y, z);
|
||||
int x = portalCell.x * 16 + 8;
|
||||
int z = portalCell.z * 16 + 8;
|
||||
player.setPositionAndUpdate(x, TCMazeHandler.TELEPORT_LAYER_Y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package makeo.gadomancy.common.utils.world;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
@@ -9,9 +10,7 @@ import net.minecraft.world.WorldProvider;
|
||||
import net.minecraft.world.biome.WorldChunkManagerHell;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import thaumcraft.common.config.Config;
|
||||
import thaumcraft.common.lib.world.ThaumcraftWorldGenerator;
|
||||
import thaumcraft.common.lib.world.dim.ChunkProviderOuter;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
@@ -58,12 +57,12 @@ public class WorldProviderTCEldrich extends WorldProvider {
|
||||
|
||||
public void registerWorldChunkManager() {
|
||||
this.worldChunkMgr = new WorldChunkManagerHell(ThaumcraftWorldGenerator.biomeEldritchLands, 0.0F);
|
||||
this.dimensionId = Config.dimensionOuterId;
|
||||
this.dimensionId = ModConfig.dimOuterId;
|
||||
this.hasNoSky = true;
|
||||
}
|
||||
|
||||
public IChunkProvider createChunkGenerator() {
|
||||
return new ChunkProviderOuter(this.worldObj, this.worldObj.getSeed(), true);
|
||||
return new ChunkProviderTCOuter(this.worldObj, this.worldObj.getSeed(), true);
|
||||
}
|
||||
|
||||
public float calculateCelestialAngle(long p_76563_1_, float p_76563_3_) {
|
||||
|
||||
@@ -17,13 +17,11 @@ import net.minecraft.server.MinecraftServer;
|
||||
*/
|
||||
public class WorldUtil {
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
public static void teleportToFakeOuter(EntityPlayerMP player) {
|
||||
MinecraftServer mServer = FMLCommonHandler.instance().getMinecraftServerInstance();
|
||||
mServer.getConfigurationManager().transferPlayerToDimension(player, ModConfig.dimOuterId, new TeleporterNothing(mServer.worldServerForDimension(ModConfig.dimOuterId)));
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
public static void tryTeleportBack(EntityPlayerMP player, int dim) {
|
||||
MinecraftServer mServer = FMLCommonHandler.instance().getMinecraftServerInstance();
|
||||
mServer.getConfigurationManager().transferPlayerToDimension(player, dim, new TeleporterNothing(mServer.worldServerForDimension(dim)));
|
||||
|
||||
Reference in new issue
Block a user