Skip to content

Commit

Permalink
Merge pull request #8 from cassiancc/1.21.1
Browse files Browse the repository at this point in the history
Port to 1.21.1
  • Loading branch information
hamusuke0323 authored Oct 15, 2024
2 parents cb174aa + f0f8235 commit f8783a3
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 70 deletions.
70 changes: 36 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# Automatically build the project and run any configured tests for every push
# and submitted pull request. This can help catch issues that only occur on
# certain platforms or Java versions, and provides a first line of defence
# against bad commits.
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle

name: build
on: [pull_request, push]
name: Gradle Package

on: [push]
jobs:
build:
strategy:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and Windows
os: [ubuntu-20.04, windows-2022]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: checkout repository
uses: actions/checkout@v2
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: setup jdk ${{ matrix.java }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v2
with:
name: Artifacts
path: build/libs/
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew build

- name: Upload Build
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand Down Expand Up @@ -42,8 +42,8 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
// Minecraft 1.21 upwards uses Java 21.
it.options.release = 21
}

java {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.2
loader_version=0.14.21
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.7


# Mod Properties
mod_version=1.20.1-1.0.0
mod_version=1.21.1+1.0.0
maven_group=com.hamusuke
archives_base_name=fly-command-mod
# Dependencies
fabric_version=0.83.1+1.20.1
fabric_version=0.102.0+1.21.1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion src/main/java/com/hamusuke/flycommod/FlyCommandMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class FlyCommandMod implements ModInitializer {
public static final String MOD_ID = "flycommand";
public static final Item FLYING_STICK = Registry.register(Registries.ITEM, new Identifier(MOD_ID, "flying_stick"), new FlyingStickItem());
public static final Item FLYING_STICK = Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "flying_stick"), new FlyingStickItem());

@Override
public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemGroups;

Expand All @@ -17,15 +18,15 @@ public class FlyCommandModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register(entries -> entries.add(FlyCommandMod.FLYING_STICK));

