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());
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations