Skip to content

Commit

Permalink
Start getting Forge/NeoForged mashed in. Also start creating ModLoade…
Browse files Browse the repository at this point in the history
…rUtil for future ease
  • Loading branch information
tr7zw committed Jan 12, 2024
1 parent 37f37bf commit 61fdcd8
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 40 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,44 @@ jobs:
uses: softprops/action-gh-release@v1
with:
files: 'versions/**/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
- name: Publish-1.20.4-forge-Curseforge
uses: Kir-Antipov/mc-publish@v3.2
with:
curseforge-id: 333287
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
loaders: forge
name: ${{github.ref_name}}-1.20.4 - Forge
version-type: beta
files: 'versions/1.20.4-forge/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.20.4
- name: Publish-1.20.4-forge-Modrinth
uses: Kir-Antipov/mc-publish@v3.2
with:
modrinth-id: H5XMjpHi
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
loaders: forge
name: ${{github.ref_name}}-1.20.4 - Forge
files: 'versions/1.20.4-forge/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.20.4
- name: Publish-1.20.4-neoforge-Curseforge
uses: Kir-Antipov/mc-publish@v3.2
with:
curseforge-id: 333287
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
loaders: neoforge
name: ${{github.ref_name}}-1.20.4 - NeoForge
version-type: beta
files: 'versions/1.20.4-neoforge/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.20.4
- name: Publish-1.20.4-neoforge-Modrinth
uses: Kir-Antipov/mc-publish@v3.2
with:
modrinth-id: H5XMjpHi
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
loaders: neoforge
name: ${{github.ref_name}}-1.20.4 - NeoForge
files: 'versions/1.20.4-neoforge/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.20.4
- name: Publish-1.20.4-fabric-Curseforge
uses: Kir-Antipov/mc-publish@v3.2
with:
Expand Down
3 changes: 3 additions & 0 deletions gradle-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ replacements:
forge_dependencies: "
modCompileOnly 'maven.modrinth:playeranimator:1.0.2-rc1+1.20-forge'\n
"
neoforge_dependencies: "
modCompileOnly 'maven.modrinth:playeranimator:1.0.2-rc1+1.20-forge'\n
"
enabledFlags:
- autopublish
- publishFabric
Expand Down
2 changes: 2 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"versions": [
"1.20.4-forge",
"1.20.4-neoforge",
"1.20.4-fabric"
]
}
31 changes: 31 additions & 0 deletions src/main/java/dev/tr7zw/firstperson/FirstPersonBootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//#if FORGE
//$$package dev.tr7zw.firstperson;
//$$
//$$import net.minecraftforge.api.distmarker.Dist;
//$$import net.minecraftforge.fml.DistExecutor;
//$$import net.minecraftforge.fml.common.Mod;
//$$
//$$@Mod("firstperson")
//$$public class FirstPersonBootstrap {
//$$
//$$ public FirstPersonBootstrap() {
//$$ DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> FirstPersonModelMod::new);
//$$ }
//$$
//$$}
//#elseif NEOFORGE
//$$package dev.tr7zw.firstperson;
//$$
//$$import net.neoforged.api.distmarker.Dist;
//$$import net.neoforged.fml.DistExecutor;
//$$import net.neoforged.fml.common.Mod;
//$$
//$$@Mod("firstperson")
//$$public class FirstPersonBootstrap {
//$$
//$$ public FirstPersonBootstrap() {
//$$ DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> FirstPersonModelMod::new);
//$$ }
//$$
//$$}
//#endif
12 changes: 9 additions & 3 deletions src/main/java/dev/tr7zw/firstperson/FirstPersonModelCore.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package dev.tr7zw.firstperson;

