Skip to content

Commit

Permalink
Minecolonies support
Browse files Browse the repository at this point in the history
as requested by #196 this adds the same support for minecolonies as added for lostcities, some default configs could probably be used though
  • Loading branch information
Thutmose committed Feb 26, 2020
1 parent 6fb738f commit e607508
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 5 deletions.
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ repositories {
name 'tterrag maven'
url "https://maven.tterrag.com/"
}
maven { // Minecolonies
name 'LDTTeam - Modding'
url 'https://ldtteam.jfrog.io/ldtteam/modding/'
}
}

dependencies {
Expand All @@ -93,6 +97,9 @@ dependencies {

//WHYLA
implementation fg.deobf("mcp.mobius.waila:Hwyla:${version_hwyla}")

//Minecolonies
implementation fg.deobf("libs:minecolonies-${version_minecolonies}")

}

Expand All @@ -110,8 +117,8 @@ jar {
}

task sourcesJar(type: Jar) {
classifier = "sources"
from sourceSets.main.allJava
classifier = "sources"
from sourceSets.main.allJava
}

task deobfJar(type: Jar) {
Expand All @@ -120,6 +127,6 @@ task deobfJar(type: Jar) {
}

artifacts {
archives sourcesJar
archives sourcesJar
archives deobfJar
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ version_cct=1.86.2
version_jei=6.0.0.27
version_lostcities=1.14-2.0.28-alpha-deobf
version_hwyla=1.10.6-B67_1.14.4
version_minecolonies=api
Binary file added libs/minecolonies-api.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/java/pokecube/compat/lostcities/Compat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pokecube.compat.lostcities;

import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -8,7 +9,7 @@
@Mod.EventBusSubscriber
public class Compat
{
@SubscribeEvent
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void serverAboutToStart(final FMLServerAboutToStartEvent event)
{
if (ModList.get().isLoaded("lostcities")) Impl.register();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pokecube/compat/lostcities/Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public int getSubBiome(final IWorld world_in, final Vector3 v, final TerrainSegm
type = PokecubeTerrainChecker.structureSubbiomeMap.get(type);
return BiomeType.getBiome(type, true).getType();
}
return super.getSubBiome(world_in, v, segment, caveAdjusted);
return this.parent.getSubBiome(world_in, v, segment, caveAdjusted);
}

}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/pokecube/compat/minecolonies/Compat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pokecube.compat.minecolonies;

import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;

@Mod.EventBusSubscriber
public class Compat
{
@SubscribeEvent
public static void serverAboutToStart(final FMLServerAboutToStartEvent event)
{
if (ModList.get().isLoaded("minecolonies")) Impl.register();
}
}
73 changes: 73 additions & 0 deletions src/main/java/pokecube/compat/minecolonies/Impl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package pokecube.compat.minecolonies;

import java.util.Locale;
import java.util.Set;

import com.google.common.collect.Sets;
import com.minecolonies.api.IMinecoloniesAPI;
import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.buildings.IBuilding;

import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IWorld;
import net.minecraft.world.server.ServerChunkProvider;
import pokecube.core.PokecubeCore;
import pokecube.core.world.terrain.PokecubeTerrainChecker;
import thut.api.maths.Vector3;
import thut.api.terrain.BiomeType;
import thut.api.terrain.TerrainSegment;
import thut.api.terrain.TerrainSegment.ISubBiomeChecker;

public class Impl
{
private static boolean reged = false;

private static IMinecoloniesAPI instance;
private static Set<String> logged = Sets.newHashSet();

public static void register()
{
if (Impl.reged) return;
Impl.reged = true;
TerrainSegment.defaultChecker = new TerrainChecker(TerrainSegment.defaultChecker);
Impl.instance = IMinecoloniesAPI.getInstance();
}

public static class TerrainChecker extends PokecubeTerrainChecker
{
ISubBiomeChecker parent;

public TerrainChecker(final ISubBiomeChecker parent)
{
this.parent = parent;
}

@Override
public int getSubBiome(final IWorld world, final Vector3 v, final TerrainSegment segment,
final boolean caveAdjusted)
{
check:
if (caveAdjusted) if (world.getChunkProvider() instanceof ServerChunkProvider)
{
if (!Impl.instance.getColonyManager().isCoordinateInAnyColony(world.getWorld(), v.getPos()))
break check;

final IColony colony = Impl.instance.getColonyManager().getClosestColony(world.getWorld(), v.getPos());
final Vec3d vec = new Vec3d(v.x, v.y, v.z);
for (final IBuilding b : colony.getBuildingManager().getBuildings().values())
{
String type = b.getSchematicName();
type = type.toLowerCase(Locale.ROOT);
if (Impl.logged.add(type)) PokecubeCore.LOGGER.info("Minecolonies Structure: " + type);
if (PokecubeTerrainChecker.structureSubbiomeMap.containsKey(type))
type = PokecubeTerrainChecker.structureSubbiomeMap.get(type);
else continue;
final AxisAlignedBB box = b.getTargetableArea(colony.getWorld());
if (box.contains(vec)) return BiomeType.getBiome(type, true).getType();
}
}
return this.parent.getSubBiome(world, v, segment, caveAdjusted);
}
}
}

0 comments on commit e607508

Please sign in to comment.