use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.
the class TileManaInteracter method suckManaFrom.
public boolean suckManaFrom(TileManaInteracter interacterFrom, SuckRule suckRule) {
if (getWizardryCap() == null || interacterFrom.getWizardryCap() == null)
return false;
if (!isAllowOutsideSucking() && interacterFrom.isAllowOutsideSucking())
return false;
if (!suckRule.condition.test(this, interacterFrom))
return false;
CapManager thisManager = new CapManager(getWizardryCap());
CapManager theirManager = new CapManager(interacterFrom.getWizardryCap());
if (thisManager.isManaFull())
return false;
if (theirManager.isManaEmpty())
return false;
if (suckRule.equalize && Math.abs(thisManager.getMana() - theirManager.getMana()) <= suckRule.idealAmount)
return false;
Vec3d thisPos = new Vec3d(getPos()).addVector(0.5, 0.5, 0.5);
Vec3d theirPos = new Vec3d(interacterFrom.getPos()).addVector(0.5, 0.5, 0.5);
// DEBUG
// ParticleBuilder helix = new ParticleBuilder(200);
// helix.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
// helix.setAlphaFunction(new InterpFadeInOut(0.1f, 0.1f));
// ParticleSpawner.spawn(helix, world, new StaticInterp<>(thisPos), 1, 0, (someFloat, particleBuilder) -> {
// particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0xFF0000), RandUtil.nextInt(50, 200)));
// particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
// particleBuilder.disableRandom();
// particleBuilder.setPositionFunction(new InterpLine(Vec3d.ZERO, theirPos.subtract(thisPos)));
// particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
// });
double ratio = theirManager.getMana() / thisManager.getMana();
if (suckRule.equalize && Double.isFinite(ratio) && ratio <= 1.2)
return false;
if (getCachedDistanceSq(interacterFrom) > ConfigValues.networkLinkDistance * ConfigValues.networkLinkDistance)
return false;
if (!suckRule.ignoreTrace) {
Vec3d thisSub = theirPos.subtract(thisPos.add(getOffset()));
Vec3d thisNorm = thisSub.normalize();
RayTraceResult trace = new RayTrace(world, thisNorm, thisPos.add(getOffset() == Vec3d.ZERO ? thisNorm : getOffset()), ConfigValues.networkLinkDistance * ConfigValues.networkLinkDistance).setSkipEntities(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
if (!trace.getBlockPos().equals(interacterFrom.getPos()))
return false;
}
double amount = interacterFrom.drainMana(suckRule.idealAmount);
if (amount <= 0)
return false;
thisManager.addMana(amount);
ClientRunnable.run(new ClientRunnable() {
@Override
@SideOnly(Side.CLIENT)
public void runIfClient() {
ParticleBuilder helix = new ParticleBuilder(200);
helix.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
helix.setAlphaFunction(new InterpFadeInOut(0.1f, 0.1f));
ParticleSpawner.spawn(helix, world, new StaticInterp<>(new Vec3d(interacterFrom.getPos()).addVector(0.5, 1, 0.5)), 1, 0, (someFloat, particleBuilder) -> {
particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0x0097FF), RandUtil.nextInt(50, 200)));
particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
particleBuilder.setPositionFunction(new InterpBezier3D(Vec3d.ZERO, new Vec3d(getPos().subtract(interacterFrom.getPos())), new Vec3d(0, 5, 0), new Vec3d(0, -5, 0)));
particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
});
}
});
return true;
}
use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.
the class TileManaInteracter method drainMana.
public double drainMana(double mana) {
if (!world.isBlockLoaded(pos))
return -1;
IWizardryCapability cap = getWizardryCap();
if (cap == null)
return -1;
double amount = MathHelper.clamp(cap.getMana(), 0, mana);
CapManager manager = new CapManager(cap);
manager.removeMana(amount);
return amount;
}
use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.
the class TileCraftingPlateRenderer method animationLoop.
public void animationLoop(int i, boolean motionInvert) {
LocationAndAngle locationAndAngle = pop(i);
if (locationAndAngle == null)
return;
CapManager manager = new CapManager(tile.getWizardryCap());
Vec3d newDest;
double t = manager.getCap() == null ? 1 : 1 - (manager.getMana() / manager.getMaxMana());
double radius = RandUtil.nextDouble(5, 8) * t;
locationAndAngle.angle += RandUtil.nextDouble(-1.5, 1.5);
double x = MathHelper.cos((float) locationAndAngle.angle) * radius;
double z = MathHelper.sin((float) locationAndAngle.angle) * radius;
newDest = new Vec3d(x, (2 + (RandUtil.nextFloat() * 7)) * t, z);
BasicAnimation<LocationAndAngle> anim = new BasicAnimation<>(locationAndAngle, "location");
anim.setTo(newDest);
anim.setDuration((float) (RandUtil.nextDouble(50, 100) * (tile.suckingCooldown <= 0 ? MathHelper.clamp(t * 2, 0, 1) : t)));
anim.setEasing(!manager.isManaEmpty() ? Easing.easeInOutQuint : Easing.easeInOutSine);
anim.setCompletion(() -> animationLoop(i, !motionInvert));
animator.add(anim);
}
use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.
the class TileManaBatteryRenderer method render.
@Override
public void render(float partialTicks, int destroyStage, float alpha) {
super.render(partialTicks, destroyStage, alpha);
if (!getBakedModels())
return;
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
TextureManager texturemanager = Minecraft.getMinecraft().renderEngine;
if (texturemanager != null) {
texturemanager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
}
if (Minecraft.isAmbientOcclusionEnabled())
GlStateManager.shadeModel(GL11.GL_SMOOTH);
else
GlStateManager.shadeModel(GL11.GL_FLAT);
CapManager manager = new CapManager(tile.getWizardryCap());
float fill = (float) (manager.getMana() / manager.getMaxMana()) / 50.0f;
GlStateManager.translate(0, 0.5, 0);
GlStateManager.disableRescaleNormal();
{
double x = RandUtil.nextDouble(-fill, fill), y = RandUtil.nextDouble(-fill, fill), z = RandUtil.nextDouble(-fill, fill);
GlStateManager.translate(0, Math.sin((tile.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks()) / 40) / 8, 0);
GlStateManager.translate(x, y, z);
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(modelCrystal, 1.0F, 1, 1, 1);
GlStateManager.translate(-x, -y, -z);
}
GlStateManager.translate(0.5, 0, 0.5);
GlStateManager.rotate(tile.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, 1, 0);
GlStateManager.translate(-0.5, 0, -0.5);
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(modelRing, 1.0F, 1, 1, 1);
GlStateManager.translate(0.5, 0, 0.5);
GlStateManager.rotate(tile.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, -1, 0);
GlStateManager.rotate(tile.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, -1, 0);
GlStateManager.translate(-0.5, 0, -0.5);
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(modelRingOuter, 1.0F, 1, 1, 1);
GlStateManager.disableBlend();
GlStateManager.popMatrix();
HashSet<BlockPos> errors = ((IStructure) tile.getBlockType()).getErroredBlocks(tile.getWorld(), tile.getPos());
if (tile.revealStructure && tile.getBlockType() instanceof IStructure && !errors.isEmpty()) {
IStructure structure = ((IStructure) tile.getBlockType());
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.enablePolygonOffset();
GlStateManager.doPolygonOffset(1f, -0.05f);
GlStateManager.translate(-structure.offsetToCenter().getX(), -structure.offsetToCenter().getY(), -structure.offsetToCenter().getZ());
Minecraft mc = Minecraft.getMinecraft();
Tessellator tes = Tessellator.getInstance();
BufferBuilder buffer = tes.getBuffer();
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
for (BlockRenderLayer layer : cachedStructure.blocks.keySet()) {
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
buffer.addVertexData(cachedStructure.vboCaches.get(layer));
for (int i = 0; i < buffer.getVertexCount(); i++) {
int idx = buffer.getColorIndex(i + 1);
buffer.putColorRGBA(idx, 255, 255, 255, 200);
}
tes.draw();
}
GlStateManager.disablePolygonOffset();
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.enableDepth();
GlStateManager.popMatrix();
} else if (!tile.revealStructure && !errors.isEmpty()) {
for (BlockPos error : errors) StructureErrorRenderer.INSTANCE.addError(error);
}
if (tile.getBlockType() == ModBlocks.CREATIVE_MANA_BATTERY) {
double angle = tile.getWorld().getTotalWorldTime() / 10.0;
double x1 = Math.cos((float) angle);
double y1 = Math.sin((float) angle);
ParticleBuilder builder = new ParticleBuilder(10);
builder.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
builder.setCollision(true);
builder.disableRandom();
builder.disableMotionCalculation();
ParticleSpawner.spawn(builder, tile.getWorld(), new InterpCircle(new Vec3d(tile.getPos()).addVector(0.5, 0.5, 0.5), new Vec3d(x1, x1, y1), 1.5f), 20, 0, (aFloat, particleBuilder) -> {
particleBuilder.setScale(0.5f);
particleBuilder.setColor(new Color(0xd600d2));
particleBuilder.setAlphaFunction(new InterpFadeInOut(1, 1));
particleBuilder.setLifetime(RandUtil.nextInt(5, 10));
});
}
}
use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.
the class TilePearlHolderRenderer method render.
@Override
public void render(TilePearlHolder te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
if (te.containsSomething()) {
boolean isPearl = te.containsNacrePearl();
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.translate(x + 0.5, y + 0.5, z + 0.5);
GlStateManager.disableRescaleNormal();
float sin = (float) Math.sin((te.getWorld().getTotalWorldTime() + partialTicks + te.getPos().hashCode()) / 10.0);
boolean gravitating = false;
// Hover towards block
if (te.containsSomething()) {
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(te.getPos());
for (int i = -6; i < 6; i++) for (int j = -6; j < 6; j++) for (int k = -6; k < 6; k++) {
pos.setPos(te.getPos().getX() + i, te.getPos().getY() + j, te.getPos().getZ() + k);
Block block = te.getWorld().getBlockState(pos).getBlock();
if (te.containsNacrePearl() && block == ModBlocks.MANA_MAGNET) {
gravitating = true;
Vec3d direction = new Vec3d(te.getPos()).subtract(new Vec3d(pos)).normalize();
GlStateManager.translate(sin * direction.x / 5.0, sin * direction.y / 5.0, sin * direction.z / 5.0);
break;
}
if (te.containsManaOrb() && block == ModBlocks.MANA_BATTERY) {
gravitating = true;
Vec3d direction = new Vec3d(te.getPos()).subtract(new Vec3d(pos)).normalize();
GlStateManager.translate(sin * direction.x / 5.0, sin * direction.y / 5.0, sin * direction.z / 5.0);
break;
}
}
}
if (!gravitating)
GlStateManager.translate(0, sin / 10.0, 0);
GlStateManager.rotate((te.getWorld().getTotalWorldTime() + partialTicks) * 4.0f, 0, 1, 0);
GlStateManager.translate(0, 0.6, 0);
GlStateManager.rotate(45f, 1, 0, 1);
{
GlStateManager.disableCull();
GlStateManager.enableLighting();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
RenderHelper.disableStandardItemLighting();
if (te.containsNacrePearl()) {
Minecraft.getMinecraft().getTextureManager().bindTexture(pearlTexture);
renderCube(0.1, new Color(Minecraft.getMinecraft().getItemColors().colorMultiplier(te.getItemStack(), 0)));
} else if (te.containsAnyOrb()) {
CapManager manager = new CapManager(te.getWizardryCap());
Color c = new Color(1f, 1f, 1f, (float) (manager.getMana() / manager.getMaxMana()));
Minecraft.getMinecraft().getTextureManager().bindTexture(manaOrb);
renderCube(0.13, c);
Minecraft.getMinecraft().getTextureManager().bindTexture(glassOrb);
renderCube(0.135, new Color(1, 1, 1, 0.8f));
}
GlStateManager.disableRescaleNormal();
}
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
Aggregations