Search in sources :

Example 1 with NemezTracker

use of com.teamwizardry.wizardry.common.core.nemez.NemezTracker in project Wizardry by TeamWizardry.

the class WizardryNemezManager method getOrCreateNemezDrive.

public static NemezTracker getOrCreateNemezDrive(World world, Entity entity) {
    WizardryWorld worldCap = WizardryWorldCapability.get(world);
    HashMap<UUID, NemezTracker> nemezDrives = worldCap.getEntityNemezDrives();
    if (nemezDrives.containsKey(entity.getUniqueID()))
        return nemezDrives.get(entity.getUniqueID());
    return worldCap.addNemezDrive(entity.getUniqueID(), new NemezTracker());
}
Also used : WizardryWorld(com.teamwizardry.wizardry.api.capability.world.WizardryWorld) NemezTracker(com.teamwizardry.wizardry.common.core.nemez.NemezTracker) UUID(java.util.UUID)

Example 2 with NemezTracker

use of com.teamwizardry.wizardry.common.core.nemez.NemezTracker in project Wizardry by TeamWizardry.

the class WizardryNemezManager method getAndRemoveNemezDrive.

@Nullable
public static NemezTracker getAndRemoveNemezDrive(World world, UUID uuid) {
    WizardryWorld worldCap = WizardryWorldCapability.get(world);
    if (worldCap.getEntityNemezDrives().containsKey(uuid)) {
        NemezTracker tracker = worldCap.getEntityNemezDrives().get(uuid);
        worldCap.removeNemezDrive(uuid);
        return tracker;
    }
    return null;
}
Also used : WizardryWorld(com.teamwizardry.wizardry.api.capability.world.WizardryWorld) NemezTracker(com.teamwizardry.wizardry.common.core.nemez.NemezTracker) Nullable(javax.annotation.Nullable)

Example 3 with NemezTracker

use of com.teamwizardry.wizardry.common.core.nemez.NemezTracker in project Wizardry by TeamWizardry.

the class WizardryNemezManager method getAndRemoveNemezDrive.

@Nullable
public static NemezTracker getAndRemoveNemezDrive(World world, BlockPos pos) {
    WizardryWorld worldCap = WizardryWorldCapability.get(world);
    if (worldCap.getBlockNemezDrives().containsKey(pos)) {
        NemezTracker tracker = worldCap.getBlockNemezDrives().get(pos);
        worldCap.removeNemezDrive(pos);
        return tracker;
    }
    return null;
}
Also used : WizardryWorld(com.teamwizardry.wizardry.api.capability.world.WizardryWorld) NemezTracker(com.teamwizardry.wizardry.common.core.nemez.NemezTracker) Nullable(javax.annotation.Nullable)

Example 4 with NemezTracker

use of com.teamwizardry.wizardry.common.core.nemez.NemezTracker in project Wizardry by TeamWizardry.

the class ModuleEffectPhase method run.

@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    Entity caster = spell.getCaster(world);
    Entity targetEntity = spell.getVictim(world);
    BlockPos targetPos = spell.getTargetPos();
    EnumFacing faceHit = spell.getFaceHit();
    double duration = spellRing.getAttributeValue(world, AttributeRegistry.DURATION, spell) * 20;
    double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell);
    double range = spellRing.getAttributeValue(world, AttributeRegistry.RANGE, spell);
    if (!spellRing.taxCaster(world, spell, true))
        return false;
    if (targetEntity instanceof EntityLivingBase) {
        EntityLivingBase entity = (EntityLivingBase) targetEntity;
        entity.addPotionEffect(new PotionEffect(ModPotions.PHASE, (int) duration, 0, true, false));
        world.playSound(null, targetEntity.getPosition(), ModSounds.ETHEREAL, SoundCategory.NEUTRAL, 1, 1);
    }
    if (targetPos != null && faceHit != null) {
        world.playSound(null, targetPos, ModSounds.ETHEREAL, SoundCategory.NEUTRAL, 1, 1);
        NemezTracker nemezDrive = WizardryNemezManager.getOrCreateNemezDrive(world, targetPos);
        BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos(targetPos);
        faceHit = faceHit.getOpposite();
        IBlockState targetState = world.getBlockState(mutable);
        if (BlockUtils.isAnyAir(targetState))
            return true;
        Set<BlockPos> poses = new HashSet<>();
        HashMap<BlockPos, IBlockState> stateCache = new HashMap<>();
        int rangeTick = 0;
        while (rangeTick <= (int) range) {
            AxisAlignedBB bb = new AxisAlignedBB(mutable, mutable);
            switch(faceHit) {
                case DOWN:
                case UP:
                    bb = bb.grow(area + 1, 0, area + 1);
                    break;
                case NORTH:
                case SOUTH:
                    bb = bb.grow(area + 1, area + 1, 0);
                    break;
                case WEST:
                case EAST:
                    bb = bb.grow(0, area + 1, area + 1);
                    break;
            }
            Set<BlockPos> edges = new HashSet<>();
            switch(faceHit) {
                case DOWN:
                case UP:
                    for (int x = (int) bb.minX; x <= (int) bb.maxX; x++) {
                        for (int z = (int) bb.minZ; z <= (int) bb.maxZ; z++) {
                            if (x == (int) bb.maxX || x == (int) bb.minX) {
                                edges.add(new BlockPos(x, mutable.getY(), z));
                            } else if (z == (int) bb.minZ || z == (int) bb.maxZ) {
                                edges.add(new BlockPos(x, mutable.getY(), z));
                            }
                        }
                    }
                    break;
                case NORTH:
                case SOUTH:
                    for (int x = (int) bb.minX; x <= (int) bb.maxX; x++) {
                        for (int y = (int) bb.minY; y <= (int) bb.maxY; y++) {
                            if (y == (int) bb.maxY || y == (int) bb.minY) {
                                edges.add(new BlockPos(x, y, mutable.getZ()));
                            } else if (x == (int) bb.minX || x == (int) bb.maxX) {
                                edges.add(new BlockPos(x, y, mutable.getZ()));
                            }
                        }
                    }
                    break;
                case WEST:
                case EAST:
                    for (int z = (int) bb.minZ; z <= (int) bb.maxZ; z++) {
                        for (int y = (int) bb.minY; y <= (int) bb.maxY; y++) {
                            if (y == (int) bb.maxY || y == (int) bb.minY) {
                                edges.add(new BlockPos(mutable.getX(), y, z));
                            } else if (z == (int) bb.minZ || z == (int) bb.maxZ) {
                                edges.add(new BlockPos(mutable.getX(), y, z));
                            }
                        }
                    }
                    break;
            }
            HashMap<BlockPos, IBlockState> tmp = new HashMap<>();
            boolean fullAirPlane = true;
            int edgeAirCount = 0;
            int edgeBlockCount = 0;
            for (BlockPos pos : BlockPos.getAllInBox((int) bb.minX, (int) bb.minY, (int) bb.minZ, (int) bb.maxX, (int) bb.maxY, (int) bb.maxZ)) {
                IBlockState originalState = world.getBlockState(pos);
                Block block = originalState.getBlock();
                if (edges.contains(pos)) {
                    stateCache.put(pos, originalState);
                    if (block == Blocks.AIR)
                        edgeAirCount++;
                    else
                        edgeBlockCount++;
                    continue;
                }
                if (block != Blocks.AIR)
                    fullAirPlane = false;
                if (block == ModBlocks.FAKE_AIR)
                    continue;
                if (world.getTileEntity(pos) != null)
                    continue;
                tmp.put(pos, originalState);
            }
            if (!fullAirPlane) {
                if (edgeAirCount <= edgeBlockCount) {
                    for (Map.Entry<BlockPos, IBlockState> entry : tmp.entrySet()) {
                        nemezDrive.trackBlock(entry.getKey(), entry.getValue());
                        IBlockState state = ModBlocks.FAKE_AIR.getDefaultState();
                        BlockUtils.placeBlock(world, entry.getKey(), state, (EntityPlayerMP) caster);
                        stateCache.put(entry.getKey(), state);
                        nemezDrive.trackBlock(entry.getKey(), state);
                    }
                    poses.addAll(tmp.keySet());
                } else {
                    for (Map.Entry<BlockPos, IBlockState> entry : tmp.entrySet()) {
                        if (entry.getValue().getBlock() == Blocks.AIR) {
                            stateCache.put(entry.getKey(), entry.getValue());
                            continue;
                        }
                        nemezDrive.trackBlock(entry.getKey(), entry.getValue());
                        IBlockState state = ModBlocks.FAKE_AIR.getDefaultState();
                        BlockUtils.placeBlock(world, entry.getKey(), state, (EntityPlayerMP) caster);
                        stateCache.put(entry.getKey(), state);
                        nemezDrive.trackBlock(entry.getKey(), state);
                        poses.add(entry.getKey());
                    }
                }
            } else
                break;
            mutable.move(faceHit);
            rangeTick++;
        }
        nemezDrive.endUpdate();
        nemezDrive.collapse();
        // spell.addData(SpellData.DefaultKeys.NEMEZ, nemezDrive.serializeNBT());
        spell.addData(SpellData.DefaultKeys.BLOCK_SET, new BlockSet(poses));
        spell.addData(SpellData.DefaultKeys.BLOCKSTATE_CACHE, new BlockStateCache(stateCache));
        addDelayedSpell(world, spellRing, spell, (int) duration);
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) NemezTracker(com.teamwizardry.wizardry.common.core.nemez.NemezTracker) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) BlockSet(com.teamwizardry.wizardry.api.spell.SpellDataTypes.BlockSet) BlockStateCache(com.teamwizardry.wizardry.api.spell.SpellDataTypes.BlockStateCache) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 5 with NemezTracker

use of com.teamwizardry.wizardry.common.core.nemez.NemezTracker in project Wizardry by TeamWizardry.

the class ModuleEffectPhase method runDelayedEffect.

@Override
public void runDelayedEffect(@Nonnull World world, SpellData spell, SpellRing spellRing) {
    BlockPos targetPos = spell.getTargetPos();
    if (targetPos == null)
        return;
    NemezTracker nemezDrive = WizardryNemezManager.getAndRemoveNemezDrive(world, targetPos);
    if (nemezDrive != null) {
        NemezEventHandler.reverseTime(world, nemezDrive, targetPos);
    }
}
Also used : NemezTracker(com.teamwizardry.wizardry.common.core.nemez.NemezTracker) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

NemezTracker (com.teamwizardry.wizardry.common.core.nemez.NemezTracker)10 WizardryWorld (com.teamwizardry.wizardry.api.capability.world.WizardryWorld)6 BlockPos (net.minecraft.util.math.BlockPos)5 Nullable (javax.annotation.Nullable)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UUID (java.util.UUID)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 SpellObjectManager (com.teamwizardry.wizardry.api.SpellObjectManager)1 BlockSet (com.teamwizardry.wizardry.api.spell.SpellDataTypes.BlockSet)1 BlockStateCache (com.teamwizardry.wizardry.api.spell.SpellDataTypes.BlockStateCache)1 HashSet (java.util.HashSet)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 NBTBase (net.minecraft.nbt.NBTBase)1 PotionEffect (net.minecraft.potion.PotionEffect)1 EnumFacing (net.minecraft.util.EnumFacing)1