forked from tom5454/CustomPlayerModels
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
107 changed files
with
6,202 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
CustomPlayerModels-1.21.4/src/platform-shared/java/com/tom/cpm/CommonBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
CustomPlayerModels-1.21.4/src/platform-shared/java/com/tom/cpm/Log4JLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
CustomPlayerModels-1.21.4/src/platform-shared/java/com/tom/cpm/MinecraftServerObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
CustomPlayerModels-1.21.4/src/platform-shared/java/com/tom/cpm/client/CPMTagLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
CustomPlayerModels-1.21.4/src/platform-shared/java/com/tom/cpm/client/ClientBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.