Skip to content

Commit

Permalink
more general rendering adjustments
Browse files Browse the repository at this point in the history
fixes some issues with transparencies in textures, this makes gastly more foggy, and fixes the issue with the glasses.

improved smoothness of animations in various guis
  • Loading branch information
Thutmose committed Sep 7, 2022
1 parent b5ada12 commit 79de02c
Show file tree
Hide file tree
Showing 23 changed files with 264 additions and 143 deletions.
Binary file added blender_files/mega_glasses.blend
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public void render(final PoseStack matrixStack, final int mouseX, final int mous
final int dx = -50;
final int dy = +20;
// Draw the actual pokemob
GuiPokemobBase.renderMob(this.pokemob.getEntity(), x + dx, y + dy, 0, yaw, 0, yaw, 0.75f);
GuiPokemobBase.renderMob(this.pokemob.getEntity(), x + dx, y + dy, 0, yaw, 0, yaw, 0.75f, partialTicks);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,10 @@ public void render(final PoseStack matrixStack, final int mouseX, final int mous
final int dy = 10;
int i = 0;

LivingEntity mob;
if (this.parent.entity instanceof LivingEntity)
if (this.parent.entity instanceof LivingEntity mob)
{
mob = (LivingEntity) this.parent.entity;
final float yaw = Util.getMillis() / 40;
GuiPokemobBase.renderMob(mob, x - 60, y + 80, 0, yaw, 0, yaw, 1f);
GuiPokemobBase.renderMob(mob, x - 60, y + 80, 0, yaw, 0, yaw, 1f, partialTicks);
}

this.font.draw(matrixStack, I18n.get("Trainer Type"), x + 20, y + dy * i++, 0xFFFFFFFF);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package pokecube.adventures.client.render.layers;

import java.util.Set;
import java.lang.reflect.Field;
import java.util.Map;

import com.google.common.collect.Sets;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import pokecube.api.entity.trainers.IHasPokemobs;
import pokecube.api.entity.trainers.TrainerCaps;
import thut.wearables.EnumWearable;
Expand All @@ -29,21 +33,43 @@
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class BeltLayerRender<T extends LivingEntity, M extends HumanoidModel<T>> extends RenderLayer<T, M>
{

private static final Set<RenderLayerParent<?, ?>> addedLayers = Sets.newHashSet();

@SuppressWarnings(
{ "rawtypes", "unchecked" })
@SubscribeEvent
public static void renderSpecial(final RenderLivingEvent.Post<LivingEntity, EntityModel<LivingEntity>> event)
public static void registerLayers(final EntityRenderersEvent.AddLayers event)
{
// Only apply to model bipeds.
if (!(event.getRenderer().getModel() instanceof HumanoidModel<?>)) return;
// Only one layer per renderer.
if (addedLayers.contains(event.getRenderer())) return;
event.getRenderer().addLayer(new BeltLayerRender(event.getRenderer()));
try
{
Field f = event.getClass().getDeclaredField("renderers");
f.setAccessible(true);
Map<EntityType<?>, EntityRenderer<?>> renderers = (Map<EntityType<?>, EntityRenderer<?>>) f.get(event);
for (EntityType<?> type : ForgeRegistries.ENTITIES.getValues())
{
EntityRenderer<?> render = renderers.get(type);
if (render instanceof LivingEntityRenderer livingRender
&& livingRender.getModel() instanceof HumanoidModel)
{
livingRender.addLayer(new BeltLayerRender(livingRender));
}
}

EntityRenderer<? extends Player> renderer = event.getSkin("slim");
if (renderer instanceof LivingEntityRenderer livingRenderer)
{
livingRenderer.addLayer(new BeltLayerRender<>(livingRenderer));
}

renderer = event.getSkin("default");
if (renderer instanceof LivingEntityRenderer livingRenderer)
{
livingRenderer.addLayer(new BeltLayerRender<>(livingRenderer));
}
}
catch (Exception e)
{
e.printStackTrace();
}

addedLayers.add(event.getRenderer());
}

private final RenderLayerParent<?, ?> parent;
Expand Down Expand Up @@ -73,7 +99,7 @@ public void render(final PoseStack mat, final MultiBufferSource buff, final int

mat.pushPose();
theModel.body.translateAndRotate(mat);
mat.translate(0, 0.65, -.125);
mat.translate(0, 0.7, -.125);
mat.mulPose(Vector3f.XP.rotationDegrees(180));
mat.mulPose(Vector3f.YP.rotationDegrees(180));
mat.scale(0.25f, 0.25f, 0.25f);
Expand Down Expand Up @@ -117,7 +143,6 @@ public void render(final PoseStack mat, final MultiBufferSource buff, final int
buff, packedLightIn);
mat.popPose();
}

mat.popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void render(final PoseStack mat, final VertexConsumer buffer)
mat.pushPose();
this.preRender(mat);
mat.translate(this.offsets.offset.x, this.offsets.offset.y, this.offsets.offset.z);

mat.scale(1, -1, -1);
mat.mulPose(Vector3f.YP.rotationDegrees(180));

Expand Down Expand Up @@ -163,25 +164,29 @@ public static void applyWearables(final LivingEntity wearer, final IModelRendere
if (offsets != null && imodel.getParts().containsKey(offsets.parent))
{
WearableRenderWrapper wrapper;
final IExtendedModelPart part = imodel.getParts().get(offsets.parent);
if (imodel.getParts().get(ident) instanceof WearableRenderWrapper wrap)
{
wrapper = wrap;
}
else
{
wrapper = new WearableRenderWrapper(ident, offsets);
final IExtendedModelPart part = imodel.getParts().get(offsets.parent);
wrapper.setParent(part);
part.addChild(wrapper);
part.getRenderOrder().add(ident);
imodel.getParts().put(ident, wrapper);
imodel.getRenderOrder().add(ident);
}
wrapper.setOffsets(offsets);
wrapper.slot = wearable;
wrapper.wearer = wearer;
wrapper.stack = worn.getWearable(wearable);
wrapper.wrapped = w;
wrapper.subIndex = i;
imodel.getRenderOrder().remove(ident);
imodel.getRenderOrder().add(ident);
part.preProcess();
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/pokecube/core/client/gui/AnimationGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ else if (s < sml)
}

@Override
public void render(final PoseStack mat, final int unk1, final int unk2, final float partialTicks)
public void render(final PoseStack mat, final int unk1, final int unk2, float partialTicks)
{
if (this.bg)
{
Expand All @@ -463,6 +463,8 @@ public void render(final PoseStack mat, final int unk1, final int unk2, final fl
}
super.render(mat, unk1, unk2, partialTicks);

if (this.isPauseScreen()) partialTicks = 0;

final int yOffset = this.height / 2;
this.font.draw(mat, "State-General", this.width - 101, yOffset - 42 - yOffset / 2, 0xFFFFFF);
this.font.draw(mat, "State-Combat", this.width - 101, yOffset - 22 - yOffset / 2, 0xFFFFFF);
Expand Down Expand Up @@ -514,7 +516,7 @@ public void render(final PoseStack mat, final int unk1, final int unk2, final fl
if (l <= 0.0001 || l > 1e10) AnimationGui.entry.getModelSize().set(1, 1, 1);
GuiPokemobBase.autoScale = false;
GuiPokemobBase.renderMob(mat, entity, j, k, this.yRenderAngle, this.xRenderAngle, this.yHeadRenderAngle,
this.xHeadRenderAngle, zoom);
this.xHeadRenderAngle, zoom, partialTicks);
GuiPokemobBase.autoScale = true;
if (this.renderHolder != null) this.renderHolder.overrideAnim = false;
mat.popPose();
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/pokecube/core/client/gui/GuiChooseFirstPokemob.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class GuiChooseFirstPokemob extends Screen
{

public final static float POKEDEX_RENDER = 1.5f;
public static boolean special = false;
public static boolean pick = false;
public static boolean special = false;
public static boolean pick = false;

public static PokedexEntry[] starters;

Expand All @@ -47,9 +47,9 @@ public class GuiChooseFirstPokemob extends Screen

private boolean gotSpecial = true;

protected Player player = null;
protected Player player = null;
protected PokedexEntry pokedexEntry = null;
int index = 0;
int index = 0;

Button next;

Expand Down Expand Up @@ -94,23 +94,23 @@ public void init()
if (GuiChooseFirstPokemob.starters.length > 0)
{
final Component next = TComponent.translatable("block.pc.next");
this.addRenderableWidget(this.next = new Button(this.width / 2 - xOffset + 65, this.height / 2 - yOffset,
50, 20, next, b ->
this.addRenderableWidget(
this.next = new Button(this.width / 2 - xOffset + 65, this.height / 2 - yOffset, 50, 20, next, b ->
{
this.index++;
if (this.index >= GuiChooseFirstPokemob.starters.length) this.index = 0;
}));
final Component prev = TComponent.translatable("block.pc.previous");
this.addRenderableWidget(this.prev = new Button(this.width / 2 - xOffset - 115, this.height / 2 - yOffset,
50, 20, prev, b ->
this.addRenderableWidget(
this.prev = new Button(this.width / 2 - xOffset - 115, this.height / 2 - yOffset, 50, 20, prev, b ->
{
if (this.index > 0) this.index--;
else this.index = GuiChooseFirstPokemob.starters.length - 1;
}));
}

this.addRenderableWidget(this.choose = new Button(this.width / 2 - xOffset - 25, this.height / 2 - yOffset
+ 160, 50, 20, TComponent.translatable("gui.pokemob.select"), b ->
this.addRenderableWidget(this.choose = new Button(this.width / 2 - xOffset - 25,
this.height / 2 - yOffset + 160, 50, 20, TComponent.translatable("gui.pokemob.select"), b ->
{
this.sendMessage(this.pokedexEntry);
this.player.closeContainer();
Expand Down Expand Up @@ -171,7 +171,8 @@ public void render(final PoseStack mat, final int i, final int j, final float f)
return;
}
if (GuiChooseFirstPokemob.starters == null || GuiChooseFirstPokemob.starters.length == 0)
GuiChooseFirstPokemob.starters = new PokedexEntry[] { Pokedex.getInstance().getFirstEntry() };
GuiChooseFirstPokemob.starters = new PokedexEntry[]
{ Pokedex.getInstance().getFirstEntry() };

this.pokedexEntry = GuiChooseFirstPokemob.starters[this.index % GuiChooseFirstPokemob.starters.length];

Expand All @@ -185,8 +186,8 @@ public void render(final PoseStack mat, final int i, final int j, final float f)
GuiComponent.drawCenteredString(mat, this.font, I18n.get("gui.pokemob.choose1st"), this.width / 2, 17,
0xffffff);

GuiComponent.drawCenteredString(mat, this.font, I18n.get(this.pokedexEntry.getUnlocalizedName()), this.width
/ 2, 45, 0xffffff);
GuiComponent.drawCenteredString(mat, this.font, I18n.get(this.pokedexEntry.getUnlocalizedName()),
this.width / 2, 45, 0xffffff);

int n = 0;
int m = 0;
Expand All @@ -195,9 +196,9 @@ public void render(final PoseStack mat, final int i, final int j, final float f)
final int l = 40;
final int k = 150;

if (this.pokedexEntry.getType2() == PokeType.unknown) GuiComponent.drawCenteredString(mat, this.font, PokeType
.getTranslatedName(this.pokedexEntry.getType1()), this.width / 2, 65, this.pokedexEntry
.getType1().colour);
if (this.pokedexEntry.getType2() == PokeType.unknown)
GuiComponent.drawCenteredString(mat, this.font, PokeType.getTranslatedName(this.pokedexEntry.getType1()),
this.width / 2, 65, this.pokedexEntry.getType1().colour);
else
{
GuiComponent.drawCenteredString(mat, this.font, PokeType.getTranslatedName(this.pokedexEntry.getType1()),
Expand Down Expand Up @@ -241,7 +242,7 @@ public void render(final PoseStack mat, final int i, final int j, final float f)
GuiComponent.drawCenteredString(mat, this.font, DS + ": ", n + k - 18, m + l + 55, 0x57933A);
GuiComponent.drawCenteredString(mat, this.font, S + ": ", n + k - 10, m + l + 67, 0xB44062);

this.renderMob(mat);
this.renderMob(mat, f);
this.renderItem(n + 00, m + 75, 40);
}

Expand Down Expand Up @@ -271,7 +272,7 @@ public void renderItem(final double x, final double y, final double z)
}
}

private void renderMob(final PoseStack stack)
private void renderMob(final PoseStack stack, float partialTicks)
{
try
{
Expand All @@ -291,7 +292,7 @@ private void renderMob(final PoseStack stack)
//@formatter:on
stack.pushPose();
stack.translate(0, 0, 100);
GuiPokemobBase.renderMob(entity, dx, dy, 0, yaw, hx, hy, size);
GuiPokemobBase.renderMob(entity, dx, dy, 0, yaw, hx, hy, size, partialTicks);
stack.popPose();
}
catch (final Throwable e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ else if ((lastMove = MovesUtils.getMoveFromName(pokemob.getLastMoveUsed())) != n
this.blit(evt.getMat(), mobOffsetX, mobOffsetY, 0, 0, 42, 42);

GuiPokemobBase.renderMob(evt.getMat(), pokemob.getEntity(), mobOffsetX - 30, mobOffsetY - 25, 0, 0, 0, 0,
0.75f);
0.75f, Minecraft.getInstance().getFrameTime());
evt.getMat().popPose();
}
}
Expand Down Expand Up @@ -468,7 +468,8 @@ public void drawTarget(final GuiEvent.RenderTargetInfo evt)
final int mobBoxOffsetY = 0;
this.blit(evt.getMat(), mobBoxOffsetX, mobBoxOffsetY, 0, 0, 42, 42);
// Render Mob
GuiPokemobBase.renderMob(evt.getMat(), entity, mobBoxOffsetX - 30, mobBoxOffsetY - 25, 0, 0, 0, 0, 0.75f);
GuiPokemobBase.renderMob(evt.getMat(), entity, mobBoxOffsetX - 30, mobBoxOffsetY - 25, 0, 0, 0, 0, 0.75f,
Minecraft.getInstance().getFrameTime());
evt.getMat().popPose();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pokecube/core/client/gui/GuiPokedex.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void render(final PoseStack mat, final int mouseX, final int mouseY, fina
final float pitch = 0;
final float hx = 0;
final float hy = yaw;
GuiPokemobBase.renderMob(renderMob.getEntity(), j2, k2 + 40, pitch, yaw, hx, hy, 1);
GuiPokemobBase.renderMob(renderMob.getEntity(), j2, k2 + 40, pitch, yaw, hx, hy, 1, partialTick);

// Draw info about mob
final int yOffset = this.height / 2 - 80;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/pokecube/core/client/gui/WearableSetupGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void onUpdated()
}

@Override
public void render(final PoseStack mat, final int unk1, final int unk2, final float partialTicks)
public void render(final PoseStack mat, final int unk1, final int unk2, float partialTicks)
{
if (this.bg)
{
Expand Down Expand Up @@ -366,8 +366,10 @@ public void render(final PoseStack mat, final int unk1, final int unk2, final fl
// Sometimes things go bad and this happens
if (l <= 0.0001 || l > 1e10) WearableSetupGui.entry.getModelSize().set(1, 1, 1);
GuiPokemobBase.autoScale = false;
if (this.isPauseScreen()) partialTicks = 0;
else partialTicks = Minecraft.getInstance().getFrameTime();
GuiPokemobBase.renderMob(mat, entity, j, k, this.yRenderAngle, this.xRenderAngle, this.yHeadRenderAngle,
this.xHeadRenderAngle, zoom);
this.xHeadRenderAngle, zoom, partialTicks);
GuiPokemobBase.autoScale = true;
if (this.renderHolder != null) this.renderHolder.overrideAnim = false;
mat.popPose();
Expand Down
Loading

0 comments on commit 79de02c

Please sign in to comment.