diff --git a/src/main/java/mcjty/theoneprobe/apiimpl/providers/ChestHorseInfoProvider.java b/src/main/java/mcjty/theoneprobe/apiimpl/providers/ChestHorseInfoProvider.java new file mode 100644 index 00000000..6f6661ef --- /dev/null +++ b/src/main/java/mcjty/theoneprobe/apiimpl/providers/ChestHorseInfoProvider.java @@ -0,0 +1,74 @@ +package mcjty.theoneprobe.apiimpl.providers; + +import mcjty.theoneprobe.api.IProbeHitEntityData; +import mcjty.theoneprobe.api.IProbeInfo; +import mcjty.theoneprobe.api.IProbeInfoEntityProvider; +import mcjty.theoneprobe.api.ProbeMode; +import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.AbstractChestHorse; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.world.World; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; +import topextras.Utilities; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class ChestHorseInfoProvider implements IProbeInfoEntityProvider { + + private final List stacks = new ArrayList<>(); + private final Set foundItems = new HashSet<>(); + + @Override + public String getID() { + return Utilities.getProviderId("chest_horse"); + } + + @Override + public void addProbeEntityInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, Entity entity, IProbeHitEntityData data) { + // hopper and chest minecarts + if (entity instanceof AbstractChestHorse && ((AbstractChestHorse) entity).hasChest()) { + int maxSlots; + if (entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) { + IItemHandler capability = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); + if (capability == null) { + stacks.clear(); + foundItems.clear(); + return; + } + + maxSlots = capability.getSlots(); + // start at 3 to ignore armor/saddle + for (int i = 3; i < maxSlots; i++) { + Utilities.addItemStack(stacks, foundItems, capability.getStackInSlot(i)); + } + } else { + NBTTagCompound compound = entity.writeToNBT(new NBTTagCompound()); + if (!compound.hasKey("Items")) { + stacks.clear(); + foundItems.clear(); + return; + } + + NBTTagList list = compound.getTagList("Items", 10); + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound tagCompound = list.getCompoundTagAt(i); + int slot = tagCompound.getByte("Slot") & 255; + + // start at 3 to ignore armor/saddle + if (slot > 2) Utilities.addItemStack(stacks, foundItems, new ItemStack(tagCompound)); + } + } + if (!stacks.isEmpty()) Utilities.showChestContents(probeInfo, stacks, mode); + stacks.clear(); + foundItems.clear(); + } + } +} \ No newline at end of file diff --git a/src/main/java/mcjty/theoneprobe/apiimpl/providers/EnchantingPowerInfoProvider.java b/src/main/java/mcjty/theoneprobe/apiimpl/providers/EnchantingPowerInfoProvider.java new file mode 100644 index 00000000..7a92e3e3 --- /dev/null +++ b/src/main/java/mcjty/theoneprobe/apiimpl/providers/EnchantingPowerInfoProvider.java @@ -0,0 +1,53 @@ +package mcjty.theoneprobe.apiimpl.providers; + +import mcjty.theoneprobe.api.*; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityEnchantmentTable; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeHooks; +import topextras.Utilities; + +import javax.annotation.Nonnull; + +public class EnchantingPowerInfoProvider implements IProbeInfoProvider { + + private static final ItemStack ENCHANTED_BOOK = new ItemStack(Items.ENCHANTED_BOOK); + + @Override + public String getID() { + return Utilities.getProviderId("enchanting_power"); + } + + @Override + public void addProbeInfo(ProbeMode mode, @Nonnull IProbeInfo probeInfo, EntityPlayer player, @Nonnull World world, @Nonnull IBlockState blockState, @Nonnull IProbeHitData data) { + float enchantingPower = ForgeHooks.getEnchantPower(world, data.getPos()); + if (blockState.getBlock().hasTileEntity(blockState) && world.getTileEntity(data.getPos()) instanceof TileEntityEnchantmentTable) { + BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(data.getPos()); + enchantingPower = 0.0F; + for (int x = -1; x <= 1; x++) { + for (int z = -1; z <= 1; z++) { + if ((x != 0 || z != 0) && world.isAirBlock(pos.add(z, 0, x)) && world.isAirBlock(pos.add(z, 1, x))) { + enchantingPower += ForgeHooks.getEnchantPower(world, pos.add(z * 2, 0, x * 2)); + enchantingPower += ForgeHooks.getEnchantPower(world, pos.add(z * 2, 1, x * 2)); + if (z != 0 && x != 0) { + enchantingPower += ForgeHooks.getEnchantPower(world, pos.add(z * 2, 0, x)); + enchantingPower += ForgeHooks.getEnchantPower(world, pos.add(z * 2, 1, x)); + enchantingPower += ForgeHooks.getEnchantPower(world, pos.add(z, 0, x * 2)); + enchantingPower += ForgeHooks.getEnchantPower(world, pos.add(z, 1, x * 2)); + } + } + } + } + } + if (enchantingPower > 0.0F) { + probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)) + .item(ENCHANTED_BOOK) + .text(TextStyleClass.LABEL + "{*topextras.top.enchanting_power*} " + TextFormatting.LIGHT_PURPLE + Utilities.FORMAT.format(enchantingPower)); + } + } +} \ No newline at end of file diff --git a/src/main/java/mcjty/theoneprobe/apiimpl/providers/MinecartInfoProvider.java b/src/main/java/mcjty/theoneprobe/apiimpl/providers/MinecartInfoProvider.java new file mode 100644 index 00000000..7d5818d9 --- /dev/null +++ b/src/main/java/mcjty/theoneprobe/apiimpl/providers/MinecartInfoProvider.java @@ -0,0 +1,62 @@ +package mcjty.theoneprobe.apiimpl.providers; + +import mcjty.theoneprobe.api.IProbeHitEntityData; +import mcjty.theoneprobe.api.IProbeInfo; +import mcjty.theoneprobe.api.IProbeInfoEntityProvider; +import mcjty.theoneprobe.api.ProbeMode; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityMinecartContainer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; +import topextras.Utilities; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class MinecartInfoProvider implements IProbeInfoEntityProvider { + + private final List stacks = new ArrayList<>(); + private final Set foundItems = new HashSet<>(); + + @Override + public String getID() { + return Utilities.getProviderId("minecart"); + } + + @Override + public void addProbeEntityInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, Entity entity, IProbeHitEntityData data) { + // hopper and chest minecarts + if (entity instanceof EntityMinecartContainer) { + int maxSlots; + if (entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) { + IItemHandler capability = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); + if (capability == null) { + stacks.clear(); + foundItems.clear(); + return; + } + + maxSlots = capability.getSlots(); + for (int i = 0; i < maxSlots; i++) { + Utilities.addItemStack(stacks, foundItems, capability.getStackInSlot(i)); + } + } else { + IInventory inventory = (IInventory) entity; + maxSlots = inventory.getSizeInventory(); + for (int i = 0; i < maxSlots; i++) { + Utilities.addItemStack(stacks, foundItems, inventory.getStackInSlot(i)); + } + } + if (!stacks.isEmpty()) Utilities.showChestContents(probeInfo, stacks, mode); + stacks.clear(); + foundItems.clear(); + } + } +} \ No newline at end of file diff --git a/src/main/java/mcjty/theoneprobe/apiimpl/providers/PaintingInfoProvider.java b/src/main/java/mcjty/theoneprobe/apiimpl/providers/PaintingInfoProvider.java new file mode 100644 index 00000000..1e6e36f3 --- /dev/null +++ b/src/main/java/mcjty/theoneprobe/apiimpl/providers/PaintingInfoProvider.java @@ -0,0 +1,30 @@ +package mcjty.theoneprobe.apiimpl.providers; + +import mcjty.theoneprobe.api.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityPainting; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import org.apache.commons.lang3.StringUtils; +import topextras.Utilities; + +public class PaintingInfoProvider implements IProbeInfoEntityProvider { + + @Override + public String getID() { + return Utilities.getProviderId("painting"); + } + + @Override + public void addProbeEntityInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, Entity entity, IProbeHitEntityData data) { + if (entity instanceof EntityPainting) { + NBTTagCompound compound = entity.writeToNBT(new NBTTagCompound()); + if (compound.hasKey("Motive")) { + probeInfo.text(TextStyleClass.INFO + TextFormatting.ITALIC.toString() + + StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(compound.getString("Motive")), ' ')); + } + } + } +} \ No newline at end of file