Skip to content

Commit

Permalink
Add the actual mod stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
josephcsible committed Jul 22, 2016
1 parent 194791e commit 1267808
Show file tree
Hide file tree
Showing 9 changed files with 655 additions and 28 deletions.
File renamed without changes.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ExpandedBonemeal

## Basics

### What does this mod do?
It gives bone meal the following new abilities:
- Growing cactus, sugar canes, nether wart, and vines
- Generating melons and pumpkins from their mature stems
- Duplicating lily pads and flowers as items (like sunflowers in vanilla)
- Generating dead bushes on sand, hardened clay, and stained clay
- Turning cobblestone and stone bricks into their mossy variants

### How do I use this mod?
You need Minecraft Forge installed first. Once that's done, just drop
expandedbonemeal-*version*.jar in your Minecraft instance's mods/ directory.
Optionally, you can configure it to taste (see below).

### What settings does this mod have?
Each new ability added by this mod can be individually disabled.

## Development

### How do I compile this mod from source?
You need a JDK installed first. Start a command prompt or terminal in the
directory you downloaded the source to. If you're on Windows, type
`gradlew.bat build`. Otherwise, type `./gradlew build`. Once it's done, the mod
will be saved to build/libs/expandedbonemeal-*version*.jar.

### How can I contribute to this mod's development?
Send pull requests. Note that by doing so, you agree to release your
contributions under this mod's license.

## Licensing/Permissions

### What license is this released under?
It's released under the GPL v2 or later.

