Skip to content

Commit

Permalink
Update to fix a lot of issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Aug 17, 2014
1 parent f8ed3b0 commit 7e6cd43
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -28,7 +28,7 @@ apply plugin: "maven"
apply plugin: "idea-utils"

group = "net.doubledoordev.timber"
version = "1.0.0"
version = "1.0.1"

targetCompatibility = 1.7
sourceCompatibility = 1.7
Expand Down
Expand Up @@ -28,7 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package net.doubledoordev.timber;
package net.doubledoordev.lumberjack;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
Expand All @@ -39,8 +39,8 @@
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.doubledoordev.lib.DevPerks;
import net.doubledoordev.timber.items.ItemLumberAxe;
import net.doubledoordev.timber.util.Point;
import net.doubledoordev.lumberjack.items.ItemLumberAxe;
import net.doubledoordev.lumberjack.util.Point;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayerMP;
Expand All @@ -51,22 +51,24 @@
import net.minecraftforge.event.world.BlockEvent;
import org.apache.logging.log4j.Logger;

import static net.doubledoordev.timber.util.Constants.MODID;
import java.util.HashSet;

import static net.doubledoordev.lumberjack.util.Constants.*;

/**
* @author Dries007
*/
@Mod(modid = MODID)
public class Timber
public class Lumberjack
{
@Mod.Instance(MODID)
public static Timber instance;
public static Lumberjack instance;

public Logger logger;
public boolean debug = false;
public int limit = 1024;
public int mode = 0;
public boolean leaves = false;
public boolean debug = false;
public int limit = 1024;
public int mode = 0;
public boolean leaves = false;
public HashMultimap<String, Point> pointMap = HashMultimap.create();
public HashMultimap<String, Point> nextMap = HashMultimap.create();

Expand All @@ -93,17 +95,25 @@ public void preInit(FMLPreInitializationEvent event)
public void init(FMLInitializationEvent event)
{
if (debug) logger.info("Registering all tools");
HashSet<Item> items = new HashSet<>(Item.ToolMaterial.values().length);
for (Item.ToolMaterial material : Item.ToolMaterial.values())
{
try
{
new ItemLumberAxe(material);
}
catch (Exception e)
if (material.func_150995_f() == null && debug) logger.warn("The ToolMaterial " + material + " doesn't have a crafting item set. No LumberAxe from that!");
else if (items.contains(material.func_150995_f()) && debug) logger.warn("The ToolMaterial " + material + " uses an item that has already been used.");
else
{
// Noop
try
{
new ItemLumberAxe(material);
items.add(material.func_150995_f());
}
catch (Exception e)
{
// Noop
}
}
}
if (debug) logger.info("Table of materials: \n" + makeTable(new TableData("Tool Material", ItemLumberAxe.toolMaterials), new TableData("Texture string", ItemLumberAxe.textureStrings), new TableData("Item name", ItemLumberAxe.itemNames), new TableData("Crafting Items", ItemLumberAxe.craftingItems)));
}

@SubscribeEvent
Expand Down
Expand Up @@ -28,10 +28,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package net.doubledoordev.timber.items;
package net.doubledoordev.lumberjack.items;

import cpw.mods.fml.common.registry.GameRegistry;
import net.doubledoordev.timber.Timber;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
Expand All @@ -43,8 +42,9 @@
import net.minecraftforge.oredict.ShapedOreRecipe;

import java.lang.reflect.Field;
import java.util.ArrayList;

import static net.doubledoordev.timber.util.Constants.MODID;
import static net.doubledoordev.lumberjack.util.Constants.MODID;

/**
* @author Dries007
Expand All @@ -57,6 +57,11 @@ public class ItemLumberAxe extends ItemAxe
damageVsEntityField.setAccessible(true);
}

public static ArrayList<String> toolMaterials = new ArrayList<>();
public static ArrayList<String> textureStrings = new ArrayList<>();
public static ArrayList<String> itemNames = new ArrayList<>();
public static ArrayList<String> craftingItems = new ArrayList<>();

public ItemLumberAxe(ToolMaterial toolMaterial)
{
super(toolMaterial);
Expand All @@ -72,7 +77,9 @@ public ItemLumberAxe(ToolMaterial toolMaterial)
setUnlocalizedName(name);
GameRegistry.registerItem(this, name);

if (Timber.instance.debug) Timber.instance.logger.info(String.format("ToolMaterial: %s \tTexture string: %s \tItem name: %s", toolMaterial, iconString, name));
toolMaterials.add(toolMaterial.toString());
textureStrings.add(iconString);
itemNames.add(name);

try
{
Expand All @@ -83,11 +90,23 @@ public ItemLumberAxe(ToolMaterial toolMaterial)
e.printStackTrace();
}

String items = "";
ItemStack craftingItem = new ItemStack(toolMaterial.func_150995_f());
for (int id : OreDictionary.getOreIDs(craftingItem))
int[] ids = OreDictionary.getOreIDs(craftingItem);
if (ids.length == 0)
{
GameRegistry.addRecipe(new ShapedOreRecipe(this, "XX", "SX", "SX", 'S', "stickWood", 'X', craftingItem).setMirrored(true));
items = craftingItem.getUnlocalizedName();
}
else
{
GameRegistry.addRecipe(new ShapedOreRecipe(this, "XX", "SX", "SX", 'S', "stickWood", 'X', OreDictionary.getOreName(id)).setMirrored(true));
for (int id : ids)
{
GameRegistry.addRecipe(new ShapedOreRecipe(this, "XX", "SX", "SX", 'S', "stickWood", 'X', OreDictionary.getOreName(id)).setMirrored(true));
items += OreDictionary.getOreName(id) + ", ";
}
}
craftingItems.add(items);
}

@Override
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/net/doubledoordev/lumberjack/util/Constants.java
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2014, DoubleDoorDevelopment
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package net.doubledoordev.lumberjack.util;

import java.util.ArrayList;

/**
* @author Dries007
*/
public class Constants
{
public static final String MODID = "Lumberjack";

public static final class TableData
{
public String header;
public ArrayList<String> strings;
private int width;

public TableData(String header, ArrayList<String> data)
{
this.header = header;
this.strings = data;
width = header.length();

updateWidth();
}

private void updateWidth()
{
for (String string : strings) if (width < string.length()) width = string.length();
}
}

public static String makeTable(TableData... datas)
{
int size = 0;
for (TableData data : datas) size += data.width * data.strings.size();
StringBuilder stringBuilder = new StringBuilder(size);

for (TableData data : datas) stringBuilder.append('|').append(' ').append(data.header).append(new String(new char[data.width - data.header.length() + 1]).replace('\0', ' '));
stringBuilder.append('|').append('\n');
for (TableData data : datas) stringBuilder.append('+').append(new String(new char[data.width + 2]).replace('\0', '-'));
stringBuilder.append('+').append('\n');
int i = 0;
while (i < datas[0].strings.size())
{
for (TableData data : datas) stringBuilder.append('|').append(' ').append(data.strings.get(i)).append(new String(new char[data.width - data.strings.get(i).length() + 1]).replace('\0', ' '));
stringBuilder.append('|').append('\n');
i++;
}

return stringBuilder.toString();
}
}
Expand Up @@ -28,7 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package net.doubledoordev.timber.util;
package net.doubledoordev.lumberjack.util;

/**
* @author Dries007
Expand Down
39 changes: 0 additions & 39 deletions src/main/java/net/doubledoordev/timber/util/Constants.java

This file was deleted.

0 comments on commit 7e6cd43

Please sign in to comment.