Files
2019-02-24 22:29:41 +08:00

96 lines
3.2 KiB
Diff

--- ../src-base/minecraft/net/minecraft/inventory/Slot.java
+++ ../src-work/minecraft/net/minecraft/inventory/Slot.java
@@ -8,7 +8,7 @@
public class Slot
{
- private final int slotIndex;
+ public final int slotIndex; // CatServer - private -> public
public final IInventory inventory;
public int slotNumber;
public int xPos;
@@ -90,7 +90,7 @@
@SideOnly(Side.CLIENT)
public String getSlotTexture()
{
- return null;
+ return backgroundName;
}
public ItemStack decrStackSize(int amount)
@@ -113,4 +113,74 @@
{
return true;
}
+
+ /*========================================= FORGE START =====================================*/
+ protected String backgroundName = null;
+ protected net.minecraft.util.ResourceLocation backgroundLocation = null;
+ protected Object backgroundMap;
+ /**
+ * Gets the path of the texture file to use for the background image of this slot when drawing the GUI.
+ * @return The resource location for the background image
+ */
+ @SideOnly(Side.CLIENT)
+ public net.minecraft.util.ResourceLocation getBackgroundLocation()
+ {
+ return (backgroundLocation == null ? net.minecraft.client.renderer.texture.TextureMap.LOCATION_BLOCKS_TEXTURE : backgroundLocation);
+ }
+
+ /**
+ * Sets the texture file to use for the background image of the slot when it's empty.
+ * @param texture the resourcelocation for the texture
+ */
+ @SideOnly(Side.CLIENT)
+ public void setBackgroundLocation(net.minecraft.util.ResourceLocation texture)
+ {
+ this.backgroundLocation = texture;
+ }
+
+ /**
+ * Sets which icon index to use as the background image of the slot when it's empty.
+ * @param name The icon to use, null for none
+ */
+ public void setBackgroundName(@Nullable String name)
+ {
+ this.backgroundName = name;
+ }
+
+ @Nullable
+ @SideOnly(Side.CLIENT)
+ public net.minecraft.client.renderer.texture.TextureAtlasSprite getBackgroundSprite()
+ {
+ String name = getSlotTexture();
+ return name == null ? null : getBackgroundMap().getAtlasSprite(name);
+ }
+
+ @SideOnly(Side.CLIENT)
+ protected net.minecraft.client.renderer.texture.TextureMap getBackgroundMap()
+ {
+ if (backgroundMap == null) backgroundMap = net.minecraft.client.Minecraft.getMinecraft().getTextureMapBlocks();
+ return (net.minecraft.client.renderer.texture.TextureMap)backgroundMap;
+ }
+
+ /**
+ * Retrieves the index in the inventory for this slot, this value should typically not
+ * be used, but can be useful for some occasions.
+ *
+ * @return Index in associated inventory for this slot.
+ */
+ public int getSlotIndex()
+ {
+ return slotIndex;
+ }
+
+ /**
+ * Checks if the other slot is in the same inventory, by comparing the inventory reference.
+ * @param other
+ * @return true if the other slot is in the same inventory
+ */
+ public boolean isSameInventory(Slot other)
+ {
+ return this.inventory == other.inventory;
+ }
+ /*========================================= FORGE END =====================================*/
}