import dev.tr7zw.firstperson.api.FirstPersonAPI;
import dev.tr7zw.firstperson.config.ConfigScreenProvider;
import dev.tr7zw.firstperson.modsupport.ModSupportLoader;
import dev.tr7zw.firstperson.modsupport.PlayerAnimatorSupport;
import dev.tr7zw.firstperson.versionless.FirstPersonBase;
import dev.tr7zw.util.ModLoaderUtil;
import lombok.Getter;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
Expand All @@ -18,6 +21,8 @@ public abstract class FirstPersonModelCore extends FirstPersonBase {

public FirstPersonModelCore() {
instance = this;
ModLoaderUtil.disableDisplayTest();
ModLoaderUtil.registerConfigScreen(ConfigScreenProvider::createConfigScreen);
}

public void sharedSetup() {
Expand All @@ -26,10 +31,11 @@ public void sharedSetup() {

super.loadConfig();

registerKeybinds();
}
ModLoaderUtil.registerKeybind(keyBinding);
ModLoaderUtil.registerClientTickListener(this::onTick);

public abstract void registerKeybinds();
ModSupportLoader.loadSupport();
}

private void lateInit() {
try {
Expand Down
41 changes: 15 additions & 26 deletions src/main/java/dev/tr7zw/firstperson/FirstPersonModelMod.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
package dev.tr7zw.firstperson;

import dev.tr7zw.firstperson.api.FirstPersonAPI;
import dev.tr7zw.firstperson.modsupport.FreecamSupport;
//spotless:off
//#if FABRIC
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;

public class FirstPersonModelMod extends FirstPersonModelCore implements ClientModInitializer {

@Override
public void onInitializeClient() {
sharedSetup();
ClientTickEvents.END_CLIENT_TICK.register(e -> {
onTick();
});
try {
if (FabricLoader.getInstance().isModLoaded("freecam")) {
FirstPersonAPI.registerPlayerHandler(new FreecamSupport());
FirstPersonModelCore.LOGGER.info("Freecam support loaded.");
}
} catch (Throwable ex) {
FirstPersonModelCore.LOGGER.warn("Error during initialization of mod support.", ex);
}
}

@Override
public void registerKeybinds() {
KeyBindingHelper.registerKeyBinding(keyBinding);
}

@Override
public void onInitializeClient() {
sharedSetup();
}
//#else
//$$ import dev.tr7zw.util.ModLoaderUtil;
//$$ public class FirstPersonModelMod extends FirstPersonModelCore {
//$$ public FirstPersonModelMod() {
//$$ ModLoaderUtil.registerClientSetupListener(this::sharedSetup);
//$$ }
//#endif
//spotless:on

}
13 changes: 7 additions & 6 deletions src/main/java/dev/tr7zw/firstperson/LogicHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,20 @@ public void updatePositionOffset(Entity player, Vec3 defValue) {
* @return
*/
public boolean isSwimming(Player player) {
return player.isSwimming();
return player.isSwimming();
}

/**
* Util method to quicker find where the crawling/swimming animation is referenced
* Util method to quicker find where the crawling/swimming animation is
* referenced
*
* @param player
* @return
*/
public boolean isCrawlingOrSwimming(Player player) {
return player.isVisuallySwimming();
return player.isVisuallySwimming();
}

public boolean showVanillaHands() {
return FirstPersonModelMod.config.vanillaHands
|| autoVanillaHandItems.contains(client.player.getMainHandItem().getItem())
Expand All @@ -154,7 +155,7 @@ public void addAutoVanillaHandsItem(Item item) {
public void clearAutoVanillaHandsList() {
this.autoVanillaHandItems.clear();
}

public void reloadAutoVanillaHandsSettings() {
clearAutoVanillaHandsList();
Item invalid = BuiltInRegistries.ITEM.get(new ResourceLocation("minecraft", "air"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//#if FABRIC
package dev.tr7zw.firstperson.fabric;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
Expand All @@ -15,3 +16,4 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
}

}
//#endif
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ private void renderArmor(PoseStack matrices, MultiBufferSource vertexConsumers,
info.cancel();
}
if (equipmentSlot == EquipmentSlot.CHEST && FirstPersonModelCore.isRenderingPlayer
&& (livingEntity instanceof LocalPlayer player && FirstPersonModelCore.instance.getLogicHandler().isSwimming(player))) {
&& (livingEntity instanceof LocalPlayer player
&& FirstPersonModelCore.instance.getLogicHandler().isSwimming(player))) {
info.cancel();
}
if (equipmentSlot == EquipmentSlot.CHEST && FirstPersonModelCore.isRenderingPlayer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public PlayerRenderMixin(Context ctx, PlayerModel<AbstractClientPlayer> model, f
}

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/player/PlayerRenderer;setModelProperties(Lnet/minecraft/client/player/AbstractClientPlayer;)V"))
private void setModelPoseRedirect(PlayerRenderer playerEntityRenderer,
AbstractClientPlayer player, AbstractClientPlayer abstractClientPlayerEntity_1, float f,
float g, PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int i) {
private void setModelPoseRedirect(PlayerRenderer playerEntityRenderer, AbstractClientPlayer player,
AbstractClientPlayer abstractClientPlayerEntity_1, float f, float g, PoseStack matrixStack,
MultiBufferSource vertexConsumerProvider, int i) {
setModelProperties(player);
if (FirstPersonModelCore.isRenderingPlayer) {
PlayerModel<AbstractClientPlayer> model = this.getModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public void render(PoseStack matrices, float tickDelta, long limitTime, boolean
Vec3 vec3d = camera.getPosition();
MultiBufferSource.BufferSource immediate = this.renderBuffers.bufferSource();
FirstPersonModelCore.isRenderingPlayer = true;
this.renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), tickDelta, matrices, (MultiBufferSource) immediate);
this.renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), tickDelta, matrices,
(MultiBufferSource) immediate);
FirstPersonModelCore.isRenderingPlayer = false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//#if FABRIC
package dev.tr7zw.firstperson.modsupport;

import dev.tr7zw.firstperson.api.ActivationHandler;
Expand All @@ -16,3 +17,4 @@ public boolean preventFirstperson() {
}

}
//#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.tr7zw.firstperson.modsupport;

import dev.tr7zw.firstperson.FirstPersonModelCore;
import dev.tr7zw.firstperson.api.FirstPersonAPI;
import dev.tr7zw.util.ModLoaderUtil;

public class ModSupportLoader {

public static void loadSupport() {
// spotless:off
//#if FABRIC
try {
if (ModLoaderUtil.isModLoaded("freecam")) {
FirstPersonAPI.registerPlayerHandler(new FreecamSupport());
FirstPersonModelCore.LOGGER.info("Freecam support loaded.");
}
} catch (Throwable ex) {
FirstPersonModelCore.LOGGER.warn("Error during initialization of mod support.", ex);
}
//#endif
//spotless:on
}

}
Loading

0 comments on commit 61fdcd8

Please sign in to comment.