use of hellfirepvp.fracture.common.fissure.FissureData in project Fracture by HellFirePvP.
the class FissureSwapHelper method prepareSwap.
public static boolean prepareSwap(TileFissureDevice device) {
if (!device.isLinked())
return false;
int originDim = device.getWorld().provider.getDimension();
BlockPos originPos = device.getPos();
FissureData originData = FissureDataController.getFissureData(originDim, originPos);
if (originData == null)
return false;
int linkedDim = device.getLinkedDimension();
BlockPos linkedPos = device.getLinkedPos();
FissureData targetData = FissureDataController.getFissureData(linkedDim, linkedPos);
if (targetData == null)
return false;
BlockPos originMin = originData.getMin();
BlockPos originMax = originData.getMax();
BlockPos targetMin = targetData.getMin();
BlockPos targetMax = targetData.getMax();
BlockPos minOffset = new BlockPos(originMin.getX() < targetMin.getX() ? originMin.getX() : targetMin.getX(), originMin.getY() < targetMin.getY() ? originMin.getY() : targetMin.getY(), originMin.getZ() < targetMin.getZ() ? originMin.getZ() : targetMin.getZ());
BlockPos maxOffset = new BlockPos(originMax.getX() > targetMax.getX() ? originMax.getX() : targetMax.getX(), originMax.getY() > targetMax.getY() ? originMax.getY() : targetMax.getY(), originMax.getZ() > targetMax.getZ() ? originMax.getZ() : targetMax.getZ());
FissureSwapPreparation.updateTicket(originDim, minOffset.add(originPos), maxOffset.add(originPos), originPos);
FissureSwapPreparation.updateTicket(linkedDim, minOffset.add(linkedPos), maxOffset.add(linkedPos), linkedPos);
return true;
}
use of hellfirepvp.fracture.common.fissure.FissureData in project Fracture by HellFirePvP.
the class FissureSwapHelper method doSwap.
public static boolean doSwap(TileFissureDevice device) {
if (!device.isLinked())
return false;
int originDim = device.getWorld().provider.getDimension();
BlockPos originPos = device.getPos();
FissureData originData = FissureDataController.getFissureData(originDim, originPos);
if (originData == null)
return false;
int linkedDim = device.getLinkedDimension();
BlockPos linkedPos = device.getLinkedPos();
FissureData targetData = FissureDataController.getFissureData(linkedDim, linkedPos);
if (targetData == null)
return false;
BlockPos originMin = originData.getMin();
BlockPos originMax = originData.getMax();
BlockPos targetMin = targetData.getMin();
BlockPos targetMax = targetData.getMax();
BlockPos minOffset = new BlockPos(originMin.getX() < targetMin.getX() ? originMin.getX() : targetMin.getX(), originMin.getY() < targetMin.getY() ? originMin.getY() : targetMin.getY(), originMin.getZ() < targetMin.getZ() ? originMin.getZ() : targetMin.getZ());
BlockPos maxOffset = new BlockPos(originMax.getX() > targetMax.getX() ? originMax.getX() : targetMax.getX(), originMax.getY() > targetMax.getY() ? originMax.getY() : targetMax.getY(), originMax.getZ() > targetMax.getZ() ? originMax.getZ() : targetMax.getZ());
// Load worlds if not loaded yet
World originWorld = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(originDim);
World targetWorld = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(linkedDim);
AxisAlignedBB boxOrigin = new AxisAlignedBB(minOffset.add(originPos), maxOffset.add(originPos));
AxisAlignedBB boxTarget = new AxisAlignedBB(minOffset.add(linkedPos), maxOffset.add(linkedPos));
List<BlockPos> ignoreOffsets = new LinkedList<>();
Map<BlockPos, IBlockState> realOffsetStates = new HashMap<>();
for (BlockPos pos : BlockPos.getAllInBox(minOffset.add(originPos), maxOffset.add(originPos))) {
IBlockState from = originWorld.getBlockState(pos);
if (originWorld.getTileEntity(pos) == null && from.getBlockHardness(originWorld, pos) >= 0F) {
realOffsetStates.put(pos.subtract(originPos), from);
} else {
ignoreOffsets.add(pos.subtract(originPos));
}
}
Map<BlockPos, IBlockState> targetOffsetStates = new HashMap<>();
for (BlockPos pos : BlockPos.getAllInBox(minOffset.add(linkedPos), maxOffset.add(linkedPos))) {
if (ignoreOffsets.contains(pos.subtract(linkedPos)))
continue;
IBlockState from = targetWorld.getBlockState(pos);
if (targetWorld.getTileEntity(pos) == null && from.getBlockHardness(targetWorld, pos) >= 0F) {
targetOffsetStates.put(pos.subtract(linkedPos), from);
} else {
realOffsetStates.remove(pos.subtract(linkedPos));
}
}
for (Map.Entry<BlockPos, IBlockState> entry : realOffsetStates.entrySet()) {
targetWorld.setBlockState(entry.getKey().add(linkedPos), entry.getValue());
}
for (Map.Entry<BlockPos, IBlockState> entry : targetOffsetStates.entrySet()) {
originWorld.setBlockState(entry.getKey().add(originPos), entry.getValue());
}
List<EntityPlayer> originEntities = originWorld.getEntitiesWithinAABB(EntityPlayer.class, boxOrigin);
List<EntityPlayer> targetEntities = targetWorld.getEntitiesWithinAABB(EntityPlayer.class, boxTarget);
for (EntityPlayer e : originEntities) {
Vector3 to = Vector3.atEntityCorner(e).subtract(originPos).add(linkedPos);
MiscUtils.transferEntityTo(e, linkedDim, to);
}
for (EntityPlayer e : targetEntities) {
Vector3 to = Vector3.atEntityCorner(e).subtract(linkedPos).add(originPos);
MiscUtils.transferEntityTo(e, originDim, to);
}
FissureSwapPreparation.removeTicket(originDim, originPos);
FissureSwapPreparation.removeTicket(linkedDim, linkedPos);
return true;
}
use of hellfirepvp.fracture.common.fissure.FissureData in project Fracture by HellFirePvP.
the class TileFissureDevice method update.
@Override
public void update() {
ticksExisted++;
if (!world.isRemote) {
if ((ticksExisted % 20 == 0) && getStructureDepth() > 0) {
FissureDataController.updateFissureServer(this);
}
if (activatedPlayer != null) {
// 7.5 sq
if (activatedPlayer.getDistanceSqToCenter(getPos()) >= 56.25 || activatedPlayer.isDead) {
this.active = false;
this.activatedPlayer = null;
this.inSwap = false;
this.swapPerc = 0F;
markForUpdate();
}
} else if (inSwap || active || swapPerc > 0F) {
this.active = false;
this.activatedPlayer = null;
this.inSwap = false;
this.swapPerc = 0F;
markForUpdate();
}
markForUpdate();
if (!isLinked) {
FissureData thisData = FissureDataController.getFissureData(this.world.provider.getDimension(), this.getPos());
if (thisData != null && thisData.hasOtherLink()) {
this.isLinked = true;
this.linkedDimension = thisData.getOtherLinkDim();
this.linkedPos = thisData.getOtherLinkPos();
markForUpdate();
} else {
Tuple<Integer, BlockPos> linkPair = FissureDataController.getRandomFissureExcept(this);
if (linkPair != null) {
this.isLinked = true;
this.linkedDimension = linkPair.getFirst();
this.linkedPos = linkPair.getSecond();
markForUpdate();
}
}
} else {
FissureData thisData = FissureDataController.getFissureData(this.world.provider.getDimension(), this.getPos());
if (thisData != null) {
// The other end died :(
if (!thisData.hasOtherLink()) {
this.isLinked = false;
this.linkedDimension = -1;
this.linkedPos = BlockPos.ORIGIN;
markForUpdate();
} else {
FissureData otherData = FissureDataController.getFissureData(this.getLinkedDimension(), this.getLinkedPos());
if (otherData != null && otherData.hasOtherLink() && otherData.getOtherLinkDim() == world.provider.getDimension() && otherData.getOtherLinkPos().equals(getPos()) && activatedPlayer != null && inSwap) {
FissureSwapHelper.prepareSwap(this);
this.swapPerc = Math.min(1F, this.swapPerc + 0.01F);
if (this.swapPerc >= 1F) {
if (FissureSwapHelper.doSwap(this)) {
this.activatedPlayer = null;
this.inSwap = false;
this.active = false;
this.swapPerc = 0F;
}
}
markForUpdate();
}
}
}
}
} else {
float accel = 0.025F;
if (this.active && this.getStructureDepth() > 0) {
this.percActive = Math.min(1F, this.percActive + accel);
if (percActive >= 1F) {
float accelDraw = 0.01F;
this.percDrawFissure = Math.min(1F, this.percDrawFissure + accelDraw);
}
} else {
this.percActive = Math.max(0F, this.percActive - accel);
this.percDrawFissure = 0F;
}
if (this.active && this.getStructureDepth() > 0 && this.isLinked) {
FissureData otherLink = FissureDataController.getFissureData(this.getLinkedDimension(), this.getLinkedPos());
if (otherLink != null && this.percDrawFissure >= 1F) {
ClientFissureWorldHandler.activate(this);
}
} else {
ClientFissureWorldHandler.deactivate(this);
this.percDrawFissure = 0F;
}
playEffects();
}
}
use of hellfirepvp.fracture.common.fissure.FissureData in project SomeModjam5Mod by HellFirePvP.
the class DataFissures method readRawFromPacket.
@Override
public void readRawFromPacket(NBTTagCompound compound) {
NBTTagList listUpdate = compound.getTagList("update", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < listUpdate.tagCount(); i++) {
NBTTagCompound dimFissure = listUpdate.getCompoundTagAt(i);
int dim = dimFissure.getInteger("dim");
Map<BlockPos, FissureData> fissures = new HashMap<>();
clientUpdateRequested.put(dim, fissures);
NBTTagList listFissures = dimFissure.getTagList("list", Constants.NBT.TAG_COMPOUND);
for (int j = 0; j < listFissures.tagCount(); j++) {
NBTTagCompound tagFissure = listFissures.getCompoundTagAt(j);
BlockPos pos = new BlockPos(tagFissure.getInteger("x"), tagFissure.getInteger("y"), tagFissure.getInteger("z"));
NBTTagCompound tagFissureData = tagFissure.getCompoundTag("fissure");
FissureData data = FissureData.readFromNBT(tagFissureData);
fissures.put(pos, data);
}
}
NBTTagList listRemoval = compound.getTagList("remove", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < listRemoval.tagCount(); i++) {
NBTTagCompound dimRemove = listRemoval.getCompoundTagAt(i);
int dim = dimRemove.getInteger("dim");
List<BlockPos> removals = new LinkedList<>();
clientRemovalRequested.put(dim, removals);
NBTTagList listRemovals = dimRemove.getTagList("list", Constants.NBT.TAG_COMPOUND);
for (int j = 0; j < listRemovals.tagCount(); j++) {
NBTTagCompound tagRemove = listRemovals.getCompoundTagAt(j);
BlockPos pos = new BlockPos(tagRemove.getInteger("x"), tagRemove.getInteger("y"), tagRemove.getInteger("z"));
removals.add(pos);
}
}
}
use of hellfirepvp.fracture.common.fissure.FissureData in project SomeModjam5Mod by HellFirePvP.
the class DataFissures method writeAllDataToPacket.
@Override
public void writeAllDataToPacket(NBTTagCompound compound) {
Map<Integer, Map<BlockPos, FissureData>> fissures = FissureDataController.getFissures();
NBTTagList dimFissures = new NBTTagList();
for (int dim : fissures.keySet()) {
NBTTagCompound dimFissure = new NBTTagCompound();
dimFissure.setInteger("dim", dim);
NBTTagList listFissures = new NBTTagList();
for (Map.Entry<BlockPos, FissureData> fissure : fissures.get(dim).entrySet()) {
NBTTagCompound cmp = new NBTTagCompound();
cmp.setInteger("x", fissure.getKey().getX());
cmp.setInteger("y", fissure.getKey().getY());
cmp.setInteger("z", fissure.getKey().getZ());
NBTTagCompound tagFissure = new NBTTagCompound();
fissure.getValue().writeToNBT(tagFissure);
cmp.setTag("fissure", tagFissure);
listFissures.appendTag(cmp);
}
dimFissure.setTag("list", listFissures);
dimFissures.appendTag(dimFissure);
}
compound.setTag("update", dimFissures);
compound.setTag("remove", new NBTTagList());
}
Aggregations