Skip to content

Commit

Permalink
Rewrite to use CreateFluidSourceEvent instead of coremodding
Browse files Browse the repository at this point in the history
  • Loading branch information
josephcsible committed Jul 24, 2016
1 parent 0376532 commit ac1815d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 313 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ 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/infinitefluids-*version*.jar.

### When I try to run this mod from my IDE, it doesn't load!
Copy the dummy.jar file into the IDE instance's mods/ directory.

### 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.
Expand Down
8 changes: 1 addition & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {
id "net.minecraftforge.gradle.forge" version "2.0.2"
}
*/
version = "1.0.1"
version = "1.1.0"
group= "josephcsible.infinitefluids" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "infinitefluids"

Expand All @@ -37,12 +37,6 @@ minecraft {
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}

jar {
manifest {
attributes 'FMLCorePlugin': 'josephcsible.infinitefluids.InfiniteFluidsLoadingPlugin'
}
}

dependencies {
// you may put jars on which you depend on in ./libs
// or you may define them like so..
Expand Down
Binary file removed dummy.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,64 +23,46 @@
import java.util.HashSet;
import java.util.Set;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.DummyModContainer;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.ModMetadata;
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.Event.Result;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class InfiniteFluidsModContainer extends DummyModContainer {
public static Configuration config;
public static boolean invertInsideNether, invertOutsideNether;
public static Set<String> fluidsInsideNether, fluidsOutsideNether;
public static final String[] INSIDE_NETHER_DEFAULT = {}, OUTSIDE_NETHER_DEFAULT = {"minecraft:water"};

@Mod(modid = InfiniteFluids.MODID, version = InfiniteFluids.VERSION, dependencies = "required-after:Forge@[12.18.1.2023,)", guiFactory = "josephcsible.infinitefluids.InfiniteFluidsGuiFactory")
public class InfiniteFluids
{
// XXX duplication with mcmod.info and build.gradle
public static final String MODID = "infinitefluids";
public static final String VERSION = "1.0.1";

public InfiniteFluidsModContainer() {
super(new ModMetadata());
ModMetadata metadata = getMetadata();
metadata.modId = MODID;
metadata.version = VERSION;
metadata.name = "InfiniteFluids";
metadata.description = "Allows fluids other than water to be infinite (i.e., turn non-source blocks next to source blocks into source blocks).";
metadata.url = "http://minecraft.curseforge.com/projects/infinitefluids";
metadata.authorList.add("Joseph C. Sible");
}

@Override
public String getGuiClassName() {
return InfiniteFluidsGuiFactory.class.getName();
}
public static final String VERSION = "1.1.0";

@Override
public boolean registerBus(EventBus bus, LoadController controller) {
bus.register(this);
return true;
}
public static Configuration config;
protected static boolean invertInsideNether, invertOutsideNether;
protected static Set<String> fluidsInsideNether, fluidsOutsideNether;
protected static final String[] INSIDE_NETHER_DEFAULT = {}, OUTSIDE_NETHER_DEFAULT = {"minecraft:water"};

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

@Subscribe
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
@EventHandler
public static void init(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(InfiniteFluids.class);
}

@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent eventArgs) {
public static void onConfigChanged(OnConfigChangedEvent eventArgs) {
if(eventArgs.getModID().equals(MODID))
syncConfig();
}
Expand All @@ -107,4 +89,25 @@ protected static void syncConfig() {
if(config.hasChanged())
config.save();
}

protected static boolean fluidIsInfinite(Block block, World world) {
if(world.provider.doesWaterVaporize()) {
return fluidsInsideNether.contains(Block.REGISTRY.getNameForObject(block).toString()) ^ invertInsideNether;
} else {
return fluidsOutsideNether.contains(Block.REGISTRY.getNameForObject(block).toString()) ^ invertOutsideNether;
}
}

@SubscribeEvent
public static void onCreateFluidSource(CreateFluidSourceEvent event) {
Block block = event.getState().getBlock();
// Be careful not to change the result if it's the default anyway, so we don't unnecessarily interfere with other mods.
if(fluidIsInfinite(block, event.getWorld())) {
if(block != Blocks.FLOWING_WATER) {
event.setResult(Result.ALLOW);
}
} else if(block == Blocks.FLOWING_WATER) {
event.setResult(Result.DENY);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public static class InfiniteFluidsGuiConfig extends GuiConfig {
public InfiniteFluidsGuiConfig(GuiScreen parent) {
super(
parent,
new ConfigElement(InfiniteFluidsModContainer.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
InfiniteFluidsModContainer.MODID, false, false, GuiConfig.getAbridgedConfigPath(InfiniteFluidsModContainer.config.toString())
new ConfigElement(InfiniteFluids.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
InfiniteFluids.MODID, false, false, GuiConfig.getAbridgedConfigPath(InfiniteFluids.config.toString())
);
}
}
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/josephcsible/infinitefluids/InfiniteFluidsHooks.java

This file was deleted.

Loading

0 comments on commit ac1815d

Please sign in to comment.