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 12, 2016
1 parent 6e431c0 commit c5b9373
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 @@ -20,9 +20,9 @@ plugins {
id "net.minecraftforge.gradle.forge" version "2.0.2"
}
*/
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.10.2-12.18.1.2011"
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.

66 changes: 66 additions & 0 deletions src/main/java/josephcsible/webshooter/PlayerInWebMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
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 io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class PlayerInWebMessage implements IMessage {
// The coordinates of the web block
public BlockPos pos;

public PlayerInWebMessage() {}

public PlayerInWebMessage(BlockPos pos) {
this.pos = pos;
}

@Override
public void fromBytes(ByteBuf buf) {
pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
}

@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(pos.getX());
buf.writeInt(pos.getY());
buf.writeInt(pos.getZ());
}

public static class Handler implements IMessageHandler<PlayerInWebMessage, IMessage>{
@Override
public IMessage onMessage(final PlayerInWebMessage msg, MessageContext ctx) {
final Minecraft mc = Minecraft.getMinecraft();
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
mc.theWorld.setBlockState(msg.pos, Blocks.WEB.getDefaultState());
mc.thePlayer.setInWeb();
}
});
return null;
}
}
}
115 changes: 115 additions & 0 deletions src/main/java/josephcsible/webshooter/WebShooter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
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.block.state.IBlockState;
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.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.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);
}

@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent eventArgs) {
if(eventArgs.getModID().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.getSource().getEntity() instanceof EntitySpider))
return;

Entity target = event.getEntity();
World world = target.worldObj;
BlockPos pos = new BlockPos(target.posX, target.posY, target.posZ);
IBlockState state = world.getBlockState(pos);
Block oldBlock = state.getBlock();

if(!oldBlock.isReplaceable(world, pos))
return;

if(!allowReplacement && !oldBlock.isAir(state, world, pos))
return;

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

world.setBlockState(pos, Blocks.WEB.getDefaultState());
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(pos), (EntityPlayerMP)target);
}
}
}
61 changes: 61 additions & 0 deletions src/main/java/josephcsible/webshooter/WebShooterGuiFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
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 net.minecraftforge.fml.client.IModGuiFactory;
import net.minecraftforge.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 c5b9373

Please sign in to comment.