Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.

Commit

Permalink
Added config options for bomb, fire, and lightning arrows. Made ice a…
Browse files Browse the repository at this point in the history
…rrows create frosted ice instead of regular ice when hittting water.
  • Loading branch information
Forstride committed Jul 12, 2016
1 parent 2fbda8f commit 76cd96a
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 15 deletions.
32 changes: 32 additions & 0 deletions src/main/java/bullseye/client/gui/GuiBEConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package bullseye.client.gui;

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

import bullseye.config.ConfigurationHandler;
import bullseye.core.Bullseye;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.fml.client.config.DummyConfigElement;
import net.minecraftforge.fml.client.config.GuiConfig;
import net.minecraftforge.fml.client.config.IConfigElement;

public class GuiBEConfig extends GuiConfig
{
public GuiBEConfig(GuiScreen parentScreen)
{
super(parentScreen, GuiBEConfig.getConfigElements(), Bullseye.MOD_ID, false, false, "/bullseye");
}

private static List<IConfigElement> getConfigElements()
{
List<IConfigElement> list = new ArrayList<IConfigElement>();

List<IConfigElement> arrowSettings = new ConfigElement(ConfigurationHandler.config.getCategory(ConfigurationHandler.arrowSettings.toLowerCase())).getChildElements();

list.add(new DummyConfigElement.DummyCategoryElement(I18n.translateToLocal("config.category.arrowSettings.title"), "config.category.arrowSettings", arrowSettings));

return list;
}
}
25 changes: 25 additions & 0 deletions src/main/java/bullseye/client/gui/GuiFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package bullseye.client.gui;

import java.util.Set;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.IModGuiFactory;

public class GuiFactory implements IModGuiFactory {

@Override
public void initialize(Minecraft minecraftInstance) { }

@Override
public Class<? extends GuiScreen> mainConfigGuiClass()
{
return GuiBEConfig.class;
}

@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() { return null; }

@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { return null; }
}
63 changes: 63 additions & 0 deletions src/main/java/bullseye/config/ConfigurationHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright 2015-2016, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/

package bullseye.config;

import java.io.File;

import bullseye.core.Bullseye;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ConfigurationHandler
{
public static Configuration config;

public static String arrowSettings = "Arrow Settings";

public static boolean explodeBombArrows;
public static boolean burnFireArrows;
public static boolean fireLightningArrows;

public static void init(File configFile)
{
if (config == null)
{
config = new Configuration(configFile);
loadConfiguration();
}
}

private static void loadConfiguration()
{
try
{
explodeBombArrows = config.getBoolean("Bombs Arrows Destroy Blocks", arrowSettings, true, "Allow Bomb Arrows to destroy blocks.");
burnFireArrows = config.getBoolean("Fire Arrows Burn Blocks", arrowSettings, true, "Allow Fire Arrows to catch fire to blocks.");
fireLightningArrows = config.getBoolean("Lightning Arrows Burn Blocks", arrowSettings, true, "Allow Lightning Arrows to catch fire to blocks.");
}
catch (Exception e)
{
Bullseye.logger.error("Bullseye has encountered a problem loading misc.cfg", e);
}
finally
{
if (config.hasChanged()) config.save();
}
}

@SubscribeEvent
public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
{
if (event.getModID().equalsIgnoreCase(Bullseye.MOD_ID))
{
loadConfiguration();
}
}
}
10 changes: 9 additions & 1 deletion src/main/java/bullseye/core/Bullseye.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
******************************************************************************/
package bullseye.core;

