Contraption actors and blockzapper screen

- Fixed harvesters and drill animating incorrectly on contraptions
- Ported blockzapper and worldshaper screen
This commit is contained in:
simibubi 2020-05-28 13:37:15 +02:00
parent 467af2ea20
commit c53f9c2079
4 changed files with 47 additions and 70 deletions

View file

@ -7,6 +7,7 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.utility.MatrixStacker;
import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.foundation.utility.SuperByteBuffer;
@ -16,6 +17,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.util.Direction;
public class DrillRenderer extends KineticTileEntityRenderer { public class DrillRenderer extends KineticTileEntityRenderer {
@ -25,7 +27,7 @@ public class DrillRenderer extends KineticTileEntityRenderer {
@Override @Override
protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { protected SuperByteBuffer getRotatedModel(KineticTileEntity te) {
return getRotatingModel(te.getBlockState()); return AllBlockPartials.DRILL_HEAD.renderOnDirectional(te.getBlockState());
} }
protected static SuperByteBuffer getRotatingModel(BlockState state) { protected static SuperByteBuffer getRotatingModel(BlockState state) {
@ -36,20 +38,25 @@ public class DrillRenderer extends KineticTileEntityRenderer {
IRenderTypeBuffer buffer) { IRenderTypeBuffer buffer) {
MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal }; MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal };
BlockState state = context.state; BlockState state = context.state;
SuperByteBuffer superBuffer = getRotatingModel(state); SuperByteBuffer superBuffer = AllBlockPartials.DRILL_HEAD.renderOn(state);
Direction facing = state.get(DrillBlock.FACING);
float speed = (float) (context.contraption.stalled float speed = (float) (context.contraption.stalled
|| !VecHelper.isVecPointingTowards(context.relativeMotion, state.get(FACING) || !VecHelper.isVecPointingTowards(context.relativeMotion, state.get(FACING)
.getOpposite()) ? context.getAnimationSpeed() : 0); .getOpposite()) ? context.getAnimationSpeed() : 0);
float time = AnimationTickHolder.getRenderTick() / 20; float time = AnimationTickHolder.getRenderTick() / 20;
float angle = (float) (((time * speed) % 360) / 180 * (float) Math.PI); float angle = (float) (((time * speed) % 360));
for (MatrixStack m : matrixStacks) for (MatrixStack m : matrixStacks)
MatrixStacker.of(m) MatrixStacker.of(m)
.centre() .centre()
.rotateY(angle) .rotateY(AngleHelper.horizontalAngle(facing))
.rotateX(AngleHelper.verticalAngle(facing))
.rotateZ(angle)
.unCentre(); .unCentre();
superBuffer.light(msLocal.peek()
superBuffer
.light(msLocal.peek()
.getModel()) .getModel())
.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); .renderInto(ms, buffer.getBuffer(RenderType.getSolid()));
} }

View file

@ -6,8 +6,8 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.MatrixStacker;
import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.VecHelper;
@ -16,7 +16,6 @@ import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -30,42 +29,36 @@ public class HarvesterRenderer extends SafeTileEntityRenderer<HarvesterTileEntit
protected void renderSafe(HarvesterTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, protected void renderSafe(HarvesterTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) { int light, int overlay) {
BlockState blockState = te.getBlockState(); BlockState blockState = te.getBlockState();
SuperByteBuffer superBuffer = AllBlockPartials.HARVESTER_BLADE.renderOnHorizontal(blockState); SuperByteBuffer superBuffer = AllBlockPartials.HARVESTER_BLADE.renderOnHorizontal(blockState);
transformHead(ms, 0);
superBuffer.light(light) superBuffer.light(light)
.renderInto(ms, buffer.getBuffer(RenderType.getCutoutMipped())); .renderInto(ms, buffer.getBuffer(RenderType.getCutoutMipped()));
} }
public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal,
IRenderTypeBuffer buffers) { IRenderTypeBuffer buffers) {
MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal };
BlockState blockState = context.state; BlockState blockState = context.state;
Direction facing = blockState.get(HORIZONTAL_FACING); Direction facing = blockState.get(HORIZONTAL_FACING);
SuperByteBuffer superBuffer = AllBlockPartials.HARVESTER_BLADE.renderOnHorizontal(blockState); SuperByteBuffer superBuffer = AllBlockPartials.HARVESTER_BLADE.renderOn(blockState);
int offset = facing.getAxisDirection()
.getOffset() * (facing.getAxis() == Axis.X ? 1 : -1);
float speed = (float) (!VecHelper.isVecPointingTowards(context.relativeMotion, facing.getOpposite()) float speed = (float) (!VecHelper.isVecPointingTowards(context.relativeMotion, facing.getOpposite())
? context.getAnimationSpeed() * offset ? context.getAnimationSpeed()
: 0); : 0);
if (context.contraption.stalled) if (context.contraption.stalled)
speed = 0; speed = 0;
float time = AnimationTickHolder.getRenderTick() / 20; float time = AnimationTickHolder.getRenderTick() / 20;
float angle = (time * speed) % 360; float angle = (time * speed) % 360;
float originOffset = 1 / 16f;
Vec3d rotOffset = new Vec3d(0, -2 * originOffset, originOffset).add(VecHelper.getCenterOf(BlockPos.ZERO));
for (MatrixStack m : matrixStacks) superBuffer.rotateCentered(Direction.UP, AngleHelper.rad(AngleHelper.horizontalAngle(facing)))
transformHead(m, angle); .translate(rotOffset.x, rotOffset.y, rotOffset.z)
superBuffer.light(msLocal.peek().getModel()) .rotate(Direction.WEST, AngleHelper.rad(angle))
.translate(-rotOffset.x, -rotOffset.y, -rotOffset.z)
.light(msLocal.peek()
.getModel())
.renderInto(ms, buffers.getBuffer(RenderType.getCutoutMipped())); .renderInto(ms, buffers.getBuffer(RenderType.getCutoutMipped()));
} }
public static void transformHead(MatrixStack ms, float angle) { public static void transformHead(MatrixStack ms, float angle) {}
float originOffset = 1 / 16f;
Vec3d offset = new Vec3d(0, -2 * originOffset, -originOffset).add(VecHelper.getCenterOf(BlockPos.ZERO));
MatrixStacker.of(ms)
.translate(offset)
.rotateX(angle)
.translateBack(offset);
}
} }

