Skip to content

Commit

Permalink
0.6.19b
Browse files Browse the repository at this point in the history
24w45a port

Fixed glowing eyes on 1.21.3 (tom5454#702)
Fixed crash with Iris on 1.21.3 (Closes tom5454#701)
Fixed startup crash with Minecraft Forge on 1.21.3
  • Loading branch information
tom5454 authored and FurryRbl committed Nov 9, 2024
1 parent 34923da commit 497aa20
Show file tree
Hide file tree
Showing 107 changed files with 6,202 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CustomPlayerModels-1.21.3/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod_name=Customizable Player Models
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT License
# The mod version. See https://semver.org/
mod_version=0.6.19a
mod_version=0.6.19b
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class CustomRenderTypes extends RenderType {
public static final RenderType ENTITY_COLOR = entityTranslucent(ResourceLocation.parse("textures/misc/white.png"));
public static final RenderType LINES_NO_DEPTH = create("cpm:lines_no_depth", DefaultVertexFormat.POSITION_COLOR_NORMAL, VertexFormat.Mode.LINES, 256, false, false, RenderType.CompositeState.builder().setShaderState(RENDERTYPE_LINES_SHADER).setLineState(new RenderStateShard.LineStateShard(OptionalDouble.empty())).setLayeringState(VIEW_OFFSET_Z_LAYERING).setTransparencyState(TRANSLUCENT_TRANSPARENCY).setOutputState(ITEM_ENTITY_TARGET).setWriteMaskState(COLOR_DEPTH_WRITE).setCullState(NO_CULL).setDepthTestState(NO_DEPTH_TEST).createCompositeState(false));
public static final RenderType ENTITY_COLOR_EYES = eyes(ResourceLocation.parse("textures/misc/white.png"));
public static final RenderType ENTITY_COLOR_EYES = glowingEyes(ResourceLocation.parse("textures/misc/white.png"));

public CustomRenderTypes(String nameIn, VertexFormat formatIn, Mode drawModeIn, int bufferSizeIn,
boolean useDelegateIn, boolean needsSortingIn, Runnable setupTaskIn, Runnable clearTaskIn) {
Expand All @@ -35,7 +35,7 @@ public static RenderType linesNoDepth() {
}

public static RenderType glowingEyes(ResourceLocation rl) {
RenderType rt = RenderType.eyes(rl);
RenderType rt = RenderType.EYES.apply(rl, ADDITIVE_TRANSPARENCY);
if (ClientBase.irisLoaded)
((BlendingStateHolder) rt).setTransparencyType(TransparencyType.DECAL);
return rt;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.tom.cpm;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.minecraft.SharedConstants;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.world.entity.player.Player;

import com.tom.cpl.block.BlockStateHandler;
import com.tom.cpl.block.entity.EntityTypeHandler;
import com.tom.cpl.config.ModConfigFile;
import com.tom.cpl.item.ItemStackHandler;
import com.tom.cpl.text.TextRemapper;
import com.tom.cpl.text.TextStyle;
import com.tom.cpl.util.ILogger;
import com.tom.cpm.api.CPMApiManager;
import com.tom.cpm.common.BlockStateHandlerImpl;
import com.tom.cpm.common.EntityTypeHandlerImpl;
import com.tom.cpm.common.ItemStackHandlerImpl;
import com.tom.cpm.shared.MinecraftCommonAccess;

public abstract class CommonBase implements MinecraftCommonAccess {
public static final Logger LOG = LogManager.getLogger("CPM");
public static final ILogger log = new Log4JLogger(LOG);

public static CPMApiManager api;
protected ModConfigFile cfg;

public CommonBase() {
api = new CPMApiManager();
}

protected void apiInit() {
LOG.info("Customizable Player Models API initialized: " + api.getPluginStatus());
api.buildCommon().player(Player.class).init();
}

@Override
public ModConfigFile getConfig() {
return cfg;
}

@Override
public ILogger getLogger() {
return log;
}

@Override
public TextRemapper<MutableComponent> getTextRemapper() {
return new TextRemapper<>(Component::translatable, Component::literal, MutableComponent::append, Component::keybind,
CommonBase::styleText);
}

private static MutableComponent styleText(MutableComponent in, TextStyle style) {
return in.withStyle(Style.EMPTY.withBold(style.bold).withItalic(style.italic).withUnderlined(style.underline).withStrikethrough(style.strikethrough));
}

@Override
public CPMApiManager getApi() {
return api;
}

@Override
public String getMCVersion() {
return SharedConstants.getCurrentVersion().getName();
}

@Override
public BlockStateHandler<?> getBlockStateHandler() {
return BlockStateHandlerImpl.impl;
}

@Override
public ItemStackHandler<?> getItemStackHandler() {
return ItemStackHandlerImpl.impl;
}

@Override
public EntityTypeHandler<?> getEntityTypeHandler() {
return EntityTypeHandlerImpl.impl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.tom.cpm;

import org.apache.logging.log4j.Logger;

import com.tom.cpl.util.ILogger;

public class Log4JLogger implements ILogger {
private Logger log;

public Log4JLogger(Logger log) {
this.log = log;
}

@Override
public void warn(String text, Throwable thr) {
log.warn(text, thr);
}

@Override
public void warn(String text) {
log.warn(text);
}

@Override
public void info(String text) {
log.info(text);
}

@Override
public void error(String text, Throwable thr) {
log.error(text, thr);
}

@Override
public void error(String text) {
log.error(text);
}

@Override
public void info(String text, Throwable thr) {
log.info(text, thr);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.tom.cpm;

import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.storage.LevelResource;

import com.tom.cpl.block.BiomeHandler;
import com.tom.cpl.config.ModConfigFile;
import com.tom.cpm.common.BiomeHandlerImpl;
import com.tom.cpm.common.ServerHandler;
import com.tom.cpm.shared.MinecraftServerAccess;
import com.tom.cpm.shared.network.NetHandler;

public class MinecraftServerObject implements MinecraftServerAccess {
public static final LevelResource CONFIG = new LevelResource("data/cpm.json");
private MinecraftServer server;
private ModConfigFile cfg;

public MinecraftServerObject(MinecraftServer server) {
this.server = server;
cfg = ModConfigFile.createServer(server.getWorldPath(CONFIG).toFile());
}

@Override
public ModConfigFile getConfig() {
return cfg;
}

@Override
public NetHandler<?, ?, ?> getNetHandler() {
return ServerHandler.netHandler;
}

public MinecraftServer getServer() {
return server;
}

@Override
public BiomeHandler<?> getBiomeHandler() {
return BiomeHandlerImpl.serverImpl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.tom.cpm.client;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.minecraft.client.Minecraft;
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
import net.minecraft.util.profiling.ProfilerFiller;

import com.tom.cpl.tag.TagManager;
import com.tom.cpm.shared.MinecraftObjectHolder;
import com.tom.cpm.shared.util.ErrorLog;
import com.tom.cpm.shared.util.ErrorLog.LogLevel;

public class CPMTagLoader extends SimplePreparableReloadListener<Map<String, List<Map<String, Object>>>> {
private final TagManager<?> tags;
private final String prefix;

public CPMTagLoader(Minecraft mc, TagManager<?> tags, String prefix) {
this.tags = tags;
this.prefix = prefix;
ResourceManager mngr = mc.getResourceManager();
if (mngr != null) {
init(mngr);
} else {
mc.schedule(() -> init(mc.getResourceManager()));
}
}

private void init(ResourceManager mngr) {
tags.applyBuiltin(load(mngr), prefix);
if(mngr instanceof ReloadableResourceManager r)
r.registerReloadListener(this);
}

@Override
protected Map<String, List<Map<String, Object>>> prepare(ResourceManager mngr, ProfilerFiller profiler) {
return load(mngr);
}

@Override
protected void apply(Map<String, List<Map<String, Object>>> tagMap, ResourceManager mngr, ProfilerFiller profiler) {
tags.applyBuiltin(tagMap, prefix);
}

@SuppressWarnings("unchecked")
private Map<String, List<Map<String, Object>>> load(ResourceManager mngr) {
Map<String, List<Map<String, Object>>> el = new HashMap<>();
mngr.listResourceStacks("cpm_tags/" + prefix, l -> l.getPath().endsWith(".json")).forEach((rl, rs) -> {
List<Map<String, Object>> res = new ArrayList<>();
el.put(rl.getNamespace() + ":" + rl.getPath().substring(9, rl.getPath().length() - 5), res);
rs.forEach(r -> {
try (BufferedReader rd = r.openAsReader()) {
Map<String, Object> tag = (Map<String, Object>) MinecraftObjectHolder.gson.fromJson(rd, Object.class);
res.add(tag);
} catch (Exception e) {
ErrorLog.addLog(LogLevel.WARNING, "Failed to load cpm builtin tag: " + rl, e);
}
});
});
return el;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.tom.cpm.client;

import java.util.function.Function;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ElytraModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.PlayerModel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;

import com.tom.cpm.CustomPlayerModels;
import com.tom.cpm.common.ByteArrayPayload;
import com.tom.cpm.common.PlayerAnimUpdater;
import com.tom.cpm.mixinplugin.IrisDetector;
import com.tom.cpm.mixinplugin.OFDetector;
import com.tom.cpm.shared.model.RenderManager;
import com.tom.cpm.shared.network.NetHandler;
import com.tom.cpm.shared.util.Log;

public abstract class ClientBase {
public static final ResourceLocation DEFAULT_CAPE = ResourceLocation.parse("cpm:textures/template/cape.png");
public static boolean optifineLoaded, irisLoaded, vrLoaded;
public static MinecraftObject mc;
protected Minecraft minecraft;
public RenderManager<GameProfile, net.minecraft.world.entity.player.Player, Model, MultiBufferSource> manager;
public NetHandler<CustomPacketPayload.Type<ByteArrayPayload>, net.minecraft.world.entity.player.Player, ClientPacketListener> netHandler;

public void init0() {
minecraft = Minecraft.getInstance();
mc = new MinecraftObject(minecraft);
optifineLoaded = OFDetector.doApply();
vrLoaded = Platform.isModLoaded("vivecraft");
irisLoaded = IrisDetector.doApply();
if(optifineLoaded)Log.info("Optifine detected, enabling optifine compatibility");
if(vrLoaded)Log.info("ViveCraft detected, enabling ViveCraft compatibility");
if(irisLoaded)Log.info("Iris detected, enabling iris compatibility");
}

public void init1() {
manager = new RenderManager<>(mc.getPlayerRenderManager(), mc.getDefinitionLoader(), net.minecraft.world.entity.player.Player::getGameProfile);
manager.setGPGetters(GameProfile::getProperties, Property::value);
netHandler = new NetHandler<>((k, v) -> new CustomPacketPayload.Type<>(ResourceLocation.tryBuild(k, v)));
netHandler.setExecutor(() -> minecraft);
netHandler.setSendPacketClient(Function.identity(), (c, rl, pb) -> c.send(new ServerboundCustomPayloadPacket(new ByteArrayPayload(rl, pb))));
netHandler.setPlayerToLoader(net.minecraft.world.entity.player.Player::getGameProfile);
netHandler.setGetPlayerById(id -> {
Entity ent = Minecraft.getInstance().level.getEntity(id);
if(ent instanceof net.minecraft.world.entity.player.Player) {
return (net.minecraft.world.entity.player.Player) ent;
}
return null;
});
netHandler.setGetClient(() -> minecraft.player);
netHandler.setGetNet(c -> ((LocalPlayer)c).connection);
netHandler.setDisplayText(t -> minecraft.player.displayClientMessage(t.remap(), false));
netHandler.setGetPlayerAnimGetters(new PlayerAnimUpdater());
}

public static void apiInit() {
CustomPlayerModels.api.buildClient().voicePlayer(net.minecraft.world.entity.player.Player.class, net.minecraft.world.entity.player.Player::getUUID).
renderApi(Model.class, ResourceLocation.class, RenderType.class, MultiBufferSource.class, GameProfile.class, ModelTexture::new).
localModelApi(GameProfile::new).init();
}

public void playerRenderPost(MultiBufferSource buffer, PlayerModel model) {
manager.unbindClear(model);
}

public void renderHand(MultiBufferSource buffer, PlayerModel model) {
renderHand(minecraft.player, buffer, model);
}

public void renderHand(AbstractClientPlayer pl, MultiBufferSource buffer, PlayerModel model) {
manager.bindHand(pl, buffer, model);
}

public void renderHandPost(MultiBufferSource buffer, HumanoidModel model) {
manager.unbindClear(model);
}

public void renderSkull(Model skullModel, GameProfile profile, MultiBufferSource buffer) {
manager.bindSkull(profile, buffer, skullModel);
}

public void renderSkullPost(MultiBufferSource buffer, Model model) {
manager.unbindFlush(model);
}

public void renderElytra(HumanoidModel<HumanoidRenderState> player, ElytraModel model) {
manager.bindElytra(player, model);
}

public void renderArmor(HumanoidModel<HumanoidRenderState> modelArmor, HumanoidModel<HumanoidRenderState> modelLeggings,
HumanoidModel<HumanoidRenderState> player) {
manager.bindArmor(player, modelArmor, 1);
manager.bindArmor(player, modelLeggings, 2);
}

public void updateJump() {
if(minecraft.player.onGround() && minecraft.player.input.keyPresses.jump()) {
manager.jump(minecraft.player);
}
}
}
Loading

0 comments on commit 497aa20

Please sign in to comment.