Added the Binding array

Hehe lightning go brrrrrr
This commit is contained in:
WayofTime 2020-11-28 21:41:28 -05:00
parent 2075fa5be3
commit 507c541d5b
15 changed files with 407 additions and 6 deletions

View file

@ -19,6 +19,7 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.api.compat.IMultiWillTool;
import wayoftime.bloodmagic.client.model.MimicColor;
import wayoftime.bloodmagic.client.render.block.RenderAlchemyArray;
import wayoftime.bloodmagic.client.render.block.RenderAltar;
@ -34,7 +35,6 @@ import wayoftime.bloodmagic.common.item.ItemSacrificialDagger;
import wayoftime.bloodmagic.common.item.sigil.ItemSigilToggleable;
import wayoftime.bloodmagic.common.item.soul.ItemSentientSword;
import wayoftime.bloodmagic.common.registries.BloodMagicEntityTypes;
import wayoftime.bloodmagic.api.compat.IMultiWillTool;
import wayoftime.bloodmagic.tile.TileAlchemyArray;
import wayoftime.bloodmagic.tile.TileAltar;
import wayoftime.bloodmagic.tile.TileDemonCrucible;
@ -98,6 +98,7 @@ public class ClientEvents
Minecraft.getInstance().getBlockColors().register(new MimicColor(), BloodMagicBlocks.MIMIC.get());
RenderTypeLookup.setRenderLayer(BloodMagicBlocks.MIMIC.get(), (RenderType) -> true);
});
}
public static void registerItemModelProperties(FMLClientSetupEvent event)

View file

