Skip to content

Commit

Permalink
Merge branch 'api-13' into api-14
Browse files Browse the repository at this point in the history
# Conflicts:
#	SpongeAPI
  • Loading branch information
Yeregorix committed Feb 24, 2025
2 parents 350167e + 5956182 commit eb215af
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 104 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,33 @@ jobs:
fail-fast: false
matrix:
project:
- common
- vanilla
- forge
- neoforge
include:
- project: common
gradleProject: ''
skipUpdateBranch: false
- project: vanilla
gradleProject: SpongeVanilla
gradleProject: ':SpongeVanilla'
skipUpdateBranch: false
- project: forge
gradleProject: SpongeForge
gradleProject: ':SpongeForge'
skipUpdateBranch: true
- project: neoforge
gradleProject: SpongeNeo
gradleProject: ':SpongeNeo'
skipUpdateBranch: true
steps:
- name: setup
if: "!startsWith(github.ref, 'refs/heads/update/') || matrix.project == 'vanilla'"
if: "!(matrix.skipUpdateBranch && startsWith(github.ref, 'refs/heads/update/'))"
id: setup
uses: SpongePowered/.github/.github/actions/setup-java-env@master
with:
runtime_version: 21
publishing_branch_regex: ''
- name: setup / minecraft cache
if: "!startsWith(github.ref, 'refs/heads/update/') || matrix.project == 'vanilla'"
if: "!(matrix.skipUpdateBranch && startsWith(github.ref, 'refs/heads/update/'))"
uses: "actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9" # v4.0.2
with:
path: |
Expand All @@ -58,14 +65,14 @@ jobs:
${{ runner.os }}-minecraft-${{ env.CACHE_REV }}-
# We don't need to run tests again, so we just publish
- name: setup / workspace
if: "!startsWith(github.ref, 'refs/heads/update/') || matrix.project == 'vanilla'"
if: "!(matrix.skipUpdateBranch && startsWith(github.ref, 'refs/heads/update/'))"
run: |
echo "GIT_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
echo "BUILD_NUMBER=${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV
- name: Publish to Sponge Maven & GitHub Packages
if: "!startsWith(github.ref, 'refs/heads/update/') || matrix.project == 'vanilla'"
run: ./gradlew -s -Pprojects=vanilla,${{ matrix.project }} :${{ matrix.gradleProject }}:publish
if: "!(matrix.skipUpdateBranch && startsWith(github.ref, 'refs/heads/update/'))"
run: ./gradlew -s -Pprojects=${{ matrix.project }} ${{ matrix.gradleProject }}:publish
env:
CI_SYSTEM: Github Actions
GITHUB_USERNAME: "${{ github.actor }}"
Expand Down
2 changes: 1 addition & 1 deletion SpongeAPI
20 changes: 0 additions & 20 deletions forge/src/main/java/org/spongepowered/forge/SpongeForgeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
package org.spongepowered.forge;

