Skip to content

Commit c5b9373

Browse files
committed
Add the actual mod stuff
1 parent 6e431c0 commit c5b9373

File tree

9 files changed

+634
-29
lines changed

9 files changed

+634
-29
lines changed
File renamed without changes.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# WebShooter
2+
3+
## Basics
4+
5+
### What does this mod do?
6+
It causes spiders to create webs at the feet of players (or other things) that
7+
they attack. This makes spiders a little bit more dangerous, since it's harder
8+
to run away from them, and it also makes webs a renewable resource.
9+
10+
### How do I use this mod?
11+
You need Minecraft Forge installed first. Once that's done, just drop
12+
webshooter-*version*.jar in your Minecraft instance's mods/ directory.
13+
Optionally, you can configure it to taste (see below).
14+
15+
### What settings does this mod have?
16+
You can configure the chance that each attack creates a web, from 0.0
17+
(effectively disabling the mod), to 1.0 (every attack generates a web when
18+
possible). The default is 0.15. Also, you can configure whether replaceable
19+
blocks (like snow) can be overwritten with webs.
20+
21+
## Development
22+
23+
### How do I compile this mod from source?
24+
You need a JDK installed first. Start a command prompt or terminal in the
25+
directory you downloaded the source to. If you're on Windows, type
26+
`gradlew.bat build`. Otherwise, type `./gradlew build`. Once it's done, the mod
27+
will be saved to build/libs/webshooter-*version*.jar.
28+
29+
### How can I contribute to this mod's development?
30+
Send pull requests. Note that by doing so, you agree to release your
31+
contributions under this mod's license.
32+
33+
### My mod adds a new kind of spider, and I want it to shoot webs too.
34+
Make your spider's entity a subclass of EntitySpider (see EntityCaveSpider
35+
in vanilla for an example).
36+
37+
## Licensing/Permissions
38+
39+
### What license is this released under?
40+
It's released under the GPL v2 or later.
41+
42+
### Can I use this in my modpack?
43+
Yes, even if you monetize it with adf.ly or something, and you don't need to
44+
ask me for my permission first.

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ plugins {
2020
id "net.minecraftforge.gradle.forge" version "2.0.2"
2121
}
2222
*/
23-
version = "1.0"
24-
group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
25-
archivesBaseName = "modid"
23+
version = "1.0.0"
24+
group= "josephcsible.webshooter" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
25+
archivesBaseName = "webshooter"
2626

