Skip to content

Commit

Permalink
Revert "move Itemizer out of mixins" since event version doesn't work…
Browse files Browse the repository at this point in the history
… for unknown reasons
  • Loading branch information
GlassSpirit committed Nov 23, 2019
1 parent 2d3dac4 commit 842d726
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import cz.neumimto.rpg.sponge.NtRpgPlugin;
import cz.neumimto.rpg.sponge.entities.players.ISpongeCharacter;
import cz.neumimto.rpg.sponge.entities.players.SpongeCharacterServise;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import noppes.npcs.api.NpcAPI;
Expand All @@ -20,7 +17,6 @@
import noppes.npcs.entity.EntityNPCInterface;
import org.spongepowered.api.entity.living.player.Player;
import ru.glassspirit.cnpcntrpg.sponge.CnpcRpgSponge;
import ru.glassspirit.cnpcntrpg.sponge.ItemizerHelper;

import java.util.*;

Expand Down Expand Up @@ -106,30 +102,4 @@ public void onNpcDeath2(LivingDeathEvent event) {
}
}
}

//=========================Itemizer=====================================

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onLivingDrops(LivingDropsEvent event) {
if (ItemizerHelper.isItemizerLoaded()) {
if (event.getEntityLiving() instanceof EntityNPCInterface) {
for (EntityItem item : event.getDrops()) {
ItemStack stack = item.getItem();
if (stack.getDisplayName().startsWith("#IT")) {
String[] str = stack.getDisplayName().split("#");
if (str[2].equalsIgnoreCase("id")) {
int quantity = item.getItem().getCount();
item.setItem((ItemStack) (Object) ItemizerHelper.getItemService().retrieve(str[3]).orElse(org.spongepowered.api.item.inventory.ItemStack.empty()));
item.getItem().setCount(item.getItem().getCount() * quantity);
} else if (str[2].equalsIgnoreCase("pool")) {
int quantity = item.getItem().getCount();
item.setItem((ItemStack) (Object) ItemizerHelper.getItemService().fetch(str[3]).orElse(org.spongepowered.api.item.inventory.ItemStack.empty()));
item.getItem().setCount(item.getItem().getCount() * quantity);
}
}
}
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.glassspirit.cnpcntrpg.mixin;

import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import noppes.npcs.entity.data.DataInventory;
import org.spongepowered.api.Sponge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import ru.glassspirit.cnpcntrpg.sponge.ItemizerHelper;

@Mixin(value = DataInventory.class, remap = false)
public abstract class MixinDataInventory {

@Redirect(method = "dropStuff", at = @At(value = "INVOKE", target = "Lnoppes/npcs/entity/data/DataInventory;getEntityItem(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/entity/item/EntityItem;"))
private EntityItem onDropStuffItemizer(DataInventory data, ItemStack stack) {
if (Sponge.getPluginManager().isLoaded("itemizer")) {
if (stack.getDisplayName().startsWith("#IT")) {
String[] str = stack.getDisplayName().split("#");
if (str[2].equalsIgnoreCase("id")) {
return data.getEntityItem((ItemStack) (Object) ItemizerHelper.getItemService().retrieve(str[3]).orElse(org.spongepowered.api.item.inventory.ItemStack.empty()));
} else if (str[2].equalsIgnoreCase("pool")) {
return data.getEntityItem((ItemStack) (Object) ItemizerHelper.getItemService().fetch(str[3]).orElse(org.spongepowered.api.item.inventory.ItemStack.empty()));
}
}
}
return data.getEntityItem(stack);
}

}
1 change: 1 addition & 0 deletions src/main/resources/mixins.cnpcntrpg.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"target": "@env(DEFAULT)",
"mixins": [
"MixinCustomNpcs",
"MixinDataInventory",
"MixinDataStats",
"MixinEntityNPCInterface",
"MixinScriptContainer"
Expand Down

0 comments on commit 842d726

Please sign in to comment.