Skip to content
Permalink
Browse files

Random cleanup and util tweaks. Added more anvil / welding recipes fo…

…r steel processing
  • Loading branch information...
alcatrazEscapee committed Feb 18, 2019
1 parent a556d10 commit e0bc4b572b5cb44f94f54f189e344648a33a9f8b
@@ -56,6 +56,7 @@ public RockCategory getRockCategory()
return rockCategory;
}

@SuppressWarnings("ConstantConditions")
@Override
public String toString()
{
@@ -148,7 +148,7 @@ public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Bloc
@Override
public boolean canPlaceBlockAt(World worldIn, @Nonnull BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) && Helpers.getASolidFacing(worldIn, pos, EnumFacing.HORIZONTALS, null) != null;
return super.canPlaceBlockAt(worldIn, pos) && Helpers.getASolidFacing(worldIn, pos, null, EnumFacing.HORIZONTALS) != null;
}

public int getSlotFromPos(IBlockState state, float x, float y, float z)
@@ -185,7 +185,7 @@ public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing
{
if (facing.getAxis() == EnumFacing.Axis.Y)
facing = placer.getHorizontalFacing().getOpposite();
return this.getDefaultState().withProperty(FACING, Helpers.getASolidFacing(worldIn, pos, EnumFacing.HORIZONTALS, facing));
return this.getDefaultState().withProperty(FACING, Helpers.getASolidFacing(worldIn, pos, facing, EnumFacing.HORIZONTALS));
}

@Override
@@ -26,7 +26,6 @@
/*
* Metals
*/
// Tier I
public static final ResourceLocation BISMUTH = new ResourceLocation(MOD_ID, "bismuth");
public static final ResourceLocation BISMUTH_BRONZE = new ResourceLocation(MOD_ID, "bismuth_bronze");
public static final ResourceLocation BLACK_BRONZE = new ResourceLocation(MOD_ID, "black_bronze");
@@ -41,12 +40,9 @@
public static final ResourceLocation TIN = new ResourceLocation(MOD_ID, "tin");
public static final ResourceLocation ZINC = new ResourceLocation(MOD_ID, "zinc");
public static final ResourceLocation STERLING_SILVER = new ResourceLocation(MOD_ID, "sterling_silver");
// Tier III
public static final ResourceLocation WROUGHT_IRON = new ResourceLocation(MOD_ID, "wrought_iron");
public static final ResourceLocation PIG_IRON = new ResourceLocation(MOD_ID, "pig_iron");
// Tier IV
public static final ResourceLocation STEEL = new ResourceLocation(MOD_ID, "steel");
// Tier V
public static final ResourceLocation PLATINUM = new ResourceLocation(MOD_ID, "platinum");
public static final ResourceLocation BLACK_STEEL = new ResourceLocation(MOD_ID, "black_steel");
public static final ResourceLocation BLUE_STEEL = new ResourceLocation(MOD_ID, "blue_steel");
@@ -58,7 +54,6 @@
public static final ResourceLocation HIGH_CARBON_BLUE_STEEL = new ResourceLocation(MOD_ID, "high_carbon_blue_steel");
public static final ResourceLocation HIGH_CARBON_RED_STEEL = new ResourceLocation(MOD_ID, "high_carbon_red_steel");
public static final ResourceLocation HIGH_CARBON_BLACK_STEEL = new ResourceLocation(MOD_ID, "high_carbon_black_steel");
// Tier I, Special
public static final ResourceLocation UNKNOWN = new ResourceLocation(MOD_ID, "unknown");