import java.io.File;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import bullseye.init.ModConfiguration;
import bullseye.init.ModCrafting;
import bullseye.init.ModEntities;
import bullseye.init.ModItems;
Expand All @@ -20,12 +23,13 @@
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = Bullseye.MOD_ID, version = Bullseye.MOD_VERSION, name = Bullseye.MOD_NAME)
@Mod(modid = Bullseye.MOD_ID, version = Bullseye.MOD_VERSION, name = Bullseye.MOD_NAME, guiFactory = Bullseye.GUI_FACTORY)
public class Bullseye
{
public static final String MOD_NAME = "Bullseye";
public static final String MOD_ID = "Bullseye";
public static final String MOD_VERSION = "@MOD_VERSION@";
public static final String GUI_FACTORY = "bullseye.client.gui.GuiFactory";

@Instance(MOD_ID)
public static Bullseye instance;
Expand All @@ -34,10 +38,14 @@ public class Bullseye
public static CommonProxy proxy;

public static Logger logger = LogManager.getLogger(MOD_ID);
public static File configDirectory;

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
configDirectory = new File(event.getModConfigurationDirectory(), "bullseye");
ModConfiguration.init(configDirectory);

ModEntities.init();
ModItems.init();
ModVanillaCompat.init();
Expand Down
57 changes: 43 additions & 14 deletions src/main/java/bullseye/entities/projectile/EntityBEArrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.common.base.Predicates;

import bullseye.api.BEItems;
import bullseye.config.ConfigurationHandler;
import bullseye.core.Bullseye;
import bullseye.item.ItemBEArrow;
import bullseye.particle.BEParticleTypes;
Expand All @@ -27,7 +28,6 @@
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.PotionTypes;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
Expand All @@ -37,12 +37,8 @@
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.network.play.server.SPacketChangeGameState;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
Expand All @@ -52,8 +48,6 @@
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand Down Expand Up @@ -343,6 +337,10 @@ public void onUpdate()
{
this.worldObj.setBlockState(blockpos, Blocks.WATER.getDefaultState());
}
if (worldObj.getBlockState(blockpos) == Blocks.FROSTED_ICE.getDefaultState())
{
this.worldObj.setBlockState(blockpos, Blocks.WATER.getDefaultState());
}
if (worldObj.getBlockState(blockpos) == Blocks.SNOW_LAYER.getDefaultState())
{
this.worldObj.setBlockState(blockpos, Blocks.AIR.getDefaultState());
Expand Down Expand Up @@ -399,7 +397,7 @@ public void onUpdate()
if (!this.worldObj.isRemote)
{
float f = 2.0F;
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, true);
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, ConfigurationHandler.explodeBombArrows);
}
int itemId = Item.getIdFromItem(BEItems.arrow);
int itemMeta = this.getArrowType().ordinal();
Expand All @@ -413,8 +411,21 @@ public void onUpdate()
{
if (!this.worldObj.isRemote)
{
EntityLightningBolt entityLightningBolt = new EntityLightningBolt(this.worldObj, this.posX, this.posY, this.posZ, inGround);
EntityLightningBolt entityLightningBolt = new EntityLightningBolt(this.worldObj, this.posX, this.posY, this.posZ, !(ConfigurationHandler.fireLightningArrows));
this.worldObj.addWeatherEffect(entityLightningBolt);

if (!(ConfigurationHandler.fireLightningArrows))
{
double d0 = 3.0D;
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, new AxisAlignedBB(entityLightningBolt.posX - d0, entityLightningBolt.posY - d0, entityLightningBolt.posZ - d0, entityLightningBolt.posX + d0, entityLightningBolt.posY + 6.0D + d0, entityLightningBolt.posZ + d0));

for (int i1 = 0; i1 < list.size(); ++i1)
{
Entity entity1 = (Entity)list.get(i1);
if (!net.minecraftforge.event.ForgeEventFactory.onEntityStruckByLightning(entity1, entityLightningBolt))
entity1.onStruckByLightning(entityLightningBolt);
}
}
}
int itemId = Item.getIdFromItem(BEItems.arrow);
int itemMeta = this.getArrowType().ordinal();
Expand Down Expand Up @@ -599,7 +610,7 @@ protected void onHit(RayTraceResult raytraceResultIn)
{
if (iblockstate.getMaterial() == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
{
this.worldObj.setBlockState(blockpos, Blocks.ICE.getDefaultState());
this.worldObj.setBlockState(blockpos, Blocks.FROSTED_ICE.getDefaultState(), 2);
this.setDead();
}
}
Expand All @@ -619,8 +630,12 @@ protected void onHit(RayTraceResult raytraceResultIn)

if (worldObj.isAirBlock(pos) && this.worldObj.isBlockFullCube(blockpos) && iblockstate.getMaterial() != Material.LAVA && iblockstate.getMaterial() != Material.WATER && iblockstate != Blocks.ICE.getDefaultState() && iblockstate != Blocks.SNOW_LAYER.getDefaultState() && iblockstate != Blocks.SNOW.getDefaultState() && iblockstate != Blocks.PACKED_ICE.getDefaultState())
{
this.worldObj.setBlockState(pos, Blocks.FIRE.getDefaultState(), 11);
this.setDead();
if (ConfigurationHandler.burnFireArrows)
{
this.worldObj.setBlockState(pos, Blocks.FIRE.getDefaultState(), 11);
}

this.setDead();
}
}
}
Expand Down Expand Up @@ -729,7 +744,7 @@ protected void onHit(RayTraceResult raytraceResultIn)
if (!this.worldObj.isRemote)
{
float f1 = 2.0F;
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f1, true);
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f1, ConfigurationHandler.explodeBombArrows);
}
int itemId = Item.getIdFromItem(BEItems.arrow);
int itemMeta = this.getArrowType().ordinal();
Expand All @@ -743,9 +758,23 @@ protected void onHit(RayTraceResult raytraceResultIn)
{
if (!this.worldObj.isRemote)
{
EntityLightningBolt entityLightningBolt = new EntityLightningBolt(this.worldObj, this.posX, this.posY, this.posZ, inGround);
EntityLightningBolt entityLightningBolt = new EntityLightningBolt(this.worldObj, this.posX, this.posY, this.posZ, !(ConfigurationHandler.fireLightningArrows));
this.worldObj.addWeatherEffect(entityLightningBolt);

if (!(ConfigurationHandler.fireLightningArrows))
{
double d0 = 3.0D;
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, new AxisAlignedBB(entityLightningBolt.posX - d0, entityLightningBolt.posY - d0, entityLightningBolt.posZ - d0, entityLightningBolt.posX + d0, entityLightningBolt.posY + 6.0D + d0, entityLightningBolt.posZ + d0));

for (int i1 = 0; i1 < list.size(); ++i1)
{
Entity entity1 = (Entity)list.get(i1);
if (!net.minecraftforge.event.ForgeEventFactory.onEntityStruckByLightning(entity1, entityLightningBolt))
entity1.onStruckByLightning(entityLightningBolt);
}
}
}

int itemId = Item.getIdFromItem(BEItems.arrow);
int itemMeta = this.getArrowType().ordinal();
for (int ii = 0; ii < 16; ++ii)
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/bullseye/init/ModConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright 2014-2016, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/

package bullseye.init;

import java.io.File;

import bullseye.config.ConfigurationHandler;
import net.minecraftforge.common.MinecraftForge;

public class ModConfiguration
{
public static void init(File configDirectory)
{
ConfigurationHandler.init(new File(configDirectory, "config.cfg"));
MinecraftForge.EVENT_BUS.register(new ConfigurationHandler());
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/bullseye/lang/en_US.lang
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
itemGroup.tabBullseye=Bullseye

config.category.arrowSettings.title=Arrow Settings

item.bomb_arrow.name=Bomb Arrow
item.bomb_arrow_topper.name=Bomb Arrow Topper
item.diamond_arrow.name=Diamond Arrow
Expand Down

0 comments on commit 76cd96a

Please sign in to comment.