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
Add missing information to instances of LootContext #4443
Merged
LexManos
merged 5 commits into
MinecraftForge:1.12.x
from
Daomephsta:improved-loot-contexts
Dec 17, 2017
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7e7467
Add missing data to LootContexts
leviathan143 1b28e22
Add test mod
leviathan143 630c9df
Fix some small style issues
leviathan143 0dd4626
Remove unnecessary patch line
leviathan143 92fc5f9
Remove unnecessary requirements tag
leviathan143 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
patches/minecraft/net/minecraft/advancements/AdvancementRewards.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- ../src-base/minecraft/net/minecraft/advancements/AdvancementRewards.java | ||
+++ ../src-work/minecraft/net/minecraft/advancements/AdvancementRewards.java | ||
@@ -49,7 +49,7 @@ | ||
public void func_192113_a(final EntityPlayerMP p_192113_1_) | ||
{ | ||
p_192113_1_.func_71023_q(this.field_192115_b); | ||
- LootContext lootcontext = (new LootContext.Builder(p_192113_1_.func_71121_q())).func_186472_a(p_192113_1_).func_186471_a(); | ||
+ LootContext lootcontext = (new LootContext.Builder(p_192113_1_.func_71121_q())).func_186472_a(p_192113_1_).func_186470_a(p_192113_1_).func_186469_a(p_192113_1_.func_184817_da()).func_186471_a(); // Forge: add player & luck to LootContext | ||
boolean flag = false; | ||
|
||
for (ResourceLocation resourcelocation : this.field_192116_c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
patches/minecraft/net/minecraft/tileentity/TileEntityLockableLoot.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- ../src-base/minecraft/net/minecraft/tileentity/TileEntityLockableLoot.java | ||
+++ ../src-work/minecraft/net/minecraft/tileentity/TileEntityLockableLoot.java | ||
@@ -73,7 +73,7 @@ | ||
|
||
if (p_184281_1_ != null) | ||
{ | ||
- lootcontext$builder.func_186469_a(p_184281_1_.func_184817_da()); | ||
+ lootcontext$builder.func_186469_a(p_184281_1_.func_184817_da()).func_186470_a(p_184281_1_); // Forge: add player to LootContext | ||
} | ||
|
||
loottable.func_186460_a(this, random, lootcontext$builder.func_186471_a()); |
105 changes: 105 additions & 0 deletions
105
src/test/java/net/minecraftforge/debug/LootContextTweaksTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package net.minecraftforge.debug; | ||
|
||
import java.util.Random; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSyntaxException; | ||
|
||
import net.minecraft.init.Biomes; | ||
import net.minecraft.init.Items; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.storage.loot.LootContext; | ||
import net.minecraft.world.storage.loot.LootEntryItem; | ||
import net.minecraft.world.storage.loot.LootPool; | ||
import net.minecraft.world.storage.loot.LootTableList; | ||
import net.minecraft.world.storage.loot.RandomValueRange; | ||
import net.minecraft.world.storage.loot.conditions.EntityHasProperty; | ||
import net.minecraft.world.storage.loot.conditions.LootCondition; | ||
import net.minecraft.world.storage.loot.conditions.LootConditionManager; | ||
import net.minecraft.world.storage.loot.functions.LootFunction; | ||
import net.minecraft.world.storage.loot.functions.SetCount; | ||
import net.minecraft.world.storage.loot.properties.EntityOnFire; | ||
import net.minecraft.world.storage.loot.properties.EntityProperty; | ||
import net.minecraftforge.event.LootTableLoadEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber; | ||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.registry.ForgeRegistries; | ||
|
||
@EventBusSubscriber | ||
@Mod(modid = LootContextTweaksTest.MODID, name = "LootContextTweaksTest", version = "1.0", acceptableRemoteVersions = "*") | ||
public class LootContextTweaksTest | ||
{ | ||
public static final String MODID = "loot_context_tweaks_test"; | ||
public static final boolean ENABLED = false; | ||
|
||
@Mod.EventHandler | ||
public void preInit(FMLPreInitializationEvent event) | ||
{ | ||
if (!ENABLED) return; | ||
LootConditionManager.registerCondition(new InBiome.Serialiser()); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void onLootTableLoad(LootTableLoadEvent event) | ||
{ | ||
if (!ENABLED) return; | ||
if (event.getName().equals(LootTableList.GAMEPLAY_FISHING)) | ||
{ | ||
LootPool main = event.getTable().getPool("main"); | ||
main.addEntry(new LootEntryItem(Items.ACACIA_BOAT, 100, 1, new LootFunction[0], new LootCondition[] {new InBiome(Biomes.SAVANNA)}, "fishing_test")); | ||
} | ||
else if (event.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) | ||
{ | ||
LootPool main = event.getTable().getPool("main"); | ||
LootCondition onFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(true)}, LootContext.EntityTarget.KILLER_PLAYER); | ||
main.addEntry(new LootEntryItem(Items.BLAZE_POWDER, 100, 1, new LootFunction[] {new SetCount(new LootCondition[0], new RandomValueRange(64))}, new LootCondition[] {onFire}, "minecart_test")); | ||
} | ||
} | ||
|
||
private static class InBiome implements LootCondition | ||
{ | ||
private final Biome requiredBiome; | ||
|
||
public InBiome(Biome requiredBiome) | ||
{ | ||
this.requiredBiome = requiredBiome; | ||
} | ||
|
||
@Override | ||
public boolean testCondition(Random rand, LootContext context) | ||
{ | ||
if (context.getLootedEntity() == null) return false; | ||
Biome biome = context.getWorld().getBiome(context.getLootedEntity().getPosition()); | ||
return biome == requiredBiome; | ||
} | ||
|
||
private static class Serialiser extends LootCondition.Serializer<InBiome> | ||
{ | ||
protected Serialiser() | ||
{ | ||
super(new ResourceLocation(MODID, "in_biome"), InBiome.class); | ||
} | ||
|
||
@Override | ||
public void serialize(JsonObject json, InBiome value, JsonSerializationContext context) | ||
{ | ||
json.addProperty("biome", value.requiredBiome.getRegistryName().toString()); | ||
} | ||
|
||
@Override | ||
public InBiome deserialize(JsonObject json, JsonDeserializationContext context) | ||
{ | ||
if (!json.has("biome")) throw new JsonSyntaxException("Missing biome tag, expected to find a biome registry name"); | ||
ResourceLocation biomeResLoc = new ResourceLocation(json.get("biome").getAsString()); | ||
Biome biome = ForgeRegistries.BIOMES.getValue(biomeResLoc); | ||
if (biome == null) throw new JsonSyntaxException("Invalid biome tag. " + biomeResLoc + " does not exist in the biome registry."); | ||
return new InBiome(biome); | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/resources/assets/loot_context_tweaks_test/advancements/test/root.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"display": | ||
{ | ||
"icon": { | ||
"item": "minecraft:stone" | ||
}, | ||
"description": "From LootContextTweaksTest", | ||
"title": "Test", | ||
"background": "minecraft:textures/blocks/stone.png" | ||
}, | ||
"criteria": | ||
{ | ||
"no": | ||
{ | ||
"trigger": "minecraft:impossible" | ||
} | ||
}, | ||
"rewards": | ||
{ | ||
"loot": ["minecraft:chests/simple_dungeon"] | ||
}, | ||
"requirements": [["no"]] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"requirements" can be omitted if all of the criteria are needed, as it is in this case.