-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff4f978
commit d84587e
Showing
9 changed files
with
634 additions
and
29 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
src/main/java/josephcsible/webshooter/PlayerInWebMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
62
src/main/java/josephcsible/webshooter/WebShooterGuiFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters