Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.17 port #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '0.2.2-SNAPSHOT'
id 'fabric-loom' version '0.8-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand All @@ -17,10 +17,10 @@ dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
// modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand All @@ -29,9 +29,8 @@ dependencies {
processResources {
inputs.property "version", project.mod_version

from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.mod_version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

Expand All @@ -45,14 +44,14 @@ tasks.withType(JavaCompile) {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
java{
withSourcesJar()
}

jar {
from "LICENSE"
}
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}}

// configure the maven publication
publishing {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.14.2
yarn_mappings=1.14.2+build.7
loader_version=0.4.8+build.155
minecraft_version=1.17
yarn_mappings=1.17+build.6
loader_version=0.11.3

# Mod Properties
mod_version = 1.1.0
mod_version = 1.1.1
maven_group = com.extracraftx.minecraft
archives_base_name = BeaconFlight

Expand Down
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-4.10.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginManagement {
repositories {
jcenter()
mavenCentral()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static void onBeaconUpdate(PlayerEntity player, int duration, int level){
return;
if(!checkItem(config.feet, sp.getEquippedStack(EquipmentSlot.FEET)))
return;
ServerAdvancementLoader advLoader = sp.getServer().getAdvancementManager();
PlayerAdvancementTracker playerAdv = sp.getAdvancementManager();
ServerAdvancementLoader advLoader = sp.getServer().getAdvancementLoader();
PlayerAdvancementTracker playerAdv = sp.getAdvancementTracker();
for(Identifier advancement : config.advancements){
if(!playerAdv.getProgress(advLoader.get(advancement)).isDone())
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
package com.extracraftx.minecraft.beaconflight.mixin;

import java.util.Iterator;
import java.util.List;

import com.extracraftx.minecraft.beaconflight.events.EventHandler;

import net.minecraft.block.entity.BeaconBlockEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
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.LocalCapture;

import net.minecraft.block.entity.BeaconBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BoundingBox;
import java.util.List;

@Mixin(BeaconBlockEntity.class)
public abstract class BeaconBlockEntityMixin {

@Shadow
private int level;

//I dunno why the old one kept failing
@Inject(method = "applyPlayerEffects",
at = @At(value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/entity/player/PlayerEntity;addPotionEffect(Lnet/minecraft/entity/effect/StatusEffectInstance;)Z",
ordinal = 0
at = @At(value = "TAIL"
), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onApplyPlayerEffects(CallbackInfo info, double d, int i, int duration, BoundingBox bb, List l, Iterator it, PlayerEntity player) {
EventHandler.onBeaconUpdate(player, duration, level);
private static void onApplyPlayerEffects(World world, BlockPos blockPos, int i, @Nullable StatusEffect statusEffect, @Nullable StatusEffect statusEffect2, CallbackInfo info, double d, int y, int duration, Box bb, List<PlayerEntity> list) {
for (PlayerEntity playerEntity : list) {
EventHandler.onBeaconUpdate(playerEntity, duration, i);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.extracraftx.minecraft.beaconflight.interfaces.FlyEffectable;
import com.mojang.authlib.GameProfile;

import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameMode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -14,15 +18,15 @@
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity implements FlyEffectable{
public ServerPlayerEntityMixin(World world, GameProfile profile){
super(world, profile);

public ServerPlayerEntityMixin(World world, BlockPos blockPos, float f, GameProfile gameProfile) {
super(world, blockPos, f, gameProfile);
}

private int flyTicksLeft = 0;
Expand All @@ -32,6 +36,7 @@ public ServerPlayerEntityMixin(World world, GameProfile profile){
public void allowFlight(int ticks, boolean setFlying) {
flyTicksLeft = Math.max(flyTicksLeft, ticks);
if(Config.INSTANCE.xpDrainRate == 0 || totalExperience > 0){
PlayerAbilities abilities = getAbilities();
abilities.allowFlying = true;
if(setFlying)
abilities.flying = true;
Expand All @@ -41,17 +46,19 @@ public void allowFlight(int ticks, boolean setFlying) {

@Override
public void disallowFlight() {
PlayerAbilities abilities = getAbilities();
abilities.allowFlying = false;
abilities.flying = false;
sendAbilitiesUpdate();
addPotionEffect(new StatusEffectInstance(StatusEffects.SLOW_FALLING, Config.INSTANCE.slowFallingTime*20));
if (Config.INSTANCE.slowFallingTime > 0)
addStatusEffect(new StatusEffectInstance(StatusEffects.SLOW_FALLING, Config.INSTANCE.slowFallingTime*20));
}

@Override
public void tickFlight() {
if(flyTicksLeft > 0){
if(Config.INSTANCE.xpDrainRate != 0){
if(abilities.flying){
if(getAbilities().flying){
xpCounter += Config.INSTANCE.xpDrainRate;
addExperience(-(int)Math.floor(xpCounter));
xpCounter %= 1;
Expand All @@ -77,18 +84,17 @@ private void onTick(CallbackInfo info){
EventHandler.onPlayerTick(this);
}

@Inject(method = "setGameMode", at = @At("RETURN"))
private void onSetGameMode(GameMode gameMode, CallbackInfo info){
@Inject(method = "changeGameMode", at = @At("HEAD"))
private void onSetGameMode(GameMode gameMode, CallbackInfoReturnable<Boolean> cir){
EventHandler.onSetGameMode(gameMode, this);
}

@Inject(method = "writeCustomDataToTag", at = @At("RETURN"))
private void onWriteCustomDataToTag(CompoundTag tag, CallbackInfo info){
@Inject(method = "writeCustomDataToNbt", at = @At("RETURN"))
private void onWriteCustomDataToTag(NbtCompound tag, CallbackInfo info){
tag.putInt("flyTicksLeft", flyTicksLeft);
}

@Inject(method = "readCustomDataFromTag", at = @At("RETURN"))
private void onReadCustomDataFromTag(CompoundTag tag, CallbackInfo info){
@Inject(method = "readCustomDataFromNbt", at = @At("RETURN"))
private void onReadCustomDataFromTag(NbtCompound tag, CallbackInfo info){
allowFlight(tag.getInt("flyTicksLeft"), false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/beaconflight.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required": true,
"package": "com.extracraftx.minecraft.beaconflight.mixin",
"compatibilityLevel": "JAVA_8",
"compatibilityLevel": "JAVA_16",
"mixins": [
"BeaconBlockEntityMixin",
"ServerPlayerEntityMixin"
Expand Down