ClientPlayNetworking.registerGlobalReceiver(NetworkManager.NO_FALL_MARK_PACKET, (client, handler, buf, responseSender) -> {
if (client.world != null) {
MarkNoFallDamagePacket packet = new MarkNoFallDamagePacket(buf);
Entity entity = client.world.getEntityById(packet.getEntityId());
PayloadTypeRegistry.playS2C().register(MarkNoFallDamagePacket.PACKET_ID, MarkNoFallDamagePacket.PACKET_CODEC);
ClientPlayNetworking.registerGlobalReceiver(MarkNoFallDamagePacket.PACKET_ID, ((payload, context) -> {
if (context.client().world != null) {
MarkNoFallDamagePacket packet = new MarkNoFallDamagePacket(payload);
Entity entity = context.client().world.getEntityById(packet.getEntityId());
if (entity instanceof LivingEntityInvoker invoker) {
invoker.markNoFallDamage(packet.getMarkFlag());
}
}
});
}));
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/hamusuke/flycommod/item/FlyingStickItem.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.hamusuke.flycommod.item;

import com.hamusuke.flycommod.invoker.LivingEntityInvoker;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.Rarity;
Expand All @@ -19,13 +18,14 @@

public class FlyingStickItem extends Item {
public FlyingStickItem() {
super(new FabricItemSettings().equipmentSlot(stack -> EquipmentSlot.MAINHAND).fireproof().rarity(Rarity.EPIC).recipeRemainder(Items.ELYTRA).maxCount(1));
super(new Item.Settings().equipmentSlot((entity, stack) -> EquipmentSlot.MAINHAND).fireproof().rarity(Rarity.EPIC).recipeRemainder(Items.ELYTRA).maxCount(1));
}


@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
tooltip.add(Text.translatable(this.getTranslationKey() + ".desc"));
super.appendTooltip(stack, world, tooltip, context);
super.appendTooltip(stack, context, tooltip, type);
}

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

import com.hamusuke.flycommod.invoker.LivingEntityInvoker;
import com.hamusuke.flycommod.network.MarkNoFallDamagePacket;
import com.hamusuke.flycommod.network.NetworkManager;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity implements LivingEntityInvoker {
@Shadow public abstract boolean blockedByShield(DamageSource source);

private boolean isNoFallDamageMarked;

LivingEntityMixin(EntityType<?> type, World world) {
Expand Down Expand Up @@ -48,8 +48,7 @@ public void readNbt(NbtCompound nbt, CallbackInfo ci) {
@Override
public void markNoFallDamage(boolean flag) {
if (!this.getWorld().isClient) {
PacketByteBuf byteBuf = new MarkNoFallDamagePacket(this.getId(), flag).write(PacketByteBufs.create());
this.getWorld().getServer().getPlayerManager().getPlayerList().forEach(serverPlayerEntity -> serverPlayerEntity.networkHandler.sendPacket(new CustomPayloadS2CPacket(NetworkManager.NO_FALL_MARK_PACKET, byteBuf)));
this.getWorld().getServer().getPlayerManager().sendToAll((new CustomPayloadS2CPacket(new MarkNoFallDamagePacket(this.getId(), flag))));
}

this.isNoFallDamageMarked = flag;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.hamusuke.flycommod.network;

import com.hamusuke.flycommod.FlyCommandMod;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;

public class MarkNoFallDamagePacket {
public class MarkNoFallDamagePacket implements CustomPayload {
private final int entityId;
private final boolean flag;

Expand All @@ -15,16 +19,34 @@ public MarkNoFallDamagePacket(PacketByteBuf byteBuf) {
this(byteBuf.readVarInt(), byteBuf.readBoolean());
}

public MarkNoFallDamagePacket(MarkNoFallDamagePacket payload) {
this.entityId = payload.entityId;
this.flag = payload.flag;
}

public PacketByteBuf write(PacketByteBuf byteBuf) {
byteBuf.writeVarInt(this.entityId).writeBoolean(this.flag);
return byteBuf;
}

// Static method, buffer-first
public static void write2(PacketByteBuf byteBuf, MarkNoFallDamagePacket packet) {
byteBuf.writeVarInt(packet.entityId).writeBoolean(packet.flag);
}

public int getEntityId() {
return this.entityId;
}

public boolean getMarkFlag() {
return this.flag;
}

public static final CustomPayload.Id<MarkNoFallDamagePacket> PACKET_ID = new CustomPayload.Id<>(Identifier.of(FlyCommandMod.MOD_ID, "no_fall_mark_packet"));
public static final PacketCodec<PacketByteBuf, MarkNoFallDamagePacket> PACKET_CODEC = PacketCodec.ofStatic(MarkNoFallDamagePacket::write2, MarkNoFallDamagePacket::new);

@Override
public Id<? extends CustomPayload> getId() {
return PACKET_ID;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.hamusuke.flycommod.network;

import com.hamusuke.flycommod.FlyCommandMod;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;
import net.minecraft.util.Uuids;

import java.util.UUID;

public final class NetworkManager {
public static final Identifier NO_FALL_MARK_PACKET = new Identifier(FlyCommandMod.MOD_ID, "no_fall_mark_packet");
public static final Identifier NO_FALL_MARK_PACKET = Identifier.of(FlyCommandMod.MOD_ID, "no_fall_mark_packet");

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"result": {
"item": "flycommand:flying_stick",
"id": "flycommand:flying_stick",
"count": 1
}
}
8 changes: 4 additions & 4 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"flycommand.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.17",
"fabric": "*",
"minecraft": ">=1.20-",
"java": ">=17"
"fabricloader": ">=0.16.5",
"fabric-api": "*",
"minecraft": ">=1.21-",
"java": ">=21"
}
}

0 comments on commit f8783a3

Please sign in to comment.