2727
minecraft {
2828
version = "1.10.2-12.18.1.2011"

gpl-2.0.txt

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/com/example/examplemod/ExampleMod.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
WebShooter Minecraft Mod
3+
Copyright (C) 2016 Joseph C. Sible
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
package josephcsible.webshooter;
21+
22+
import io.netty.buffer.ByteBuf;
23+
import net.minecraft.client.Minecraft;
24+
import net.minecraft.init.Blocks;
25+
import net.minecraft.util.math.BlockPos;
26+
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
27+
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
28+
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
29+
30+
public class PlayerInWebMessage implements IMessage {
31+
// The coordinates of the web block
32+
public BlockPos pos;
33+
34+
public PlayerInWebMessage() {}
35+
36+
public PlayerInWebMessage(BlockPos pos) {
37+
this.pos = pos;
38+
}
39+
40+
@Override
41+
public void fromBytes(ByteBuf buf) {
42+
pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
43+
}
44+
45+
@Override
46+
public void toBytes(ByteBuf buf) {
47+
buf.writeInt(pos.getX());
48+
buf.writeInt(pos.getY());
49+
buf.writeInt(pos.getZ());
50+
}
51+
52+
public static class Handler implements IMessageHandler<PlayerInWebMessage, IMessage>{
53+
@Override
54+
public IMessage onMessage(final PlayerInWebMessage msg, MessageContext ctx) {
55+
final Minecraft mc = Minecraft.getMinecraft();
56+
mc.addScheduledTask(new Runnable() {
57+
@Override
58+
public void run() {
59+
mc.theWorld.setBlockState(msg.pos, Blocks.WEB.getDefaultState());
60+
mc.thePlayer.setInWeb();
61+
}
62+
});
63+
return null;
64+
}
65+
}
66+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
WebShooter Minecraft Mod
3+
Copyright (C) 2016 Joseph C. Sible
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
package josephcsible.webshooter;
21+
22+
import net.minecraft.block.Block;
23+
import net.minecraft.block.state.IBlockState;
24+
import net.minecraft.entity.Entity;
25+
import net.minecraft.entity.monster.EntitySpider;
26+
import net.minecraft.entity.player.EntityPlayerMP;
27+
import net.minecraft.init.Blocks;
28+
import net.minecraft.util.math.BlockPos;
29+
import net.minecraft.world.World;
30+
import net.minecraftforge.common.MinecraftForge;
31+
import net.minecraftforge.common.config.Configuration;
32+
import net.minecraftforge.event.entity.living.LivingAttackEvent;
33+
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
34+
import net.minecraftforge.fml.common.FMLCommonHandler;
35+
import net.minecraftforge.fml.common.Mod;
36+
import net.minecraftforge.fml.common.Mod.EventHandler;
37+
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
38+
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
39+
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
40+
import net.minecraftforge.fml.common.network.NetworkRegistry;
41+
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
42+
import net.minecraftforge.fml.relauncher.Side;
43+
44+
@Mod(modid = WebShooter.MODID, version = WebShooter.VERSION, guiFactory = "josephcsible.webshooter.WebShooterGuiFactory")
45+
public class WebShooter
46+
{
47+
// XXX duplication with mcmod.info and build.gradle
48+
public static final String MODID = "webshooter";
49+
public static final String VERSION = "1.0.0";
50+
51+
public static Configuration config;
52+
public static SimpleNetworkWrapper netWrapper;
53+
protected double webChance;
54+
protected boolean allowReplacement;
55+
56+
@EventHandler
57+
public void preInit(FMLPreInitializationEvent event) {
58+
netWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
59+
netWrapper.registerMessage(PlayerInWebMessage.Handler.class, PlayerInWebMessage.class, 0, Side.CLIENT);
60+
config = new Configuration(event.getSuggestedConfigurationFile());
61+
syncConfig();
62+
}
63+
64+
protected void syncConfig() {
65+
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();
66+
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();
67+
if(config.hasChanged())
68+
config.save();
69+
}
70+
71+
@EventHandler
72+
public void init(FMLInitializationEvent event)
73+
{
74+
MinecraftForge.EVENT_BUS.register(this);
75+
}
76+
77+
@SubscribeEvent
78+
public void onConfigChanged(OnConfigChangedEvent eventArgs) {
79+
if(eventArgs.getModID().equals(MODID))
80+
syncConfig();
81+
}
82+
83+
@SubscribeEvent
84+
public void onLivingAttack(LivingAttackEvent event) {
85+
// Mod authors: If your mod adds custom spiders, and you want them to work with
86+
// this mod, make them subclass EntitySpider (like vanilla cave spiders do).
87+
if(!(event.getSource().getEntity() instanceof EntitySpider))
88+
return;
89+
90+
Entity target = event.getEntity();
91+
World world = target.worldObj;
92+
BlockPos pos = new BlockPos(target.posX, target.posY, target.posZ);
93+
IBlockState state = world.getBlockState(pos);
94+
Block oldBlock = state.getBlock();
95+
96+
if(!oldBlock.isReplaceable(world, pos))
97+
return;
98+
99+
if(!allowReplacement && !oldBlock.isAir(state, world, pos))
100+
return;
101+
102+
if(webChance < world.rand.nextDouble())
103+
return;
104+
105+
world.setBlockState(pos, Blocks.WEB.getDefaultState());
106+
target.setInWeb();
107+
if(target instanceof EntityPlayerMP) {
108+
// If we don't tell the client about the web ourself, it won't get told until after the
109+
// attack resolves. This will result in the client thinking the player got knocked back
110+
// further than they really did, which in turn will result in a "player moved wrongly"
111+
// message on the server.
112+
netWrapper.sendTo(new PlayerInWebMessage(pos), (EntityPlayerMP)target);
113+
}
114+
}
115+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
WebShooter Minecraft Mod
3+
Copyright (C) 2016 Joseph C. Sible
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
package josephcsible.webshooter;
21+
22+
import java.util.Set;
23+
import net.minecraft.client.Minecraft;
24+
import net.minecraft.client.gui.GuiScreen;
25+
import net.minecraftforge.common.config.ConfigElement;
26+
import net.minecraftforge.common.config.Configuration;
27+
import net.minecraftforge.fml.client.IModGuiFactory;
28+
import net.minecraftforge.fml.client.config.GuiConfig;
29+
30+
public class WebShooterGuiFactory implements IModGuiFactory {
31+
32+
public static class WebShooterGuiConfig extends GuiConfig {
33+
public WebShooterGuiConfig(GuiScreen parent) {
34+
super(
35+
parent,
36+
new ConfigElement(WebShooter.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
37+
WebShooter.MODID, false, false, GuiConfig.getAbridgedConfigPath(WebShooter.config.toString())
38+
);
39+
}
40+
}
41+
42+
@Override
43+
public void initialize(Minecraft minecraftInstance) {
44+
}
45+
46+
@Override
47+
public Class<? extends GuiScreen> mainConfigGuiClass() {
48+
return WebShooterGuiConfig.class;
49+
}
50+
51+
@Override
52+
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
53+
return null;
54+
}
55+
56+
@Override
57+
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
58+
return null;
59+
}
60+
61+
}

src/main/resources/mcmod.info

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[
22
{
3-
"modid": "examplemod",
4-
"name": "Example Mod",
5-
"description": "Example placeholder mod.",
3+
"modid": "webshooter",
4+
"name": "WebShooter",
5+
"description": "Makes spider attacks cause their target to get covered in a cobweb",
66
"version": "${version}",
77
"mcversion": "${mcversion}",
8-
"url": "",
8+
"url": "http://minecraft.curseforge.com/projects/webshooter",
99
"updateUrl": "",
10-
"authorList": ["ExampleDude"],
11-
"credits": "The Forge and FML guys, for making this example",
10+
"authorList": ["Joseph C. Sible"],
11+
"credits": "",
1212
"logoFile": "",
1313
"screenshots": [],
1414
"dependencies": []

0 commit comments

Comments
 (0)