Add files via upload

master
Trent Patterson 2017-11-19 20:45:12 -05:00 committed by GitHub
parent 26bd93e1d1
commit 240c5a9ada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 1236 additions and 0 deletions

63
build.gradle Normal file
View File

@ -0,0 +1,63 @@
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
apply plugin: 'forge'
version = "1.0.0.0"
group= "com.jtrent238.jtrent238bags" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "jtrent238bags"
minecraft {
version = "1.7.10-10.13.4.1448-1.7.10"
runDir = "eclipse"
}
dependencies {
// you may put jars on which you depend on in ./libs
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
//compile "some.group:artifact:version"
// real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// for more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}

View File

@ -0,0 +1,142 @@
package com.jtrent238.jtrent238bags;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.jtrent238.jtrent238bags.common.CommonProxy;
import com.jtrent238.jtrent238bags.inventory.InventoryBag;
import com.jtrent238.jtrent238bags.client.ClientProxy;
import com.jtrent238.jtrent238bags.ForgeSubscribe;
import com.jtrent238.jtrent238bags.bags.ItemBag;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.command.ICommandManager;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.ChestGenHooks;
@Mod(modid = BagMod.MODID, name = BagMod.MODNAME, version = BagMod.MODVERSION)
public final class BagMod
{
public static final String MODID = "jtrent238bags";
@Instance(MODID)
public static BagMod instance;
public static final String MODVERSION = "1.0.0.0";
public static final String MODNAME = "jtrent238's Bag Mod";
public static final String MODAUTHOR = "jtrent238";
public static final String MC = "1.7.10";
@SidedProxy(clientSide="com.jtrent238.jtrent238bags.client.ClientProxy", serverSide="com.jtrent238.jtrent238bags.common.CommonProxy")
public static CommonProxy proxy;
/** This is used to keep track of GUIs that we make*/
private static int modGuiIndex = 0;
/** Set our custom inventory Gui index to the next available Gui index */
public static final int GUI_ITEM_INV = modGuiIndex++;
// ITEMS ETC.
public static Item ItemBag;
public static CreativeTabs BagTab = new CreativeTabs("BagTab")
{
public Item getTabIconItem() {
return new ItemStack(ItemLoader.ItemBag).getItem();
}
public boolean hasSearchBar(){
return false;
}
/*
@SideOnly(Side.CLIENT)
public String getBackgroundImageName()
{
return "EpicProportionsMod_Halloween.png";
}
@SideOnly(Side.CLIENT)
public boolean drawInForegroundOfTab()
{
return false;
}
*/
};
private List List;
private Collection Colection;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
ItemLoader.LoadItems();
//BlockLoader.loadBlocks();
Recipes.registerRecpies();
//EntityLoader.LoadEntitys();
OreDict.addores();
//Achievements.loadAchievements();
//Stats.RegisterStats();
//ChestGen.registerItems();
}
@EventHandler
public void load(FMLInitializationEvent event)
{
// no renderers or entities to register, but whatever
proxy.registerRenderers();
// register CommonProxy as our GuiHandler
NetworkRegistry.INSTANCE.registerGuiHandler(this, new CommonProxy());
Recipes.registerRecpies();
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
Recipes.registerRecpies();
}
@EventHandler
public void serverStart(FMLServerStartingEvent event)
{
MinecraftServer server = MinecraftServer.getServer();
// Get's the current server instance
ICommandManager command = server.getCommandManager();
//ServerCommandManager manager = (ServerCommandManager) command;
//manager.registerCommand(new CommandModInfo());
//manager.registerCommand(new CommandChangelog());
}
}

View File

@ -0,0 +1,9 @@
package com.jtrent238.jtrent238bags;
import cpw.mods.fml.common.eventhandler.EventPriority;
public @interface ForgeSubscribe {
EventPriority priority();
}

View File

@ -0,0 +1,37 @@
package com.jtrent238.jtrent238bags;
import com.jtrent238.jtrent238bags.bags.ItemBag;
import com.jtrent238.jtrent238bags.items.ItemDebug;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.item.Item;
public class ItemLoader {
public static Item ItemBag;
public static Item ItemDebug;
public static void LoadItems() {
ItemBag = new ItemBag(0, 0, ItemBag, null, null, null).setUnlocalizedName("ItemBag").setTextureName(BagMod.MODID + ":" + "ItemBag").setCreativeTab(BagMod.BagTab);
ItemDebug = new ItemDebug().setUnlocalizedName("ItemDebug").setTextureName(BagMod.MODID + ":" + "ItemDebug");
registerItems();
}
private static void registerItems() {
GameRegistry.registerItem(ItemBag, ItemBag.getUnlocalizedName().substring(5));
GameRegistry.registerItem(ItemDebug, ItemDebug.getUnlocalizedName().substring(5));
}
}

View File

@ -0,0 +1,43 @@
package com.jtrent238.jtrent238bags;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import com.jtrent238.jtrent238bags.bags.ItemBag;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
public class OreDict {
public static void addores() {
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[0].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 0));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[1].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 1));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[2].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 2));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[3].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 3));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[4].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 4));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[5].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 5));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[6].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 6));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[7].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 7));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[8].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 8));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[9].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 9));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[10].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 10));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[11].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 11));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[12].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 12));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[13].toUpperCase(), new ItemStack(ItemLoader.ItemBag));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[14].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 14));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[15].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 15));
OreDictionary.registerOre("bag" + ItemBag.field_150923_a[16].toUpperCase(), new ItemStack(ItemLoader.ItemBag, 16));
//OreDictionary.registerOre("bag" + ItemBag.field_150923_a[17], ItemLoader.ItemBag.getItemById(17));
}
}

View File

@ -0,0 +1,58 @@
package com.jtrent238.jtrent238bags;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
public class Recipes {
/**
* Register Recipes with Game Registry.
*/
public static void registerRecpies(){
addShaplessRecpies();
addShapedRecpies();
addsmeltigrecipies();
}
/**
* Add Shaped Recipes.
*/
private static void addShapedRecpies(){
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 0), "SXS", "XBX", "XXX", 'X', Items.leather, 'S', Items.string);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 1), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 1), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 2), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 2), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 3), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 4), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 4), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 5), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 5), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 6), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 6), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 9), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 7), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 10), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 8), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 11), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 9), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 12), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 10), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 13), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 11), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 14), 'B', ItemLoader.ItemBag);
GameRegistry.addShapedRecipe(new ItemStack(ItemLoader.ItemBag, 1, 12), "XXX", "XBX", "XXX", 'X', new ItemStack(Items.dye, 1, 15), 'B', ItemLoader.ItemBag);
}
/**
* Add Shapeless Recipes.
*/
private static void addShaplessRecpies(){
}
/**
* Add Smelting Recipes
*/
private static void addsmeltigrecipies(){
}
}

View File

@ -0,0 +1,123 @@
package com.jtrent238.jtrent238bags.bags;
import java.util.Collection;
import java.util.List;
import com.jtrent238.jtrent238bags.BagMod;
import com.jtrent238.jtrent238bags.inventory.InventoryBag;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class ItemBag extends Item
{
public static final String[] field_150923_a = new String[] {"Plain", "red", "green","blue", "purple", "cyan", "pink", "lime", "yellow", "lightBlue", "magenta", "orange", "white", "Cow", "JSQ", "_MrGregor_", "jtrent238"};
public static final String[] field_150921_b = new String[] {"Plain", "red", "green","blue", "purple", "cyan", "pink", "lime", "yellow", "lightBlue", "magenta", "orange", "white", "Cow", "JSQ", "_MrGregor_", "jtrent238"};
public static final int[] field_150922_c = new int[] {1973019, 11743532, 3887386, 5320730, 2437522, 8073150, 2651799, 11250603, 4408131, 14188952, 4312372, 14602026, 6719955, 12801229, 15435844, 15790320};
@SideOnly(Side.CLIENT)
private IIcon[] field_150920_d;
private IInventory Inventory;
private static final String __OBFID = "CL_00000022";
public ItemBag(int par1,int p_77647_1_, Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_, Collection c)
{
super();
// ItemStacks that store an NBT Tag Compound are limited to stack size of 1
setMaxStackSize(1);
// you'll want to set a creative tab as well, so you can get your item
setCreativeTab(BagMod.BagTab);
this.getMetadata(p_77647_1_);
//this.setMaxDamage(0);
this.setHasSubtypes(true);
}
/**
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
*/
@SideOnly(Side.CLIENT)
public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_)
{
//for (int i = 0; i < [AmountOfBags]; ++i)
for (int i = 0; i < 17; ++i)
{
p_150895_3_.add(new ItemStack(p_150895_1_, 1, i));
}
}
/**
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
* different names based on their damage or NBT.
*/
public String getUnlocalizedName(ItemStack p_77667_1_)
{
int i = MathHelper.clamp_int(p_77667_1_.getItemDamage(), 0, 17);
return super.getUnlocalizedName() + "." + field_150923_a[i];
}
/**
* Gets an icon index based on an item's damage value
*/
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int p_77617_1_)
{
int j = MathHelper.clamp_int(p_77617_1_, 0, 17);
return this.field_150920_d[j];
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister p_94581_1_)
{
this.field_150920_d = new IIcon[field_150921_b.length];
for (int i = 0; i < field_150921_b.length; ++i)
{
this.field_150920_d[i] = p_94581_1_.registerIcon(this.getIconString() + "_" + field_150921_b[i]);
}
}
/*
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister)
{
this.itemIcon = iconRegister.registerIcon(BagMod.MODID + ":" + this.getUnlocalizedName().substring(5));
}
*/
// Without this method, your inventory will NOT work!!!
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 1; // return any value greater than zero
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
{
if (!world.isRemote)
{
// If player not sneaking, open the inventory gui
if (!player.isSneaking()) {
player.openGui(BagMod.instance, BagMod.GUI_ITEM_INV, world, 0, 0, 0);
}
// Otherwise, stealthily place some diamonds in there for a nice surprise next time you open it up :)
else {
new InventoryBag(player.getHeldItem()).setInventorySlotContents(0, new ItemStack(Items.diamond,4));
}
}
return itemstack;
}
}

View File

@ -0,0 +1,9 @@
package com.jtrent238.jtrent238bags.client;
import com.jtrent238.jtrent238bags.common.CommonProxy;
public class ClientProxy extends CommonProxy
{
@Override
public void registerRenderers() {}
}

View File

@ -0,0 +1,39 @@
package com.jtrent238.jtrent238bags.common;
import com.jtrent238.jtrent238bags.BagMod;
import com.jtrent238.jtrent238bags.container.ContainerBag;
import com.jtrent238.jtrent238bags.gui.GuiBagInventory;
import com.jtrent238.jtrent238bags.inventory.InventoryBag;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public class CommonProxy implements IGuiHandler
{
public void registerRenderers() {}
@Override
public Object getServerGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
{
// Hooray, no 'magic' numbers - we know exactly which Gui this refers to
if (guiId == BagMod.GUI_ITEM_INV)
{
// Use the player's held item to create the inventory
return new ContainerBag(player, player.inventory, new InventoryBag(player.getHeldItem()));
}
return null;
}
@Override
public Object getClientGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
{
if (guiId == BagMod.GUI_ITEM_INV)
{
// We have to cast the new container as our custom class
// and pass in currently held item for the inventory
return new GuiBagInventory((ContainerBag) new ContainerBag(player, player.inventory, new InventoryBag(player.getHeldItem())));
}
return null;
}
}

View File

@ -0,0 +1,319 @@
package com.jtrent238.jtrent238bags.container;
import com.jtrent238.jtrent238bags.bags.ItemBag;
import com.jtrent238.jtrent238bags.inventory.InventoryBag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerBag extends Container
{
/** The Item Inventory for this Container, only needed if you want to reference isUseableByPlayer */
public final InventoryBag inventory;
/** Using these will make transferStackInSlot easier to understand and implement
* INV_START is the index of the first slot in the Player's Inventory, so our
* InventoryItem's number of slots (e.g. 5 slots is array indices 0-4, so start at 5)
* Notice how we don't have to remember how many slots we made? We can just use
* InventoryItem.INV_SIZE and if we ever change it, the Container updates automatically. */
private static final int INV_START = InventoryBag.INV_SIZE, INV_END = INV_START+26,
HOTBAR_START = INV_END+1, HOTBAR_END = HOTBAR_START+8;
// If you're planning to add armor slots, put those first like this:
// ARMOR_START = InventoryItem.INV_SIZE, ARMOR_END = ARMOR_START+3,
// INV_START = ARMOR_END+1, and then carry on like above.
public ContainerBag(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, InventoryBag inventoryItem)
{
this.inventory = inventoryItem;
int i;
// ITEM INVENTORY - you'll need to adjust the slot locations to match your texture file
// I have them set vertically in columns of 4 to the right of the player model
for (i = 0; i < InventoryBag.INV_SIZE; ++i)
{
// You can make a custom Slot if you need different behavior,
// such as only certain item types can be put into this slot
// We made a custom slot to prevent our inventory-storing item
// from being stored within itself, but if you want to allow that and
// you followed my advice at the end of the above step, then you
// could get away with using the vanilla Slot class
this.addSlotToContainer(new SlotItemInv(this.inventory, i, 80 + (18 * (int)(i/4)), 8 + (18*(i%4))));
}
// If you want, you can add ARMOR SLOTS here as well, but you need to
// make a public version of SlotArmor. I won't be doing that in this tutorial.
/*
for (i = 0; i < 4; ++i)
{
// These are the standard positions for survival inventory layout
this.addSlotToContainer(new SlotArmor(this.player, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 8, 8 + i * 18, i));
}
*/
// PLAYER INVENTORY - uses default locations for standard inventory texture file
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
// PLAYER ACTION BAR - uses default locations for standard action bar texture file
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
// be sure to return the inventory's isUseableByPlayer method
// if you defined special behavior there:
return inventory.isUseableByPlayer(entityplayer);
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int index)
{
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
// If item is in our custom Inventory or armor slot
if (index < INV_START)
{
// try to place in player inventory / action bar
if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END+1, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
// Item is in inventory / hotbar, try to place in custom inventory or armor slots
else
{
/*
If your inventory only stores certain instances of Items,
you can implement shift-clicking to your inventory like this:
// Check that the item is the right type
if (itemstack1.getItem() instanceof ItemCustom)
{
// Try to merge into your custom inventory slots
// We use 'InventoryItem.INV_SIZE' instead of INV_START just in case
// you also add armor or other custom slots
if (!this.mergeItemStack(itemstack1, 0, InventoryItem.INV_SIZE, false))
{
return null;
}
}
// If you added armor slots, check them here as well:
// Item being shift-clicked is armor - try to put in armor slot
if (itemstack1.getItem() instanceof ItemArmor)
{
int type = ((ItemArmor) itemstack1.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false))
{
return null;
}
}
Otherwise, you have basically 2 choices:
1. shift-clicking between player inventory and custom inventory
2. shift-clicking between action bar and inventory
Be sure to choose only ONE of the following implementations!!!
*/
/**
* Implementation number 1: Shift-click into your custom inventory
*/
if (index >= INV_START)
{
// place in custom inventory
if (!this.mergeItemStack(itemstack1, 0, INV_START, false))
{
return null;
}
}
/**
* Implementation number 2: Shift-click items between action bar and inventory
*/
// item is in player's inventory, but not in action bar
if (index >= INV_START && index < HOTBAR_START)
{
// place in action bar
if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_END+1, false))
{
return null;
}
}
// item in action bar - place in player inventory
else if (index >= HOTBAR_START && index < HOTBAR_END+1)
{
if (!this.mergeItemStack(itemstack1, INV_START, INV_END+1, false))
{
return null;
}
}
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack) null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
}
return itemstack;
}
/**
* You should override this method to prevent the player from moving the stack that
* opened the inventory, otherwise if the player moves it, the inventory will not
* be able to save properly
*/
@Override
public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) {
// this will prevent the player from interacting with the item that opened the inventory:
if (slot >= 0 && getSlot(slot) != null && getSlot(slot).getStack() == player.getHeldItem()) {
return null;
}
return super.slotClick(slot, button, flag, player);
}
/*
Special note: If your custom inventory's stack limit is 1 and you allow shift-clicking itemstacks into it,
you will need to override mergeStackInSlot to avoid losing all the items but one in a stack when you shift-click.
*/
/**
* Vanilla mergeItemStack method doesn't correctly handle inventories whose
* max stack size is 1 when you shift-click into the inventory.
* This is a modified method I wrote to handle such cases.
* Note you only need it if your slot / inventory's max stack size is 1
*/
@Override
protected boolean mergeItemStack(ItemStack stack, int start, int end, boolean backwards)
{
boolean flag1 = false;
int k = (backwards ? end - 1 : start);
Slot slot;
ItemStack itemstack1;
if (stack.isStackable())
{
while (stack.stackSize > 0 && (!backwards && k < end || backwards && k >= start))
{
slot = (Slot) inventorySlots.get(k);
itemstack1 = slot.getStack();
if (!slot.isItemValid(stack)) {
k += (backwards ? -1 : 1);
continue;
}
if (itemstack1 != null && itemstack1.getItem() == stack.getItem() &&
(!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, itemstack1))
{
int l = itemstack1.stackSize + stack.stackSize;
if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) {
stack.stackSize = 0;
itemstack1.stackSize = l;
inventory.markDirty();
flag1 = true;
} else if (itemstack1.stackSize < stack.getMaxStackSize() && l < slot.getSlotStackLimit()) {
stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize;
itemstack1.stackSize = stack.getMaxStackSize();
inventory.markDirty();
flag1 = true;
}
}
k += (backwards ? -1 : 1);
}
}
if (stack.stackSize > 0)
{
k = (backwards ? end - 1 : start);
while (!backwards && k < end || backwards && k >= start) {
slot = (Slot) inventorySlots.get(k);
itemstack1 = slot.getStack();
if (!slot.isItemValid(stack)) {
k += (backwards ? -1 : 1);
continue;
}
if (itemstack1 == null) {
int l = stack.stackSize;
if (l <= slot.getSlotStackLimit()) {
slot.putStack(stack.copy());
stack.stackSize = 0;
inventory.markDirty();
flag1 = true;
break;
} else {
putStackInSlot(k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage()));
stack.stackSize -= slot.getSlotStackLimit();
inventory.markDirty();
flag1 = true;
}
}
k += (backwards ? -1 : 1);
}
}
return flag1;
}
/*
Making the custom slot is very simple, if you're going that route:
*/
public class SlotItemInv extends Slot
{
public SlotItemInv(IInventory inv, int index, int xPos, int yPos)
{
super(inv, index, xPos, yPos);
}
// This is the only method we need to override so that
// we can't place our inventory-storing Item within
// its own inventory (thus making it permanently inaccessible)
// as well as preventing abuse of storing backpacks within backpacks
/**
* Check if the stack is a valid item for this slot.
*/
@Override
public boolean isItemValid(ItemStack itemstack)
{
// Everything returns true except an instance of our Item
return !(itemstack.getItem() instanceof ItemBag);
}
}
}

View File

@ -0,0 +1,115 @@
package com.jtrent238.jtrent238bags.gui;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import com.jtrent238.jtrent238bags.BagMod;
import com.jtrent238.jtrent238bags.container.ContainerBag;
import com.jtrent238.jtrent238bags.inventory.InventoryBag;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
public class GuiBagInventory extends GuiContainer
{
/** x and y size of the inventory window in pixels. Defined as float, passed as int
* These are used for drawing the player model. */
private float xSize_lo;
private float ySize_lo;
/** ResourceLocation takes 2 parameters: ModId, path to texture at the location:
* "src/minecraft/assets/modid/"
*
* I have provided a sample texture file that works with this tutorial. Download it
* from Forge_Tutorials/textures/gui/
*/
private static final ResourceLocation iconLocation = new ResourceLocation(BagMod.MODID, "textures/gui/InventoryBag.png");
/** The inventory to render on screen */
private final InventoryBag inventory;
public GuiBagInventory(ContainerBag containerItem)
{
super(containerItem);
this.inventory = containerItem.inventory;
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int par1, int par2, float par3)
{
super.drawScreen(par1, par2, par3);
this.xSize_lo = (float)par1;
this.ySize_lo = (float)par2;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
//String s = this.inventory.isInvNameLocalized() ? this.inventory.getInventoryName() : I18n.getString(this.inventory.getInventoryName());
//this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 0, 4210752);
//this.fontRendererObj.drawString(I18n.getString("container.inventory"), 26, this.ySize - 96 + 4, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(iconLocation);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int i1;
drawPlayerModel(k + 51, l + 75, 30, (float)(k + 51) - this.xSize_lo, (float)(l + 75 - 50) - this.ySize_lo, this.mc.thePlayer);
}
/**
* This renders the player model in standard inventory position (in later versions of Minecraft / Forge, you can
* simply call GuiInventory.drawEntityOnScreen directly instead of copying this code)
*/
public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity) {
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glPushMatrix();
GL11.glTranslatef(x, y, 50.0F);
GL11.glScalef(-scale, scale, scale);
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
float f2 = entity.renderYawOffset;
float f3 = entity.rotationYaw;
float f4 = entity.rotationPitch;
float f5 = entity.prevRotationYawHead;
float f6 = entity.rotationYawHead;
GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-((float) Math.atan(pitch / 40.0F)) * 20.0F, 1.0F, 0.0F, 0.0F);
entity.renderYawOffset = (float) Math.atan(yaw / 40.0F) * 20.0F;
entity.rotationYaw = (float) Math.atan(yaw / 40.0F) * 40.0F;
entity.rotationPitch = -((float) Math.atan(pitch / 40.0F)) * 20.0F;
entity.rotationYawHead = entity.rotationYaw;
entity.prevRotationYawHead = entity.rotationYaw;
GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
RenderManager.instance.playerViewY = 180.0F;
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
entity.renderYawOffset = f2;
entity.rotationYaw = f3;
entity.rotationPitch = f4;
entity.prevRotationYawHead = f5;
entity.rotationYawHead = f6;
GL11.glPopMatrix();
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
}

View File

@ -0,0 +1,207 @@
package com.jtrent238.jtrent238bags.inventory;
import com.jtrent238.jtrent238bags.bags.ItemBag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
public class InventoryBag implements IInventory
{
private String name = "Inventory Item";
/** Provides NBT Tag Compound to reference */
private final ItemStack invItem;
/** Defining your inventory size this way is handy */
public static final int INV_SIZE = 8;
/** Inventory's size must be same as number of slots you add to the Container class */
private ItemStack[] inventory = new ItemStack[INV_SIZE];
/**
* @param itemstack - the ItemStack to which this inventory belongs
*/
public InventoryBag(ItemStack stack)
{
invItem = stack;
// Create a new NBT Tag Compound if one doesn't already exist, or you will crash
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
}
// note that it's okay to use stack instead of invItem right there
// both reference the same memory location, so whatever you change using
// either reference will change in the other
// Read the inventory contents from NBT
readFromNBT(stack.getTagCompound());
}
@Override
public int getSizeInventory()
{
return inventory.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inventory[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amount)
{
ItemStack stack = getStackInSlot(slot);
if(stack != null)
{
if(stack.stackSize > amount)
{
stack = stack.splitStack(amount);
// Don't forget this line or your inventory will not be saved!
markDirty();
}
else
{
// this method also calls onInventoryChanged, so we don't need to call it again
setInventorySlotContents(slot, null);
}
}
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
ItemStack stack = getStackInSlot(slot);
setInventorySlotContents(slot, null);
return stack;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
inventory[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit())
{
stack.stackSize = getInventoryStackLimit();
}
// Don't forget this line or your inventory will not be saved!
markDirty();
}
@Override
public String getInventoryName()
{
return name;
}
@Override
public boolean hasCustomInventoryName()
{
return name.length() > 0;
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
/**
* This is the method that will handle saving the inventory contents, as it is called (or should be called!)
* anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also
* let you change things in your inventory without ever opening a Gui, if you want.
*/
@Override
public void markDirty()
{
for (int i = 0; i < getSizeInventory(); ++i)
{
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {
inventory[i] = null;
}
}
// This line here does the work:
writeToNBT(invItem.getTagCompound());
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return true;
}
public void openInventory() {}
public void closeInventory() {}
/**
* This method doesn't seem to do what it claims to do, as
* items can still be left-clicked and placed in the inventory
* even when this returns false
*/
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
// Don't want to be able to store the inventory item within itself
// Bad things will happen, like losing your inventory
// Actually, this needs a custom Slot to work
return !(itemstack.getItem() instanceof ItemBag);
}
/**
* A custom method to read our inventory from an ItemStack's NBT compound
*/
public void readFromNBT(NBTTagCompound compound)
{
// Gets the custom taglist we wrote to this compound, if any
// 1.7.2+ change to compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);
NBTTagList items = compound.getTagList("BagInventory", 0);
for (int i = 0; i < items.tagCount(); ++i)
{
// 1.7.2+ change to items.getCompoundTagAt(i)
NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i);
int slot = item.getInteger("Slot");
// Just double-checking that the saved slot index is within our inventory array bounds
if (slot >= 0 && slot < getSizeInventory()) {
inventory[slot] = ItemStack.loadItemStackFromNBT(item);
}
}
}
/**
* A custom method to write our inventory to an ItemStack's NBT compound
*/
public void writeToNBT(NBTTagCompound tagcompound)
{
// Create a new NBT Tag List to store itemstacks as NBT Tags
NBTTagList items = new NBTTagList();
for (int i = 0; i < getSizeInventory(); ++i)
{
// Only write stacks that contain items
if (getStackInSlot(i) != null)
{
// Make a new NBT Tag Compound to write the itemstack and slot index to
NBTTagCompound item = new NBTTagCompound();
item.setInteger("Slot", i);
// Writes the itemstack in slot(i) to the Tag Compound we just made
getStackInSlot(i).writeToNBT(item);
// add the tag compound to our tag list
items.appendTag(tagcompound);
}
}
// Add the TagList to the ItemStack's Tag Compound with the name "ItemInventory"
tagcompound.setTag("BagInventory", items);
}
}

