Skip to content

Commit

Permalink
Merge pull request #56 from dshadowwolf/nme-api-update
Browse files Browse the repository at this point in the history
new API port
  • Loading branch information
jriwanek authored May 1, 2018
2 parents 696974a + d90800a commit 43bde7f
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 132 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/mcmoddev/nethermetals/NetherMetals.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.mcmoddev.nethermetals.proxy.CommonProxy;
import com.mcmoddev.nethermetals.util.Config;

import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLConstructionEvent;
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
Expand Down Expand Up @@ -55,6 +57,11 @@ public void onFingerprintViolation(FMLFingerprintViolationEvent event) {
logger.warn("Invalid fingerprint detected!");
}

@EventHandler
public void constructing(FMLConstructionEvent ev) {
Config.init();
}

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
proxy.preInit(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import com.mcmoddev.lib.init.Materials;
import com.mcmoddev.lib.material.MMDMaterial;
import com.mcmoddev.lib.util.Oredicts;
import com.mcmoddev.nethermetals.NetherMetals;

import net.minecraft.block.Block;
import net.minecraftforge.fml.common.Loader;

/**
* This class initializes all blocks in Nether Metals.
Expand All @@ -24,9 +24,9 @@ public class NetherBlocks extends com.mcmoddev.lib.init.Blocks {
*
*/
public static void init() {
Materials.init();
/* Materials.init();
ItemGroups.init();

*/
List<String> knownMaterials = Arrays.asList("coal", "diamond", "emerald", "gold", "iron", "lapis",
"redstone", "antimony", "bismuth", "copper", "lead", "mercury", "nickel", "platinum",
"silver", "tin", "zinc", "aluminum", "cadmium", "chromium", "iridium", "magnesium",
Expand Down Expand Up @@ -54,6 +54,7 @@ private static void createBasicNetherOreWrapper(String materialName ) {

private static void createNetherOreWrapper(String materialName) {
List<String> vanillaMats = Arrays.asList("coal", "diamond", "emerald", "gold", "iron", "lapis", "redstone");
NetherMetals.logger.fatal("Creating NetherOre for material named %s", materialName);
if (vanillaMats.contains(materialName))
createVanillaNetherOreWrapper(materialName);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@MMDPlugin(addonId=NetherMetals.MODID, pluginId=ThermalExpansion.PLUGIN_MODID)
@MMDPlugin(addonId=NetherMetals.MODID, pluginId=ThermalExpansion.PLUGIN_MODID,
versions = ThermalExpansion.PLUGIN_MODID+"@(,5.3.12.17];")
public class ThermalExpansion extends ThermalExpansionBase implements IIntegration {
@Override
public void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.mcmoddev.lib.data.Names;
import com.mcmoddev.lib.init.Materials;
import com.mcmoddev.lib.integration.IIntegration;
import com.mcmoddev.lib.integration.IntegrationInitEvent;
import com.mcmoddev.lib.integration.MMDPlugin;
import com.mcmoddev.lib.material.MMDMaterial;
import com.mcmoddev.lib.util.ConfigBase.Options;
import com.mcmoddev.lib.util.Oredicts;
import com.mcmoddev.lib.integration.plugins.TinkersConstructBase;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.TinkerRegistry;
import slimeknights.tconstruct.library.smeltery.MeltingRecipe;
import slimeknights.mantle.util.RecipeMatch;
Expand All @@ -22,7 +25,7 @@
*/
@MMDPlugin(addonId = NetherMetals.MODID,
pluginId = TinkersConstruct.PLUGIN_MODID,
postInitCallback="registerExtraMelting")
versions=TinkersConstruct.PLUGIN_MODID+"@[1.12.2-2.7.4.0,);")
public class TinkersConstruct extends TinkersConstructBase implements IIntegration {

@Override
Expand All @@ -31,10 +34,13 @@ public void init() {
return;
}

MinecraftForge.EVENT_BUS.register(this);
}

private boolean registered = false;
public void registerExtraMelting() {

@SubscribeEvent
public void registerExtraMeltings(IntegrationInitEvent ev) {
if (registered) return;
registered = true;
Materials.getAllMaterials().stream()
Expand Down
128 changes: 2 additions & 126 deletions src/main/java/com/mcmoddev/nethermetals/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,18 @@
package com.mcmoddev.nethermetals.proxy;

import com.mcmoddev.nethermetals.util.Config;
import com.mcmoddev.lib.init.Materials;
import com.mcmoddev.lib.integration.IntegrationManager;
import com.mcmoddev.lib.material.MMDMaterial;
import com.mcmoddev.lib.oregen.FallbackGenerator;
import com.mcmoddev.lib.util.ConfigBase.Options;
import com.mcmoddev.lib.util.Oredicts;
import com.mcmoddev.nethermetals.NetherMetals;
import com.mcmoddev.nethermetals.init.*;
import com.mcmoddev.nethermetals.init.ItemGroups;
import com.mcmoddev.nethermetals.init.Recipes;

import java.util.HashSet;
import java.util.Random;

import com.mcmoddev.lib.block.BlockMMDNetherOre;

import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.MissingModsException;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
Expand All @@ -57,11 +33,6 @@ public void preInit(FMLPreInitializationEvent event) {
}

ItemGroups.init();
NetherBlocks.init();

MinecraftForge.EVENT_BUS.register(this);
IntegrationManager.INSTANCE.preInit(event);
IntegrationManager.INSTANCE.runCallbacks("preInit");
}

public void init(FMLInitializationEvent event) {
Expand All @@ -74,99 +45,4 @@ public void postInit(FMLPostInitializationEvent event) {
Config.postInit();
}

// even though no items are directly created there are ItemBlock instances that need registered as well
@SubscribeEvent
public void registerItems(RegistryEvent.Register<Item> event) {
// NetherMetals doesn't do any of its own materials, just its own blocks
// so it actually needs this helper :)
Materials.getAllMaterials().stream()
.forEach( mat -> {
mat.getItems().stream()
.map(itemStack -> itemStack.getItem())
.filter(this::itemFilterFunc)
.forEach(event.getRegistry()::register);
});

Oredicts.registerItemOreDictionaryEntries();
Oredicts.registerBlockOreDictionaryEntries();
}

private boolean itemFilterFunc(Item item) {
return matchModId(item.getRegistryName());
}

@SubscribeEvent
public void registerBlocks(RegistryEvent.Register<Block> event) {
// NetherMetals doesn't do any of its own materials, just its own blocks
// so it actually needs this helper :)
Materials.getAllMaterials().stream()
.forEach( mat -> {
mat.getBlocks().stream()
.filter(this::blockFilterFunc)
.forEach(event.getRegistry()::register);
});
}

private boolean blockFilterFunc(Block block) {
return matchModId(block.getRegistryName());
}

private boolean matchModId(ResourceLocation rl) {
return rl.getResourceDomain().equals(NetherMetals.MODID);
}

public void angerPigmen(BlockPos pos, World world, EntityPlayer player, int range) {
int rr = range / 2;
BlockPos work1 = new BlockPos(pos).add(-rr,-rr,-rr);
BlockPos work2 = new BlockPos(pos).add(+rr,+rr,+rr);
AxisAlignedBB bb = new AxisAlignedBB(work1, work2);
for( final EntityLivingBase entity : world.getEntitiesWithinAABB(EntityPigZombie.class, bb) ) {
entity.setRevengeTarget(player);
}
}

@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent event) {
boolean silk = hasSilkTouch(event.getPlayer());
int currentDimension = event.getWorld().provider.getDimension();
Block targetBlock = event.getState().getBlock();
World w = event.getWorld();
if ((event.getPlayer() != null) && (!event.getPlayer().getHeldItemMainhand().isEmpty())) {
if (((!silk) && (currentDimension == -1)) && (isExplodingBlock(targetBlock))) {
doExplode(event.getPos(), event.getPlayer(), w);
}
}
}

private void doExplode(BlockPos pos, EntityPlayer player, World w) {
int randomNum = new Random().nextInt((100 - 1) + 1) + 1;
if (randomNum <= Options.explosionChance() || Options.explosionChance() > 100) {
w.createExplosion(player, pos.getX(), pos.getY(), pos.getZ(), 4.0F, true);
if (Options.angerPigmenRange() > 0 )
this.angerPigmen(pos, w, player, Options.angerPigmenRange());
}
}

private boolean isExplodingBlock(Block targetBlock) {
if (((targetBlock instanceof BlockMMDNetherOre) &&
(((BlockMMDNetherOre)targetBlock).doesExplode())) ||
(targetBlock.equals(Blocks.QUARTZ_ORE))) {
return true;
}
return false;
}

private boolean hasSilkTouch(EntityPlayer player) {
if( (player == null) || (player.getHeldItemMainhand().isEmpty())) return false;
NBTTagList enchants = player.getHeldItemMainhand().getEnchantmentTagList();
if (enchants != null) {
for (int index = 0; index < enchants.tagCount(); index++) {
short enchantId = enchants.getCompoundTagAt(index).getShort("id");
if (Enchantment.getEnchantmentByID(enchantId) != null &&
Enchantment.getEnchantmentByID(enchantId) == Enchantments.SILK_TOUCH)
return true;
}
}
return false;
}
}
Loading

0 comments on commit 43bde7f

Please sign in to comment.