Search in sources :

Example 1 with FissureData

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;
}
Also used : FissureData(hellfirepvp.fracture.common.fissure.FissureData) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with FissureData

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;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) Vector3(hellfirepvp.fracture.common.util.Vector3) World(net.minecraft.world.World) LinkedList(java.util.LinkedList) FissureData(hellfirepvp.fracture.common.fissure.FissureData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with FissureData

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();
    }
}
Also used : FissureData(hellfirepvp.fracture.common.fissure.FissureData) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with FissureData

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);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) FissureData(hellfirepvp.fracture.common.fissure.FissureData) HashMap(java.util.HashMap) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) LinkedList(java.util.LinkedList)

Example 5 with FissureData

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());
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) FissureData(hellfirepvp.fracture.common.fissure.FissureData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

FissureData (hellfirepvp.fracture.common.fissure.FissureData)14 BlockPos (net.minecraft.util.math.BlockPos)12 HashMap (java.util.HashMap)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 NBTTagList (net.minecraft.nbt.NBTTagList)6 Map (java.util.Map)5 Vector3 (hellfirepvp.fracture.common.util.Vector3)3 LinkedList (java.util.LinkedList)3 IBlockState (net.minecraft.block.state.IBlockState)3 EffectLightning (hellfirepvp.fracture.client.effect.fx.EffectLightning)2 EntityFXFacingParticle (hellfirepvp.fracture.client.effect.fx.EntityFXFacingParticle)2 BlockAir (net.minecraft.block.BlockAir)2 Tuple (net.minecraft.util.Tuple)2 Vec3i (net.minecraft.util.math.Vec3i)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 World (net.minecraft.world.World)1