View File

@ -0,0 +1,38 @@
package com.jtrent238.jtrent238bags.items;
import com.jtrent238.jtrent238bags.inventory.InventoryBag;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItemDebug extends Item{
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
{
if (!world.isRemote)
{
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++DEBUG+++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println(player.inventoryContainer.inventorySlots.toString());
System.out.println("Player DisplayName: " + player.getDisplayName().toString());
//System.out.println("Player Bed Location: " + player.getBedLocation().posX + ", " + player.getBedLocation().posY + ", " + player.getBedLocation().posZ);
System.out.println("Player PersistentID: " + player.getPersistentID().toString());
System.out.println("Player UniqueID: " + player.getUniqueID().toString());
System.out.println("Minecraft Debug Information: " + Minecraft.getMinecraft().debug.toString());
System.out.println("Amount of Entitys in World: " + Minecraft.getMinecraft().debugInfoEntities().toString());
System.out.println("InfoRenders: " + Minecraft.getMinecraft().debugInfoRenders().toString());
System.out.println("WorldProviderName: " + Minecraft.getMinecraft().getWorldProviderName().toString());
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
}
return itemstack;
}
}

View File

@ -0,0 +1,18 @@
itemGroup.BagTab=jtrent238's Bag Mod
item.ItemBag.Plain.name=Plain Bag
item.ItemBag.red.name=Red Bag
item.ItemBag.green.name=Green Bag
item.ItemBag.blue.name=Blue Bag
item.ItemBag.purple.name=Purple Bag
item.ItemBag.cyan.name=Cyan Bag
item.ItemBag.pink.name=Pink Bag
item.ItemBag.lime.name=Lime Bag
item.ItemBag.yellow.name=Yellow Bag
item.ItemBag.lightBlue.name=Light Blue Bag
item.ItemBag.magenta.name=Magenta Bag
item.ItemBag.orange.name=Orange Bag
item.ItemBag.white.name=White Bag
item.ItemBag.Cow.name=Cow Bag
item.ItemBag.JSQ.name=xJSQ Bag
item.ItemBag._MrGregor_.name=_MrGregor_ Bag
item.ItemBag.jtrent238.name=jtrent238 Bag

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

View File

@ -0,0 +1,16 @@
[
{
"modid": "examplemod",
"name": "Example Mod",
"description": "Example placeholder mod.",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "",
"updateUrl": "",
"authorList": ["ExampleDude"],
"credits": "The Forge and FML guys, for making this example",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]