Skip to content

Commit

Permalink
Add IMC for selectively disabling worldgen in custom dimensions (#11)
Browse files Browse the repository at this point in the history
* Update buildscript & spotlessApply

* Add IMC for selectively disabling worldgen in custom dimensions
  • Loading branch information
eigenraven authored Jul 5, 2022
1 parent 264c9a6 commit 8c222b0
Show file tree
Hide file tree
Showing 195 changed files with 6,744 additions and 6,598 deletions.
520 changes: 429 additions & 91 deletions build.gradle

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

dependencies {

compile("com.github.GTNewHorizons:Mantle:0.3.4:dev")
compile("com.github.GTNewHorizons:Mantle:0.3.4:dev")

compileOnly("com.github.GTNewHorizons:waila:1.5.18:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:ForgeMultipart:1.2.7:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.1.22-GTNH:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.9.0.9-GTNH:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:waila:1.5.21:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:ForgeMultipart:1.2.7:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.2.17-GTNH:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.9.0-16-GTNH:dev") {
transitive = false
}

compileOnly("curse.maven:minefactory-reloaded-66672:2366150") {
transitive = false
}
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {
transitive = false
}
compileOnly("curse.maven:minefactory-reloaded-66672:2366150") {
transitive = false
}
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {
transitive = false
}
}
20 changes: 10 additions & 10 deletions repositories.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Add any additional repositiroes for your dependencies here

repositories {
maven {
name = "GTNH Maven"
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
}
maven {
url "https://cursemaven.com"
}
maven {
url = "https://jitpack.io"
}
maven {
name = "GTNH Maven"
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
}
maven {
url "https://cursemaven.com"
}
maven {
url = "https://jitpack.io"
}
}
5 changes: 2 additions & 3 deletions src/main/java/mods/natura/CloudMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
public class CloudMaterial extends Material {
public CloudMaterial() {
super(MapColor.snowColor);
//this.setReplaceable();
// this.setReplaceable();
this.setNoPushMobility();
}

/* Returns if blocks of these materials are liquids. */
@Override
public boolean isLiquid () {
public boolean isLiquid() {
return false;
}

Expand All @@ -31,5 +31,4 @@ public boolean isSolid() {
public boolean getCanBlockGrass() {
return false;
}

}
96 changes: 80 additions & 16 deletions src/main/java/mods/natura/Natura.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package mods.natura;

import java.util.Random;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import mantle.lib.TabTools;
import mantle.pulsar.control.PulseManager;
import mods.natura.common.NContent;
Expand All @@ -41,27 +41,37 @@
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.player.BonemealEvent;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.world.ChunkDataEvent;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(modid = "Natura", name = "Natura", version = "GRADLETOKEN_VERSION", acceptedMinecraftVersions = "[1.7.10]", dependencies = "required-after:Mantle;after:TConstruct")
@Mod(
modid = "Natura",
name = "Natura",
version = "GRADLETOKEN_VERSION",
acceptedMinecraftVersions = "[1.7.10]",
dependencies = "required-after:Mantle;after:TConstruct")
public class Natura {
/* Proxies for sides, used for graphics processing */
@SidedProxy(clientSide = "mods.natura.client.NProxyClient", serverSide = "mods.natura.common.NProxyCommon")
public static NProxyCommon proxy;

public static final String modID = "Natura";
/* Instance of this mod, used for grabbing prototype fields */
@Instance(modID)
public static Natura instance;

public static Material cloud = new CloudMaterial();

public static Logger logger = LogManager.getLogger(modID);

public static final PulseManager pulsar = new PulseManager(modID, "Natura-Dynamic");

@EventHandler
Expand All @@ -86,11 +96,20 @@ public void preInit(FMLPreInitializationEvent evt) {
public static BaseCloudWorldgen clouds;
public static BaseTreeWorldgen trees;

public static final int DIM_WORLDGEN_CROP_BIT = 1;
public static final int DIM_WORLDGEN_CLOUD_BIT = 2;
public static final int DIM_WORLDGEN_TREE_BIT = 4;
private static final Map<Integer, Integer> dimensionWorldgenOverrides = new HashMap<>();

@EventHandler
public void init(FMLInitializationEvent evt) {
if(PHNatura.enableBerryBushes | PHNatura.enableNetherBerryBushes) GameRegistry.registerWorldGenerator(crops = new BaseCropWorldgen(), 20); // TODO 1.7 Find correct weight (param 2)
GameRegistry.registerWorldGenerator(clouds = new BaseCloudWorldgen(), 20); // TODO 1.7 Find correct weight (param 2)
GameRegistry.registerWorldGenerator(trees = new BaseTreeWorldgen(), 20); // TODO 1.7 Find correct weight (param 2)
if (PHNatura.enableBerryBushes | PHNatura.enableNetherBerryBushes)
GameRegistry.registerWorldGenerator(
crops = new BaseCropWorldgen(), 20); // TODO 1.7 Find correct weight (param 2)
GameRegistry.registerWorldGenerator(
clouds = new BaseCloudWorldgen(), 20); // TODO 1.7 Find correct weight (param 2)
GameRegistry.registerWorldGenerator(
trees = new BaseTreeWorldgen(), 20); // TODO 1.7 Find correct weight (param 2)

proxy.registerRenderer();
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new NGuiHandler());
Expand Down Expand Up @@ -121,6 +140,45 @@ public void postInit(FMLPostInitializationEvent evt) {
pulsar.postInit(evt);
}

/**
* IMC Handler
*
* Message tag: set-worldgen-overrides
* Message NBT data:
* dimensions: int[] - array of dimension IDs to update
* settings: int[] - array of settings to set for the corresponding dimension IDs
* Both arrays must be of the same length
* Settings format: integer with bitfields, enable bits: 1 = crops (berry bushes), 2 = clouds, 4 = trees
*/
@EventHandler
public void imcHandler(FMLInterModComms.IMCEvent event) {
for (final FMLInterModComms.IMCMessage message : event.getMessages()) {
try {
if (message.key.equalsIgnoreCase("set-worldgen-overrides") && message.isNBTMessage()) {
NBTTagCompound tag = message.getNBTValue();
int[] dimensions = tag.getIntArray("dimensions");
int[] settings = tag.getIntArray("settings");
if (dimensions == null || settings == null || dimensions.length != settings.length) {
FMLLog.warning("Invalid Natura IMC format, mismatched array lengths");
continue;
}
synchronized (dimensionWorldgenOverrides) {
for (int i = 0; i < dimensions.length; i++) {
dimensionWorldgenOverrides.put(dimensions[i], settings[i]);
}
}
}
} catch (Exception e) {
FMLLog.warning("Exception while handling a Natura IMC message `{}`", message.key, e);
}
}
}

public static int getDimensionWorldgenOverrides(int dimId) {
Integer val = dimensionWorldgenOverrides.get(dimId);
return (val != null) ? val : Integer.MAX_VALUE;
}

@SubscribeEvent
public void bonemealEvent(BonemealEvent event) {
if (!event.world.isRemote && !event.isCanceled() && event.getResult() != Result.ALLOW) {
Expand All @@ -139,11 +197,15 @@ public void bonemealEvent(BonemealEvent event) {

@SubscribeEvent
public void interactEvent(EntityInteractEvent event) {
//if (event.target == null)
// if (event.target == null)
if (event.target instanceof EntityCow || event.target instanceof EntitySheep) {
ItemStack equipped = event.entityPlayer.getCurrentEquippedItem();
EntityAnimal creature = (EntityAnimal) event.target;
if (equipped != null && equipped.getItem() == NContent.plantItem && equipped.getItemDamage() == 0 && creature.getGrowingAge() == 0 && !creature.isInLove()) {
if (equipped != null
&& equipped.getItem() == NContent.plantItem
&& equipped.getItemDamage() == 0
&& creature.getGrowingAge() == 0
&& !creature.isInLove()) {
EntityPlayer player = event.entityPlayer;
if (!player.capabilities.isCreativeMode) {
--equipped.stackSize;
Expand All @@ -161,20 +223,22 @@ public void interactEvent(EntityInteractEvent event) {
@SubscribeEvent
public void spawnEvent(EntityJoinWorldEvent event) {
if (event.entity instanceof EntityCow || event.entity instanceof EntitySheep) {
((EntityLiving) event.entity).tasks.addTask(3, new EntityAITempt((EntityCreature) event.entity, 0.25F, NContent.plantItem, false));
((EntityLiving) event.entity)
.tasks.addTask(
3, new EntityAITempt((EntityCreature) event.entity, 0.25F, NContent.plantItem, false));
} else if (event.entity instanceof EntityChicken) {
((EntityLiving) event.entity).tasks.addTask(3, new EntityAITempt((EntityCreature) event.entity, 0.25F, NContent.seeds, false));
((EntityLiving) event.entity)
.tasks.addTask(3, new EntityAITempt((EntityCreature) event.entity, 0.25F, NContent.seeds, false));
}
}

public static boolean retrogen;

@SubscribeEvent
public void chunkDataSave (ChunkDataEvent.Save event) {
public void chunkDataSave(ChunkDataEvent.Save event) {
event.getData().setBoolean("Natura.Retrogen", true);
}

NContent content;
public static Random random = new Random();

}
20 changes: 15 additions & 5 deletions src/main/java/mods/natura/blocks/CloudBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class CloudBlock extends NBlock {
public CloudBlock() {
super(Natura.cloud, 0.3F, new String[] { "cloud_white", "cloud_gray", "cloud_dark", "cloud_sulfur" });
super(Natura.cloud, 0.3F, new String[] {"cloud_white", "cloud_gray", "cloud_dark", "cloud_sulfur"});
this.setStepSound(soundTypeCloth);
this.setBlockName("cloud");
this.setCreativeTab(NaturaTab.tab);
Expand All @@ -30,7 +30,15 @@ public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity e
EntityArrow entityarrow = (EntityArrow) entity;

if (entityarrow.isBurning()) {
this.explode(world, x, y, z, 1, entityarrow.shootingEntity instanceof EntityLiving ? (EntityLiving) entityarrow.shootingEntity : null);
this.explode(
world,
x,
y,
z,
1,
entityarrow.shootingEntity instanceof EntityLiving
? (EntityLiving) entityarrow.shootingEntity
: null);
world.setBlockToAir(x, y, z);
return;
}
Expand All @@ -43,9 +51,12 @@ public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity e
}

@Override
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
public boolean onBlockActivated(
World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 3 && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.flint_and_steel) {
if (meta == 3
&& player.getCurrentEquippedItem() != null
&& player.getCurrentEquippedItem().getItem() == Items.flint_and_steel) {
world.setBlockToAir(x, y, z);
this.explode(world, x, y, z, 1, player);
return true;
Expand Down Expand Up @@ -119,5 +130,4 @@ public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y,
return AxisAlignedBB.getBoundingBox(x, y, z, x + 1.0D, y + 0.0625D, z + 1.0D);
}
}

}
Loading

0 comments on commit 8c222b0

Please sign in to comment.