Skip to content

Commit 6990a3f

Browse files
committed
1.19
1 parent 224bf30 commit 6990a3f

File tree

11 files changed

+95
-81
lines changed

11 files changed

+95
-81
lines changed

build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ dependencies {
2828
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
2929

3030
// Fabric API. This is technically optional, but you probably want it anyway.
31-
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
31+
[
32+
"fabric-api-base",
33+
"fabric-command-api-v2",
34+
"fabric-lifecycle-events-v1",
35+
"fabric-entity-events-v1",
36+
"fabric-events-interaction-v0"
37+
].forEach {
38+
include(modImplementation(fabricApi.module(it, project.fabric_version)))
39+
}
3240
}
3341

3442
processResources {

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Done to increase the memory available to gradle.
22
org.gradle.jvmargs=-Xmx1G
33
# Fabric Properties
4-
minecraft_version=1.19-pre1
5-
yarn_mappings=1.19-pre1+build.1
6-
loader_version=0.14.5
4+
minecraft_version=1.19
5+
yarn_mappings=1.19+build.2
6+
loader_version=0.14.7
77
#Fabric api
8-
fabric_version=0.52.4+1.19
8+
fabric_version=0.55.3+1.19
99
# Mod Properties
1010
mod_version=0.5.2
1111
maven_group=org.samo_lego

src/main/java/org/samo_lego/golfiv/GolfIV.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.samo_lego.golfiv;
22

33
import net.fabricmc.api.ModInitializer;
4-
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
4+
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
55
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
66
import net.fabricmc.loader.api.FabricLoader;
77
import org.samo_lego.golfiv.commands.GolfCommand;
@@ -26,9 +26,8 @@ public class GolfIV implements ModInitializer {
2626
public void onInitialize() {
2727
golfConfig = GolfConfig.loadConfig(new File(FabricLoader.getInstance().getConfigDir() + "/GolfIV_config.json"));
2828

29-
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
30-
GolfCommand.registerCommand(dispatcher);
31-
});
29+
CommandRegistrationCallback.EVENT.register((dispatcher, ignored, ignored1) ->
30+
GolfCommand.registerCommand(dispatcher));
3231

3332
// Events
3433
CombatModule.registerEvents();

src/main/java/org/samo_lego/golfiv/event/combat/AngleCheck.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package org.samo_lego.golfiv.event.combat;
22

3+
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
4+
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
35
import net.minecraft.entity.Entity;
46
import net.minecraft.entity.player.PlayerEntity;
57
import net.minecraft.util.ActionResult;
8+
import net.minecraft.util.Hand;
69
import net.minecraft.util.hit.EntityHitResult;
710
import net.minecraft.util.math.Box;
11+
import net.minecraft.world.World;
12+
import org.jetbrains.annotations.Nullable;
813

914
import static org.samo_lego.golfiv.GolfIV.golfConfig;
1015

11-
public class AngleCheck implements EntityInteractPacketCallback {
16+
public class AngleCheck implements UseEntityCallback, AttackEntityCallback {
1217
public AngleCheck() {
1318
}
1419

@@ -17,12 +22,12 @@ public AngleCheck() {
1722
*
1823
* @param player player trying to interact with entity.
1924
* @param victim entity player is trying to interact with.
20-
* @param maxDistanceSquared maximal allowed distance for interaction, squared.
2125
* @return {@link ActionResult#FAIL} if player shouldn't be able to hit the victim, otherwise {@link ActionResult#PASS}
2226
*/
2327
@Override
24-
public ActionResult onEntityInteractPacket(PlayerEntity player, Entity victim, double maxDistanceSquared) {
25-
if(golfConfig.combat.checkHitAngle) {
28+
public ActionResult interact(PlayerEntity player, World world, Hand hand, Entity victim, @Nullable EntityHitResult hitResult) {
29+
30+
if (golfConfig.combat.checkHitAngle) {
2631
EntityHitResult entityHit = new EntityHitResult(victim);
2732
double victimDistanceSquared = entityHit.squaredDistanceTo(player);
2833
double victimDistance = Math.sqrt(victimDistanceSquared);
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
package org.samo_lego.golfiv.event.combat;
22

3+
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
4+
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
5+
36
public class CombatModule {
47
public static void registerEvents() {
5-
EntityInteractPacketCallback.EVENT.register(new AngleCheck());
6-
EntityInteractPacketCallback.EVENT.register(new ReachCheck());
7-
EntityInteractPacketCallback.EVENT.register(new WallHitCheck());
8-
EntityInteractPacketCallback.EVENT.register(new InventoryHitCheck());
8+
var angleCheck = new AngleCheck();
9+
var reachCheck = new ReachCheck();
10+
var wallHitCheck = new WallHitCheck();
11+
var invHitCheck = new InventoryHitCheck();
12+
13+
UseEntityCallback.EVENT.register(angleCheck);
14+
AttackEntityCallback.EVENT.register(angleCheck);
15+
16+
UseEntityCallback.EVENT.register(reachCheck);
17+
AttackEntityCallback.EVENT.register(reachCheck);
18+
19+
UseEntityCallback.EVENT.register(wallHitCheck);
20+
AttackEntityCallback.EVENT.register(wallHitCheck);
21+
22+
UseEntityCallback.EVENT.register(invHitCheck);
23+
AttackEntityCallback.EVENT.register(invHitCheck);
924
}
1025
}
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package org.samo_lego.golfiv.event.combat;
22

3+
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
4+
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
35
import net.minecraft.entity.Entity;
46
import net.minecraft.entity.player.PlayerEntity;
57
import net.minecraft.util.ActionResult;
8+
import net.minecraft.util.Hand;
9+
import net.minecraft.util.hit.EntityHitResult;
10+
import net.minecraft.world.World;
11+
import org.jetbrains.annotations.Nullable;
612
import org.samo_lego.golfiv.casts.Golfer;
713

814
import static org.samo_lego.golfiv.GolfIV.golfConfig;
915

10-
public class InventoryHitCheck implements EntityInteractPacketCallback {
16+
public class InventoryHitCheck implements UseEntityCallback, AttackEntityCallback {
1117

1218
public InventoryHitCheck() {
1319
}
@@ -17,12 +23,10 @@ public InventoryHitCheck() {
1723
* while having open inventory.
1824
*
1925
* @param player player trying to interact with entity.
20-
* @param victim entity player is trying to interact with.
21-
* @param maxDistanceSquared maximal allowed distance for interaction, squared.
2226
* @return {@link ActionResult#FAIL} if player shouldn't be able to hit the victim, otherwise {@link ActionResult#PASS}
2327
*/
2428
@Override
25-
public ActionResult onEntityInteractPacket(PlayerEntity player, Entity victim, double maxDistanceSquared) {
29+
public ActionResult interact(PlayerEntity player, World world, Hand hand, Entity entity, @Nullable EntityHitResult hitResult) {
2630
return golfConfig.main.checkInventoryActions && ((Golfer) player).hasOpenGui() ? ActionResult.FAIL : ActionResult.PASS;
2731
}
2832
}
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package org.samo_lego.golfiv.event.combat;
22

3+
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
4+
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
35
import net.minecraft.entity.Entity;
46
import net.minecraft.entity.player.PlayerEntity;
57
import net.minecraft.util.ActionResult;
8+
import net.minecraft.util.Hand;
69
import net.minecraft.util.hit.EntityHitResult;
10+
import net.minecraft.world.World;
11+
import org.jetbrains.annotations.Nullable;
712

813
import static org.samo_lego.golfiv.GolfIV.golfConfig;
914

10-
public class ReachCheck implements EntityInteractPacketCallback {
15+
public class ReachCheck implements UseEntityCallback, AttackEntityCallback {
1116
public ReachCheck() {
1217
}
1318

@@ -17,19 +22,19 @@ public ReachCheck() {
1722
*
1823
* @param player player trying to interact with entity.
1924
* @param victim entity player is trying to interact with.
20-
* @param maxDistanceSquared maximal allowed distance for interaction, squared.
2125
* @return {@link ActionResult#FAIL} if player shouldn't be able to hit the victim, otherwise {@link ActionResult#PASS}
2226
*/
2327
@Override
24-
public ActionResult onEntityInteractPacket(PlayerEntity player, Entity victim, double maxDistanceSquared) {
25-
if(golfConfig.combat.checkHitDistance) {
28+
public ActionResult interact(PlayerEntity player, World world, Hand hand, Entity victim, @Nullable EntityHitResult hitResult) {
29+
if (golfConfig.combat.checkHitDistance) {
2630
EntityHitResult entityHit = new EntityHitResult(victim);
2731
double victimDistanceSquared = entityHit.squaredDistanceTo(player);
2832

29-
if(golfConfig.combat.checkHitDistance && !player.isCreative() && victimDistanceSquared > 22) {
33+
if (golfConfig.combat.checkHitDistance && !player.isCreative() && victimDistanceSquared > 22) {
3034
return ActionResult.FAIL;
3135
}
3236
}
3337
return ActionResult.PASS;
38+
3439
}
3540
}
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package org.samo_lego.golfiv.event.combat;
22

3+
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
4+
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
35
import net.minecraft.entity.Entity;
46
import net.minecraft.entity.player.PlayerEntity;
57
import net.minecraft.util.ActionResult;
8+
import net.minecraft.util.Hand;
69
import net.minecraft.util.hit.BlockHitResult;
710
import net.minecraft.util.hit.EntityHitResult;
11+
import net.minecraft.world.World;
12+
import org.jetbrains.annotations.Nullable;
813

914
import static org.samo_lego.golfiv.GolfIV.golfConfig;
1015

11-
public class WallHitCheck implements EntityInteractPacketCallback {
16+
public class WallHitCheck implements AttackEntityCallback, UseEntityCallback {
1217
public WallHitCheck() {
1318
}
1419

@@ -18,23 +23,23 @@ public WallHitCheck() {
1823
*
1924
* @param player player trying to interact with entity.
2025
* @param victim entity player is trying to interact with.
21-
* @param maxDistanceSquared maximal allowed distance for interaction, squared.
2226
* @return {@link ActionResult#FAIL} if player shouldn't be able to hit the victim, otherwise {@link ActionResult#PASS}
2327
*/
2428
@Override
25-
public ActionResult onEntityInteractPacket(PlayerEntity player, Entity victim, double maxDistanceSquared) {
26-
if(golfConfig.combat.preventWallHit) {
29+
public ActionResult interact(PlayerEntity player, World world, Hand hand, Entity victim, @Nullable EntityHitResult hitResult) {
30+
if (golfConfig.combat.preventWallHit) {
2731
EntityHitResult entityHit = new EntityHitResult(victim);
2832
double victimDistanceSquared = entityHit.squaredDistanceTo(player);
2933
double victimDistance = Math.sqrt(victimDistanceSquared);
3034

3135
// Through-wall hit check
32-
BlockHitResult blockHit = (BlockHitResult) player.raycast(Math.sqrt(maxDistanceSquared), 0, false);
36+
BlockHitResult blockHit = (BlockHitResult) player.raycast(Math.sqrt(64.0), 0, false);
3337

34-
if(Math.sqrt(blockHit.squaredDistanceTo(player)) + 0.5D < victimDistance) {
38+
if (Math.sqrt(blockHit.squaredDistanceTo(player)) + 0.5D < victimDistance) {
3539
return ActionResult.FAIL;
3640
}
3741
}
3842
return ActionResult.PASS;
43+
3944
}
4045
}
Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package org.samo_lego.golfiv.mixin.packets;
22

3-
import net.minecraft.entity.Entity;
43
import net.minecraft.network.Packet;
5-
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket;
64
import net.minecraft.server.MinecraftServer;
75
import net.minecraft.server.network.ServerPlayNetworkHandler;
86
import net.minecraft.server.network.ServerPlayerEntity;
9-
import net.minecraft.server.world.ServerWorld;
10-
import net.minecraft.util.ActionResult;
117
import org.samo_lego.golfiv.event.S2CPacket.S2CPacketCallback;
12-
import org.samo_lego.golfiv.event.combat.EntityInteractPacketCallback;
138
import org.spongepowered.asm.mixin.Final;
149
import org.spongepowered.asm.mixin.Mixin;
1510
import org.spongepowered.asm.mixin.Shadow;
1611
import org.spongepowered.asm.mixin.injection.At;
1712
import org.spongepowered.asm.mixin.injection.Inject;
1813
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
19-
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
2014

2115
@Mixin(ServerPlayNetworkHandler.class)
2216
public abstract class ServerPlayNetworkHandlerMixin_PacketEvents {
@@ -33,43 +27,9 @@ public abstract class ServerPlayNetworkHandlerMixin_PacketEvents {
3327
* @param packet
3428
* @param ci
3529
*/
36-
@Inject(
37-
method = "sendPacket(Lnet/minecraft/network/Packet;)V",
38-
at = @At("HEAD"),
39-
cancellable = true
40-
)
30+
@Inject(method = "sendPacket(Lnet/minecraft/network/Packet;)V",
31+
at = @At("HEAD"))
4132
private void onPacket(Packet<?> packet, CallbackInfo ci) {
4233
S2CPacketCallback.EVENT.invoker().preSendPacket(packet, player, server);
4334
}
44-
45-
/**
46-
* Checks whether player is hitting entity through wall
47-
* by comparing raycast distance of the block and targeted entity.
48-
*
49-
* Checks distance from attacker to attacked entity as well,
50-
* in order to prevent reach hacks.
51-
*
52-
* Also checks the angle at which player is hitting the entity.
53-
*
54-
* @param packet
55-
* @param ci
56-
* @param serverWorld
57-
* @param victim
58-
* @param distanceSquared
59-
*/
60-
@Inject(
61-
method = "onPlayerInteractEntity(Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket;)V",
62-
at = @At(
63-
value = "INVOKE",
64-
target = "Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket;handle(Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$Handler;)V"
65-
),
66-
locals = LocalCapture.CAPTURE_FAILHARD,
67-
cancellable = true
68-
)
69-
private void entityInteractCheck(PlayerInteractEntityC2SPacket packet, CallbackInfo ci, ServerWorld serverWorld, Entity victim, double distanceSquared) {
70-
ActionResult result = EntityInteractPacketCallback.EVENT.invoker().onEntityInteractPacket(this.player, victim, distanceSquared);
71-
if(result == ActionResult.FAIL) {
72-
ci.cancel();
73-
}
74-
}
7535
}

src/main/java/org/samo_lego/golfiv/storage/GolfConfig.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.gson.GsonBuilder;
55
import com.google.gson.TypeAdapter;
66
import com.google.gson.annotations.JsonAdapter;
7+
import com.google.gson.annotations.SerializedName;
78
import com.google.gson.stream.JsonReader;
89
import com.google.gson.stream.JsonWriter;
910
import it.unimi.dsi.fastutil.objects.Object2FloatMaps;
@@ -14,9 +15,20 @@
1415
import net.minecraft.util.Identifier;
1516
import net.minecraft.util.registry.Registry;
1617

17-
import java.io.*;
18+
import java.io.BufferedReader;
19+
import java.io.File;
20+
import java.io.FileInputStream;
21+
import java.io.FileOutputStream;
22+
import java.io.IOException;
23+
import java.io.InputStreamReader;
24+
import java.io.OutputStreamWriter;
25+
import java.io.Writer;
1826
import java.nio.charset.StandardCharsets;
19-
import java.util.*;
27+
import java.util.ArrayList;
28+
import java.util.Arrays;
29+
import java.util.Collections;
30+
import java.util.HashSet;
31+
import java.util.Set;
2032

2133
import static org.samo_lego.golfiv.utils.BallLogger.logError;
2234

@@ -53,6 +65,10 @@ public static class Main {
5365
*/
5466
@JsonAdapter(BlockSetAdapter.class)
5567
public Set<Block> allowedDestructibleByHeadlessPistons = Collections.singleton(Blocks.PISTON_HEAD);
68+
69+
@SerializedName("// What altitude in the nether should start inflicting void damage (e.g. 128). -1 disables it.")
70+
public final String _comment_inflictNetherRoofDamage = "";
71+
public int inflictNetherRoofDamage = -1;
5672
}
5773

5874
/**

0 commit comments

Comments
 (0)