forked from McJtyMods/TheOneProbe
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/main/java/mcjty/theoneprobe/apiimpl/providers/ChestHorseInfoProvider.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,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<ItemStack> stacks = new ArrayList<>(); | ||
private final Set<Item> 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(); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/mcjty/theoneprobe/apiimpl/providers/EnchantingPowerInfoProvider.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,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)); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/mcjty/theoneprobe/apiimpl/providers/MinecartInfoProvider.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,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<ItemStack> stacks = new ArrayList<>(); | ||
private final Set<Item> 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(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/mcjty/theoneprobe/apiimpl/providers/PaintingInfoProvider.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,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")), ' ')); | ||
} | ||
} | ||
} | ||
} |