From 14441b86ac9e40f5fe72c695cff6efdc4bf9324c Mon Sep 17 00:00:00 2001 From: uberswe Date: Thu, 3 Oct 2024 19:24:27 +0200 Subject: [PATCH] Prevent deployers from fishing crates --- .../java/draylar/gofish/impl/GoFishLootTables.java | 1 + .../draylar/gofish/mixin/FishingBobberLootMixin.java | 12 +++++++++++- .../gameplay/fishing/overworld}/fishing.json | 0 3 files changed, 12 insertions(+), 1 deletion(-) rename src/main/resources/data/{minecraft/loot_tables/gameplay => gofish/loot_tables/gameplay/fishing/overworld}/fishing.json (100%) diff --git a/src/main/java/draylar/gofish/impl/GoFishLootTables.java b/src/main/java/draylar/gofish/impl/GoFishLootTables.java index 5021fd6..b16d7d8 100644 --- a/src/main/java/draylar/gofish/impl/GoFishLootTables.java +++ b/src/main/java/draylar/gofish/impl/GoFishLootTables.java @@ -5,6 +5,7 @@ public class GoFishLootTables { + public static final Identifier OVERWORLD_FISHING = GoFish.id("gameplay/fishing/overworld/fishing"); public static final Identifier NETHER_FISHING = GoFish.id("gameplay/fishing/nether/fishing"); public static final Identifier END_FISHING = GoFish.id("gameplay/fishing/end/fishing"); } diff --git a/src/main/java/draylar/gofish/mixin/FishingBobberLootMixin.java b/src/main/java/draylar/gofish/mixin/FishingBobberLootMixin.java index 0c297e9..9980563 100644 --- a/src/main/java/draylar/gofish/mixin/FishingBobberLootMixin.java +++ b/src/main/java/draylar/gofish/mixin/FishingBobberLootMixin.java @@ -2,6 +2,7 @@ import draylar.gofish.api.FireproofEntity; import draylar.gofish.impl.GoFishLootTables; +import net.fabricmc.fabric.api.entity.FakePlayer; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.ItemEntity; @@ -13,6 +14,7 @@ import net.minecraft.loot.LootTables; import net.minecraft.loot.context.LootContext; import net.minecraft.loot.context.LootContextParameterSet; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; @@ -40,6 +42,14 @@ private FishingBobberLootMixin(EntityType type, World world) { private LootTable getTable(LootManager lootManager, Identifier id) { assert getWorld().getServer() != null; + FishingBobberEntity bobber = (FishingBobberEntity) (Object) this; + Entity owner = bobber.getOwner(); + + if (!(owner instanceof ServerPlayerEntity) || (owner instanceof FakePlayer)) { + // If a fishing is being done by a fake player give regular loot + return this.getWorld().getServer().getLootManager().getLootTable(LootTables.FISHING_GAMEPLAY); + } + final DimensionType dimension = getWorld().getDimension(); if(dimension.ultrawarm()) { return this.getWorld().getServer().getLootManager().getLootTable(GoFishLootTables.NETHER_FISHING); @@ -48,7 +58,7 @@ private LootTable getTable(LootManager lootManager, Identifier id) { } // Default - return this.getWorld().getServer().getLootManager().getLootTable(LootTables.FISHING_GAMEPLAY); + return this.getWorld().getServer().getLootManager().getLootTable(GoFishLootTables.OVERWORLD_FISHING); } @Inject( diff --git a/src/main/resources/data/minecraft/loot_tables/gameplay/fishing.json b/src/main/resources/data/gofish/loot_tables/gameplay/fishing/overworld/fishing.json similarity index 100% rename from src/main/resources/data/minecraft/loot_tables/gameplay/fishing.json rename to src/main/resources/data/gofish/loot_tables/gameplay/fishing/overworld/fishing.json