Gate of the fold complete
This commit is contained in:
parent
c8b004c9b6
commit
01acf08ad4
|
@ -10,10 +10,14 @@ import WayofTime.bloodmagic.teleport.Teleports;
|
|||
import WayofTime.bloodmagic.tile.TileDimensionalPortal;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.audio.Sound;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
@ -76,27 +80,24 @@ public class BlockDimensionalPortal extends BlockInteger {
|
|||
if (!world.isRemote && world.getTileEntity(pos) instanceof TileDimensionalPortal) {
|
||||
TileDimensionalPortal tile = (TileDimensionalPortal) world.getTileEntity(pos);
|
||||
|
||||
if (LocationsHandler.getLocationsHandler() != null) {
|
||||
ArrayList<PortalLocation> linkedLocations = LocationsHandler.getLocationsHandler().getLinkedLocations(tile.portalID);
|
||||
LocationsHandler.verifyIsInitialized();
|
||||
ArrayList<PortalLocation> linkedLocations = LocationsHandler.getLinkedLocations(tile.portalID);
|
||||
|
||||
if (linkedLocations != null && !linkedLocations.isEmpty() && linkedLocations.size() > 1) {
|
||||
if (world.getTileEntity(tile.getMasterStonePos()) != null && world.getTileEntity(tile.getMasterStonePos()) instanceof IMasterRitualStone) {
|
||||
IMasterRitualStone masterRitualStone = (IMasterRitualStone) world.getTileEntity(tile.getMasterStonePos());
|
||||
if (linkedLocations.get(0).equals(new PortalLocation(masterRitualStone.getBlockPos().up(), world.provider.getDimension()))) {
|
||||
PortalLocation portal = linkedLocations.get(1);
|
||||
if (portal.getDimension() == world.provider.getDimension()) {
|
||||
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), false));
|
||||
} else {
|
||||
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), world, portal.getDimension(), false));
|
||||
}
|
||||
} else if (linkedLocations.get(1).equals(new PortalLocation(masterRitualStone.getBlockPos().up(), world.provider.getDimension()))) {
|
||||
PortalLocation portal = linkedLocations.get(0);
|
||||
if (portal.getDimension() == world.provider.getDimension()) {
|
||||
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), false));
|
||||
} else {
|
||||
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), world, portal.getDimension(), false));
|
||||
}
|
||||
}
|
||||
if (linkedLocations != null && linkedLocations.size() > 1) {
|
||||
if (world.getTileEntity(tile.getMasterStonePos()) != null && world.getTileEntity(tile.getMasterStonePos()) instanceof IMasterRitualStone) {
|
||||
IMasterRitualStone masterRitualStone = (IMasterRitualStone) world.getTileEntity(tile.getMasterStonePos());
|
||||
PortalLocation portal;
|
||||
int index = linkedLocations.size() - 1; //index of most recent PortalLocation
|
||||
if (linkedLocations.get(index).equals(new PortalLocation(masterRitualStone.getBlockPos().up(), world.provider.getDimension()))) {
|
||||
portal = linkedLocations.get(index-1); // if most recent PortalLocaiton = this, get the 2nd most recent
|
||||
} else {
|
||||
portal = linkedLocations.get(index);
|
||||
}
|
||||
|
||||
if (portal.getDimension() == world.provider.getDimension()) {
|
||||
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), false));
|
||||
} else {
|
||||
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), world, portal.getDimension(), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,39 +9,30 @@ import java.io.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LocationsHandler implements Serializable {
|
||||
public final class LocationsHandler implements Serializable {
|
||||
|
||||
public static final long serialVersionUID = 10102001;
|
||||
private static final String fileName = String.valueOf(DimensionManager.getCurrentSaveRootDirectory()) + "/" + BloodMagic.MODID + "/PortalLocations.dat";
|
||||
private static HashMap<String, ArrayList<PortalLocation>> portals;
|
||||
private static LocationsHandler locationsHandler;
|
||||
private static boolean initialized = false;
|
||||
|
||||
private LocationsHandler() {}
|
||||
|
||||
private LocationsHandler() {
|
||||
portals = new HashMap<>();
|
||||
}
|
||||
|
||||
public boolean addLocation(String name, PortalLocation location) {
|
||||
public static boolean addLocation(String name, PortalLocation location) {
|
||||
ArrayList<PortalLocation> portalLocations = portals.get(name);
|
||||
if (portalLocations == null) {
|
||||
portals.put(name, new ArrayList<>());
|
||||
updateFile(fileName, portals);
|
||||
}
|
||||
if (!portals.get(name).isEmpty() && portals.get(name).size() >= 2) {
|
||||
BMLog.DEBUG.info("Location {} already exists.", name);
|
||||
updateFile(fileName, portals);
|
||||
return false;
|
||||
} else {
|
||||
portals.get(name).add(location);
|
||||
BMLog.DEBUG.info("Adding {}", name);
|
||||
updateFile(fileName, portals);
|
||||
return true;
|
||||
}
|
||||
portals.get(name).add(location);
|
||||
BMLog.DEBUG.info("Adding {}", name);
|
||||
updateFile(fileName, portals);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeLocation(String name, PortalLocation location) {
|
||||
public static boolean removeLocation(String name, PortalLocation location) {
|
||||
if (portals.get(name) != null && !portals.get(name).isEmpty()) {
|
||||
if (portals.get(name).contains(location)) {
|
||||
portals.get(name).remove(location);
|
||||
if (portals.get(name).remove(location)) {
|
||||
BMLog.DEBUG.info("Removing {}", name);
|
||||
updateFile(fileName, portals);
|
||||
return true;
|
||||
|
@ -54,17 +45,17 @@ public class LocationsHandler implements Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
public ArrayList<PortalLocation> getLinkedLocations(String name) {
|
||||
public static ArrayList<PortalLocation> getLinkedLocations(String name) {
|
||||
return portals.get(name);
|
||||
}
|
||||
|
||||
public static LocationsHandler getLocationsHandler() {
|
||||
if (locationsHandler == null || loadFile() == null) {
|
||||
locationsHandler = new LocationsHandler();
|
||||
return locationsHandler;
|
||||
} else {
|
||||
portals = loadFile();
|
||||
return locationsHandler;
|
||||
public static void verifyIsInitialized() {
|
||||
if (!initialized) {
|
||||
HashMap<String, ArrayList<PortalLocation>> map = loadFile();
|
||||
if(map == null) {
|
||||
portals = new HashMap<>();
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,11 +86,10 @@ public class RitualPortal extends Ritual {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (LocationsHandler.getLocationsHandler().addLocation(name, new PortalLocation(x, y + 1, z, world.provider.getDimension()))) {
|
||||
portalRitualTag.setString(PORTAL_ID_TAG, name);
|
||||
return true;
|
||||
}
|
||||
LocationsHandler.verifyIsInitialized();
|
||||
LocationsHandler.addLocation(name, new PortalLocation(x, y + 1, z, world.provider.getDimension()));
|
||||
portalRitualTag.setString(PORTAL_ID_TAG, name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -152,7 +151,8 @@ public class RitualPortal extends Ritual {
|
|||
int z = masterRitualStone.getBlockPos().getZ();
|
||||
EnumFacing direction = masterRitualStone.getDirection();
|
||||
|
||||
LocationsHandler.getLocationsHandler().removeLocation(portalRitualTag.getString(PORTAL_ID_TAG), new PortalLocation(x, y + 1, z, world.provider.getDimension()));
|
||||
LocationsHandler.verifyIsInitialized();
|
||||
LocationsHandler.removeLocation(portalRitualTag.getString(PORTAL_ID_TAG), new PortalLocation(x, y + 1, z, world.provider.getDimension()));
|
||||
|
||||
if (direction == EnumFacing.NORTH || direction == EnumFacing.SOUTH) {
|
||||
for (int i = x - 2; i <= x + 2; i++) {
|
||||
|
@ -172,7 +172,7 @@ public class RitualPortal extends Ritual {
|
|||
}
|
||||
}
|
||||
|
||||
portalRitualTag.removeTag(PORTAL_ID_TAG);
|
||||
portalRitualTag.removeTag(portalRitualTag.getString(PORTAL_ID_TAG));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue