There dad u got ur thingy
also who put these null itemstacks here bad
This commit is contained in:
Shadows_of_Fire 2017-08-01 22:20:47 -04:00
parent c6c43fe5a8
commit f2b24c3318
17 changed files with 125 additions and 19 deletions

View file

@ -126,7 +126,7 @@ public final class ActuallyAdditionsAPI{
* @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time)
*/
public static void addCrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance){
CRUSHER_RECIPES.add(new CrusherRecipe(input, outputOne, outputTwo, outputTwoChance));
CRUSHER_RECIPES.add(new CrusherRecipe(input, outputOne, outputTwo == null ? ItemStack.EMPTY : outputTwo, outputTwoChance));
}
/**

View file

@ -0,0 +1,12 @@
package de.ellpeck.actuallyadditions.api.misc;
public interface IDisableableItem {
/**
* Represents an item that can be disabled in the configuration of the mod.
* If this returns true, assume the item is not registered with the game, but may still be instantiated.
* @return If the item has not been registered with the Forge Registry.
*/
public boolean isDisabled();
}

View file

@ -129,6 +129,8 @@ public class ActuallyAdditions{
InitBooklet.postInit();
proxy.postInit(event);
ConfigurationHandler.redefineConfigs();
ModUtil.LOGGER.info("PostInitialization Finished.");
}

View file

