Skip to content
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
73 changes: 37 additions & 36 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,76 +1,77 @@
plugins {
id 'fabric-loom' version '0.2.2-SNAPSHOT'
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

minecraft {
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}

dependencies {
//to change the versions see the gradle.properties file
// 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}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
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.
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
}

processResources {
inputs.property "version", project.mod_version
inputs.property "version", project.version

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

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}

// 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 {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

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

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(jar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
from components.java
}
}

// select the repositories you want to publish to
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// uncomment to publish to the local maven
// mavenLocal()
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx3G

# 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.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.12

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

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric
fabric_version=0.3.0+build.184
fabric_version=0.72.0+1.19.3
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Jan 13 20:57:14 AEDT 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BeaconFlight implements ModInitializer{

public static final String MOD_ID = "beaconflight";
public static final String MOD_NAME = "BeaconFlight";
public static final String MOD_VER = "1.1.0";
public static final String MOD_VER = "1.2.2";

public static Logger LOGGER = LogManager.getLogger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.registry.Registries;

public class Config{
public static Config INSTANCE = new Config();
Expand Down Expand Up @@ -101,6 +101,6 @@ private void generateTransients(){
}

private static Item getItem(String id){
return Registry.ITEM.get(new Identifier(id));
return Registries.ITEM.get(new Identifier(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,14 @@ 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;
}
FlyEffectable p = (FlyEffectable)player;
if(config.flightLingerTime != 0)
p.allowFlight(config.flightLingerTime, false);
else
p.allowFlight(duration, false);
p.allowFlight(duration, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,47 @@
import java.util.Iterator;
import java.util.List;

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

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.effect.StatusEffect;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BoundingBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.util.math.Box;

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

@Shadow
private int level;

@Inject(method = "applyPlayerEffects",
at = @At(value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/entity/player/PlayerEntity;addPotionEffect(Lnet/minecraft/entity/effect/StatusEffectInstance;)Z",
ordinal = 0
), 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);
public class BeaconBlockEntityMixin {

@Inject(method = "applyPlayerEffects", at = @At("TAIL"))
private static void applyPlayerEffects(World world, BlockPos pos, int beaconLevel, StatusEffect primaryEffect, StatusEffect secondaryEffect, CallbackInfo ci) {
Config config = Config.INSTANCE;

// Calculate duration of effect
int duration = (2 * beaconLevel + 9) * 20;
// Calc range of beacon
double d = beaconLevel * 10 + 10;

if (config.flightLingerTime != 0) {
duration = config.flightLingerTime * 20;
}

// Create box around beacon that represents the status effect range
Box box = (new Box(pos)).expand(d).stretch(0.0D, world.getHeight(), 0.0D);
// Get all players in the box
List<PlayerEntity> players = world.getNonSpectatingEntities(PlayerEntity.class, box);

// Iterate over all players
for (Iterator<PlayerEntity> iterator = players.iterator(); iterator.hasNext();) {
PlayerEntity player = iterator.next();
// Call event handler
EventHandler.onBeaconUpdate(player, duration, beaconLevel);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.entity.EquipmentSlot;
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.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;

@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 pos, float yaw, GameProfile profile) {
super(world, pos, yaw, profile);
}

private int flyTicksLeft = 0;
Expand All @@ -32,26 +34,32 @@ 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){
abilities.allowFlying = true;
getAbilities().allowFlying = true;
if(setFlying)
abilities.flying = true;
getAbilities().flying = true;
sendAbilitiesUpdate();
}
}

@Override
public void disallowFlight() {
abilities.allowFlying = false;
abilities.flying = false;
// if in creative mode dont disallow flight
if(getAbilities().creativeMode)
return;
getAbilities().allowFlying = false;
getAbilities().flying = false;
sendAbilitiesUpdate();
addPotionEffect(new StatusEffectInstance(StatusEffects.SLOW_FALLING, Config.INSTANCE.slowFallingTime*20));
// if player is wearing elytra dont add slow falling effect
if(!getEquippedStack(EquipmentSlot.CHEST).getItem().equals(Items.ELYTRA)) {
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 +85,13 @@ private void onTick(CallbackInfo info){
EventHandler.onPlayerTick(this);
}

@Inject(method = "setGameMode", at = @At("RETURN"))
private void onSetGameMode(GameMode gameMode, CallbackInfo info){
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/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "beaconflight",
"version": "1.1.0",
"version": "${version}",

"name": "BeaconFlight",
"description": "This mod allows flying when in range of a beacon when certain configurable conditions are met.",
Expand Down