Skip to content

Commit

Permalink
Spartan Weaponry Integration! #222
Browse files Browse the repository at this point in the history
  • Loading branch information
Davoleo committed Mar 9, 2024
1 parent 9dabd36 commit 0683b69
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 31 deletions.
12 changes: 7 additions & 5 deletions misc/shell_rename_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ do

echo $file

OLD="\"_block"
NEW="\"_bricks"
OLD="_adamantine"
NEW="_wood"
# Modifica delle string all'interno del file
# sed "s/old_string/new_string/g" $file
# remove -i to preview changes
sed -i "s/$OLD/$NEW/g" $file

wordToRemove="block - Copy.json"
wordToAdd="bricks.json"
wordToRemove="_custom.json"
wordToAdd="_adamantine.json"

# file = test_chest.json -> test_
new=${file//$wordToRemove/}

# file = test_ -> test_chestplate.json
# $nomevariabile1$nomevariabile2 = string contatenation
# mv "vecchia string" "nuova string" -> file rename
mv "$file" "$new$wordToAdd"
if [ $file != $new ]; then
mv "$file" "$new$wordToAdd"
fi

echo LASAGNE!

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/it/hurts/metallurgy_reforged/Metallurgy.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class Metallurgy {

public static final String MODID = "metallurgy";
public static final String NAME = "Metallurgy 4: Reforged";
public static final String VERSION = "1.3.9";
public static final String VERSION = "1.4.0";

public static Logger logger;

Expand Down Expand Up @@ -116,19 +116,19 @@ public void preInit(FMLPreInitializationEvent event)
logger.info("Metallurgy Advancement Criteria Registered!");

//checks if tinker is installed
if (ModChecker.isTConLoaded && !GeneralConfig.tinkerIntegration)
if (ModChecker.isTConLoaded && GeneralConfig.tiCIntegration)
{
IntegrationTIC.preInit();
logger.info("Tinkers' Construct Compatibility module has been pre-initialized");

if (ModChecker.isConarmLoaded && !GeneralConfig.armoryIntegration)
if (ModChecker.isConarmLoaded && GeneralConfig.conarmIntegration)
{
IntegrationCArmory.preInit();
logger.info("Construct's Armory Compatibility module has been pre-initialized");
}
}

if (ModChecker.isIFLoaded && !GeneralConfig.inForegoingIntegration)
if (ModChecker.isIFLoaded && GeneralConfig.inForegoingIntegration)
{
IntegrationIF.preInit();
logger.info("Industrial Foregoing Compatibility module has been pre-initialized");
Expand All @@ -140,7 +140,7 @@ public void preInit(FMLPreInitializationEvent event)
logger.info("CraftTweaker Compatibility module has been pre-initialized");
}

if (ModChecker.isSilentGemsLoaded)
if (ModChecker.isSilentGemsLoaded && GeneralConfig.silentGemsIntegration)
{
IntegrationSilentGems.init();
logger.info("CraftTweaker Compatibility module has been initialized");
Expand All @@ -167,12 +167,12 @@ public void init(FMLInitializationEvent event)
ModRecipes.initFurnaceRecipes();
logger.info("Furnace Recipes loaded!");

if (ModChecker.isTConLoaded && !GeneralConfig.tinkerIntegration)
if (ModChecker.isTConLoaded && GeneralConfig.tiCIntegration)
{
IntegrationTIC.init();
logger.info("Tinkers' Construct Compatibility module has been initialized");

if (ModChecker.isConarmLoaded && !GeneralConfig.armoryIntegration)
if (ModChecker.isConarmLoaded && GeneralConfig.conarmIntegration)
{
IntegrationCArmory.init();
logger.info("Construct's Armory Compatibility module has been initialized");
Expand Down Expand Up @@ -216,7 +216,7 @@ public void postInit(FMLPostInitializationEvent event)
PacketManager.init();
logger.info(NAME + "'s Network System Loaded");

if (ModChecker.isTConLoaded && !GeneralConfig.tinkerIntegration)
if (ModChecker.isTConLoaded && GeneralConfig.tiCIntegration)
IntegrationTIC.postInit();
logger.info("Tinker's alloy recipes loaded");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ public class GeneralConfig {
@Config.RangeDouble(min = 1)
public static double roadSpeed = 1.50D;

@Config.Name("Disable tinker integration")
@Config.Comment("Set to true to disable Tinkers' Construct Integration")
public static boolean tinkerIntegration = false;
@Config.Name("Tinkers' Construct integration")
@Config.Comment("Set to false to disable Tinkers' Construct Integration")
public static boolean tiCIntegration = true;

@Config.Name("Tinker Materials Blacklist")
@Config.Name("Tinkers' Materials Blacklist")
@Config.Comment("Add a material in this array to blacklist it during game boot - material name format is \"snake_case\" (e.g. 'osmium' or 'damascus_steel')")
@Config.RequiresMcRestart
public static String[] tinkerMaterialsBlacklist = new String[]{ };

@Config.Name("Disable ConArm Integration")
@Config.Comment("Set to true to disable Construct's Armory Integration")
public static boolean armoryIntegration = false;
@Config.Name("Disable Construct's Armory integration")
@Config.Comment("Set to false to disable Construct's Armory Integration")
public static boolean conarmIntegration = true;

@Config.Name("Disable IF Integration")
@Config.Comment("Set to true to disable Industrial Foregoing Integration")
public static boolean inForegoingIntegration = false;
@Config.Name("Industrial Foregoing integration")
@Config.Comment("Set to false to disable Industrial Foregoing integration")
public static boolean inForegoingIntegration = true;

@Config.Name("Disable Automatic EMC values")
@Config.Comment("Set to true to disable default EMC values")
public static boolean projectEIntegration = false;
@Config.Name("ProjectE Integration")
@Config.Comment("Set to false to disable default EMC values (ProjectE)")
public static boolean projectEIntegration = true;

@Config.Name("Enable Duplication Trait")
@Config.Comment("When set to true the duplication trait from tinker integration is enabled")
Expand Down Expand Up @@ -114,6 +114,14 @@ public class GeneralConfig {
@Config.Comment("Disabling this option will prevent modification to tooltip borders for metal items (useful when the modpack has another system to modify tooltips that conflicts with Metallurgy or hinders the consistency of modpack tooltips).")
public static boolean metalColoredTooltipBorders = true;

@Config.Name("Silent's Gems Integration")
@Config.Comment("Set to false to disable Silent's Gems integration")
public static boolean silentGemsIntegration = true;

@Config.Name("Spartan Weaponry Integration")
@Config.Comment("Set to false to disable Spartan Weaponry integration (WARNING: integration items use up a lot of IDs!)")
public static boolean spartanWeaponryIntegration = true;

//Handles Config Synchronization
public static class ChangeListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
import it.hurts.metallurgy_reforged.capabilities.effect.EffectDataProvider;
import it.hurts.metallurgy_reforged.capabilities.entity.EntityDataProvider;
import it.hurts.metallurgy_reforged.capabilities.punch.PunchEffectProvider;
import it.hurts.metallurgy_reforged.config.GeneralConfig;
import it.hurts.metallurgy_reforged.config.RegistrationConfig;
import it.hurts.metallurgy_reforged.entity.EntityPierKnight;
import it.hurts.metallurgy_reforged.entity.MetallurgyPrimedTNT;
import it.hurts.metallurgy_reforged.fluid.ModFluids;
import it.hurts.metallurgy_reforged.integration.IntegrationSW;
import it.hurts.metallurgy_reforged.item.ModItems;
import it.hurts.metallurgy_reforged.item.tool.EnumTools;
import it.hurts.metallurgy_reforged.material.ModMetals;
import it.hurts.metallurgy_reforged.render.ModRenderers;
import it.hurts.metallurgy_reforged.render.knuckles.BrassKnucklesBakedModel;
import it.hurts.metallurgy_reforged.sound.ModSounds;
import it.hurts.metallurgy_reforged.util.ItemUtils;
import it.hurts.metallurgy_reforged.util.ModChecker;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
Expand Down Expand Up @@ -112,6 +115,11 @@ public static void registerItems(RegistryEvent.Register<Item> event)
//Init OreDictionary (Register keys)
OreDictHandler.init();
Metallurgy.logger.info(Metallurgy.NAME + ": OreDictionary has been initialized");

if (ModChecker.isSpartanWeaponryLoaded && GeneralConfig.spartanWeaponryIntegration) {
IntegrationSW.registerItems(event.getRegistry());
Metallurgy.logger.info(Metallurgy.NAME + ": Spartan Weaponry Integration items have been registered");
}
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*==============================================================================
= Class: IntegrationSW
= This class is part of Metallurgy 4: Reforged
= Complete source code is available at https://github.com/Davoleo/Metallurgy-4-Reforged
= This code is licensed under GNU GPLv3
= Authors: Davoleo, ItHurtsLikeHell, PierKnight100
= Copyright (c) 2018-2024.
=============================================================================*/

package it.hurts.metallurgy_reforged.integration;

import com.oblivioussp.spartanweaponry.api.IWeaponCallback;
import com.oblivioussp.spartanweaponry.api.SpartanWeaponryAPI;
import it.hurts.metallurgy_reforged.Metallurgy;
import it.hurts.metallurgy_reforged.integration.spartanweaponry.SpartanMetal;
import it.hurts.metallurgy_reforged.integration.spartanweaponry.SpartanMetallurgyTab;
import it.hurts.metallurgy_reforged.integration.spartanweaponry.SpartanWeaponType;
import it.hurts.metallurgy_reforged.material.ModMetals;
import net.minecraft.item.Item;
import net.minecraftforge.registries.IForgeRegistry;

import java.util.ArrayList;
import java.util.List;

public class IntegrationSW {

public static final String MODID = "spartanweaponry";

public static final IWeaponCallback NOOP = (material, stack, world, tooltip, flag) -> {
};

public static final SpartanMetallurgyTab CREATIVE_TAB = new SpartanMetallurgyTab();

public static final List<SpartanMetal> spartanMetals = new ArrayList<>();

public static void registerItems(IForgeRegistry<Item> registry) {
ModMetals.metalMap.forEach((name, metal) -> {
if (metal.hasToolSet()) {
spartanMetals.add(new SpartanMetal(registry, metal.getStats()));
}
});

spartanMetals.forEach(spartanMetal -> {
SpartanWeaponryAPI.registerColourHandler(
spartanMetal.getMaterialEx(),
spartanMetal.getItems().values().toArray(new Item[0])
);

for (SpartanWeaponType weaponType : SpartanWeaponType.values()) {
SpartanWeaponryAPI.addItemModelToRegistry(spartanMetal.getWeapon(weaponType),
Metallurgy.MODID, IntegrationSW.MODID + '/' + weaponType.name().toLowerCase());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*==============================================================================
= Class: SpartanWeaponInitalizer
= This class is part of Metallurgy 4: Reforged
= Complete source code is available at https://github.com/Davoleo/Metallurgy-4-Reforged
= This code is licensed under GNU GPLv3
= Authors: Davoleo, ItHurtsLikeHell, PierKnight100
= Copyright (c) 2018-2024.
=============================================================================*/

package it.hurts.metallurgy_reforged.integration.spartanweaponry;

import com.oblivioussp.spartanweaponry.api.ToolMaterialEx;
import com.oblivioussp.spartanweaponry.api.weaponproperty.WeaponProperty;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

@FunctionalInterface
public interface ISpartanWeaponInitalizer {

Item create(ToolMaterialEx toolMaterialEx, String modid, CreativeTabs creativeTab, WeaponProperty... properties);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*==============================================================================
= Class: SpartanMetal
= This class is part of Metallurgy 4: Reforged
= Complete source code is available at https://github.com/Davoleo/Metallurgy-4-Reforged
= This code is licensed under GNU GPLv3
= Authors: Davoleo, ItHurtsLikeHell, PierKnight100
= Copyright (c) 2018-2024.
=============================================================================*/

package it.hurts.metallurgy_reforged.integration.spartanweaponry;

import com.google.common.base.CaseFormat;
import com.google.common.collect.Maps;
import com.oblivioussp.spartanweaponry.api.ToolMaterialEx;
import it.hurts.metallurgy_reforged.Metallurgy;
import it.hurts.metallurgy_reforged.integration.IntegrationSW;
import it.hurts.metallurgy_reforged.material.MetalStats;
import net.minecraft.item.Item;
import net.minecraftforge.registries.IForgeRegistry;

import java.util.Map;

public class SpartanMetal {

private final MetalStats stats;

private final ToolMaterialEx toolMaterial;

private final Map<SpartanWeaponType, Item> items = Maps.newEnumMap(SpartanWeaponType.class);

public SpartanMetal(IForgeRegistry<Item> registry, MetalStats stats) {
this.stats = stats;

final String ingotOre = "ingot" + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, stats.getName());
final int metalColor = stats.getColorHex();
this.toolMaterial = new ToolMaterialEx(
stats.getName(), ingotOre, Metallurgy.MODID, metalColor, metalColor,
stats.getToolMaterial().getHarvestLevel(), stats.getToolMaterial().getMaxUses(), stats.getToolMaterial().getEfficiency(),
stats.getToolMaterial().getAttackDamage(), stats.getToolMaterial().getEnchantability()
);

for (SpartanWeaponType type : SpartanWeaponType.values()) {
final Item weapon = type.initializer.create(toolMaterial, Metallurgy.MODID, IntegrationSW.CREATIVE_TAB);
items.put(type, weapon);

if (weapon != null) {
registry.register(weapon);
}
}
}

public MetalStats getStats() {
return stats;
}

public ToolMaterialEx getMaterialEx() {
return toolMaterial;
}

public Map<SpartanWeaponType, Item> getItems() {
return items;
}

public Item getWeapon(SpartanWeaponType type) {
return items.get(type);
}

public boolean isWeaponEnabled(SpartanWeaponType type) {
return items.get(type) != null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*==============================================================================
= Class: SpartanMetallurgyTab
= This class is part of Metallurgy 4: Reforged
= Complete source code is available at https://github.com/Davoleo/Metallurgy-4-Reforged
= This code is licensed under GNU GPLv3
= Authors: Davoleo, ItHurtsLikeHell, PierKnight100
= Copyright (c) 2018-2024.
=============================================================================*/

package it.hurts.metallurgy_reforged.integration.spartanweaponry;

import it.hurts.metallurgy_reforged.integration.IntegrationSW;
import it.hurts.metallurgy_reforged.util.MetallurgyTabs;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;

public class SpartanMetallurgyTab extends MetallurgyTabs {

public SpartanMetallurgyTab() {
super(9, IntegrationSW.MODID);
}

@Nonnull
@Override
public ItemStack createIcon() {
return new ItemStack(IntegrationSW.spartanMetals.get(0).getWeapon(SpartanWeaponType.KATANA));
}
}
Loading

0 comments on commit 0683b69

Please sign in to comment.