Skip to content

Commit

Permalink
Added Interdiction Torch
Browse files Browse the repository at this point in the history
  • Loading branch information
Wurmatron committed Apr 17, 2017
1 parent 1a67b34 commit 0115ba4
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 108 deletions.
62 changes: 33 additions & 29 deletions src/main/java/wurmatron/viral/Viral.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import wurmatron.viral.common.blocks.ViralInterdictionTorch;
import wurmatron.viral.common.blocks.ViralInterdictionTorchInverted;
import wurmatron.viral.common.capabilities.IViral;
import wurmatron.viral.common.capabilities.ViralData;
import wurmatron.viral.common.capabilities.ViralStorage;
Expand All @@ -27,37 +29,39 @@
@Mod(modid = Global.MODID, name = Global.NAME, version = Global.VERSION, guiFactory = Global.GUIFACTORY)
public class Viral {

@Mod.Instance(Global.MODID)
public static Viral instance;
@Mod.Instance(Global.MODID)
public static Viral instance;

@SidedProxy(serverSide = Global.COMMONPROXY, clientSide = Global.CLIENTPROXY)
public static CommonProxy proxy;
@SidedProxy(serverSide = Global.COMMONPROXY, clientSide = Global.CLIENTPROXY)
public static CommonProxy proxy;

public static final ItemSyringe syringe = new ItemSyringe();
public static final ItemStack syringeEmpty = new ItemStack(syringe, 1, 0);
public static final ItemStack syringeFilled = new ItemStack(syringe, 1, 1);
public static final ItemStack syringeCure = new ItemStack(syringe, 1, 2);
public static final ItemStack syringeImunity = new ItemStack(syringe, 1, 3);
public static final ItemSyringe syringe = new ItemSyringe();
public static final ItemStack syringeEmpty = new ItemStack(syringe, 1, 0);
public static final ItemStack syringeFilled = new ItemStack(syringe, 1, 1);
public static final ItemStack syringeCure = new ItemStack(syringe, 1, 2);
public static final ItemStack syringeImunity = new ItemStack(syringe, 1, 3);
public static final ViralInterdictionTorch torchInterdiction = new ViralInterdictionTorch();
public static final ViralInterdictionTorchInverted torchInterdictionInverted = new ViralInterdictionTorchInverted();

@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent e) {
ConfigHandler.preInit(e);
}
@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent e) {
ConfigHandler.preInit(e);
}

@Mod.EventHandler
public void onInit(FMLInitializationEvent e) {
CapabilityManager.INSTANCE.register(IViral.class, new ViralStorage(), ViralData.class);
MinecraftForge.EVENT_BUS.register(new CapabilityHandler());
MinecraftForge.EVENT_BUS.register(new ViralEventHandler());
MinecraftForge.EVENT_BUS.register(new InteractEvent());
proxy.register();
GameRegistry.register(syringe);
if (Settings.recipes) {
LogHandler.info("Adding Recipes");
GameRegistry.addRecipe(new ShapedOreRecipe(Viral.syringeEmpty, " A ", "IGI", " S ", 'A', new ItemStack(Items.ARROW), 'I', "ingotIron", 'G', "blockGlass", 'S', "stickWood"));
GameRegistry.addSmelting(Viral.syringeFilled, Viral.syringeEmpty, 0f);
GameRegistry.addRecipe(new ShapelessOreRecipe(Viral.syringeCure, Viral.syringeFilled, "dustGlowstone", "treeSapling", "ingotIron"));
GameRegistry.addRecipe(new ShapelessOreRecipe(Viral.syringeImunity, Viral.syringeCure, new ItemStack(Items.GOLDEN_APPLE, 1, 0), Items.DIAMOND));
}
}
@Mod.EventHandler
public void onInit(FMLInitializationEvent e) {
CapabilityManager.INSTANCE.register(IViral.class, new ViralStorage(), ViralData.class);
MinecraftForge.EVENT_BUS.register(new CapabilityHandler());
MinecraftForge.EVENT_BUS.register(new ViralEventHandler()); MinecraftForge.EVENT_BUS.register(new InteractEvent());
GameRegistry.register(syringe); GameRegistry.registerWithItem(torchInterdiction);
GameRegistry.registerWithItem(torchInterdictionInverted); if (Settings.recipes) {
LogHandler.info("Adding Recipes");
GameRegistry.addRecipe(new ShapedOreRecipe(Viral.syringeEmpty, " A ", "IGI", " S ", 'A', new ItemStack(Items.ARROW), 'I', "ingotIron", 'G', "blockGlass", 'S', "stickWood"));
GameRegistry.addSmelting(Viral.syringeFilled, Viral.syringeEmpty, 0f);
GameRegistry.addRecipe(new ShapelessOreRecipe(Viral.syringeCure, Viral.syringeFilled, "dustGlowstone", "treeSapling", "ingotIron"));
GameRegistry.addRecipe(new ShapelessOreRecipe(Viral.syringeImunity, Viral.syringeCure, new ItemStack(Items.GOLDEN_APPLE, 1, 0), Items.DIAMOND));
GameRegistry.addRecipe(new ShapedOreRecipe(Viral.torchInterdiction, "DXD", "XAX", " A ", 'D', "gemDiamond", 'X', Viral.syringeImunity, 'A', Items.NETHERBRICK));
GameRegistry.addRecipe(new ShapelessOreRecipe(Viral.torchInterdictionInverted, Viral.torchInterdiction, Viral.syringeEmpty));
} proxy.register();
}
}
7 changes: 5 additions & 2 deletions src/main/java/wurmatron/viral/client/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import wurmatron.viral.Viral;
Expand All @@ -19,10 +20,12 @@ public void register() {
registerItemModels();
}