/*
@@ -161,18 +156,18 @@ public static void onPreRegisterMetal(TFCRegistryEvent.RegisterPreBlock<Metal> e
new Metal(ZINC, TIER_I, true, 0.21f, 420, 0xFFBBB9C4, null),
new Metal(STERLING_SILVER, TIER_I, true, 0.35f, 900, 0xFFAC927B, null),
new Metal(WROUGHT_IRON, TIER_III, true, 0.35f, 1535, 0xFF989897, ToolMaterialsTFC.IRON),
new Metal(PIG_IRON, TIER_IV, true, 0.35f, 1535, 0xFF6A595C, null),
new Metal(PIG_IRON, TIER_III, true, 0.35f, 1535, 0xFF6A595C, null),
new Metal(STEEL, TIER_IV, true, 0.35f, 1540, 0xFF5F5F5F, ToolMaterialsTFC.STEEL),
new Metal(PLATINUM, TIER_V, true, 0.35f, 1730, 0xFF9DADC0, null),
new Metal(BLACK_STEEL, TIER_V, true, 0.35f, 1485, 0xFF111111, ToolMaterialsTFC.BLACK_STEEL),
new Metal(BLUE_STEEL, TIER_VI, true, 0.35f, 1540, 0xFF2D5596, ToolMaterialsTFC.BLUE_STEEL),
new Metal(RED_STEEL, TIER_VI, true, 0.35f, 1540, 0xFF700503, ToolMaterialsTFC.RED_STEEL),
new Metal(WEAK_STEEL, TIER_V, false, 0.35f, 1540, 0xFF111111, null),
new Metal(WEAK_BLUE_STEEL, TIER_VI, false, 0.35f, 1540, 0xFF2D5596, null),
new Metal(WEAK_RED_STEEL, TIER_VI, false, 0.35f, 1540, 0xFF700503, null),
new Metal(HIGH_CARBON_STEEL, TIER_V, false, 0.35f, 1540, 0xFF5F5F5F, null),
new Metal(HIGH_CARBON_BLUE_STEEL, TIER_VI, false, 0.35f, 1540, 0xFF2D5596, null),
new Metal(HIGH_CARBON_RED_STEEL, TIER_VI, false, 0.35f, 1540, 0xFF700503, null),
new Metal(WEAK_BLUE_STEEL, TIER_V, false, 0.35f, 1540, 0xFF2D5596, null),
new Metal(WEAK_RED_STEEL, TIER_V, false, 0.35f, 1540, 0xFF700503, null),
new Metal(HIGH_CARBON_STEEL, TIER_IV, false, 0.35f, 1540, 0xFF5F5F5F, null),
new Metal(HIGH_CARBON_BLUE_STEEL, TIER_V, false, 0.35f, 1540, 0xFF2D5596, null),
new Metal(HIGH_CARBON_RED_STEEL, TIER_V, false, 0.35f, 1540, 0xFF700503, null),
new Metal(HIGH_CARBON_BLACK_STEEL, TIER_V, false, 0.35f, 1540, 0xFF111111, null),
new Metal(UNKNOWN, TIER_I, false, 0.5f, 1250, 0xFF2F2B27, null)
);
@@ -26,6 +26,7 @@

import static net.dries007.tfc.api.types.Metal.ItemType.*;
import static net.dries007.tfc.api.util.TFCConstants.MOD_ID;
import static net.dries007.tfc.types.DefaultMetals.*;
import static net.dries007.tfc.util.forge.ForgeRule.*;

@Mod.EventBusSubscriber(modid = MOD_ID)
@@ -38,6 +39,7 @@ public static void onRegisterKnappingRecipeEvent(RegistryEvent.Register<Knapping

for (Rock.ToolType type : Rock.ToolType.values())
{
// This covers all stone -> single tool head recipes
KnappingRecipe r = new KnappingRecipe.Stone(KnappingRecipe.Type.STONE, c -> new ItemStack(ItemRockToolHead.get(c, type)), type.getPattern());
event.getRegistry().register(r.setRegistryName(MOD_ID, type.name().toLowerCase() + "_head"));
}
@@ -107,29 +109,41 @@ public static void onRegisterAnvilRecipeEvent(RegistryEvent.Register<AnvilRecipe
addAnvil(r, DOUBLE_SHEET, UNFINISHED_GREAVES, true, BEND_ANY, DRAW_ANY, HIT_ANY);
addAnvil(r, DOUBLE_SHEET, UNFINISHED_BOOTS, true, BEND_LAST, BEND_SECOND_LAST, SHRINK_THIRD_LAST);

// todo: more anvil recipes
// todo: bloom -> iron ingot

// Steel Working
addAnvil(r, PIG_IRON, HIGH_CARBON_STEEL);
addAnvil(r, HIGH_CARBON_STEEL, STEEL);
addAnvil(r, HIGH_CARBON_BLACK_STEEL, BLACK_STEEL);
addAnvil(r, HIGH_CARBON_BLUE_STEEL, BLUE_STEEL);
addAnvil(r, HIGH_CARBON_RED_STEEL, RED_STEEL);
}

@SubscribeEvent
public static void onRegisterWeldingRecipeEvent(RegistryEvent.Register<WeldingRecipe> event)
{
IForgeRegistry<WeldingRecipe> r = event.getRegistry();

// Welding Recipes
// Basic Parts
addWelding(r, INGOT, DOUBLE_INGOT);
addWelding(r, SHEET, DOUBLE_SHEET);

// Armor
addWelding(r, UNFINISHED_HELMET, SHEET, HELMET, true);
addWelding(r, UNFINISHED_CHESTPLATE, DOUBLE_SHEET, CHESTPLATE, true);
addWelding(r, UNFINISHED_GREAVES, DOUBLE_SHEET, GREAVES, true);
addWelding(r, UNFINISHED_BOOTS, SHEET, BOOTS, true);

// Steel Welding
addWelding(r, WEAK_STEEL, PIG_IRON, HIGH_CARBON_BLACK_STEEL);
addWelding(r, WEAK_BLUE_STEEL, BLACK_STEEL, HIGH_CARBON_BLUE_STEEL);
addWelding(r, WEAK_RED_STEEL, BLACK_STEEL, HIGH_CARBON_RED_STEEL);

// Special Recipes

// todo: shears
}

@SuppressWarnings("ConstantConditions")
private static void addAnvil(IForgeRegistry<AnvilRecipe> registry, Metal.ItemType inputType, Metal.ItemType outputType, boolean onlyToolMetals, ForgeRule... rules)
{
// Helper method for adding all recipes that take ItemType -> ItemType
@@ -143,17 +157,34 @@ private static void addAnvil(IForgeRegistry<AnvilRecipe> registry, Metal.ItemTyp
ItemStack output = new ItemStack(ItemMetal.get(metal, outputType));
if (!input.isEmpty() && !output.isEmpty())
{
//noinspection ConstantConditions
registry.register(new AnvilRecipe(new ResourceLocation(MOD_ID, (outputType.name() + "_" + metal.getRegistryName().getPath()).toLowerCase()), input, output, metal.getTier(), rules));
}
}
}

private static void addAnvil(IForgeRegistry<AnvilRecipe> registry, ResourceLocation inputMetalLoc, ResourceLocation outputMetalLoc)
{
// Helper method for adding INGOT -> INGOT with different metal working
Metal inputMetal = TFCRegistries.METALS.getValue(inputMetalLoc);
Metal outputMetal = TFCRegistries.METALS.getValue(outputMetalLoc);
if (inputMetal != null && outputMetal != null)
{
ItemStack input = new ItemStack(ItemMetal.get(inputMetal, INGOT));
ItemStack output = new ItemStack(ItemMetal.get(outputMetal, INGOT));
if (!input.isEmpty() && !output.isEmpty())
{
//noinspection ConstantConditions
registry.register(new AnvilRecipe(new ResourceLocation(MOD_ID, ("ingot_" + outputMetal.getRegistryName().getPath()).toLowerCase()), input, output, outputMetal.getTier(), HIT_LAST, HIT_SECOND_LAST, HIT_THIRD_LAST));
}
}
}

private static void addWelding(IForgeRegistry<WeldingRecipe> registry, Metal.ItemType inputType, Metal.ItemType outputType)
{
addWelding(registry, inputType, inputType, outputType, false);
}

@SuppressWarnings("ConstantConditions")
private static void addWelding(IForgeRegistry<WeldingRecipe> registry, Metal.ItemType inputType1, Metal.ItemType inputType2, Metal.ItemType outputType, boolean onlyToolMetals)
{
// Helper method for adding all recipes that take ItemType -> ItemType
@@ -169,8 +200,29 @@ private static void addWelding(IForgeRegistry<WeldingRecipe> registry, Metal.Ite
if (!input1.isEmpty() && !input2.isEmpty() && !output.isEmpty())
{
// Note: Welding recipes require one less than the tier of the metal
//noinspection ConstantConditions
registry.register(new WeldingRecipe(new ResourceLocation(MOD_ID, (outputType.name() + "_" + metal.getRegistryName().getPath()).toLowerCase()), input1, input2, output, metal.getTier().previous()));
}
}
}

private static void addWelding(IForgeRegistry<WeldingRecipe> registry, ResourceLocation input1Loc, ResourceLocation input2Loc, ResourceLocation outputLoc)
{
Metal inputMetal1 = TFCRegistries.METALS.getValue(input1Loc);
Metal inputMetal2 = TFCRegistries.METALS.getValue(input2Loc);
Metal outputMetal = TFCRegistries.METALS.getValue(outputLoc);
if (inputMetal1 != null && inputMetal2 != null && outputMetal != null)
{
// Create a recipe for each metal / item type combination
ItemStack input1 = new ItemStack(ItemMetal.get(inputMetal1, INGOT));
ItemStack input2 = new ItemStack(ItemMetal.get(inputMetal2, INGOT));
ItemStack output = new ItemStack(ItemMetal.get(outputMetal, INGOT));
if (!input1.isEmpty() && !input2.isEmpty() && !output.isEmpty())
{
// Note: Welding recipes require one less than the tier of the metal
//noinspection ConstantConditions
registry.register(new WeldingRecipe(new ResourceLocation(MOD_ID, ("ingot_" + outputMetal.getRegistryName().getPath()).toLowerCase()), input1, input2, output, outputMetal.getTier().previous()));
}
}
}
}
@@ -12,6 +12,8 @@

import com.google.common.collect.Sets;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.items.IItemHandler;

import net.dries007.tfc.api.recipes.AlloyRecipe;
@@ -24,10 +26,10 @@
*
* @author AlcatrazEscapee
*/
public class Alloy
public class Alloy implements INBTSerializable<NBTTagCompound>
{

private final Map<Metal, Integer> MAP;
private final Map<Metal, Integer> metalMap;
private int totalAmount;
private boolean isValid;

@@ -36,7 +38,7 @@
*/
public Alloy()
{
MAP = new HashMap<>();
metalMap = new HashMap<>();
totalAmount = 0;
isValid = true;
}
@@ -85,7 +87,7 @@ public Alloy add(@Nonnull ItemStack stack)
*/
public Alloy add(@Nonnull Alloy other)
{
for (Map.Entry<Metal, Integer> entry : other.MAP.entrySet())
for (Map.Entry<Metal, Integer> entry : other.metalMap.entrySet())
add(entry.getKey(), entry.getValue());
return this;
}
@@ -101,7 +103,7 @@ public Alloy add(@Nullable Metal metal, int amount)
{
if (metal != null)
{
MAP.merge(metal, amount, (x, y) -> x + y);
metalMap.merge(metal, amount, (x, y) -> x + y);
totalAmount += amount;
}
else
@@ -118,8 +120,8 @@ public Alloy add(@Nullable Metal metal, int amount)
@Nonnull
public Metal getResult()
{
if (MAP.size() == 1)
return MAP.keySet().iterator().next(); // Easy way to get the only metal in the alloy
if (metalMap.size() == 1)
return metalMap.keySet().iterator().next(); // Easy way to get the only metal in the alloy
for (AlloyRecipe r : TFCRegistries.ALLOYS.getValuesCollection())
if (matchesRecipe(r))
return r.getResult();
@@ -145,12 +147,47 @@ public boolean isValid()
return isValid;
}

@Override
public NBTTagCompound serializeNBT()
{
NBTTagCompound nbt = new NBTTagCompound();
nbt.setBoolean("isValid", isValid);
for (Map.Entry<Metal, Integer> entry : this.metalMap.entrySet())
{
//noinspection ConstantConditions
nbt.setInteger(entry.getKey().getRegistryName().toString(), entry.getValue());
}
return nbt;
}

@Override
public void deserializeNBT(@Nullable NBTTagCompound nbt)
{
if (nbt != null)
{
this.totalAmount = 0;
this.isValid = nbt.getBoolean("isValid");
this.metalMap.clear();
for (Metal metal : TFCRegistries.METALS.getValuesCollection())
{
//noinspection ConstantConditions
String key = metal.getRegistryName().toString();
if (nbt.hasKey(key))
{
int amount = nbt.getInteger(key);
this.metalMap.put(metal, amount);
this.totalAmount += amount;
}
}
}
}

private boolean matchesRecipe(AlloyRecipe recipe)
{
if (this.MAP.containsKey(recipe.getResult()))
if (this.metalMap.containsKey(recipe.getResult()))
{
Alloy other = new Alloy().add(this);
int resultAmount = other.MAP.remove(recipe.getResult());
int resultAmount = other.metalMap.remove(recipe.getResult());
other.totalAmount -= resultAmount;
return other.matchesRecipeExact(recipe);
}
@@ -161,11 +198,11 @@ private boolean matchesRecipeExact(AlloyRecipe recipe)
{
// for each metal in the alloy, it needs to satisfy an ingredient
// for each metal in the recipe, it needs to match with an alloy
for (Metal metal : Sets.union(recipe.MAP.keySet(), MAP.keySet()))
for (Metal metal : Sets.union(recipe.MAP.keySet(), metalMap.keySet()))
{
if (!MAP.containsKey(metal) ||
if (!metalMap.containsKey(metal) ||
!recipe.MAP.containsKey(metal) ||
!recipe.MAP.get(metal).test(MAP.get(metal).floatValue() / totalAmount))
!recipe.MAP.get(metal).test(metalMap.get(metal).floatValue() / totalAmount))
return false;
}
return true;
@@ -7,7 +7,7 @@

import net.minecraft.item.ItemStack;

public final class Fuel
public class Fuel
{
private final ItemStack stack;
private final int amount;
@@ -18,7 +18,7 @@
import net.dries007.tfc.objects.items.metal.ItemOreTFC;
import net.dries007.tfc.types.DefaultMetals;

public class FuelManager
public final class FuelManager
{
private static final List<Fuel> fuels = new ArrayList<>();
private static final Fuel EMPTY = new Fuel(ItemStack.EMPTY, 0, 0);

0 comments on commit e0bc4b5

Please sign in to comment.
You can’t perform that action at this time.