Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 9f24aee

Browse files
committed
Merge branch 'feature/loot-context'
2 parents 5b630a0 + b34bda8 commit 9f24aee

File tree

8 files changed

+178
-0
lines changed

8 files changed

+178
-0
lines changed

patchwork-loot/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
archivesBaseName = "patchwork-loot"
2+
version = getSubprojectVersion(project, "0.1.0")
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.mixin.loot;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.injection.At;
24+
import org.spongepowered.asm.mixin.injection.Inject;
25+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
26+
27+
import net.minecraft.advancement.AdvancementRewards;
28+
import net.minecraft.server.network.ServerPlayerEntity;
29+
30+
@Mixin(AdvancementRewards.class)
31+
public class MixinAdvancementRewards {
32+
private static final String LOOT_CONTEXT_BUILD_TARGET =
33+
"net/minecraft/world/loot/context/LootContext$Builder.build(Lnet/minecraft/world/loot/context/LootContextType;)Lnet/minecraft/world/loot/context/LootContext;";
34+
35+
@Inject(method = "apply(Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At(value = "INVOKE", target = LOOT_CONTEXT_BUILD_TARGET))
36+
private void patchwork_addLuckToLootContext(ServerPlayerEntity player, CallbackInfo callback) {
37+
// TODO: Add luck to the loot context, figure out locals
38+
}
39+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.mixin.loot;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.Shadow;
24+
import org.spongepowered.asm.mixin.injection.At;
25+
import org.spongepowered.asm.mixin.injection.Inject;
26+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
27+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
28+
29+
import net.minecraft.entity.Entity;
30+
import net.minecraft.entity.player.PlayerEntity;
31+
import net.minecraft.entity.projectile.FishingBobberEntity;
32+
import net.minecraft.item.ItemStack;
33+
import net.minecraft.world.loot.LootSupplier;
34+
import net.minecraft.world.loot.context.LootContext;
35+
import net.minecraft.world.loot.context.LootContextParameters;
36+
37+
@Mixin(FishingBobberEntity.class)
38+
public class MixinFishingBobberEntity {
39+
private static final String LOOT_CONTEXT_BUILD_TARGET =
40+
"net/minecraft/world/loot/context/LootContext$Builder.build(Lnet/minecraft/world/loot/context/LootContextType;)Lnet/minecraft/world/loot/context/LootContext;";
41+
42+
@Shadow
43+
private final PlayerEntity owner = null;
44+
45+
@Inject(method = "method_6957(Lnet/minecraft/item/ItemStack;)I", at = @At(value = "INVOKE", target = LOOT_CONTEXT_BUILD_TARGET), locals = LocalCapture.CAPTURE_FAILHARD)
46+
private void patchwork_addFishingParameters(ItemStack stack, CallbackInfoReturnable<Integer> callback, int rodDamage, LootContext.Builder builder, LootSupplier supplier) {
47+
builder.put(LootContextParameters.KILLER_ENTITY, this.owner);
48+
builder.put(LootContextParameters.THIS_ENTITY, (Entity) (Object) this);
49+
}
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.mixin.loot;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.injection.At;
24+
import org.spongepowered.asm.mixin.injection.Inject;
25+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
26+
27+
import net.minecraft.world.loot.context.LootContextParameters;
28+
import net.minecraft.world.loot.context.LootContextType;
29+
import net.minecraft.world.loot.context.LootContextTypes;
30+
31+
@Mixin(LootContextTypes.class)
32+
public class MixinLootContextTypes {
33+
@Inject(method = "method_15970(Lnet/minecraft/world/loot/context/LootContextType$Builder;)V", at = @At("RETURN"))
34+
private static void patchwork_addChestParameters(LootContextType.Builder builder, CallbackInfo callback) {
35+
// Chest minecarts can have killers.
36+
builder.allow(LootContextParameters.KILLER_ENTITY);
37+
}
38+
39+
@Inject(method = "method_764(Lnet/minecraft/world/loot/context/LootContextType$Builder;)V", at = @At("RETURN"))
40+
private static void patchwork_addFishingParameters(LootContextType.Builder builder, CallbackInfo callback) {
41+
// Entity that is using the fishing rod
42+
builder.allow(LootContextParameters.KILLER_ENTITY);
43+
44+
// Fishing bobber entity
45+
builder.allow(LootContextParameters.THIS_ENTITY);
46+
}
47+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"schemaVersion": 1,
3+
"id": "patchwork-loot",
4+
"name": "Patchwork Loot",
5+
"version": "${version}",
6+
"license": "LGPL-2.1-only",
7+
"icon": "assets/patchwork-loot/icon.png",
8+
"contact": {
9+
"issues": "https://github.com/PatchworkMC/patchwork-api/issues",
10+
"sources": "https://github.com/PatchworkMC/patchwork-api"
11+
},
12+
"authors": [
13+
"PatchworkMC"
14+
],
15+
"depends": {
16+
"fabricloader": ">=0.6.2"
17+
},
18+
"mixins": [
19+
"patchwork-loot.mixins.json"
20+
],
21+
"description": "Implementation of the Forge's additions to loot tables.",
22+
"custom": {
23+
"modmenu:api": true,
24+
"modmenu:parent": "patchwork"
25+
}
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"required": true,
3+
"package": "com.patchworkmc.mixin.loot",
4+
"compatibilityLevel": "JAVA_8",
5+
"mixins": [
6+
"MixinAdvancementRewards",
7+
"MixinFishingBobberEntity",
8+
"MixinLootContextTypes"
9+
],
10+
"injectors": {
11+
"defaultRequire": 1
12+
}
13+
}
22.2 KB
Loading

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ include 'patchwork-extensions-shearing'
2323
include 'patchwork-extensions'
2424
include 'patchwork-extensions-item'
2525
include 'patchwork-fml'
26+
include 'patchwork-loot'
2627
include 'patchwork-registries'
2728
include 'patchwork-gui'
2829
include 'patchwork-networking'

0 commit comments

Comments
 (0)