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 11, 2016
1 parent ff4f978 commit d84587e
Show file tree
Hide file tree
Showing 9 changed files with 634 additions and 29 deletions.
File renamed without changes.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# WebShooter

## Basics

### What does this mod do?
It causes spiders to create webs at the feet of players (or other things) that
they attack. This makes spiders a little bit more dangerous, since it's harder
to run away from them, and it also makes webs a renewable resource.

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

### What settings does this mod have?
You can configure the chance that each attack creates a web, from 0.0
(effectively disabling the mod), to 1.0 (every attack generates a web when
possible). The default is 0.15. Also, you can configure whether replaceable
blocks (like snow) can be overwritten with webs.

## 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/webshooter-*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.

### My mod adds a new kind of spider, and I want it to shoot webs too.
Make your spider's entity a subclass of EntitySpider (see EntityCaveSpider
in vanilla for an example).

## 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.webshooter" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "webshooter"

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.

64 changes: 64 additions & 0 deletions src/main/java/josephcsible/webshooter/PlayerInWebMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
WebShooter 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.webshooter;

import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import io.netty.buffer.ByteBuf;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class PlayerInWebMessage implements IMessage {
// The coordinates of the web block
public int x, y, z;

public PlayerInWebMessage() {}

public PlayerInWebMessage(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}

@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
}

@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
}

public static class Handler implements IMessageHandler<PlayerInWebMessage, IMessage>{
@Override
public IMessage onMessage(PlayerInWebMessage msg, MessageContext ctx) {
Minecraft mc = Minecraft.getMinecraft();
mc.theWorld.setBlock(msg.x, msg.y, msg.z, Blocks.web);
mc.thePlayer.setInWeb();
return null;
}
}
}
116 changes: 116 additions & 0 deletions src/main/java/josephcsible/webshooter/WebShooter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
WebShooter 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.webshooter;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
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.SubscribeEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

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

public static Configuration config;
public static SimpleNetworkWrapper netWrapper;
protected double webChance;
protected boolean allowReplacement;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
netWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
netWrapper.registerMessage(PlayerInWebMessage.Handler.class, PlayerInWebMessage.class, 0, Side.CLIENT);
config = new Configuration(event.getSuggestedConfigurationFile());
syncConfig();
}

protected void syncConfig() {
webChance = config.get(Configuration.CATEGORY_GENERAL, "webChance", 0.15, "The chance per attack that a spider will create a web on an entity it attacks", 0.0, 1.0).getDouble();
allowReplacement = config.get(Configuration.CATEGORY_GENERAL, "allowReplacement", true, "Whether webs are able to replace water, lava, fire, snow, vines, and any mod-added blocks declared as replaceable").getBoolean();
if(config.hasChanged())
config.save();
}

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

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

@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event) {
// Mod authors: If your mod adds custom spiders, and you want them to work with
// this mod, make them subclass EntitySpider (like vanilla cave spiders do).
if(!(event.source.getEntity() instanceof EntitySpider))
return;

Entity target = event.entity;
World world = target.worldObj;
int blockX = (int)Math.floor(target.posX);
int blockY = (int)Math.floor(target.posY);
int blockZ = (int)Math.floor(target.posZ);
Block oldBlock = world.getBlock(blockX, blockY, blockZ);

if(!oldBlock.isReplaceable(world, blockX, blockY, blockZ))
return;

if(!allowReplacement && !oldBlock.isAir(world, blockX, blockY, blockZ))
return;

if(webChance < world.rand.nextDouble())
return;

world.setBlock(blockX, blockY, blockZ, Blocks.web);
target.setInWeb();
if(target instanceof EntityPlayerMP) {
// If we don't tell the client about the web ourself, it won't get told until after the
// attack resolves. This will result in the client thinking the player got knocked back
// further than they really did, which in turn will result in a "player moved wrongly"
// message on the server.
netWrapper.sendTo(new PlayerInWebMessage(blockX, blockY, blockZ), (EntityPlayerMP)target);
}
}
}
62 changes: 62 additions & 0 deletions src/main/java/josephcsible/webshooter/WebShooterGuiFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
WebShooter 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.webshooter;

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 WebShooterGuiFactory implements IModGuiFactory {

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

@Override
public void initialize(Minecraft minecraftInstance) {
}

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

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

@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
return null;
}

}
12 changes: 6 additions & 6 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": "webshooter",
"name": "WebShooter",
"description": "Makes spider attacks cause their target to get covered in a cobweb",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "",
"url": "http://minecraft.curseforge.com/projects/webshooter",
"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 d84587e

Please sign in to comment.