Skip to content

Commit

Permalink
more porting work
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Jul 21, 2024
1 parent 507f617 commit 10ae264
Show file tree
Hide file tree
Showing 143 changed files with 92 additions and 104 deletions.
5 changes: 2 additions & 3 deletions Common/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ minecraft = "1.21"
parchment_minecraft = "1.21"
parchment_mappings = "2024.07.07"

mixin = "0.8.5"
mixin = "0.14.0+mixin.0.8.6"
mixin_extras = "0.3.5"
asm = "9.6"
jetbrains_annotations = "24.1.0"
Expand All @@ -22,9 +22,8 @@ nv_websocket = "2.14"
[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
parchment_mappings = { module = "org.parchmentmc.data:parchment-1.21", version.ref = "parchment_mappings" }
mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }
mixin = { module = "net.fabricmc:sponge-mixin", version.ref = "mixin" }
mixin_extras = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixin_extras" }
mixin_extras_forge = { module = "io.github.llamalad7:mixinextras-forge", version.ref = "mixin_extras" }
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
asm_analysis = { module = "org.ow2.asm:asm-analysis", version.ref = "asm" }
asm_commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" }
Expand Down
2 changes: 1 addition & 1 deletion Common/src/main/java/dev/cammiescorner/icarus/Icarus.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void init() {
}

public static ResourceLocation id(String path) {
return new ResourceLocation(MODID, path);
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}

public static void onServerStart(MinecraftServer server) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
Expand All @@ -41,18 +42,12 @@ public WingsLayer(RenderLayerParent<T, M> context, EntityModelSet loader) {
}

@Override
public void render(PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
public void render(PoseStack pose, MultiBufferSource bufferSource, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
var stack = IcarusAPIClient.getWingsForRendering(entity);

if (stack.getItem() instanceof WingItem wingItem && IcarusClient.shouldRenderWings(entity)) {
float[] primaryColour = wingItem.getPrimaryColor(stack).getTextureDiffuseColors();
float[] secondaryColour = wingItem.getSecondaryColor(stack).getTextureDiffuseColors();
float r1 = primaryColour[0];
float g1 = primaryColour[1];
float b1 = primaryColour[2];
float r2 = secondaryColour[0];
float g2 = secondaryColour[1];
float b2 = secondaryColour[2];
var primaryColor = FastColor.ARGB32.color(255, wingItem.getPrimaryColor(stack).getTextureDiffuseColor());
var secondaryColor = FastColor.ARGB32.color(255, wingItem.getSecondaryColor(stack).getTextureDiffuseColor());

var wingModel = switch (wingItem.getWingType()) {
case FEATHERED, MECHANICAL_FEATHERED -> featheredWings;
Expand All @@ -79,18 +74,18 @@ public void render(PoseStack matrices, MultiBufferSource vertexConsumers, int li
ResourceLocation layer1 = wingItem.getWingType().getTextureLayer1(stack);
ResourceLocation layer2 = wingItem.getWingType().getTextureLayer2(stack);

matrices.pushPose();
matrices.translate(0.0D, 0.0D, 0.125D);
pose.pushPose();
pose.translate(0.0D, 0.0D, 0.125D);
this.getParentModel().copyPropertiesTo(wingModel);
wingModel.setupAnim(entity, limbAngle, limbDistance, animationProgress, headYaw, headPitch);
this.renderWings(wingModel, matrices, vertexConsumers, stack, RenderType.entityTranslucent(layer2), light, r2, g2, b2);
this.renderWings(wingModel, matrices, vertexConsumers, stack, RenderType.entityTranslucent(layer1), light, r1, g1, b1);
matrices.popPose();
this.renderWings(wingModel, pose, bufferSource, stack, RenderType.entityTranslucent(layer2), light, secondaryColor);
this.renderWings(wingModel, pose, bufferSource, stack, RenderType.entityTranslucent(layer1), light, primaryColor);
pose.popPose();
}
}

public void renderWings(WingEntityModel<T> model, PoseStack matrices, MultiBufferSource vertexConsumers, @Nullable ItemStack stack, RenderType renderLayer, int light, float r, float g, float b) {
VertexConsumer vertexConsumer = ItemRenderer.getArmorFoilBuffer(vertexConsumers, renderLayer, false, stack != null && stack.hasFoil());
model.renderToBuffer(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY, r, g, b, 1F);
public void renderWings(WingEntityModel<T> model, PoseStack matrices, MultiBufferSource vertexConsumers, @Nullable ItemStack stack, RenderType renderLayer, int light, int color) {
VertexConsumer vertexConsumer = ItemRenderer.getArmorFoilBuffer(vertexConsumers, renderLayer, stack != null && stack.hasFoil());
model.renderToBuffer(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY, color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import dev.cammiescorner.icarus.effect.FlightlessStatusEffect;
import dev.cammiescorner.icarus.util.Registrar;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;

Expand All @@ -11,6 +13,10 @@ public class IcarusStatusEffects {

public static Supplier<MobEffect> FLIGHTLESS;

public static Holder<MobEffect> flightlessHolder() {
return BuiltInRegistries.MOB_EFFECT.wrapAsHolder(FLIGHTLESS.get());
}

public static void register(Registrar<MobEffect> registrar) {
FLIGHTLESS = registrar.register("flightless", () -> new FlightlessStatusEffect(MobEffectCategory.NEUTRAL, "#b6ccf0"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean onFlightTick(LivingEntity entity, ItemStack wings, int ticks) {
if (IcarusConfig.wingsDurability > 0 && wings.is(IcarusItemTags.MELTS) && !(entity instanceof Player player && player.isCreative())) {
var cfg = IcarusHelper.getConfigValues(entity);
if (ticks % 20 == 0 || (cfg.maxHeightEnabled() && entity.getY() > entity.level().getHeight() + cfg.maxHeightAboveWorld() && ticks % 2 == 0)) {
wings.hurtAndBreak(1, entity, e -> e.broadcastBreakEvent(EquipmentSlot.CHEST));
wings.hurtAndBreak(1, entity, EquipmentSlot.CHEST);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package dev.cammiescorner.icarus.util;


import net.minecraft.util.FastColor;
import net.minecraft.world.item.DyeColor;

public class ColorHelper {
public static int rgbToDecimal(float[] rgb) {
return (((int) (rgb[0] * 255F) << 16) | ((int) (rgb[1] * 255F) << 8) | (int) (rgb[2] * 255F));
}

public static int dyeToDecimal(DyeColor colour) {
float[] rgb = colour.getTextureDiffuseColors();

return (((int) (rgb[0] * 255F) << 16) | ((int) (rgb[1] * 255F) << 8) | (int) (rgb[2] * 255F));
}
public static int asARGB(DyeColor color) {
var rgb = color.getTextureDiffuseColor();
return FastColor.ARGB32.color(255, rgb);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static boolean onFallFlyingTick(LivingEntity entity, @Nullable ItemStack
return false;
}

if (entity.hasEffect(IcarusStatusEffects.FLIGHTLESS.get())) {
if (entity.hasEffect(IcarusStatusEffects.flightlessHolder())) {
if (entity instanceof Player player) {
stopFlying(player);
Component message = Component.translatable("message.icarus.status.no_fly.status_effect").withStyle(ChatFormatting.BLUE);
Expand Down
2 changes: 1 addition & 1 deletion Common/src/main/resources/icarus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"package": "dev.cammiescorner.icarus.mixin",
"plugin": "dev.cammiescorner.icarus.IcarusMixinPlugin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [
"EntityMixin",
"PlayerMixin"
Expand Down
2 changes: 1 addition & 1 deletion Fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

project.configurations.runtimeClasspath {
exclude(group: "loom_mappings_1_20_4_layered_hash_1137964741_v2.net.fabricmc", module: "fabric-loader")
exclude(group: "loom_mappings_1_21_layered_hash_1837964949_v2.net.fabricmc", module: "fabric-loader")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public void onInitializeClient() {
}

private static void registerColorProvider(Item item) {
ColorProviderRegistry.ITEM.register((itemStack, tintIndex) -> tintIndex == 0 ? ColorHelper.dyeToDecimal(((WingItem) itemStack.getItem()).getPrimaryColor(itemStack)) : ColorHelper.dyeToDecimal(((WingItem) itemStack.getItem()).getSecondaryColor(itemStack)), item);
ColorProviderRegistry.ITEM.register((itemStack, tintIndex) -> tintIndex == 0 ? ColorHelper.asARGB(((WingItem) itemStack.getItem()).getPrimaryColor(itemStack)) : ColorHelper.asARGB(((WingItem) itemStack.getItem()).getSecondaryColor(itemStack)), item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.item.Equipable;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -65,10 +64,12 @@ public void onInitialize() {
ItemStack newStack = stack.copy();
newStack.setCount(1);
inv.setItem(i, newStack);
SoundEvent soundEvent = stack.getItem() instanceof Equipable eq ? eq.getEquipSound() : null;
if (!stack.isEmpty() && soundEvent != null) {
var soundEvent = stack.getItem() instanceof Equipable eq ? eq.getEquipSound() : null;
if (!stack.isEmpty()) {
user.gameEvent(GameEvent.EQUIP);
user.playSound(soundEvent, 1.0F, 1.0F);
if(soundEvent != null && !user.isSilent()) {
user.level().playSeededSound(null, user.getX(), user.getY(), user.getZ(), soundEvent, user.getSoundSource(), 1.0F, 1.0F, user.getRandom().nextLong());
}
}
stack.shrink(1);
return true;
Expand Down
2 changes: 1 addition & 1 deletion Fabric/src/main/resources/icarus.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"package": "dev.cammiescorner.icarus.fabric.mixin",
"plugin": "dev.cammiescorner.icarus.IcarusMixinPlugin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [
"MixinPlayer",
"MixinWingItem"
Expand Down
10 changes: 1 addition & 9 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ subsystems {
}
}

// Automatically enable neoforge AccessTransformers if the file exists
// This location is hardcoded in FML and can not be changed.
// https://github.com/neoforged/FancyModLoader/blob/a952595eaaddd571fbc53f43847680b00894e0c1/loader/src/main/java/net/neoforged/fml/loading/moddiscovery/ModFile.java#L118
def at = file('src/main/resources/META-INF/accesstransformer.cfg')
if (at.exists()) {
minecraft.accessTransformers.file at
}

runs {
configureEach {
// Recommended logging data for a userdev environment
Expand All @@ -82,7 +74,7 @@ runs {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
workingDirectory(project.file('run'))

modSource project(":Common").sourceSets.main
// mod?Source project(":Common").sourceSets.main
modSource sourceSets.main

if (rootProject.hasProperty('mc_java_agent_path')) {
Expand Down
4 changes: 2 additions & 2 deletions NeoForge/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
neogradle = "7.0.155"
neogradle = "7.0.154"

neoforge = "21.0.113-beta"

Expand All @@ -14,7 +14,7 @@ neoforge = { module = "net.neoforged:neoforge", version.ref = "neoforge" }

curios = { module = "top.theillusivec4.curios:curios-neoforge", version.ref = "curios" }

caelus = { module = "top.theillusivec4.caelus:caelus-neoforge", version.ref = "caelus" }
caelus = { module = "com.illusivesoulworks.caelus:caelus-neoforge", version.ref = "caelus" }

cameraoverhaul = { module = "curse.maven:camera-overhaul-reforged-1011593", version.ref = "cameraoverhaul" }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,51 @@
package dev.cammiescorner.icarus.neoforge;

import com.illusivesoulworks.caelus.api.CaelusApi;
import dev.cammiescorner.icarus.Icarus;
import dev.cammiescorner.icarus.client.IcarusClient;
import dev.cammiescorner.icarus.util.IcarusHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.server.ServerStartingEvent;
import top.theillusivec4.caelus.api.CaelusApi;
import net.neoforged.neoforge.event.tick.PlayerTickEvent;

import java.util.UUID;

@Mod.EventBusSubscriber(modid = Icarus.MODID)
@EventBusSubscriber(modid = Icarus.MODID)
public class EventHandler {

public static final UUID WINGS_FLIGHT_MODIFIER_ID = UUID.fromString("4b6eac76-f013-4382-8b22-5d43bc37939c");
public static final AttributeModifier WINGS_FLIGHT = new AttributeModifier(WINGS_FLIGHT_MODIFIER_ID, "icarus_wings", 1.0D, AttributeModifier.Operation.ADDITION);
public static final ResourceLocation WINGS_FLIGHT_MODIFIER_ID = Icarus.id("wings");
public static final AttributeModifier WINGS_FLIGHT = new AttributeModifier(WINGS_FLIGHT_MODIFIER_ID, 1.0D, AttributeModifier.Operation.ADD_VALUE);

@SuppressWarnings("UnreachableCode")
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
if(event.phase == TickEvent.Phase.START) {
var attributeInstance = event.player.getAttribute(CaelusApi.getInstance().getFlightAttribute());

if(attributeInstance != null) {
if (attributeInstance.hasModifier(WINGS_FLIGHT)) {
if(event.player.isFallFlying()) {
if (!IcarusHelper.onFallFlyingTick(event.player, IcarusHelper.getEquippedWings(event.player), true)) {
attributeInstance.removeModifier(WINGS_FLIGHT_MODIFIER_ID);
}
public static void onPlayerTick(PlayerTickEvent.Pre event) {
var attributeInstance = event.getEntity().getAttribute(CaelusApi.getInstance().getFallFlyingAttribute());

if (attributeInstance != null) {
if (attributeInstance.hasModifier(WINGS_FLIGHT.id())) {
if (event.getEntity().isFallFlying()) {
if (!IcarusHelper.onFallFlyingTick(event.getEntity(), IcarusHelper.getEquippedWings(event.getEntity()), true)) {
attributeInstance.removeModifier(WINGS_FLIGHT_MODIFIER_ID);
}
else {
if(!IcarusHelper.hasWings(event.player)) {
attributeInstance.removeModifier(WINGS_FLIGHT_MODIFIER_ID);
}
} else {
if (!IcarusHelper.hasWings(event.getEntity())) {
attributeInstance.removeModifier(WINGS_FLIGHT_MODIFIER_ID);
}
}
else {
if (IcarusHelper.hasWings(event.player)) {
attributeInstance.addTransientModifier(WINGS_FLIGHT);
}
} else {
if (IcarusHelper.hasWings(event.getEntity())) {
attributeInstance.addTransientModifier(WINGS_FLIGHT);
}
}
}

if (event.side.isServer()) {
IcarusHelper.onPlayerTick(event.player);
} else {
IcarusClient.onPlayerTick(event.player);
}
if (event.getEntity().level().isClientSide()) {
IcarusClient.onPlayerTick(event.getEntity());
}
else {
IcarusHelper.onPlayerTick(event.getEntity());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

package dev.cammiescorner.icarus.neoforge.compat;

import com.confusingfool.cameraoverhaulneoforge.core.callbacks.CameraUpdateCallback;
import com.confusingfool.cameraoverhaulneoforge.core.callbacks.ModifyCameraTransformCallback;
import com.confusingfool.cameraoverhaulneoforge.core.structures.Transform;
import dev.cammiescorner.icarus.IcarusConfig;
import io.github.avacadowizard120.cameraoverhaulneoforge.core.callbacks.CameraUpdateCallback;
import io.github.avacadowizard120.cameraoverhaulneoforge.core.callbacks.ModifyCameraTransformCallback;
import io.github.avacadowizard120.cameraoverhaulneoforge.core.structures.Transform;
import net.minecraft.client.Camera;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModList;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.client.ConfigScreenHandler;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;

@Mod.EventBusSubscriber(modid = Icarus.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
@EventBusSubscriber(modid = Icarus.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class Client {

@SubscribeEvent
Expand All @@ -33,7 +33,7 @@ public static void onClientSetup(FMLClientSetupEvent event) {
CameraOverhaulCompat.load();
}

event.enqueueWork(() -> ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((minecraft, parent) -> new ConfigScreen(parent, Icarus.CONFIGURATOR.getConfig(IcarusConfig.class)))));
event.enqueueWork(() -> ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> (modContainer, parentScreen) -> new ConfigScreen(parentScreen, Icarus.CONFIGURATOR.getConfig(IcarusConfig.class))));
}

@SubscribeEvent
Expand All @@ -42,7 +42,7 @@ public static void onRegisterColorHandlers(RegisterColorHandlersEvent.Item event
var item = entry.getValue();
var key = entry.getKey();
if(key.location().getNamespace().equals(Icarus.MODID) && item instanceof WingItem) {
event.register((itemStack, tintIndex) -> tintIndex == 0 ? ColorHelper.dyeToDecimal(((WingItem) itemStack.getItem()).getPrimaryColor(itemStack)) : ColorHelper.dyeToDecimal(((WingItem) itemStack.getItem()).getSecondaryColor(itemStack)), item);
event.register((itemStack, tintIndex) -> tintIndex == 0 ? ColorHelper.asARGB(((WingItem) itemStack.getItem()).getPrimaryColor(itemStack)) : ColorHelper.asARGB(((WingItem) itemStack.getItem()).getSecondaryColor(itemStack)), item);
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions NeoForge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ config = "${mod_id}.mixins.json"
[[mixins]]
config = "${mod_id}.neoforge.mixins.json"

[[accessTransformers]]
file = "META-INF/accesstransformer.cfg"

# https://docs.neoforged.net/docs/gettingstarted/modfiles#dependency-configurations
[dependencies]
"${mod_id}" = [
Expand All @@ -40,6 +37,9 @@ file = "META-INF/accesstransformer.cfg"
#[features.${mod_id}]
#openGLVersion="[3.2,)"

#[[accessTransformers]]
#file = "META-INF/accesstransformer.cfg"

[mc-publish]
curseforge = "${curseforge_id}"
modrinth = "${modrinth_id}"
Expand Down
Loading

0 comments on commit 10ae264

Please sign in to comment.