-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic for energy support, closes #3.
Computer and robot now consume energy; constant amount per tick while running. Added charger block to allow charging robots. Charger can charge anything with IEnergyStorage capability and items with it in an ItemHandler on top of it. Also some renames, mostly nbt -> tag.
- Loading branch information
Showing
53 changed files
with
985 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/li/cil/oc2/client/renderer/tileentity/ChargerTileEntityRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package li.cil.oc2.client.renderer.tileentity; | ||
|
||
import com.mojang.blaze3d.matrix.MatrixStack; | ||
import com.mojang.blaze3d.vertex.IVertexBuilder; | ||
import li.cil.oc2.api.API; | ||
import li.cil.oc2.client.renderer.CustomRenderType; | ||
import li.cil.oc2.common.tileentity.ChargerTileEntity; | ||
import net.minecraft.client.renderer.IRenderTypeBuffer; | ||
import net.minecraft.client.renderer.model.RenderMaterial; | ||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer; | ||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; | ||
import net.minecraft.inventory.container.PlayerContainer; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.vector.Matrix4f; | ||
|
||
public final class ChargerTileEntityRenderer extends TileEntityRenderer<ChargerTileEntity> { | ||
public static final ResourceLocation EFFECT_LOCATION = new ResourceLocation(API.MOD_ID, "block/charger/effect"); | ||
|
||
private static final RenderMaterial TEXTURE_EFFECT = new RenderMaterial(PlayerContainer.LOCATION_BLOCKS_TEXTURE, EFFECT_LOCATION); | ||
|
||
private static final int EFFECT_LAYERS = 3; | ||
private static final float EFFECT_HEIGHT = 0.5f; | ||
private static final float EFFECT_SPEED = 0.1f; | ||
private static final float EFFECT_SCALE_START = 0.6f; | ||
private static final float EFFECT_SCALE_END = 0.8f; | ||
|
||
/////////////////////////////////////////////////////////////////// | ||
|
||
private float offset = 0; | ||
|
||
/////////////////////////////////////////////////////////////////// | ||
|
||
public ChargerTileEntityRenderer(final TileEntityRendererDispatcher dispatcher) { | ||
super(dispatcher); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////// | ||
|
||
@Override | ||
public void render(final ChargerTileEntity tileEntity, final float partialTicks, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int light, final int overlay) { | ||
offset = (offset + EFFECT_SPEED * partialTicks / 20f) % (float) (Math.PI * 2); | ||
|
||
matrixStack.push(); | ||
matrixStack.translate(0.5, 1.1, 0.5); | ||
|
||
final IVertexBuilder builder = TEXTURE_EFFECT.getBuffer(buffer, CustomRenderType::getUnlitBlock); | ||
|
||
for (int i = 0; i < EFFECT_LAYERS; i++) { | ||
final float relativeY = (1 + MathHelper.sin(offset + ((float) Math.PI * 2f * i / EFFECT_LAYERS))) * 0.5f; | ||
final float y = relativeY * EFFECT_HEIGHT; | ||
final float scale = EFFECT_SCALE_START + relativeY * (EFFECT_SCALE_END - EFFECT_SCALE_START); | ||
|
||
matrixStack.push(); | ||
matrixStack.translate(0, y, 0); | ||
renderScaledQuad(matrixStack, builder, scale); | ||
matrixStack.pop(); | ||
} | ||
|
||
matrixStack.pop(); | ||
} | ||
|
||
private static void renderScaledQuad(final MatrixStack matrixStack, final IVertexBuilder builder, final float scale) { | ||
matrixStack.push(); | ||
matrixStack.scale(scale, scale, scale); | ||
renderQuad(matrixStack.getLast().getMatrix(), builder); | ||
matrixStack.pop(); | ||
} | ||
|
||
private static void renderQuad(final Matrix4f matrix, final IVertexBuilder builder) { | ||
// NB: We may get a SpriteAwareVertexBuilder here. Sadly, its chaining is broken, | ||
// because methods may return the underlying vertex builder, so e.g. calling | ||
// buffer.pos(...).tex(...) will not actually call SpriteAwareVertexBuilder.tex(...) | ||
// but SpriteAwareVertexBuilder.vertexBuilder.tex(...), skipping the UV remapping. | ||
builder.pos(matrix, -0.5f, 0, -0.5f); | ||
builder.tex(0, 0); | ||
builder.endVertex(); | ||
|
||
builder.pos(matrix, -0.5f, 0, 0.5f); | ||
builder.tex(0, 1); | ||
builder.endVertex(); | ||
|
||
builder.pos(matrix, 0.5f, 0, 0.5f); | ||
builder.tex(1, 1); | ||
builder.endVertex(); | ||
|
||
builder.pos(matrix, 0.5f, 0, -0.5f); | ||
builder.tex(1, 0); | ||
builder.endVertex(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.