public void registerItemModels() {
private void registerItemModels() {
for (int s = 0; s < ItemSyringe.NAMES.length; s++) {
ModelLoader.setCustomModelResourceLocation(Viral.syringe, s, new ModelResourceLocation(Global.MODID + ":syringe" + ItemSyringe.NAMES[s], "inventory"));
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Viral.syringe, s, new ModelResourceLocation(Global.MODID + ":syringe" + ItemSyringe.NAMES[s], "inventory"));
}
}
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(Viral.torchInterdiction),0,new ModelResourceLocation(Global.MODID + ":torchInterdiction", "inventory"));
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(Viral.torchInterdictionInverted),0,new ModelResourceLocation(Global.MODID + ":torchInterdiction", "inventory"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package wurmatron.viral.common.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockTorch;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import wurmatron.viral.common.capabilities.IViral;
import wurmatron.viral.common.capabilities.ViralProvider;
import wurmatron.viral.common.config.Settings;
import wurmatron.viral.common.utils.LogHandler;

import java.util.List;
import java.util.Random;

public class ViralInterdictionTorch extends BlockTorch {

public ViralInterdictionTorch() {
setCreativeTab(CreativeTabs.DECORATIONS);
setUnlocalizedName("torchInterdiction");
setRegistryName("torchInterdiction");
setHardness(1);
setResistance(5);
setLightLevel(12);
}

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random random) {
super.updateTick(world, pos, state, random);
world.scheduleBlockUpdate(pos, this, 1, 1);
if (!world.isRemote) {
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.getX() - Settings.radius, pos.getY() - Settings.radius, pos.getZ() - Settings.radius, pos.getX() + Settings.radius, pos.getY() + Settings.radius, pos.getZ() + Settings.radius));
for (Entity e : entities) {
if (!(e instanceof EntityPlayer)) {
IViral status = e.getCapability(ViralProvider.VIRAL, null);
if (status != null && status.status() != -1 && status.status() == 1) {
double distance = e.getDistance(pos.getX(), pos.getY(), pos.getZ());
if (distance >= Settings.radius || distance == 0)
continue;
if (distance < 1)
distance = 1;
double knockback = 1 + (1 / distance);
Vec3d angle = new Vec3d(e.posX - (pos.getX() + 0.5), e.posY - pos.getY(), e.posZ - (pos.getZ() + 0.5));
e.motionX += angle.xCoord * knockback * 0.05;
e.motionY += angle.yCoord * knockback * 0.05;
e.motionZ += angle.zCoord * knockback * 0.05;
}
}
}
}
}

@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package wurmatron.viral.common.blocks;

import net.minecraft.block.BlockTorch;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import wurmatron.viral.common.capabilities.IViral;
import wurmatron.viral.common.capabilities.ViralProvider;
import wurmatron.viral.common.config.Settings;

import java.util.List;
import java.util.Random;

