Skip to content

Commit

Permalink
Fix Chemical Reactor NPE and other recipe bugs, version number issues (
Browse files Browse the repository at this point in the history
…#2316)

* Remove MC version from mod version

* Fix Chemical Reactor NPE and other recipe bugs

* Bump mod patch version

* Apply changes suggested in code review

Moving special recipe processing to LV was the only change I didn't apply, but I now have the Chemical Reactor reloading just the special armor recipes, to prevent problems with CraftTweaker and XML recipes.

* Only regenerate Chemical Reactor recipes that haven't been removed

* Improve command output text
  • Loading branch information
Brycey92 authored Aug 15, 2023
1 parent 8b2c9f1 commit c5cd5af
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 62 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ fun getDate(): String {
return format.format(Date())
}

version = "$mcVersion-$modVersion-$buildNumber"
version = "$modVersion-$buildNumber"

println("$archiveBase v$version")
println("$archiveBase v$mcVersion-$version")

java {
toolchain {
Expand Down Expand Up @@ -203,7 +203,7 @@ val gitHash: String by lazy {

// Name pattern: [archiveBaseName]-[archiveAppendix]-[archiveVersion]-[archiveClassifier].[archiveExtension]
tasks.withType(Jar::class) {
//archiveAppendix.set(mcVersion)
archiveAppendix.set(mcVersion)
manifest {
attributes(
"Built-By" to System.getProperty("user.name"),
Expand All @@ -228,7 +228,7 @@ tasks.build {

val makeChangelog by tasks.creating(GitChangelogTask::class.java) {
file = file("changelog.html")
untaggedName = "Current release ${project.version}"
untaggedName = "Current release ${mcVersion}-${project.version}"

//Get the last commit from the cache or config if no cache exists
val lastHashFile = file("lasthash.txt")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.daemon=false
# Project
mcVersion=1.12.2
forgeVersion=14.23.5.2860
modVersion=2.0.0
modVersion=2.0.1
archiveBase=AdvancedRocketry
startGitRev=8e676bd

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,9 @@ public void serverStarted(FMLServerStartedEvent event) {
public void serverStarting(FMLServerStartingEvent event) {
event.registerServerCommand(new WorldCommand());

//Regenerate Chemical Reactor armor recipes
TileChemicalReactor.reloadRecipesSpecial();


//Open ore files

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,22 +275,22 @@ private void commandReloadRecipes(ICommandSender sender, String[] cmdstring)
AdvancedRocketry.machineRecipes.createAutoGennedRecipes(AdvancedRocketry.modProducts);
AdvancedRocketry.machineRecipes.registerXMLRecipes();

sender.sendMessage(new TextComponentString("Recipes Reloaded"));
sender.sendMessage(new TextComponentString("Recipes reloaded"));

CompatibilityMgr.reloadRecipes();
} catch (Exception e) {
sender.sendMessage(new TextComponentString("Serious error has occured! Possible recipe corruption"));
e.printStackTrace();
sender.sendMessage(new TextComponentString("Serious error has occurred! Possible recipe corruption"));
sender.sendMessage(new TextComponentString("Please check logs!"));
sender.sendMessage(new TextComponentString("You may be able to recify this error by repairing the XML and/or"));
sender.sendMessage(new TextComponentString("restarting the game"));
sender.sendMessage(new TextComponentString("You may be able to rectify this error by repairing the XML and/or restarting the game"));
}
}

private void commandSetGravity(ICommandSender sender, String[] cmdstring)
{
if(cmdstring.length >= 2) {
if( cmdstring[1].equalsIgnoreCase("help")) {
sender.sendMessage(new TextComponentString(cmdstring[0] + " <amount> - sets your gravity to amount where 1 is earthlike"));
sender.sendMessage(new TextComponentString(cmdstring[0] + " <amount> - sets your gravity to amount where 1 is Earth-like"));
return;
}
if(sender instanceof Entity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package zmaster587.advancedRocketry.tile.multiblock.machine;

import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
Expand Down Expand Up @@ -35,64 +35,46 @@
import java.util.List;

public class TileChemicalReactor extends TileMultiblockMachine {
public static final Object[][][] structure = {
public static final Object[][][] structure = {
{{null, 'c',null},
{'L', 'I','L'}},

{{'P', LibVulpesBlocks.motors, 'P'},
{{'P', LibVulpesBlocks.motors, 'P'},
{'l', 'O', 'l'}},

};

private static List<IRecipe> recipesSpecial = new LinkedList<>();

@Override
public boolean shouldHideBlock(World world, BlockPos pos, IBlockState tile) { return true; }

//Called by inventory blocks that are part of the structure
//This includes recipe management etc
@Override
public void onInventoryUpdated() {
//If we are already processing something don't bother
IRecipe recipe;
boolean flag = false;
if(getOutputs() == null && (recipe = getRecipe(getMachineRecipeList())) != null && canProcessRecipe(recipe))
{
if(!recipe.getOutput().isEmpty()) {
NBTTagList list = recipe.getOutput().get(0).getEnchantmentTagList();

/*
for( int i = 0 ; i < list.tagCount(); i++ ) {
NBTTagCompound tag = (NBTTagCompound)list.get(i);
if(tag.getInteger("id") == Enchantment.getEnchantmentID(AdvancedRocketryAPI.enchantmentSpaceProtection) ) {
flag = true;
break;
}
}
*/
flag = true;

//If we are already processing something don't bother
//If airbreathing enchantment
if(getOutputs() == null && (recipe = getRecipe(getMachineRecipeList())) != null && canProcessRecipe(recipe) && !recipe.getOutput().isEmpty()
&& EnchantmentHelper.getEnchantmentLevel(AdvancedRocketryAPI.enchantmentSpaceProtection, recipe.getOutput().get(0)) == 1) {
if(!enabled) {
setMachineRunning(false);
return;
}
}

//If airbreathing enchantment
if(flag && getOutputs() == null) {
if(enabled && (recipe = getRecipe(getMachineRecipeList())) != null && canProcessRecipe(recipe)) {
consumeItemsSpecial(recipe);
setOutputFluids(new LinkedList<>());
powerPerTick = (int)Math.ceil((getPowerMultiplierForRecipe(recipe)*recipe.getPower()));
completionTime = Math.max((int)(getTimeMultiplierForRecipe(recipe)*recipe.getTime()), 1);
consumeItemsSpecial(recipe);
setOutputFluids(new LinkedList<>());
powerPerTick = (int)Math.ceil((getPowerMultiplierForRecipe(recipe)*recipe.getPower()));
completionTime = Math.max((int)(getTimeMultiplierForRecipe(recipe)*recipe.getTime()), 1);



markDirty();
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);

setMachineRunning(true); //turn on machine
markDirty();
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);

}
else {
setMachineRunning(false);
}
setMachineRunning(true); //turn on machine
}
else {
super.onInventoryUpdated();
Expand All @@ -109,12 +91,15 @@ public void consumeItemsSpecial(IRecipe recipe) {
for (IInventory hatch : itemInPorts) {
for (int i = 0; i < hatch.getSizeInventory(); i++) {
ItemStack stackInSlot = hatch.getStackInSlot(i);
for (ItemStack stack : ingredient) {
if (!stackInSlot.isEmpty() && stackInSlot.getCount() >= stack.getCount() && (stackInSlot.getItem() == stack.getItem() && (stackInSlot.getItemDamage() == stack.getItemDamage() || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE))) {
for(ItemStack stack : ingredient) {
if(!stackInSlot.isEmpty() && stackInSlot.getCount() >= stack.getCount() && (stackInSlot.getItem() == stack.getItem() && (stackInSlot.getItemDamage() == stack.getItemDamage() || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE))) {
ItemStack stack2 = hatch.decrStackSize(i, stack.getCount());

if (stack2.getItem() instanceof ItemArmor) {
stack2.addEnchantment(AdvancedRocketryAPI.enchantmentSpaceProtection, 1);
if(stack2.getItem() instanceof ItemArmor) {
if(EnchantmentHelper.getEnchantmentLevel(AdvancedRocketryAPI.enchantmentSpaceProtection, stack2) == 0) {
stack2.addEnchantment(AdvancedRocketryAPI.enchantmentSpaceProtection, 1);
}

List<ItemStack> list = new LinkedList<>();
list.add(stack2);
setOutputs(list);
Expand All @@ -129,28 +114,95 @@ public void consumeItemsSpecial(IRecipe recipe) {
}
}
}

@Override
public void registerRecipes() {
//Chemical Reactor
if(ARConfiguration.getCurrentConfig().enableOxygen) {
RecipesMachine recipesMachine = RecipesMachine.getInstance();
List<IRecipe> recipes = recipesMachine.getRecipes(TileChemicalReactor.class);
List<IRecipe> originalRecipes = new LinkedList<>(recipes);

for(ResourceLocation key : Item.REGISTRY.getKeys()) {
Item item = Item.REGISTRY.getObject(key);

if(item instanceof ItemArmor && !(item instanceof ItemSpaceArmor)) {
ItemStack enchanted = new ItemStack(item);
enchanted.addEnchantment(AdvancedRocketryAPI.enchantmentSpaceProtection, 1);

if(((ItemArmor)item).armorType == EntityEquipmentSlot.CHEST)
RecipesMachine.getInstance().addRecipe(TileChemicalReactor.class, enchanted, 100, 10, new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(AdvancedRocketryBlocks.blockPipeSealer, 1), new NumberedOreDictStack("sheetTitaniumAluminide", 4), new ItemStack(AdvancedRocketryItems.itemPressureTank, 1, 3));
else
RecipesMachine.getInstance().addRecipe(TileChemicalReactor.class, enchanted, 100, 10, new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(AdvancedRocketryBlocks.blockPipeSealer, 1), new NumberedOreDictStack("sheetTitaniumAluminide", 4));

registerRecipe(recipesMachine, item);
}

//Create the internal special recipes list based on what recipes were added by the above generation
for(IRecipe recipe : recipes) {
if(!originalRecipes.contains(recipe)) {
recipesSpecial.add(recipe);
}
}
}
}

public static void reloadRecipesSpecial() {
//Chemical Reactor
if(ARConfiguration.getCurrentConfig().enableOxygen) {
RecipesMachine recipesMachine = RecipesMachine.getInstance();
List<IRecipe> recipes = recipesMachine.getRecipes(TileChemicalReactor.class);

//Forget any special recipes removed by another mod since generation
recipesSpecial.retainAll(recipes);

//Clear special recipes from the registry
recipes.removeAll(recipesSpecial);

List<IRecipe> originalRecipes = new LinkedList<>(recipes);

//Regenerate special recipes, but only those that weren't removed by another mod since first generation
for(IRecipe recipe : recipesSpecial) {
Item item = recipe.getOutput().get(0).getItem();
registerRecipe(recipesMachine, item);
}

//Recreate the internal special recipes list based on what recipes were added by the above generation
recipesSpecial.clear();
for(IRecipe recipe : recipes) {
if(!originalRecipes.contains(recipe)) {
recipesSpecial.add(recipe);
}
}
}
}

public static void registerRecipe(RecipesMachine recipesMachine, Item item) {
if(item instanceof ItemArmor && !(item instanceof ItemSpaceArmor)) {
ItemStack enchanted = new ItemStack(item);
enchanted.addEnchantment(AdvancedRocketryAPI.enchantmentSpaceProtection, 1);

//TODO: fix lore not appearing
/*NBTTagCompound tag = enchanted.getTagCompound();
if(tag == null) {
enchanted.setTagCompound(tag = new NBTTagCompound());
}
if(!tag.hasKey("display")) {
tag.setTag("display", new NBTTagCompound());
}
if(tag.getTagId("display") == 10) {
NBTTagCompound displayTag = tag.getCompoundTag("display");
if(!displayTag.hasKey("Lore")) {
displayTag.setTag("Lore", new NBTTagList());
}
if (displayTag.getTagId("Lore") == 9) {
NBTTagList loreTag = displayTag.getTagList("Lore", 8);
loreTag.appendTag(new NBTTagString("§eThis recipe adds the Airtight Seal enchantment"));
}
}*/

if(((ItemArmor)item).armorType == EntityEquipmentSlot.CHEST)
recipesMachine.addRecipe(TileChemicalReactor.class, enchanted, 100, 10, new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(AdvancedRocketryBlocks.blockPipeSealer, 1), new NumberedOreDictStack("sheetTitaniumAluminide", 4), new ItemStack(AdvancedRocketryItems.itemPressureTank, 1, 3));
else
recipesMachine.addRecipe(TileChemicalReactor.class, enchanted, 100, 10, new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(AdvancedRocketryBlocks.blockPipeSealer, 1), new NumberedOreDictStack("sheetTitaniumAluminide", 4));
}
}

@Override
public Object[][][] getStructure() {
return structure;
Expand Down

0 comments on commit c5cd5af

Please sign in to comment.