@ -44,7 +44,7 @@ public class EntryButton extends GuiButton{
this.mouseDragged(minecraft, mouseX, mouseY);
int textOffsetX = 0;
if(StackUtil.isValid(this.stackToRender)){
if(StackUtil.isValid(this.stackToRender == null ? ItemStack.EMPTY : this.stackToRender)){
GlStateManager.pushMatrix();
AssetUtil.renderStackToGui(this.stackToRender, this.x-4, this.y, 0.725F);
GlStateManager.popMatrix();

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.booklet.chapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.ItemStack;
@ -38,6 +39,7 @@ public class BookletChapter implements IBookletChapter{
this.identifier = identifier;
this.entry = entry;
this.displayStack = displayStack;
if(displayStack.getItem() instanceof IDisableableItem && ((IDisableableItem) displayStack.getItem()).isDisabled()) displayStack = ItemStack.EMPTY;
this.priority = priority;
this.color = TextFormatting.RESET;

View file

@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.crafting.BlankRecipe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
@ -129,7 +130,12 @@ public class PageCrafting extends BookletPage{
int width = 3;
int height = 3;
if(recipe instanceof ShapedRecipes){
if(recipe instanceof BlankRecipe){
this.recipeTypeLocKey = "tooltip."+ModUtil.MOD_ID+".disabled";
gui.addOrModifyItemRenderer(recipe.getRecipeOutput(), startX+100, startY+25, 1F, false);
return;
}
else if(recipe instanceof ShapedRecipes){
ShapedRecipes shaped = (ShapedRecipes)recipe;
width = shaped.recipeWidth;
height = shaped.recipeHeight;

View file

@ -33,7 +33,7 @@ public class ConfigurationHandler{
redefineConfigs();
}
private static void redefineConfigs(){
public static void redefineConfigs(){
ConfigValues.defineConfigValues(config);
if(config.hasChanged()){

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.creative;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
@ -349,7 +350,7 @@ public class CreativeTab extends CreativeTabs{
}
public void add(Item item){
if(item != null){
if(item != null && (!(item instanceof IDisableableItem) || (item instanceof IDisableableItem && !((IDisableableItem) item).isDisabled()))){
item.getSubItems(INSTANCE, this.list);
}
}

View file

@ -10,19 +10,23 @@
package de.ellpeck.actuallyadditions.mod.items.base;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerEnergizer;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
public class ItemArmorAA extends ItemArmor{
public class ItemArmorAA extends ItemArmor implements IDisableableItem{
private final ItemStack repairItem;
private final String name;
private final EnumRarity rarity;
private final boolean disabled;
public ItemArmorAA(String name, ArmorMaterial material, int type, ItemStack repairItem){
this(name, material, type, repairItem, EnumRarity.RARE);
@ -33,8 +37,8 @@ public class ItemArmorAA extends ItemArmor{
this.repairItem = repairItem;
this.name = name;
this.rarity = rarity;
this.register();
this.disabled = ConfigurationHandler.config.getBoolean("Disable: " + StringUtil.badTranslate(name), "Tool Control", false, "This will disable the " + StringUtil.badTranslate(name) +". It will not be registered.");
if(!disabled) this.register();
}
private void register(){
@ -64,4 +68,9 @@ public class ItemArmorAA extends ItemArmor{
public boolean getIsRepairable(ItemStack itemToRepair, ItemStack stack){
return StackUtil.isValid(this.repairItem) && ItemUtil.areItemsEqual(this.repairItem, stack, false);
}
@Override
public boolean isDisabled() {
return disabled;
}
}

View file

@ -10,18 +10,22 @@
package de.ellpeck.actuallyadditions.mod.items.base;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
public class ItemHoeAA extends ItemHoe{
public class ItemHoeAA extends ItemHoe implements IDisableableItem {
private final String name;
private final EnumRarity rarity;
private final ItemStack repairItem;
private final boolean disabled;
public ItemHoeAA(Item.ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, EnumRarity rarity){
super(toolMat);
@ -30,7 +34,8 @@ public class ItemHoeAA extends ItemHoe{
this.name = unlocalizedName;
this.rarity = rarity;
this.register();
this.disabled = ConfigurationHandler.config.getBoolean("Disable: " + StringUtil.badTranslate(name), "Tool Control", false, "This will disable the " + StringUtil.badTranslate(name) +". It will not be registered.");
if(!disabled) this.register();
}
private void register(){
@ -61,4 +66,9 @@ public class ItemHoeAA extends ItemHoe{
public boolean getIsRepairable(ItemStack itemToRepair, ItemStack stack){
return ItemUtil.areItemsEqual(this.repairItem, stack, false);
}
@Override
public boolean isDisabled() {
return disabled;
}
}

View file

@ -10,18 +10,22 @@
package de.ellpeck.actuallyadditions.mod.items.base;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
public class ItemSwordAA extends ItemSword{
public class ItemSwordAA extends ItemSword implements IDisableableItem {
private final String name;
private final EnumRarity rarity;
private final ItemStack repairItem;
private final boolean disabled;
public ItemSwordAA(ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, EnumRarity rarity){
super(toolMat);
@ -30,7 +34,8 @@ public class ItemSwordAA extends ItemSword{
this.name = unlocalizedName;
this.rarity = rarity;
this.register();
this.disabled = ConfigurationHandler.config.getBoolean("Disable: " + StringUtil.badTranslate(name), "Tool Control", false, "This will disable the " + StringUtil.badTranslate(name) +". It will not be registered.");
if(!disabled) this.register();
}
private void register(){
@ -65,4 +70,9 @@ public class ItemSwordAA extends ItemSword{
public EnumRarity getRarity(ItemStack stack){
return this.rarity;
}
@Override
public boolean isDisabled() {
return disabled;
}
}

View file

@ -10,9 +10,12 @@
package de.ellpeck.actuallyadditions.mod.items.base;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
@ -21,12 +24,13 @@ import net.minecraftforge.oredict.OreDictionary;
import java.util.Set;
public class ItemToolAA extends ItemTool{
public class ItemToolAA extends ItemTool implements IDisableableItem{
private final String name;
private final EnumRarity rarity;
private final ItemStack repairItem;
private String repairOredict;
private final boolean disabled;
public ItemToolAA(float attack, float speed, ToolMaterial toolMat, String repairItem, String unlocalizedName, EnumRarity rarity, Set<Block> effectiveStuff){
this(attack, speed, toolMat, (ItemStack)null, unlocalizedName, rarity, effectiveStuff);
@ -39,8 +43,8 @@ public class ItemToolAA extends ItemTool{
this.repairItem = repairItem;
this.name = unlocalizedName;
this.rarity = rarity;
this.register();
this.disabled = ConfigurationHandler.config.getBoolean("Disable: " + StringUtil.badTranslate(unlocalizedName), "Tool Control", false, "This will disable the " + StringUtil.badTranslate(unlocalizedName) +". It will not be registered.");
if(!disabled) this.register();
}
private void register(){
@ -82,4 +86,9 @@ public class ItemToolAA extends ItemTool{
}
return false;
}
@Override
public boolean isDisabled() {
return disabled;
}
}

View file

@ -10,6 +10,8 @@
package de.ellpeck.actuallyadditions.mod.util;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
@ -33,8 +35,10 @@ public final class StackUtil{
}
}
public static boolean isValid(ItemStack stack){
return stack != null && !stack.isEmpty();
public static boolean isValid(ItemStack stack){//Stacks are nonnull. If we are making null stacks we're stupid anyway.
Item i = stack.getItem();
if(i instanceof IDisableableItem) return !((IDisableableItem) i).isDisabled();
return !stack.isEmpty();
}
public static ItemStack getNull(){

View file

@ -46,6 +46,11 @@ public final class StringUtil{
return net.minecraft.util.text.translation.I18n.translateToLocal(langKey);
}
@SuppressWarnings("deprecation")//Configs why must you need to be translated.
public static String badTranslate(String someUnlocAAItemName) {
return net.minecraft.util.text.translation.I18n.translateToLocal("item.actuallyadditions."+someUnlocAAItemName+".name");
}
@SideOnly(Side.CLIENT)
public static void drawSplitString(FontRenderer renderer, String strg, int x, int y, int width, int color, boolean shadow){
List<String> list = renderer.listFormattedStringToWidth(strg, width);

View file

@ -0,0 +1,32 @@
package de.ellpeck.actuallyadditions.mod.util.crafting;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.minecraftforge.registries.IForgeRegistryEntry;
public class BlankRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe{
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
return false;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
return ItemStack.EMPTY;
}
@Override
public boolean canFit(int width, int height) {
return false;
}
@Override
public ItemStack getRecipeOutput() {
return ItemStack.EMPTY;
}
}

View file

@ -1,5 +1,6 @@
package de.ellpeck.actuallyadditions.mod.util.crafting;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.mod.RegistryHandler;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.block.Block;
@ -37,6 +38,8 @@ public final class RecipeHelper{
* This adds the recipe to the list of crafting recipes. Cares about names.
*/
public static void addRecipe(String name, IRecipe rec){
Item i = rec.getRecipeOutput().getItem();
if(i instanceof IDisableableItem && ((IDisableableItem) i).isDisabled()) rec = new BlankRecipe();
if(rec.getRegistryName() == null){
RECIPE_LIST.add(rec.setRegistryName(new ResourceLocation(MODID, name)));
}

View file

@ -2,6 +2,7 @@
itemGroup.actuallyadditions=Actually Additions
achievement.page.actuallyadditions=Actually Additions
actuallyadditions.lolWutHowUDoDis.name=This is bugged. Throw it away. Please.
tooltip.actuallyadditions.disabled=Disabled Object
#Fluids
fluid.actuallyadditions.refinedcanolaoil=Refined Canola Oil