### Can I use this in my modpack?
Yes, even if you monetize it with adf.ly or something, and you don't need to
ask me for my permission first.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ buildscript {

apply plugin: 'forge'

version = "1.0"
group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "modid"
version = "1.0.0"
group= "josephcsible.expandedbonemeal" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "expandedbonemeal"

minecraft {
version = "1.7.10-10.13.4.1614-1.7.10"
Expand Down
339 changes: 339 additions & 0 deletions gpl-2.0.txt

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions src/main/java/com/example/examplemod/ExampleMod.java

This file was deleted.

171 changes: 171 additions & 0 deletions src/main/java/josephcsible/expandedbonemeal/ExpandedBonemeal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
ExpandedBonemeal Minecraft Mod
Copyright (C) 2016 Joseph C. Sible
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package josephcsible.expandedbonemeal;

import java.util.Random;

import net.minecraft.init.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.entity.player.BonemealEvent;
import cpw.mods.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

@Mod(modid = ExpandedBonemeal.MODID, version = ExpandedBonemeal.VERSION, guiFactory = "josephcsible.expandedbonemeal.ExpandedBonemealGuiFactory")
public class ExpandedBonemeal
{
// XXX duplication with mcmod.info and build.gradle
public static final String MODID = "expandedbonemeal";
public static final String VERSION = "1.0.0";

public static Configuration config;
protected static boolean cactus, sugarcane, netherWart, melon, pumpkin, vine, lilyPad, deadBush, flowers, moss;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
config = new Configuration(event.getSuggestedConfigurationFile());
syncConfig();
}

@EventHandler
public void init(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(this); // for onBonemeal
FMLCommonHandler.instance().bus().register(this); // for onConfigChanged
}

@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent eventArgs) {
if(eventArgs.modID.equals(MODID))
syncConfig();
}

protected static void syncConfig() {
cactus = config.get(Configuration.CATEGORY_GENERAL, "cactus", true, "Whether using bone meal on a cactus should immediately attempt to add an additional block").getBoolean();
sugarcane = config.get(Configuration.CATEGORY_GENERAL, "sugarcane", true, "Whether using bone meal on sugar canes should immediately attempt to add an additional block").getBoolean();
netherWart = config.get(Configuration.CATEGORY_GENERAL, "netherWart", true, "Whether using bone meal on nether wart should immediately advance it to the next growth stage").getBoolean();
melon = config.get(Configuration.CATEGORY_GENERAL, "melon", true, "Whether using bone meal on a mature melon stem should immediately attempt to grow a melon").getBoolean();
pumpkin = config.get(Configuration.CATEGORY_GENERAL, "pumpkin", true, "Whether using bone meal on a mature pumpkin stem should immediately attempt to grow a pumpkin").getBoolean();
vine = config.get(Configuration.CATEGORY_GENERAL, "vine", true, "Whether using bone meal on a vine should immediately attempt to grow").getBoolean();
lilyPad = config.get(Configuration.CATEGORY_GENERAL, "lilyPad", true, "Whether using bone meal on a lily pad should cause one to drop as an item").getBoolean();
deadBush = config.get(Configuration.CATEGORY_GENERAL, "deadBush", true, "Whether using bone meal on sand or hardened clay should grow a dead bush").getBoolean();
flowers = config.get(Configuration.CATEGORY_GENERAL, "flowers", true, "Whether using bone meal on flowers should cause one to drop as an item").getBoolean();
moss = config.get(Configuration.CATEGORY_GENERAL, "moss", true, "Whether using bone meal on cobblestone or stone bricks should cause moss to grow").getBoolean();
if(config.hasChanged())
config.save();
}

protected static void growCactusOrSugarcane(BonemealEvent event) {
int y = event.y;
// if the player uses bonemeal on the bottom of a 2-high plant, do what they meant
while(event.world.getBlock(event.x, y + 1, event.z) == event.block) {
++y;
}
// don't bother even to notify the client here, since it's going to change again during updateTick
event.world.setBlockMetadataWithNotify(event.x, y, event.z, 15, 4);
event.block.updateTick(event.world, event.x, y, event.z, event.world.rand);
event.setResult(Result.ALLOW);
}

protected static void growMelonOrPumpkin(BonemealEvent event) {
// if the metadata isn't 7, vanilla already does what we want
if(event.world.getBlockMetadata(event.x, event.y, event.z) == 7) {
if(!event.world.isRemote) {
// BlockStem.updateTick generates one random number (with a varying maximum),
// and if it's zero, then it grows or makes a melon/pumpkin. rather than coremod or
// reimplement its growth code, just make sure it always gets zero.
// later it's used to pick a direction, so go back to real random for that.
event.block.updateTick(event.world, event.x, event.y, event.z, new ZeroFirstIntRandom());
}
event.setResult(Result.ALLOW);
}
}

// doesn't cause a block update, as nothing that calls it needs one
protected static void changeMetadataFromTo(BonemealEvent event, int from, int to) {
if(event.world.getBlockMetadata(event.x, event.y, event.z) == from) {
event.world.setBlockMetadataWithNotify(event.x, event.y, event.z, to, 2);
event.setResult(Result.ALLOW);
}
}

@SubscribeEvent
public void onBonemeal(BonemealEvent event) {
// in the future, maybe add stuff for saplings, mushrooms, ferns, and dirt variants
if(event.block == Blocks.cactus) {
if(cactus) growCactusOrSugarcane(event);
} else if(event.block == Blocks.reeds) {
if(sugarcane) growCactusOrSugarcane(event);
} else if(event.block == Blocks.nether_wart) {
if(netherWart) {
int meta = event.world.getBlockMetadata(event.x, event.y, event.z);
if(meta < 3) {
event.world.setBlockMetadataWithNotify(event.x, event.y, event.z, meta + 1, 2);
event.setResult(Result.ALLOW);
}
}
} else if(event.block == Blocks.melon_stem) {
if(melon) growMelonOrPumpkin(event);
} else if(event.block == Blocks.pumpkin_stem) {
if(pumpkin) growMelonOrPumpkin(event);
} else if(event.block == Blocks.vine) {
if(vine) {
// immediately try to grow new vines
Random rand = event.world.rand;
event.world.rand = new ZeroFirstIntRandom();
event.block.updateTick(event.world, event.x, event.y, event.z, rand);
event.world.rand = rand;
event.setResult(Result.ALLOW);
}
} else if(event.block == Blocks.waterlily) {
if(lilyPad) {
// drop as an item without removing the block, like sunflowers do in vanilla
event.block.dropBlockAsItem(event.world, event.x, event.y, event.z, event.world.getBlockMetadata(event.x, event.y, event.z), 0);
event.setResult(Result.ALLOW);
}
} else if(event.block == Blocks.sand || event.block == Blocks.hardened_clay || event.block == Blocks.stained_hardened_clay) { // intentionally excluding dirt, as I have other future plans in mind for it
if(deadBush && event.world.isAirBlock(event.x, event.y + 1, event.z)) {
event.world.setBlock(event.x, event.y + 1, event.z, Blocks.deadbush);
event.setResult(Result.ALLOW);
}
} else if(event.block == Blocks.red_flower || event.block == Blocks.yellow_flower) {
if(flowers) {
// drop as an item without removing the block, like sunflowers do in vanilla
event.block.dropBlockAsItem(event.world, event.x, event.y, event.z, event.world.getBlockMetadata(event.x, event.y, event.z), 0);
event.setResult(Result.ALLOW);
}
} else if(moss) {
if(event.block == Blocks.cobblestone) {
event.world.setBlock(event.x, event.y, event.z, Blocks.mossy_cobblestone, 0, 2);
event.setResult(Result.ALLOW);
} else if(event.block == Blocks.cobblestone_wall || event.block == Blocks.stonebrick) {
changeMetadataFromTo(event, 0, 1);
} else if(event.block == Blocks.monster_egg) {
changeMetadataFromTo(event, 2, 3);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
ExpandedBonemeal Minecraft Mod
Copyright (C) 2016 Joseph C. Sible
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package josephcsible.expandedbonemeal;

import java.util.Set;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.client.IModGuiFactory;
import cpw.mods.fml.client.config.GuiConfig;

public class ExpandedBonemealGuiFactory implements IModGuiFactory {

public static class ExpandedBonemealGuiConfig extends GuiConfig {
public ExpandedBonemealGuiConfig(GuiScreen parent) {
super(
parent,
new ConfigElement(ExpandedBonemeal.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
ExpandedBonemeal.MODID, false, false, GuiConfig.getAbridgedConfigPath(ExpandedBonemeal.config.toString())
);
}
}

@Override
public void initialize(Minecraft minecraftInstance) {
}

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

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

@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
ExpandedBonemeal Minecraft Mod
Copyright (C) 2016 Joseph C. Sible
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package josephcsible.expandedbonemeal;

import java.util.Random;

/**
* Always gives 0 for the first answer to nextInt(n), then goes back to being random.
*/
public class ZeroFirstIntRandom extends Random {
protected boolean firstTime = true;

@Override
public int nextInt(int n) {
if(!firstTime)
return super.nextInt(n);
firstTime = false;
return 0;
}
}
10 changes: 5 additions & 5 deletions src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"modid": "examplemod",
"name": "Example Mod",
"description": "Example placeholder mod.",
"modid": "expandedbonemeal",
"name": "ExpandedBonemeal",
"description": "Adds a lot of new uses for bone meal",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "",
"updateUrl": "",
"authorList": ["ExampleDude"],
"credits": "The Forge and FML guys, for making this example",
"authorList": ["Joseph C. Sible"],
"credits": "",
"logoFile": "",
"screenshots": [],
"dependencies": []
Expand Down

0 comments on commit 1267808

Please sign in to comment.