pattern item stuff, texture is broken
This commit is contained in:
@@ -2,6 +2,7 @@ package storagecraft.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import storagecraft.StorageCraftItems;
|
||||
import storagecraft.block.EnumGridType;
|
||||
import storagecraft.container.slot.SlotDisabled;
|
||||
@@ -13,10 +14,14 @@ import storagecraft.tile.TileGrid;
|
||||
|
||||
public class ContainerGrid extends ContainerBase
|
||||
{
|
||||
private TileGrid grid;
|
||||
|
||||
public ContainerGrid(EntityPlayer player, TileGrid grid)
|
||||
{
|
||||
super(player);
|
||||
|
||||
this.grid = grid;
|
||||
|
||||
addPlayerInventory(8, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 174 : 108);
|
||||
|
||||
if (grid.getType() == EnumGridType.CRAFTING)
|
||||
@@ -63,4 +68,15 @@ public class ContainerGrid extends ContainerBase
|
||||
addSlotToContainer(new SlotOutput(grid.getPatternInventory(), 1, 137, 150));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int id, int clickedButton, int mode, EntityPlayer player)
|
||||
{
|
||||
if (id >= 0 && getSlot(id) instanceof SlotDisabled)
|
||||
{
|
||||
grid.onPatternCreate();
|
||||
}
|
||||
|
||||
return super.slotClick(id, clickedButton, mode, player);
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,117 @@
|
||||
package storagecraft.item;
|
||||
|
||||
// @TODO: Other texture when there is an item assigned
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemPattern extends ItemBase
|
||||
{
|
||||
public static final String NBT_SLOT = "Slot_%d";
|
||||
|
||||
public ItemPattern()
|
||||
{
|
||||
super("pattern");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack cell, EntityPlayer player, List list, boolean b)
|
||||
{
|
||||
if (isValid(player.worldObj, cell))
|
||||
{
|
||||
list.add(getPatternResult(player.worldObj, cell).getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
if (hasPattern(stack))
|
||||
{
|
||||
return "item.storagecraft:pattern";
|
||||
}
|
||||
|
||||
return "item.storagecraft:pattern.blank";
|
||||
}
|
||||
|
||||
public static boolean isValid(World world, ItemStack stack)
|
||||
{
|
||||
return stack.getTagCompound() != null && hasPattern(stack) && getPatternResult(world, stack) != null;
|
||||
}
|
||||
|
||||
public static ItemStack[] getPattern(ItemStack stack)
|
||||
{
|
||||
ItemStack[] pattern = new ItemStack[9];
|
||||
|
||||
if (stack.getTagCompound() != null)
|
||||
{
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
String name = String.format(NBT_SLOT, i);
|
||||
|
||||
if (stack.getTagCompound().hasKey(name))
|
||||
{
|
||||
pattern[i] = ItemStack.loadItemStackFromNBT(stack.getTagCompound().getCompoundTag(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public static boolean hasPattern(ItemStack stack)
|
||||
{
|
||||
int empty = 0;
|
||||
|
||||
for (ItemStack slot : getPattern(stack))
|
||||
{
|
||||
if (slot == null)
|
||||
{
|
||||
empty++;
|
||||
}
|
||||
}
|
||||
|
||||
return empty != 9;
|
||||
}
|
||||
|
||||
public static ItemStack getPatternResult(World world, ItemStack stack)
|
||||
{
|
||||
InventoryCrafting crafting = new InventoryCrafting(new Container()
|
||||
{
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}, 3, 3);
|
||||
|
||||
ItemStack[] pattern = getPattern(stack);
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
crafting.setInventorySlotContents(i, pattern[i]);
|
||||
}
|
||||
|
||||
return CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
||||
}
|
||||
|
||||
public static ItemStack setPattern(ItemStack stack, ItemStack slot, int id)
|
||||
{
|
||||
if (stack.getTagCompound() == null)
|
||||
{
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagCompound slotTag = new NBTTagCompound();
|
||||
|
||||
slot.writeToNBT(slotTag);
|
||||
|
||||
stack.getTagCompound().setTag(String.format(NBT_SLOT, id), slotTag);
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
@@ -91,7 +91,14 @@ public class ClientProxy extends CommonProxy
|
||||
|
||||
ModelLoader.setCustomModelResourceLocation(StorageCraftItems.SILICON, 0, new ModelResourceLocation("storagecraft:silicon", "inventory"));
|
||||
|
||||
ModelLoader.setCustomModelResourceLocation(StorageCraftItems.PATTERN, 0, new ModelResourceLocation("storagecraft:pattern", "inventory"));
|
||||
ModelLoader.setCustomMeshDefinition(StorageCraftItems.PATTERN, new ItemMeshDefinition()
|
||||
{
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack)
|
||||
{
|
||||
return new ModelResourceLocation("storagecraft:" + (!ItemPattern.hasPattern(stack) ? "blank_" : "") + "pattern", "inventory");
|
||||
}
|
||||
});
|
||||
|
||||
ModelLoader.setCustomModelResourceLocation(StorageCraftItems.QUARTZ_ENRICHED_IRON, 0, new ModelResourceLocation("storagecraft:quartz_enriched_iron", "inventory"));
|
||||
|
||||
|
@@ -10,9 +10,11 @@ import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.StorageCraftItems;
|
||||
import storagecraft.block.BlockGrid;
|
||||
import storagecraft.block.EnumGridType;
|
||||
import storagecraft.inventory.InventorySimple;
|
||||
import storagecraft.item.ItemPattern;
|
||||
import storagecraft.network.MessageGridCraftingUpdate;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
@@ -99,13 +101,6 @@ public class TileGrid extends TileMachine
|
||||
craftingResultInventory.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftingInventory, worldObj));
|
||||
}
|
||||
|
||||
public void onPatternCraftingMatrixChanged()
|
||||
{
|
||||
markDirty();
|
||||
|
||||
patternCraftingResultInventory.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(patternCraftingInventory, worldObj));
|
||||
}
|
||||
|
||||
public void onCrafted(ItemStack[] matrixSlots)
|
||||
{
|
||||
if (isConnected() && !worldObj.isRemote)
|
||||
@@ -152,6 +147,36 @@ public class TileGrid extends TileMachine
|
||||
return patternInventory;
|
||||
}
|
||||
|
||||
public void onPatternCraftingMatrixChanged()
|
||||
{
|
||||
markDirty();
|
||||
|
||||
patternCraftingResultInventory.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(patternCraftingInventory, worldObj));
|
||||
}
|
||||
|
||||
public void onPatternCreate()
|
||||
{
|
||||
ItemStack result = patternCraftingResultInventory.getStackInSlot(0);
|
||||
|
||||
if (result != null && patternInventory.getStackInSlot(0).stackSize > 0 && patternInventory.getStackInSlot(1) == null)
|
||||
{
|
||||
ItemStack pattern = new ItemStack(StorageCraftItems.PATTERN);
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
ItemStack slot = patternCraftingInventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null)
|
||||
{
|
||||
ItemPattern.setPattern(pattern, slot, i);
|
||||
}
|
||||
}
|
||||
|
||||
patternInventory.decrStackSize(0, 1);
|
||||
patternInventory.setInventorySlotContents(1, pattern);
|
||||
}
|
||||
}
|
||||
|
||||
public int getSortingDirection()
|
||||
{
|
||||
return sortingDirection;
|
||||
|
@@ -107,4 +107,5 @@ item.storagecraft:storage_part.0.name=1k Storage Part
|
||||
item.storagecraft:storage_part.1.name=4k Storage Part
|
||||
item.storagecraft:storage_part.2.name=16k Storage Part
|
||||
item.storagecraft:storage_part.3.name=64k Storage Part
|
||||
item.storagecraft:pattern.name=Pattern
|
||||
item.storagecraft:pattern.name=Pattern
|
||||
item.storagecraft:pattern.blank.name=Blank Pattern
|
@@ -107,4 +107,5 @@ item.storagecraft:storage_part.0.name=1k Opslagdeel
|
||||
item.storagecraft:storage_part.1.name=4k Opslagdeel
|
||||
item.storagecraft:storage_part.2.name=16k Opslagdeel
|
||||
item.storagecraft:storage_part.3.name=64k Opslagdeel
|
||||
item.storagecraft:pattern.name=Patroon
|
||||
item.storagecraft:pattern.name=Patroon
|
||||
item.storagecraft:pattern.blank.name=Leeg Patroon
|
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"parent": "builtin/generated",
|
||||
"textures": {
|
||||
"layer0": "storagecraft:items/blank_pattern"
|
||||
},
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [-90, 0, 0],
|
||||
"translation": [0, 1, -3],
|
||||
"scale": [0.55, 0.55, 0.55]
|
||||
},
|
||||
"firstperson": {
|
||||
"rotation": [0, -135, 25],
|
||||
"translation": [0, 4, 2],
|
||||
"scale": [1.7, 1.7, 1.7]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 270 B |
Binary file not shown.
Before Width: | Height: | Size: 270 B After Width: | Height: | Size: 270 B |
Reference in New Issue
Block a user