Skip to content

Commit

Permalink
load supporter game profiles correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Aug 9, 2024
1 parent 7427b7a commit 457bcad
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.teamlapen.vampirism.client;

import com.mojang.authlib.GameProfile;
import de.teamlapen.lib.lib.util.IInitListener;
import de.teamlapen.lib.util.OptifineHandler;
import de.teamlapen.vampirism.REFERENCE;
Expand All @@ -14,8 +15,10 @@
import de.teamlapen.vampirism.client.renderer.VampirismClientEntityRegistry;
import de.teamlapen.vampirism.proxy.ClientProxy;
import de.teamlapen.vampirism.proxy.IProxy;
import de.teamlapen.vampirism.util.SupporterManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
Expand All @@ -24,11 +27,16 @@
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.AddReloadListenerEvent;
import net.neoforged.neoforge.event.level.LevelEvent;
import net.neoforged.neoforge.registries.datamaps.DataMapsUpdatedEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

@Mod(value = REFERENCE.MODID, dist = Dist.CLIENT)
public class VampirismModClient {
private static final Logger LOGGER = LogManager.getLogger();
Expand Down Expand Up @@ -56,6 +64,7 @@ public VampirismModClient(IEventBus modEventBus, ModContainer modContainer) {
NeoForge.EVENT_BUS.register(new ClientEventHandler());
NeoForge.EVENT_BUS.register(new ScreenEventHandler());
NeoForge.EVENT_BUS.register(new ModKeys());
NeoForge.EVENT_BUS.addListener(this::levelLoaded);

if (OptifineHandler.isOptifineLoaded()) {
LOGGER.warn("Using Optifine. Expect visual glitches and reduces blood vision functionality if using shaders.");
Expand Down Expand Up @@ -83,6 +92,13 @@ public void setupClient(@NotNull FMLClientSetupEvent event) {
});
}

public void levelLoaded(LevelEvent.Load load) {
List<CompletableFuture<Optional<GameProfile>>> list = SupporterManager.getSupporter().map(s -> SkullBlockEntity.fetchGameProfile(s.texture())).toList();
CompletableFuture.allOf(list.toArray(new CompletableFuture[0]))
.thenApply(v -> list.stream().map(CompletableFuture::join).filter(Optional::isPresent).map(Optional::get).toList())
.thenAcceptAsync(profile -> profile.forEach(s -> Minecraft.getInstance().getSkinManager().getInsecureSkin(s)));
}

public void onDataMapsUpdated(DataMapsUpdatedEvent event) {
((VampirismClientEntityRegistry)VampirismAPI.entityRegistry()).syncOverlays();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.teamlapen.vampirism.client.renderer.entity;

import com.mojang.blaze3d.vertex.PoseStack;
import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.api.entity.hunter.IAdvancedHunter;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.client.core.ModEntitiesRender;
Expand All @@ -10,17 +9,16 @@
import de.teamlapen.vampirism.client.renderer.entity.layers.PlayerFaceOverlayLayer;
import de.teamlapen.vampirism.config.VampirismConfig;
import de.teamlapen.vampirism.entity.hunter.AdvancedHunterEntity;
import de.teamlapen.vampirism.util.PlayerModelType;
import net.minecraft.client.model.HumanoidArmorModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -30,8 +28,8 @@
@OnlyIn(Dist.CLIENT)
public class AdvancedHunterRenderer extends DualBipedRenderer<AdvancedHunterEntity, BasicHunterModel<AdvancedHunterEntity>> {
private static final ResourceLocation textureCloak = VResourceLocation.mod("textures/entity/hunter_cloak.png");
private final ResourceLocation texture = VResourceLocation.mod("textures/entity/hunter_base1.png");
private final Pair<ResourceLocation, PlayerModelType> @NotNull [] textures;
private static final PlayerSkin fallback = new PlayerSkin(VResourceLocation.mod("textures/entity/hunter_base1.png"), null, null, null, PlayerSkin.Model.WIDE, false);
private final @NotNull PlayerSkin[] textures;


public AdvancedHunterRenderer(EntityRendererProvider.@NotNull Context context) {
Expand All @@ -44,14 +42,13 @@ public AdvancedHunterRenderer(EntityRendererProvider.@NotNull Context context) {
this.getModel().hat.visible = false;
this.textures = gatherTextures("textures/entity/hunter", true);
} else {
//noinspection unchecked
this.textures = new Pair[]{};
this.textures = new PlayerSkin[]{};
}
}

@Override
protected Pair<ResourceLocation, PlayerModelType> determineTextureAndModel(@NotNull AdvancedHunterEntity entity) {
if (this.textures.length == 0) return Pair.of(texture, PlayerModelType.WIDE);
protected PlayerSkin determineTextureAndModel(@NotNull AdvancedHunterEntity entity) {
if (this.textures.length == 0) return fallback;
return this.textures[entity.getBodyTexture() % this.textures.length];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package de.teamlapen.vampirism.client.renderer.entity;

import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.client.core.ModEntitiesRender;
import de.teamlapen.vampirism.client.model.BasicHunterModel;
import de.teamlapen.vampirism.client.renderer.entity.layers.CloakLayer;
import de.teamlapen.vampirism.entity.hunter.BasicHunterEntity;
import de.teamlapen.vampirism.util.PlayerModelType;
import net.minecraft.client.model.HumanoidArmorModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.resources.ResourceLocation;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;


Expand All @@ -24,7 +22,7 @@ public class BasicHunterRenderer extends DualBipedRenderer<BasicHunterEntity, Ba

private static final ResourceLocation textureCloak = VResourceLocation.mod("textures/entity/hunter_cloak.png");

private final Pair<ResourceLocation, PlayerModelType> @NotNull [] textures;
private final @NotNull PlayerSkin[] textures;

public BasicHunterRenderer(EntityRendererProvider.@NotNull Context context) {
super(context, new BasicHunterModel<>(context.bakeLayer(ModEntitiesRender.HUNTER), false), new BasicHunterModel<>(context.bakeLayer(ModEntitiesRender.HUNTER_SLIM), true), 0.5F);
Expand All @@ -35,7 +33,7 @@ public BasicHunterRenderer(EntityRendererProvider.@NotNull Context context) {


@Override
protected Pair<ResourceLocation, PlayerModelType> determineTextureAndModel(@NotNull BasicHunterEntity entity) {
protected PlayerSkin determineTextureAndModel(@NotNull BasicHunterEntity entity) {
return textures[entity.getEntityTextureType() % textures.length];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mojang.blaze3d.vertex.PoseStack;
import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.mixin.client.accessor.HumanoidArmorLayerAccessor;
import de.teamlapen.vampirism.util.PlayerModelType;
import de.teamlapen.vampirism.util.TextureComparator;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.HumanoidModel;
Expand All @@ -13,25 +12,24 @@
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.function.IntFunction;
import java.util.stream.Stream;


public abstract class DualBipedRenderer<T extends Mob, M extends HumanoidModel<T>> extends HumanoidMobRenderer<T, M> {
private final @NotNull M modelA;
private final M modelB;

private ResourceLocation currentTexture;
private PlayerSkin playerSkin;

public DualBipedRenderer(EntityRendererProvider.@NotNull Context context, @NotNull M modelBipedInA, M modelBipedInB, float shadowSize) {
super(context, modelBipedInA, shadowSize);
Expand All @@ -42,14 +40,13 @@ public DualBipedRenderer(EntityRendererProvider.@NotNull Context context, @NotNu
@NotNull
@Override
public ResourceLocation getTextureLocation(@NotNull T entity) {
return currentTexture != null ? currentTexture : DefaultPlayerSkin.getDefaultTexture(); //Steve texture is used as fallback
return this.playerSkin != null ? this.playerSkin.texture() : DefaultPlayerSkin.getDefaultTexture(); //Steve texture is used as fallback
}

@Override
public final void render(@NotNull T entityIn, float entityYaw, float partialTicks, @NotNull PoseStack matrixStackIn, @NotNull MultiBufferSource bufferIn, int packedLightIn) {
Pair<ResourceLocation, PlayerModelType> b = determineTextureAndModel(entityIn);
this.currentTexture = b.getLeft();
this.model = switch (b.getRight()) {
this.playerSkin = determineTextureAndModel(entityIn);
this.model = switch (this.playerSkin.model()) {
case SLIM -> modelB;
case WIDE -> modelA;
};
Expand All @@ -59,7 +56,7 @@ public final void render(@NotNull T entityIn, float entityYaw, float partialTick
/**
* @return Sets of texture resource location and model selecting boolean (true->b, false ->a)
*/
protected abstract Pair<ResourceLocation, PlayerModelType> determineTextureAndModel(T entity);
protected abstract PlayerSkin determineTextureAndModel(T entity);

protected void renderSelected(@NotNull T entityIn, float entityYaw, float partialTicks, @NotNull PoseStack matrixStackIn, @NotNull MultiBufferSource bufferIn, int packedLightIn) {
super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
Expand All @@ -68,11 +65,11 @@ protected void renderSelected(@NotNull T entityIn, float entityYaw, float partia
/**
* @return Array of texture and slim status
*/
protected Pair<ResourceLocation, PlayerModelType> @NotNull [] separateSlimTextures(@NotNull Stream<ResourceLocation> set) {
protected @NotNull PlayerSkin[] separateSlimTextures(@NotNull Stream<ResourceLocation> set) {
return set.map(r -> {
PlayerModelType b = r.getPath().endsWith("slim.png") ? PlayerModelType.SLIM : PlayerModelType.WIDE;
return Pair.of(r, b);
}).sorted(alphaNumericComparator()).toArray((IntFunction<Pair<ResourceLocation, PlayerModelType>[]>) Pair[]::new);
PlayerSkin.Model b = r.getPath().endsWith("slim.png") ? PlayerSkin.Model.SLIM : PlayerSkin.Model.WIDE;
return new PlayerSkin(r, null, null, null, b, false);
}).sorted(alphaNumericComparator()).toArray(PlayerSkin[]::new);
}

/**
Expand All @@ -82,17 +79,17 @@ protected void renderSelected(@NotNull T entityIn, float entityYaw, float partia
* @param required whether to throw an illegal state exception if none found
* @return Array of texture and slim status
*/
protected Pair<ResourceLocation, PlayerModelType> @NotNull [] gatherTextures(@NotNull String dirPath, boolean required) {
protected @NotNull PlayerSkin[] gatherTextures(@NotNull String dirPath, boolean required) {
Collection<ResourceLocation> hunterTextures = new ArrayList<>(Minecraft.getInstance().getResourceManager().listResources(dirPath, s -> s.getPath().endsWith(".png")).keySet());
Pair<ResourceLocation, PlayerModelType>[] textures = separateSlimTextures(hunterTextures.stream().filter(r -> REFERENCE.MODID.equals(r.getNamespace())));
PlayerSkin[] textures = separateSlimTextures(hunterTextures.stream().filter(r -> REFERENCE.MODID.equals(r.getNamespace())));
if (textures.length == 0 && required) {
throw new IllegalStateException("Must have at least one hunter texture: " + REFERENCE.MODID + ":" + dirPath + "/texture.png");
}
return textures;
}

protected Comparator<Pair<ResourceLocation, PlayerModelType>> alphaNumericComparator() {
return (o1, o2) -> TextureComparator.alphaNumericComparator().compare(o1.getLeft(), o2.getLeft());
protected Comparator<PlayerSkin> alphaNumericComparator() {
return (o1, o2) -> TextureComparator.alphaNumericComparator().compare(o1.texture(), o2.texture());
}

protected class ArmorLayer<A extends HumanoidModel<T>> extends HumanoidArmorLayer<T, M, A> {
Expand All @@ -112,13 +109,13 @@ public ArmorLayer(RenderLayerParent<T, M> pRenderer, A pInnerModel, A pInnerMode

@Override
public void render(@NotNull PoseStack pMatrixStack, @NotNull MultiBufferSource pBuffer, int pPackedLight, @NotNull T pLivingEntity, float pLimbSwing, float pLimbSwingAmount, float pPartialTicks, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch) {
Pair<ResourceLocation, PlayerModelType> b = determineTextureAndModel(pLivingEntity);
PlayerSkin b = determineTextureAndModel(pLivingEntity);

A innerModel = switch (b.getRight()) {
A innerModel = switch (b.model()) {
case SLIM -> pInnerModelSlim;
case WIDE -> pInnerModel;
};
A outerModel = switch (b.getRight()) {
A outerModel = switch (b.model()) {
case SLIM -> pOuterModelSlim;
case WIDE -> pOuterModel;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@
import de.teamlapen.vampirism.client.model.HunterMinionModel;
import de.teamlapen.vampirism.client.renderer.entity.layers.PlayerBodyOverlayLayer;
import de.teamlapen.vampirism.entity.minion.HunterMinionEntity;
import de.teamlapen.vampirism.util.PlayerModelType;
import net.minecraft.client.model.HumanoidArmorModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;

/**
* There are differently looking level 0 hunters.
* Hunter as of level 1 look all the same, but have different weapons
*/
public class HunterMinionRenderer extends DualBipedRenderer<HunterMinionEntity, HunterMinionModel<HunterMinionEntity>> {
private final Pair<ResourceLocation, PlayerModelType> @NotNull [] textures;
private final Pair<ResourceLocation, PlayerModelType> @NotNull [] minionSpecificTextures;
private final PlayerSkin @NotNull [] textures;
private final PlayerSkin @NotNull [] minionSpecificTextures;


public HunterMinionRenderer(EntityRendererProvider.@NotNull Context context) {
super(context, new HunterMinionModel<>(context.bakeLayer(ModEntitiesRender.GENERIC_BIPED), false), new HunterMinionModel<>(context.bakeLayer(ModEntitiesRender.GENERIC_BIPED_SLIM), true), 0.5F);
textures = gatherTextures("textures/entity/hunter", true);
minionSpecificTextures = gatherTextures("textures/entity/minion/hunter", false);
this.textures = gatherTextures("textures/entity/hunter", true);
this.minionSpecificTextures = gatherTextures("textures/entity/minion/hunter", false);
this.addLayer(new PlayerBodyOverlayLayer<>(this));
this.addLayer(new ArmorLayer<HumanoidModel<HunterMinionEntity>>(this, new HumanoidArmorModel<>(context.bakeLayer(ModelLayers.PLAYER_SLIM_INNER_ARMOR)), new HumanoidArmorModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), new HumanoidArmorModel<>(context.bakeLayer(ModelLayers.PLAYER_SLIM_OUTER_ARMOR)), new HumanoidArmorModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), context.getModelManager()));
}
Expand All @@ -42,12 +40,8 @@ public int getMinionSpecificTextureCount() {
}

@Override
protected Pair<ResourceLocation, PlayerModelType> determineTextureAndModel(@NotNull HunterMinionEntity entity) {
Pair<ResourceLocation, PlayerModelType> p = (entity.hasMinionSpecificSkin() && this.minionSpecificTextures.length > 0) ? minionSpecificTextures[entity.getHunterType() % minionSpecificTextures.length] : textures[entity.getHunterType() % textures.length];
if (entity.shouldRenderLordSkin()) {
return entity.getOverlayPlayerProperties().map(Pair::getRight).map(b -> Pair.of(p.getLeft(), b)).orElse(p);
}
return p;
protected PlayerSkin determineTextureAndModel(@NotNull HunterMinionEntity entity) {
return (entity.hasMinionSpecificSkin() && this.minionSpecificTextures.length > 0) ? minionSpecificTextures[entity.getHunterType() % minionSpecificTextures.length] : textures[entity.getHunterType() % textures.length];
}

@Override
Expand Down
Loading

0 comments on commit 457bcad

Please sign in to comment.