import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.event.server.ServerAboutToStartEvent;
Expand All @@ -40,8 +36,6 @@
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.Client;
Expand Down Expand Up @@ -74,7 +68,6 @@ public SpongeForgeMod(FMLJavaModLoadingContext ctx) {
// modBus: add all FML events with it
modBus.addListener(this::onCommonSetup);
modBus.addListener(this::onClientSetup);
modBus.addListener(this::onRegister);
modBus.addListener(this::onEntityAttributeCreationEvent);

// annotation events, for non-FML things
Expand Down Expand Up @@ -139,19 +132,6 @@ public void onServerStoppingEvent(final ServerStoppingEvent event) {
lifecycle.callStoppingEngineEvent((Server) event.getServer());
}

public void onRegister(RegisterEvent event) {
if (event.getRegistryKey() == ForgeRegistries.Keys.ENTITY_TYPES) {
SpongeEntityTypes.HUMAN = EntityType.Builder.of(HumanEntity::new, MobCategory.MISC)
.noSave()
.sized(0.6F, 1.8F)
.clientTrackingRange(org.spongepowered.common.util.Constants.Entity.Player.TRACKING_RANGE)
.updateInterval(2)
.build(ResourceKey.create(ForgeRegistries.Keys.ENTITY_TYPES, ResourceLocation.parse("sponge:human")))
;

event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> helper.register(HumanEntity.KEY, SpongeEntityTypes.HUMAN));
}
}
public void onEntityAttributeCreationEvent(final EntityAttributeCreationEvent event) {
event.put(SpongeEntityTypes.HUMAN, HumanEntity.createAttributes());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.forge.mixin.core.minecraftforge.registries;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.EntityType;
import net.minecraftforge.registries.GameData;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.entity.SpongeEntityTypes;

@Mixin(GameData.class)
public class GameDataMixin_Forge {

@Inject(method = "postRegisterEvents", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/ModLoader;postEventWrapContainerInModOrder(Lnet/minecraftforge/eventbus/api/Event;)V", shift = At.Shift.AFTER))
private static void forge$registerSpongeTypesLast(final CallbackInfo ci, @Nullable @Local final Registry<?> vanillaRegistry) {
if (vanillaRegistry != null && Registries.ENTITY_TYPE.equals(vanillaRegistry.key())) {
SpongeEntityTypes.register((Registry<EntityType<?>>) vanillaRegistry);
}
}
}
1 change: 1 addition & 0 deletions forge/src/mixins/resources/mixins.spongeforge.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"minecraftforge.event.world.BlockEventMixin_Forge",
"minecraftforge.internal.BrandingControlMixin_Forge",
"minecraftforge.registries.ForgeRegistryMixin_Forge",
"minecraftforge.registries.GameDataMixin_Forge",
"minecraftforge.registries.RegistryManagerMixin_Forge",
"network.ConnectionMixin_Forge",
"network.protocol.common.ClientboundCustomPayloadPacketMixin_Forge",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
package org.spongepowered.neoforge;

import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
Expand All @@ -40,7 +35,6 @@
import net.neoforged.neoforge.event.server.ServerAboutToStartEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
import net.neoforged.neoforge.registries.RegisterEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.Client;
Expand Down Expand Up @@ -69,7 +63,6 @@ public SpongeNeoMod(IEventBus modBus) {
// modBus: add all FML events with it
modBus.addListener(this::onCommonSetup);
modBus.addListener(this::onClientSetup);
modBus.addListener(this::onRegister);
modBus.addListener(this::onEntityAttributeCreationEvent);

// annotation events, for non-FML things
Expand Down Expand Up @@ -134,19 +127,6 @@ public void onServerStoppingEvent(final ServerStoppingEvent event) {
lifecycle.callStoppingEngineEvent((Server) event.getServer());
}

public void onRegister(RegisterEvent event) {
if (event.getRegistryKey() == Registries.ENTITY_TYPE) {
SpongeEntityTypes.HUMAN = EntityType.Builder.of(HumanEntity::new, MobCategory.MISC)
.noSave()
.sized(0.6F, 1.8F)
.clientTrackingRange(org.spongepowered.common.util.Constants.Entity.Player.TRACKING_RANGE)
.updateInterval(2)
.build(ResourceKey.create(Registries.ENTITY_TYPE, ResourceLocation.parse("sponge:human")));

event.register(Registries.ENTITY_TYPE, helper -> helper.register(HumanEntity.KEY, SpongeEntityTypes.HUMAN));
}
}

public void onEntityAttributeCreationEvent(final EntityAttributeCreationEvent event) {
event.put(SpongeEntityTypes.HUMAN, HumanEntity.createAttributes());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.neoforge.mixin.core.neoforge.registries;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.EntityType;
import net.neoforged.neoforge.registries.GameData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.entity.SpongeEntityTypes;

@Mixin(GameData.class)
public class GameDataMixin_Neo {

@Inject(method = "postRegisterEvents", at = @At(value = "INVOKE", target = "Lnet/neoforged/fml/ModLoader;postEventWrapContainerInModOrder(Lnet/neoforged/bus/api/Event;)V", shift = At.Shift.AFTER))
private static void neo$registerSpongeTypesLast(final CallbackInfo ci, @Local final Registry<?> registry) {
if (Registries.ENTITY_TYPE.equals(registry.key())) {
SpongeEntityTypes.register((Registry<EntityType<?>>) registry);
}
}
}
1 change: 1 addition & 0 deletions neoforge/src/mixins/resources/mixins.spongeneo.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"neoforge.event.world.BlockEvent_BreakEventMixin_Neo",
"neoforge.event.world.BlockEventMixin_Neo",
"neoforge.internal.BrandingControlMixin_Neo",
"neoforge.registries.GameDataMixin_Neo",
"neoforge.registries.RegistryManagerMixin_Neo",
"network.ConnectionMixin_Neo",
"server.BootstrapMixin_Neo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,10 @@ private static DataContainer getViewFromCompound(CompoundTag compound) {

@SuppressWarnings({"unchecked", "rawtypes"})
private static void setInternal(Tag base, byte type, DataView view, String key) {
Objects.requireNonNull(base);
Objects.requireNonNull(view);
Objects.requireNonNull(key);
Preconditions.checkArgument(!key.isEmpty());
Preconditions.checkArgument(type > Constants.NBT.TAG_END && type <= Constants.NBT.TAG_LONG_ARRAY);
Objects.requireNonNull(base, "base");
Objects.requireNonNull(view, "view");
Objects.requireNonNull(key, "key");
Preconditions.checkArgument(!key.isEmpty(), "key is empty");
switch (type) {
case Constants.NBT.TAG_BYTE:
if (key.contains(NBTTranslator.BOOLEAN_IDENTIFIER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.spongepowered.api.entity.display.BillboardType;
import org.spongepowered.api.entity.display.DisplayEntity;
import org.spongepowered.api.entity.display.ItemDisplayType;
import org.spongepowered.api.entity.display.TextAlignment;
import org.spongepowered.api.util.Color;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.api.util.Transform;
Expand Down Expand Up @@ -119,11 +120,11 @@ public static void register(final DataProviderRegistrator registrator) {
.set((h, v) -> h.invoker$setBlockState((net.minecraft.world.level.block.state.BlockState) v))
.asMutable(Display_ItemDisplayAccessor.class)
.create(Keys.ITEM_STACK_SNAPSHOT)
.get(h -> ItemStackUtil.snapshotOf(((Display_ItemDisplayAccessor)h).invoker$getItemStack()))
.get(h -> ItemStackUtil.snapshotOf(h.invoker$getItemStack()))
.set((h, v) -> h.invoker$setItemStack(ItemStackUtil.fromSnapshotToNative(v)))
.create(Keys.ITEM_DISPLAY_TYPE)
.get(h -> (ItemDisplayType) (Object) h.invoker$getItemTransform())
.set((h, v) -> ((Display_ItemDisplayAccessor) h).invoker$setItemTransform(((ItemDisplayContext) (Object) v)))
.set((h, v) -> h.invoker$setItemTransform(((ItemDisplayContext) (Object) v)))
.asMutable(Display_TextDisplayAccessor.class)
.create(Keys.DISPLAY_NAME)
.get(h -> SpongeAdventure.asAdventure(h.invoker$getText()))
Expand All @@ -143,12 +144,15 @@ public static void register(final DataProviderRegistrator registrator) {
.create(Keys.HAS_DEFAULT_BACKGROUND)
.get(h -> DisplayEntityData.getFlagValue(h, Display.TextDisplay.FLAG_USE_DEFAULT_BACKGROUND))
.set((h, v) -> DisplayEntityData.setFlagValue(h, v, Display.TextDisplay.FLAG_USE_DEFAULT_BACKGROUND))
.create(Keys.HAS_DEFAULT_BACKGROUND)
.get(h -> DisplayEntityData.getFlagValue(h, Display.TextDisplay.FLAG_USE_DEFAULT_BACKGROUND))
.set((h, v) -> DisplayEntityData.setFlagValue(h, v, Display.TextDisplay.FLAG_USE_DEFAULT_BACKGROUND))
.create(Keys.TEXT_ALIGNMENT)
.get(DisplayEntityData::getAlignment)
.set(DisplayEntityData::setAlignment)
.create(Keys.TEXT_BACKGROUND_COLOR)
.get(h -> DisplayEntityData.colorFromInt(h.invoker$getBackgroundColor()))
.set((h, v) -> h.invoker$setBackgroundColor(DisplayEntityData.colorToInt(v)))
.get(h -> DisplayEntityData.argbToColor(h.invoker$getBackgroundColor()))
.set((h, v) -> h.invoker$setBackgroundColor(DisplayEntityData.argbWithColor(h.invoker$getBackgroundColor(), v)))
.create(Keys.TEXT_BACKGROUND_OPACITY)
.get(h -> DisplayEntityData.argbToOpacity(h.invoker$getBackgroundColor()))
.set((h, v) -> h.invoker$setBackgroundColor(DisplayEntityData.argbWithOpacity(h.invoker$getBackgroundColor(), v)))
;
registrator.spongeDataStore(Keys.TELEPORT_DURATION.key(), DisplayEntity.class, Keys.TELEPORT_DURATION);
}
Expand Down Expand Up @@ -200,12 +204,45 @@ private static Integer skyLight(final int original) {
return Brightness.unpack(original).sky();
}

private static Color colorFromInt(final int color) {
return Color.ofRgb(color);
private static Color argbToColor(final int argb) {
return Color.ofRgb(argb & 0x00ffffff);
}

private static byte argbToOpacity(final int argb) {
return (byte) (argb >> 24);
}

private static int argbWithColor(final int argb, final Color color) {
final int alpha = argb & 0xff000000;
final int rgb = color.rgb();
return alpha | rgb;
}

private static int argbWithOpacity(final int argb, final Byte opacity) {
final int alpha = opacity << 24;
final int rgb = argb & 0x00ffffff;
return alpha | rgb;
}

private static int colorToInt(final Color color) {
return color.rgb();
private static TextAlignment getAlignment(final Display_TextDisplayAccessor h) {
return (TextAlignment) (Object) Display.TextDisplay.getAlign(h.invoker$getFlags());
}

private static void setAlignment(final Display_TextDisplayAccessor h, final TextAlignment alignment) {
switch ((Display.TextDisplay.Align) (Object) alignment) {
case LEFT -> {
DisplayEntityData.setFlagValue(h, true, Display.TextDisplay.FLAG_ALIGN_LEFT);
DisplayEntityData.setFlagValue(h, false, Display.TextDisplay.FLAG_ALIGN_RIGHT);
}
case RIGHT -> {
DisplayEntityData.setFlagValue(h, false, Display.TextDisplay.FLAG_ALIGN_LEFT);
DisplayEntityData.setFlagValue(h, true, Display.TextDisplay.FLAG_ALIGN_RIGHT);
}
case CENTER -> {
DisplayEntityData.setFlagValue(h, false, Display.TextDisplay.FLAG_ALIGN_LEFT);
DisplayEntityData.setFlagValue(h, false, Display.TextDisplay.FLAG_ALIGN_RIGHT);
}
}
}

private static Transform getTransform(final Display display) {
Expand Down
Loading

0 comments on commit eb215af

Please sign in to comment.