@ -0,0 +1,229 @@
package wayoftime.bloodmagic.client.render.alchemyarray;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Quaternion;
import wayoftime.bloodmagic.client.render.BloodMagicRenderer;
import wayoftime.bloodmagic.client.render.BloodMagicRenderer.Model2D;
import wayoftime.bloodmagic.client.render.RenderResizableQuadrilateral;
import wayoftime.bloodmagic.tile.TileAlchemyArray;
public class BindingAlchemyCircleRenderer extends AlchemyArrayRenderer
{
public static final int numberOfSweeps = 5;
public static final int startTime = 50;
public static final int sweepTime = 40;
public static final int inwardRotationTime = 50;
public static final float arcLength = (float) Math.sqrt(2 * (2 * 2) - 2 * 2 * 2 * Math.cos(2 * Math.PI * 2 / 5));
public static final float theta2 = (float) (18f * Math.PI / 180f);
public static final int endTime = 300;
public final ResourceLocation[] arraysResources;
public float offsetFromFace = -0.9f;
public BindingAlchemyCircleRenderer()
{
super(new ResourceLocation("bloodmagic", "textures/models/alchemyarrays/bindingarray.png"));
arraysResources = new ResourceLocation[5];
arraysResources[0] = new ResourceLocation("bloodmagic", "textures/models/alchemyarrays/bindinglightningarray.png");
arraysResources[1] = new ResourceLocation("bloodmagic", "textures/models/alchemyarrays/bindinglightningarray.png");
arraysResources[2] = new ResourceLocation("bloodmagic", "textures/models/alchemyarrays/bindinglightningarray.png");
arraysResources[3] = new ResourceLocation("bloodmagic", "textures/models/alchemyarrays/bindinglightningarray.png");
arraysResources[4] = new ResourceLocation("bloodmagic", "textures/models/alchemyarrays/bindinglightningarray.png");
}
public float getRotation(int circle, float craftTime)
{
float offset = 2;
if (circle == -1 && craftTime >= offset)
{
return (craftTime - offset) * 360 * 2 / 5 / sweepTime;
}
if (craftTime >= offset)
{
float modifier = (float) Math.pow(craftTime - offset, 1.5);
return modifier * 0.5f;
}
return 0;
}
public float getSecondaryRotation(int circle, float craftTime)
{
float offset = 50;
if (craftTime >= offset)
{
float modifier = (float) Math.pow(craftTime - offset, 1.7);
return modifier * 0.5f;
}
return 0;
}
public float getVerticalOffset(int circle, float craftTime)
{
if (circle >= 0 && circle <= 4)
{
if (craftTime >= 5)
{
if (craftTime <= 40)
{
return (float) ((0.4) * Math.pow((craftTime - 5) / 35f, 3));
} else
{
return 0.4f;
}
}
return 0;
}
if (craftTime >= 5)
{
if (craftTime <= 40)
{
return (float) ((0.4) * Math.pow((craftTime - 5) / 35f, 3));
} else
{
return 0.4f;
}
}
return 0;
}
public float getInwardRotation(int circle, float craftTime)
{
float offset = startTime + numberOfSweeps * sweepTime;
if (craftTime >= offset)
{
if (craftTime <= offset + inwardRotationTime)
{
return 90f / inwardRotationTime * (craftTime - offset);
} else
{
return 90;
}
}
return 0;
}
public void renderAt(TileAlchemyArray tileArray, double x, double y, double z, float craftTime, MatrixStack matrixStack, IRenderTypeBuffer renderer, int combinedLightIn, int combinedOverlayIn)
{
matrixStack.push();
matrixStack.translate(0.5, 0.5, 0.5);
float rot = getRotation(-1, craftTime);
float secondaryRot = getSecondaryRotation(craftTime);
float size = 3;
Direction dirRotation = tileArray.getRotation();
matrixStack.push();
matrixStack.translate(0, getVerticalOffset(craftTime), 0);
matrixStack.rotate(new Quaternion(Direction.UP.toVector3f(), -dirRotation.getHorizontalAngle(), true));
matrixStack.push();
matrixStack.rotate(new Quaternion(Direction.UP.toVector3f(), rot, true));
// matrixStack.rotate(new Quaternion(Direction.NORTH.toVector3f(), secondaryRot, true));
// matrixStack.rotate(new Quaternion(Direction.EAST.toVector3f(), secondaryRot * 0.45812f, true));
IVertexBuilder twoDBuffer = renderer.getBuffer(RenderType.getEntityTranslucent(arrayResource));
Model2D arrayModel = new BloodMagicRenderer.Model2D();
arrayModel.minX = -0.5;
arrayModel.maxX = +0.5;
arrayModel.minY = -0.5;
arrayModel.maxY = +0.5;
arrayModel.resource = arrayResource;
matrixStack.scale(size, size, size);
RenderResizableQuadrilateral.INSTANCE.renderSquare(arrayModel, matrixStack, twoDBuffer, 0xFFFFFFFF, combinedLightIn, combinedOverlayIn);
matrixStack.pop();
for (int i = 0; i < 5; i++)
{
matrixStack.push();
float newSize = 1;
float distance = BindingAlchemyCircleRenderer.getDistanceOfCircle(i, craftTime);
float angle = BindingAlchemyCircleRenderer.getAngleOfCircle(i, craftTime);
float rotation = this.getRotation(i, craftTime);
matrixStack.translate(distance * Math.sin(angle), this.getVerticalOffset(i, craftTime), -distance * Math.cos(angle));
matrixStack.rotate(new Quaternion(Direction.UP.toVector3f(), i * 360 / 5, true));
matrixStack.rotate(new Quaternion(Direction.NORTH.toVector3f(), getInwardRotation(i, craftTime), true));
matrixStack.rotate(new Quaternion(Direction.UP.toVector3f(), rotation, true));
twoDBuffer = renderer.getBuffer(RenderType.getEntityTranslucent(arraysResources[i]));
arrayModel.resource = arraysResources[i];
matrixStack.scale(newSize, newSize, newSize);
RenderResizableQuadrilateral.INSTANCE.renderSquare(arrayModel, matrixStack, twoDBuffer, 0xFFFFFFFF, combinedLightIn, combinedOverlayIn);
matrixStack.pop();
}
matrixStack.pop();
matrixStack.pop();
}
public static float getAngleOfCircle(int circle, float craftTime)
{
if (circle >= 0 && circle <= 4)
{
float originalAngle = (float) (circle * 2 * Math.PI / 5d);
double sweep = (craftTime - startTime) / sweepTime;
if (sweep >= 0 && sweep < numberOfSweeps)
{
float offset = ((int) sweep) * sweepTime + startTime;
originalAngle += 2 * Math.PI * 2 / 5 * (int) sweep + getAngle(craftTime - offset, (int) sweep);
} else if (sweep >= numberOfSweeps)
{
originalAngle += 2 * Math.PI * 2 / 5 * numberOfSweeps + (craftTime - 5 * sweepTime - startTime) * 2 * Math.PI * 2 / 5 / sweepTime;
}
return originalAngle;
}
return 0;
}
public static float getAngle(float craftTime, int sweep)
{
float rDP = craftTime / sweepTime * arcLength;
float rEnd = (float) Math.sqrt(rDP * rDP + 2 * 2 - 2 * rDP * 2 * Math.cos(theta2));
return (float) (Math.acos((2 * 2 + rEnd * rEnd - rDP * rDP) / (2 * rEnd * 2)));
}
/**
* Returns the center-to-center distance of this circle.
*/
public static float getDistanceOfCircle(int circle, float craftTime)
{ // TODO Change this so it doesn't use angle, since it is a constant speed.
double sweep = (craftTime - startTime) / sweepTime;
if (sweep >= 0 && sweep < numberOfSweeps)
{
float offset = ((int) sweep) * sweepTime + startTime;
float angle = getAngle(craftTime - offset, (int) sweep);
float thetaPrime = (float) (Math.PI - theta2 - angle);
// if(thetaPrime > 0 && thetaPrime < Math.PI) {
return (float) (2 * Math.sin(theta2) / Math.sin(thetaPrime));
// }
} else if (sweep >= numberOfSweeps && craftTime < endTime)
{
return 2 - 2 * (craftTime - startTime - numberOfSweeps * sweepTime) / (endTime - startTime - numberOfSweeps * sweepTime);
} else if (craftTime >= endTime)
{
return 0;
}
return 2;
}
}