public class ViralInterdictionTorchInverted extends BlockTorch {

private static final int radius = Settings.radius;

public ViralInterdictionTorchInverted() {
setCreativeTab(CreativeTabs.DECORATIONS);
setUnlocalizedName("torchInterdictionInverted");
setRegistryName("torchInterdictionInverted");
setHardness(1);
setResistance(5);
setLightLevel(12);
}

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random random) {
super.updateTick(world, pos, state, random);
world.scheduleBlockUpdate(pos, this, 1, 1);
if (!world.isRemote) {
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.getX() - Settings.radius, pos.getY() - Settings.radius, pos.getZ() - Settings.radius, pos.getX() + Settings.radius, pos.getY() + Settings.radius, pos.getZ() + Settings.radius));
for (Entity e : entities) {
if (!(e instanceof EntityPlayer)) {
IViral status = e.getCapability(ViralProvider.VIRAL, null);
if (status != null && status.status() != -1 && status.status() == 0) {
double distance = e.getDistance(pos.getX(), pos.getY(), pos.getZ());
if (distance >= Settings.radius || distance == 0)
continue;
if (distance < 1)
distance = 1;
double knockback = 1 + (1 / distance);
Vec3d angle = new Vec3d(e.posX - (pos.getX() + 0.5), e.posY - pos.getY(), e.posZ - (pos.getZ() + 0.5));
e.motionX += angle.xCoord * knockback * 0.05;
e.motionY += angle.yCoord * knockback * 0.05;
e.motionZ += angle.zCoord * knockback * 0.05;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ConfigHandler {
private static Property infectPassive;
public static Property hurtPassive;
public static Property passiveDamage;
public static Property torches;
public static Property radius;

public static void preInit(FMLPreInitializationEvent e) {
location = e.getSuggestedConfigurationFile();
Expand Down Expand Up @@ -51,6 +53,10 @@ public static void loadConfig() {
Settings.infectPassive = infectPassive.getBoolean();
passiveDamage = config.get(Configuration.CATEGORY_GENERAL, "passiveDamage", Defaults.passiveDamage, "How much damage do passive mobs take");
Settings.passiveDamage = passiveDamage.getDouble();
torches = config.get(Configuration.CATEGORY_GENERAL, "torches", Defaults.torches, "Are the interdiction torches enabled");
Settings.torches = torches.getBoolean();
radius = config.get(Configuration.CATEGORY_GENERAL, "radius", Defaults.radius, "Range of the interdiction torches",0,64);
Settings.radius = radius.getInt();
if (config.hasChanged()) {
LogHandler.info("Config saved");
config.save();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/wurmatron/viral/common/config/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public class Defaults {
public static final boolean infectPassive = true;
public static final boolean hurtPassive = true;
public static final double passiveDamage = 1f;
public static final boolean torches = true;
public static final int radius = 8;
}
2 changes: 2 additions & 0 deletions src/main/java/wurmatron/viral/common/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public class Settings {
public static boolean infectPassive;
public static boolean hurtPassive;
public static double passiveDamage;
public static boolean torches;
public static int radius;
}
9 changes: 3 additions & 6 deletions src/main/java/wurmatron/viral/common/event/InteractEvent.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package wurmatron.viral.common.event;

import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import wurmatron.viral.Viral;
import wurmatron.viral.common.capabilities.IViral;
import wurmatron.viral.common.capabilities.ViralProvider;
import wurmatron.viral.common.utils.LogHandler;

import java.util.Random;

Expand All @@ -28,23 +25,23 @@ public void onEntityInteract(PlayerInteractEvent.EntityInteract e) {
if (!e.getEntityPlayer().capabilities.isCreativeMode)
e.getEntityPlayer().inventory.deleteStack(e.getEntityPlayer().getHeldItemMainhand());
for (int i = 0; i <= 20; i++)
e.getTarget().worldObj.spawnParticle(EnumParticleTypes.SPELL_MOB, e.getTarget().posX, e.getTarget().posY, e.getTarget().posZ, new Random().nextDouble(), new Random().nextDouble() + 1, new Random().nextDouble());
e.getTarget().worldObj.spawnParticle(EnumParticleTypes.DRAGON_BREATH, e.getTarget().posX, e.getTarget().posY, e.getTarget().posZ, new Random().nextDouble(), new Random().nextDouble() + 1, new Random().nextDouble());
}
} else if (e.getEntityPlayer().getHeldItemMainhand().isItemEqual(Viral.syringeCure)) {
if (status.status() == 1) {
status.set(0);
if (!e.getEntityPlayer().capabilities.isCreativeMode)
e.getEntityPlayer().inventory.deleteStack(e.getEntityPlayer().getHeldItemMainhand());
for (int i = 0; i <= 20; i++)
e.getTarget().worldObj.spawnParticle(EnumParticleTypes.SPELL_MOB, e.getTarget().posX, e.getTarget().posY, e.getTarget().posZ, new Random().nextDouble(), new Random().nextDouble() + 1, new Random().nextDouble());
e.getTarget().worldObj.spawnParticle(EnumParticleTypes.DRAGON_BREATH, e.getTarget().posX, e.getTarget().posY, e.getTarget().posZ, new Random().nextDouble(), new Random().nextDouble() + 1, new Random().nextDouble());
}
} else if (e.getEntityPlayer().getHeldItemMainhand().isItemEqual(Viral.syringeImunity)) {
if (status.status() == 0) {
status.set(2);
if (!e.getEntityPlayer().capabilities.isCreativeMode)
e.getEntityPlayer().inventory.deleteStack(e.getEntityPlayer().getHeldItemMainhand());
for (int i = 0; i <= 100; i++)
e.getTarget().worldObj.spawnParticle(EnumParticleTypes.SPELL_MOB, e.getTarget().posX, e.getTarget().posY, e.getTarget().posZ, new Random().nextDouble(), new Random().nextDouble() + 1, new Random().nextDouble());
e.getTarget().worldObj.spawnParticle(EnumParticleTypes.DRAGON_BREATH, e.getTarget().posX, e.getTarget().posY, e.getTarget().posZ, new Random().nextDouble(), new Random().nextDouble() + 1, new Random().nextDouble());
} else if (status.status() == 1 && !e.getEntityPlayer().worldObj.isRemote)
e.getEntityPlayer().addChatComponentMessage(new TextComponentTranslation("chat.cannotCure.name"));
}
Expand Down
Loading

0 comments on commit 0115ba4

Please sign in to comment.