-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom stat for trading with goblins
- Loading branch information
1 parent
07ebe26
commit 11aa477
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/mrcrayfish/goblintraders/init/ModStats.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,29 @@ | ||
package com.mrcrayfish.goblintraders.init; | ||
|
||
import com.mrcrayfish.goblintraders.Reference; | ||
import net.minecraft.stats.IStatFormatter; | ||
import net.minecraft.stats.Stats; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
/** | ||
* Author: MrCrayfish | ||
*/ | ||
public class ModStats | ||
{ | ||
public static final ResourceLocation TRADE_WITH_GOBLIN = registerCustom("trade_with_goblin", IStatFormatter.DEFAULT); | ||
|
||
public static void init() | ||
{ | ||
//Does nothing, just triggers java to load static fields | ||
} | ||
|
||
private static ResourceLocation registerCustom(String name, IStatFormatter formatter) | ||
{ | ||
String key = Reference.MOD_ID + ":" + name; | ||
ResourceLocation id = new ResourceLocation(key); | ||
Registry.register(Registry.CUSTOM_STAT, key, id); | ||
Stats.CUSTOM.get(id, formatter); | ||
return id; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/mrcrayfish/goblintraders/mixin/MerchantResultSlotMixin.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,33 @@ | ||
package com.mrcrayfish.goblintraders.mixin; | ||
|
||
import com.mrcrayfish.goblintraders.entity.AbstractGoblinEntity; | ||
import com.mrcrayfish.goblintraders.init.ModStats; | ||
import net.minecraft.entity.merchant.IMerchant; | ||
import net.minecraft.inventory.container.MerchantResultSlot; | ||
import net.minecraft.util.ResourceLocation; | ||
import org.spongepowered.asm.mixin.Final; | ||
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.ModifyArg; | ||
|
||
/** | ||
* Author: MrCrayfish | ||
*/ | ||
@Mixin(MerchantResultSlot.class) | ||
public class MerchantResultSlotMixin | ||
{ | ||
@Shadow | ||
@Final | ||
private IMerchant merchant; | ||
|
||
@ModifyArg(method = "onTake", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addStat(Lnet/minecraft/util/ResourceLocation;)V")) | ||
private ResourceLocation modifyAddStat(ResourceLocation stat) | ||
{ | ||
if(this.merchant instanceof AbstractGoblinEntity) | ||
{ | ||
return ModStats.TRADE_WITH_GOBLIN; | ||
} | ||
return stat; | ||
} | ||
} |
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