Skip to content

Commit

Permalink
Dye-able bit bags. Implements #198
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Nov 11, 2018
1 parent 128606a commit 9ded1e8
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 5 deletions.
Expand Up @@ -32,14 +32,16 @@ static int[] getStorageArray(
int[] out = null;
NBTTagCompound compound = stack.getTagCompound();

if ( compound != null && compound.hasKey( "contents" ) )
if ( compound == null )
compound = new NBTTagCompound();

if ( compound.hasKey( "contents" ) )
{
out = compound.getIntArray( "contents" );
}

if ( out == null )
{
compound = new NBTTagCompound();
stack.setTagCompound( compound );
out = new int[size];
compound.setIntArray( "contents", out );
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/mod/chiselsandbits/client/ItemColorBitBag.java
@@ -0,0 +1,26 @@
package mod.chiselsandbits.client;

import mod.chiselsandbits.core.ChiselsAndBits;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;

public class ItemColorBitBag implements IItemColor
{

@Override
public int getColorFromItemstack(
ItemStack stack,
int tintIndex )
{
if ( tintIndex == 1 )
{
EnumDyeColor color = ChiselsAndBits.getItems().itemBitBag.getDyedColor( stack );
if ( color != null )
return color.func_193350_e();
}

return -1;
}

}
22 changes: 21 additions & 1 deletion src/main/java/mod/chiselsandbits/core/ClientSide.java
Expand Up @@ -39,6 +39,7 @@
import mod.chiselsandbits.chiseledblock.iterators.ChiselTypeIterator;
import mod.chiselsandbits.client.BlockColorChisled;
import mod.chiselsandbits.client.CreativeClipboardTab;
import mod.chiselsandbits.client.ItemColorBitBag;
import mod.chiselsandbits.client.ItemColorBits;
import mod.chiselsandbits.client.ItemColorChisled;
import mod.chiselsandbits.client.ItemColorPatterns;
Expand Down Expand Up @@ -239,6 +240,11 @@ public void postinit(

final ModItems modItems = ChiselsAndBits.getItems();

if ( modItems.itemBitBag != null )
{
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( new ItemColorBitBag(), modItems.itemBitBag );
}

if ( modItems.itemBlockBit != null )
{
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( new ItemColorBits(), modItems.itemBlockBit );
Expand Down Expand Up @@ -286,7 +292,6 @@ public void registerItemModels()
registerMesh( modItems.itemChiselIron, 0, new ModelResourceLocation( new ResourceLocation( modId, "chisel_iron" ), "inventory" ) );
registerMesh( modItems.itemChiselGold, 0, new ModelResourceLocation( new ResourceLocation( modId, "chisel_gold" ), "inventory" ) );
registerMesh( modItems.itemChiselDiamond, 0, new ModelResourceLocation( new ResourceLocation( modId, "chisel_diamond" ), "inventory" ) );
registerMesh( modItems.itemBitBag, 0, new ModelResourceLocation( new ResourceLocation( modId, "bit_bag" ), "inventory" ) );
registerMesh( modItems.itemWrench, 0, new ModelResourceLocation( new ResourceLocation( modId, "wrench_wood" ), "inventory" ) );
registerMesh( modItems.itemBitSawDiamond, 0, new ModelResourceLocation( new ResourceLocation( modId, "bitsaw_diamond" ), "inventory" ) );
registerMesh( modItems.itemTapeMeasure, 0, new ModelResourceLocation( new ResourceLocation( modId, "tape_measure" ), "inventory" ) );
Expand All @@ -296,6 +301,21 @@ public void registerItemModels()
registerMesh( ChiselsAndBits.getBlocks().itemBitTank, 0, new ModelResourceLocation( new ResourceLocation( modId, "bittank" ), "inventory" ) );
}

if ( modItems.itemBitBag != null )
{
ModelBakery.registerItemVariants( modItems.itemBitBag, new ResourceLocation( modId, "bit_bag" ), new ResourceLocation( modId, "bit_bag_dyed" ) );
ModelLoader.setCustomMeshDefinition( modItems.itemBitBag, new ItemMeshDefinition() {

@Override
public ModelResourceLocation getModelLocation(
final ItemStack stack )
{
return new ModelResourceLocation( new ResourceLocation( modId, modItems.itemBitBag.getDyedColor( stack ) != null ? "bit_bag_dyed" : "bit_bag" ), "inventory" );
}

} );
}

if ( modItems.itemPositiveprint != null )
{
ModelBakery.registerItemVariants( modItems.itemPositiveprint, new ResourceLocation( modId, "positiveprint" ), new ResourceLocation( modId, "positiveprint_written" ) );
Expand Down
166 changes: 166 additions & 0 deletions src/main/java/mod/chiselsandbits/crafting/BagDyeing.java
@@ -0,0 +1,166 @@
package mod.chiselsandbits.crafting;

import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.items.ItemBitBag;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;

public class BagDyeing extends CustomRecipe
{

public BagDyeing(
ResourceLocation name )
{
super( name );
}

private static class dyed_output
{
ItemStack bag;
EnumDyeColor color;

public dyed_output(
ItemStack bag,
EnumDyeColor dye )
{
this.bag = bag;
this.color = dye;
}

};

@Override
public boolean matches(
InventoryCrafting inv,
World worldIn )
{
return getOutput( inv ) != null;
}

@Override
public ItemStack getCraftingResult(
InventoryCrafting inv )
{
dyed_output output = getOutput( inv );

if ( output != null )
{
return ChiselsAndBits.getItems().itemBitBag.dyeBag( output.bag, output.color );
}

return ModUtil.getEmptyStack();
}

private dyed_output getOutput(
InventoryCrafting inv )
{
ItemStack bag = null;
ItemStack dye = null;

for ( int x = 0; x < inv.getSizeInventory(); ++x )
{
ItemStack is = inv.getStackInSlot( x );
if ( is != null && !ModUtil.isEmpty( is ) )
{
if ( is.getItem() == Items.WATER_BUCKET || getDye( is ) != null )
{
if ( dye == null )
dye = is;
else
return null;
}
else if ( is.getItem() instanceof ItemBitBag )
{
if ( bag == null )
bag = is;
else
return null;
}
else
return null;
}
}

if ( bag != null && dye != null )
{
return new dyed_output( bag, getDye( dye ) );
}

return null;
}

private EnumDyeColor getDye(
ItemStack is )
{
if ( testDye( "dyeWhite", is ) )
return EnumDyeColor.WHITE;
if ( testDye( "dyeOrange", is ) )
return EnumDyeColor.ORANGE;
if ( testDye( "dyeMagenta", is ) )
return EnumDyeColor.MAGENTA;
if ( testDye( "dyeLightBlue", is ) )
return EnumDyeColor.LIGHT_BLUE;
if ( testDye( "dyeLime", is ) )
return EnumDyeColor.LIME;
if ( testDye( "dyePink", is ) )
return EnumDyeColor.PINK;
if ( testDye( "dyeGray", is ) )
return EnumDyeColor.GRAY;
if ( testDye( "dyeLightGray", is ) )
return EnumDyeColor.SILVER;
if ( testDye( "dyeCyan", is ) )
return EnumDyeColor.CYAN;
if ( testDye( "dyePurple", is ) )
return EnumDyeColor.PURPLE;
if ( testDye( "dyeBlue", is ) )
return EnumDyeColor.BLUE;
if ( testDye( "dyeBrown", is ) )
return EnumDyeColor.BROWN;
if ( testDye( "dyeGreen", is ) )
return EnumDyeColor.GREEN;
if ( testDye( "dyeRed", is ) )
return EnumDyeColor.RED;
if ( testDye( "dyeBlack", is ) )
return EnumDyeColor.BLACK;

return null;
}

private boolean testDye(
String string,
ItemStack is )
{
if ( OreDictionary.doesOreNameExist( string ) )
{
int ore = OreDictionary.getOreID( string );
int[] list = OreDictionary.getOreIDs( is );
for ( int x = 0; x < list.length; ++x )
if ( list[x] == ore )
return true;
return false;
}
else
throw new RuntimeException( "Invalid dye: " + string );
}

@Override
public boolean func_194133_a(
int p_194133_1_,
int p_194133_2_ )
{
return p_194133_1_ * p_194133_2_ >= 2;
}

@Override
public ItemStack getRecipeOutput()
{
return ModUtil.getEmptyStack();
}

}
5 changes: 5 additions & 0 deletions src/main/java/mod/chiselsandbits/crafting/ModRecipes.java
Expand Up @@ -27,6 +27,11 @@ void registerRecipes(
String MODID = ChiselsAndBits.MODID;

// add special recipes...
if ( ChiselsAndBits.getItems().itemBitBag != null )
{
r.register( new BagDyeing( new ResourceLocation( MODID, "bitbagdyeing" ) ) );
}

if ( config.enablePositivePrintCrafting )
{
r.register( new ChiselCrafting( new ResourceLocation( MODID, "positiveprintcrafting" ) ) );
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/mod/chiselsandbits/items/ItemBitBag.java
Expand Up @@ -16,15 +16,19 @@
import mod.chiselsandbits.network.packets.PacketOpenBagGui;
import mod.chiselsandbits.render.helpers.SimpleInstanceCache;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
Expand Down Expand Up @@ -57,6 +61,17 @@ public ICapabilityProvider initCapabilities(
return new BagCapabilityProvider( stack, nbt );
}

@Override
public String getItemStackDisplayName(
ItemStack stack )
{
EnumDyeColor color = getDyedColor( stack );
if ( color != null )
return super.getItemStackDisplayName( stack ) + " - " + I18n.translateToLocal( "chiselsandbits.color." + color.getName() );
else
return super.getItemStackDisplayName( stack );
}

@Override
@SideOnly( Side.CLIENT )
public void addInformation(
Expand Down Expand Up @@ -318,4 +333,51 @@ public double getDurabilityForDisplay(

return 0;
}

@Override
public void getSubItems(
CreativeTabs itemIn,
NonNullList<ItemStack> tab )
{
if ( this.func_194125_a( itemIn ) )
{
tab.add( new ItemStack( this ) );

for ( EnumDyeColor color : EnumDyeColor.values() )
tab.add( dyeBag( new ItemStack( this ), color ) );
}
}

public ItemStack dyeBag(
ItemStack bag,
EnumDyeColor color )
{
ItemStack copy = bag.copy();

if ( !copy.hasTagCompound() )
copy.setTagCompound( new NBTTagCompound() );

if ( color == null )
copy.getTagCompound().removeTag( "color" );
else
copy.getTagCompound().setString( "color", color.getName() );

return copy;
}

public EnumDyeColor getDyedColor(
ItemStack stack )
{
if ( stack.hasTagCompound() && stack.getTagCompound().hasKey( "color" ) )
{
String name = stack.getTagCompound().getString( "color" );
for ( EnumDyeColor color : EnumDyeColor.values() )
{
if ( name.equals( color.getName() ) )
return color;
}
}

return null;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/chiselsandbits/lang/en_us.lang
Expand Up @@ -102,7 +102,7 @@ mod.chiselsandbits.help.bittank=Fill with fluid and extract bits.
mod.chiselsandbits.help.tape_measure={} and drag to measure;{} + {} to clear;Use {} to display menu.

mod.chiselsandbits.help.chiseled_block.long=Left-click to place the block. Sneak while placing to ignore block grid. Shift + Mouse Wheel to cycle placement rotation.
mod.chiselsandbits.help.bit_bag.long=Automatically re-stocks, and store bits when you exceed or go under a stack in your inventory.
mod.chiselsandbits.help.bit_bag.long=Automatically re-stocks, and store bits when you exceed or go under a stack in your inventory.\n\nCraft with any dye to color.
mod.chiselsandbits.help.wrench.long=Right-click blocks to rotate them around the axis of the face you click.
mod.chiselsandbits.help.tape_measure.long=Left-click to and drag to measure spaces. Sneak Use to remove previously created measurements. Use the menu to switch between measurement modes.
mod.chiselsandbits.help.bit.long=Left-click to chisel the highlighted area. Right-click to place at the designated area.
Expand Down Expand Up @@ -144,7 +144,7 @@ chiselsandbits.color.yellow=Yellow
chiselsandbits.color.lime=Lime
chiselsandbits.color.pink=Pink
chiselsandbits.color.gray=Gray
chiselsandbits.color.silver=Silver
chiselsandbits.color.silver=Light Gray
chiselsandbits.color.cyan=Cyan
chiselsandbits.color.purple=Purple
chiselsandbits.color.blue=Blue
Expand Down
@@ -0,0 +1,7 @@
{
"parent":"item/generated",
"textures": {
"layer0":"chiselsandbits:items/bit_bag_string",
"layer1":"chiselsandbits:items/bit_bag_dyeable"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9ded1e8

Please sign in to comment.