Skip to content

Commit

Permalink
Removed cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Sep 25, 2023
1 parent 8a46b1b commit c81293c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ public void renderBody(T cart, float partialTicks, PoseStack poseStack,
super.renderBody(cart, partialTicks, poseStack, renderTypeBuffer, packedLight,
red, green, blue, alpha);
poseStack.pushPose();
{
var displayOffset = cart.getDisplayOffset();
var scale = 0.75F;
poseStack.scale(scale, scale, scale);
poseStack.translate(-0.5D, (displayOffset - 8.0F) / 16.0F, -0.5D);
var displayOffset = cart.getDisplayOffset();
var scale = 0.75F;
poseStack.scale(scale, scale, scale);
poseStack.translate(-0.5D, (displayOffset - 8.0F) / 16.0F, -0.5D);

this.renderContents(cart, partialTicks, poseStack, renderTypeBuffer, packedLight, red, green,
blue, alpha);
}
this.renderContents(cart, partialTicks, poseStack, renderTypeBuffer, packedLight, red, green,
blue, alpha);
poseStack.popPose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public void render(T cart, float yaw, float partialTicks,
float f = (((float) (i >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
float f1 = (((float) (i >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
float f2 = (((float) (i >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
poseStack.translate((double) f, (double) f1, (double) f2);
double d0 = Mth.lerp((double) partialTicks, cart.xOld, cart.getX());
double d1 = Mth.lerp((double) partialTicks, cart.yOld, cart.getY());
double d2 = Mth.lerp((double) partialTicks, cart.zOld, cart.getZ());
poseStack.translate(f, f1, f2);
double d0 = Mth.lerp(partialTicks, cart.xOld, cart.getX());
double d1 = Mth.lerp(partialTicks, cart.yOld, cart.getY());
double d2 = Mth.lerp(partialTicks, cart.zOld, cart.getZ());
Vec3 vector3d = cart.getPos(d0, d1, d2);
float pitch = Mth.lerp(partialTicks, cart.xRotO, cart.getXRot());
if (vector3d != null) {
Vec3 vector3d1 = cart.getPosOffs(d0, d1, d2, (double) 0.3F);
Vec3 vector3d2 = cart.getPosOffs(d0, d1, d2, (double) -0.3F);
Vec3 vector3d1 = cart.getPosOffs(d0, d1, d2, 0.3F);
Vec3 vector3d2 = cart.getPosOffs(d0, d1, d2, -0.3F);
if (vector3d1 == null) {
vector3d1 = vector3d;
}
Expand All @@ -52,16 +52,16 @@ public void render(T cart, float yaw, float partialTicks,
Vec3 vector3d3 = vector3d2.add(-vector3d1.x, -vector3d1.y, -vector3d1.z);
if (vector3d3.length() != 0.0D) {
vector3d3 = vector3d3.normalize();
yaw = (float) (Math.atan2(vector3d3.z, vector3d3.x) * 180.0D / Math.PI);
pitch = (float) (Math.atan(vector3d3.y) * 73.0D);
yaw = (float) (Math.atan2(vector3d3.z, vector3d3.x) * 180 / Math.PI);
pitch = (float) (Math.atan(vector3d3.y) * 73);
}
}
yaw %= 360;
if (yaw < 0)
yaw += 360;
yaw += 360;

double serverYaw = cart.getYRot();
float serverYaw = cart.getYRot();
serverYaw += 180;
serverYaw %= 360;
if (serverYaw < 0)
Expand Down Expand Up @@ -110,12 +110,10 @@ public void render(T cart, float yaw, float partialTicks,

if (ghostTrain) {
poseStack.pushPose();
{
float scale = 1.1F;
poseStack.scale(scale, scale, scale);
this.renderBody(cart, partialTicks, poseStack, bufferSource, packedLight,
1.0F, 1.0F, 1.0F, 0.4F);
}
float scale = 1.1F;
poseStack.scale(scale, scale, scale);
this.renderBody(cart, partialTicks, poseStack, bufferSource, packedLight,
1.0F, 1.0F, 1.0F, 0.4F);
poseStack.popPose();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mods.railcraft.client.renderer.entity.cart;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import mods.railcraft.Railcraft;
import mods.railcraft.season.Seasons;
import mods.railcraft.world.entity.vehicle.locomotive.Locomotive;
Expand Down Expand Up @@ -72,24 +71,21 @@ public void renderBody(Locomotive cart, float time, PoseStack poseStack,
for (int pass = 0; pass < 3; pass++) {
float[] color = this.color[pass];
this.model.setupAnim(cart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F);
VertexConsumer vertexBuilder =
renderTypeBuffer.getBuffer(this.model.renderType(this.textures[pass]));
var vertexBuilder = renderTypeBuffer.getBuffer(this.model.renderType(this.textures[pass]));
this.model.renderToBuffer(poseStack, vertexBuilder, packedLight, OverlayTexture.NO_OVERLAY,
color[0], color[1], color[2], alpha);
}

if (Seasons.isPolarExpress(cart)) {
this.snowLayer.setupAnim(cart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F);
VertexConsumer vertexBuilder =
renderTypeBuffer.getBuffer(this.snowLayer.renderType(this.textures[3]));
var vertexBuilder = renderTypeBuffer.getBuffer(this.snowLayer.renderType(this.textures[3]));
this.snowLayer.renderToBuffer(poseStack, vertexBuilder, packedLight,
OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
}

this.getEmblemTexture(cart).ifPresent(emblemTexture -> {

VertexConsumer vertexBuilder =
renderTypeBuffer.getBuffer(RenderType.entityTranslucent(emblemTexture));
var vertexBuilder = renderTypeBuffer.getBuffer(RenderType.entityTranslucent(emblemTexture));

// float size = 0.22F;
// float offsetX = -0.25F;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mods.railcraft.client.renderer.entity.cart;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import mods.railcraft.Railcraft;
import mods.railcraft.client.model.ElectricLocomotiveLampModel;
import mods.railcraft.client.model.ElectricLocomotiveModel;
Expand Down Expand Up @@ -43,23 +42,18 @@ public void renderBody(Locomotive cart, float time, PoseStack poseStack,
super.renderBody(cart, time, poseStack, renderTypeBuffer, packedLight, red, green, blue,
alpha);
poseStack.pushPose();
{
poseStack.scale(-1, -1, 1);
poseStack.translate(0.05F, 0.0F, 0.0F);
poseStack.scale(-1, -1, 1);
poseStack.translate(0.05F, 0.0F, 0.0F);

boolean bright = ((Locomotive) cart).getMode() == Locomotive.Mode.RUNNING;
boolean bright = cart.getMode() == Locomotive.Mode.RUNNING;

VertexConsumer vertexBuilder = bright
? renderTypeBuffer.getBuffer(this.lampModel.renderType(this.lampTextureOn))
: renderTypeBuffer.getBuffer(this.lampModel.renderType(this.lampTextureOff));
var vertexBuilder = bright
? renderTypeBuffer.getBuffer(this.lampModel.renderType(this.lampTextureOn))
: renderTypeBuffer.getBuffer(this.lampModel.renderType(this.lampTextureOff));

this.lampModel.renderToBuffer(poseStack, vertexBuilder,
bright ? RenderUtil.FULL_LIGHT : packedLight, OverlayTexture.NO_OVERLAY,
red, green, blue, alpha);

}
this.lampModel.renderToBuffer(poseStack, vertexBuilder,
bright ? RenderUtil.FULL_LIGHT : packedLight, OverlayTexture.NO_OVERLAY,
red, green, blue, alpha);
poseStack.popPose();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,20 @@ protected void renderBody(T cart, float partialTicks, PoseStack poseStack,
MultiBufferSource bufferSource, int packedLight,
float red, float green, float blue, float alpha) {
poseStack.pushPose();
{
poseStack.scale(-1.0F, -1.0F, 1.0F);
var bodyModel = this.getBodyModel(cart);
var bodyVertexConsumer =
bufferSource.getBuffer(bodyModel.renderType(this.getTextureLocation(cart)));
bodyModel.setupAnim(cart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F);
bodyModel.renderToBuffer(poseStack, bodyVertexConsumer, packedLight,
OverlayTexture.NO_OVERLAY, red, green, blue, alpha);

if (Seasons.isPolarExpress(cart)) {
var snowModel = this.getSnowModel(cart);
var snowVertexConsumer =
bufferSource.getBuffer(snowModel.renderType(SNOW_TEXTURE_LOCATION));
snowModel.setupAnim(cart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F);
snowModel.renderToBuffer(poseStack, snowVertexConsumer, packedLight,
OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
}
poseStack.scale(-1.0F, -1.0F, 1.0F);
var bodyModel = this.getBodyModel(cart);
var bodyVertexConsumer =
bufferSource.getBuffer(bodyModel.renderType(this.getTextureLocation(cart)));
bodyModel.setupAnim(cart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F);
bodyModel.renderToBuffer(poseStack, bodyVertexConsumer, packedLight,
OverlayTexture.NO_OVERLAY, red, green, blue, alpha);

if (Seasons.isPolarExpress(cart)) {
var snowModel = this.getSnowModel(cart);
var snowVertexConsumer = bufferSource.getBuffer(snowModel.renderType(SNOW_TEXTURE_LOCATION));
snowModel.setupAnim(cart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F);
snowModel.renderToBuffer(poseStack, snowVertexConsumer, packedLight,
OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
}
poseStack.popPose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/mods/railcraft/world/item/CartItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.BaseRailBlock;
import net.minecraft.world.level.block.state.properties.RailShape;
import net.minecraft.world.level.gameevent.GameEvent;

public class CartItem extends Item {

Expand Down Expand Up @@ -40,6 +41,8 @@ public InteractionResult useOn(UseOnContext context) {
if (minecart != null) {
minecart.setYRot(context.getHorizontalDirection().toYRot());
level.addFreshEntity(minecart);
level.gameEvent(GameEvent.ENTITY_PLACE, railPos,
GameEvent.Context.of(player, level.getBlockState(railPos.below())));
itemStack.shrink(1);
}
}
Expand Down

0 comments on commit c81293c

Please sign in to comment.