View file

@ -2,9 +2,6 @@ package com.simibubi.create.content.curiosities.zapper;
import java.util.Vector; import java.util.Vector;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AbstractSimiScreen;
import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllGuiTextures;
@ -17,10 +14,7 @@ import com.simibubi.create.foundation.utility.Lang;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.NBTUtil;
@ -68,12 +62,14 @@ public class ZapperScreen extends AbstractSimiScreen {
int id = patternButtons.size(); int id = patternButtons.size();
PlacementPatterns pattern = PlacementPatterns.values()[id]; PlacementPatterns pattern = PlacementPatterns.values()[id];
patternButtons.add(new IconButton(i + 147 + col * 18, j + 23 + row * 18, pattern.icon)); patternButtons.add(new IconButton(i + 147 + col * 18, j + 23 + row * 18, pattern.icon));
patternButtons.get(id).setToolTip(Lang.translate("gui.blockzapper.pattern." + pattern.translationKey)); patternButtons.get(id)
.setToolTip(Lang.translate("gui.blockzapper.pattern." + pattern.translationKey));
} }
} }
if (nbt.contains("Pattern")) if (nbt.contains("Pattern"))
patternButtons.get(PlacementPatterns.valueOf(nbt.getString("Pattern")).ordinal()).active = false; patternButtons.get(PlacementPatterns.valueOf(nbt.getString("Pattern"))
.ordinal()).active = false;
widgets.addAll(patternButtons); widgets.addAll(patternButtons);
} }
@ -86,7 +82,8 @@ public class ZapperScreen extends AbstractSimiScreen {
background.draw(this, i, j); background.draw(this, i, j);
drawOnBackground(i, j); drawOnBackground(i, j);
minecraft.getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE); minecraft.getTextureManager()
.bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
RenderSystem.enableBlend(); RenderSystem.enableBlend();
renderBlock(); renderBlock();
@ -120,7 +117,8 @@ public class ZapperScreen extends AbstractSimiScreen {
if (patternButton.isHovered()) { if (patternButton.isHovered()) {
patternButtons.forEach(b -> b.active = true); patternButtons.forEach(b -> b.active = true);
patternButton.active = false; patternButton.active = false;
patternButton.playDownSound(Minecraft.getInstance().getSoundHandler()); patternButton.playDownSound(Minecraft.getInstance()
.getSoundHandler());
nbt.putString("Pattern", PlacementPatterns.values()[patternButtons.indexOf(patternButton)].name()); nbt.putString("Pattern", PlacementPatterns.values()[patternButtons.indexOf(patternButton)].name());
} }
} }
@ -129,50 +127,29 @@ public class ZapperScreen extends AbstractSimiScreen {
} }
protected void renderZapper() { protected void renderZapper() {
RenderSystem.pushLightingAttributes(); GuiGameElement.of(zapper)
RenderSystem.pushMatrix(); .at((this.width - this.sWidth) / 2 + 210, this.height / 2 - this.sHeight / 4)
.scale(4)
RenderHelper.enable(); .render();
RenderSystem.enableBlend();
RenderSystem.enableRescaleNormal();
RenderSystem.enableAlphaTest();
RenderSystem.alphaFunc(516, 0.1F);
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.translated((this.width - this.sWidth) / 2 + 260, this.height / 2 - this.sHeight / 4, 100);
RenderSystem.rotatef(90 + 0.2f * animationProgress, 0, 1, 0);
RenderSystem.rotatef(-40, .8f, 0, -.0f);
RenderSystem.scaled(100, -100, 100);
itemRenderer.renderItem(zapper, TransformType.FIXED, 0xF000F0, OverlayTexture.DEFAULT_UV, new MatrixStack(), getMinecraft().getBufferBuilders().getEntityVertexConsumers());
RenderSystem.disableAlphaTest();
RenderSystem.disableRescaleNormal();
RenderSystem.disableLighting();
RenderSystem.popMatrix();
RenderSystem.popAttributes();
} }
protected void renderBlock() { protected void renderBlock() {
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.translated(guiLeft + 1.7f, guiTop - 49, 120); RenderSystem.translated(guiLeft + 1.7f, guiTop + 48, 120);
RenderSystem.rotatef(-30f, .5f, .9f, -.1f); RenderSystem.rotatef(-30f, .5f, .9f, -.1f);
RenderSystem.scaled(20, -20, 20); RenderSystem.scaled(20, 20, 20);
BlockState state = Blocks.AIR.getDefaultState(); BlockState state = Blocks.AIR.getDefaultState();
if (zapper.hasTag() && zapper.getTag().contains("BlockUsed")) if (zapper.hasTag() && zapper.getTag()
state = NBTUtil.readBlockState(zapper.getTag().getCompound("BlockUsed")); .contains("BlockUsed"))
state = NBTUtil.readBlockState(zapper.getTag()
RenderSystem.translated(0, -5, 0); .getCompound("BlockUsed"));
GuiGameElement.of(state).render();
GuiGameElement.of(state)
.render();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
protected void writeAdditionalOptions(CompoundNBT nbt) { protected void writeAdditionalOptions(CompoundNBT nbt) {}
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB