Skip to content

Commit

Permalink
Modern IAF
Browse files Browse the repository at this point in the history
Changes to make the reducer work with the new IAF.
IAF config has been split in two, one for the new and one for 1.7.1.
This should give somewhat better performance in modern IAF.
  • Loading branch information
Charles445 committed Nov 30, 2020
1 parent 599ce32 commit fcb17a8
Show file tree
Hide file tree
Showing 33 changed files with 892 additions and 291 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.12.2-0.2.0"
version = "1.12.2-0.2.1"
group = "com.charles445.aireducer" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "AIReducer"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/charles445/aireducer/AIReducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AIReducer
{
public static final String MODID = "aireducer";
public static final String NAME = "AI Reducer";
public static final String VERSION = "0.2.0";
public static final String VERSION = "0.2.1";

@Mod.Instance(AIReducer.MODID)
public static AIReducer instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package com.charles445.aireducer.ai.myrmex;

import com.charles445.aireducer.ai.WrappedTask;
import com.charles445.aireducer.config.ModConfig;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIBase;

public class WrappedTaskMyrmexAIEscortEntity extends WrappedTaskMyrmex
public class WrappedTaskMyrmexAIEscortEntity extends WrappedTaskMyrmexRunDelay
{
public WrappedTaskMyrmexAIEscortEntity(EntityLiving entity, EntityAIBase task)
{
super(entity, task);
}

public double getUpdateChance()

@Override
public boolean canModify()
{
return ModConfig.iceandfire.myrmexUpdateChanceEscortEntity;
return ModConfig.iceandfire.myrmexModifyEscortEntity;
}

@Override
public int getRunDelay()
{
return ModConfig.iceandfire.myrmexRunDelayEscortEntity;
}

@Override
public void updateTask()
public double getUpdateChance()
{
if(entity.getRNG().nextDouble() < this.getUpdateChance())
task.updateTask();
return ModConfig.iceandfire.myrmexUpdateChanceEscortEntity;
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package com.charles445.aireducer.ai.myrmex;

import com.charles445.aireducer.ai.WrappedTask;
import com.charles445.aireducer.config.ModConfig;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIBase;

public class WrappedTaskMyrmexAIFindHidingSpot extends WrappedTaskMyrmex
public class WrappedTaskMyrmexAIFindHidingSpot extends WrappedTaskMyrmexRunDelay
{
public WrappedTaskMyrmexAIFindHidingSpot(EntityLiving entity, EntityAIBase task)
{
super(entity, task);
}

public double getUpdateChance()
@Override
public boolean canModify()
{
return ModConfig.iceandfire.myrmexUpdateChanceFindHidingSpot;
return ModConfig.iceandfire.myrmexModifyFindHidingSpot;
}

@Override
public int getRunDelay()
{
return ModConfig.iceandfire.myrmexRunDelayFindHidingSpot;
}

@Override
public void updateTask()
public double getUpdateChance()
{
if(entity.getRNG().nextDouble() < this.getUpdateChance())
task.updateTask();
return ModConfig.iceandfire.myrmexUpdateChanceFindHidingSpot;
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package com.charles445.aireducer.ai.myrmex;

import com.charles445.aireducer.ai.WrappedTask;
import com.charles445.aireducer.config.ModConfig;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIBase;

public class WrappedTaskMyrmexAIForage extends WrappedTaskMyrmex
public class WrappedTaskMyrmexAIForage extends WrappedTaskMyrmexRunDelay
{
public WrappedTaskMyrmexAIForage(EntityLiving entity, EntityAIBase task)
{
super(entity, task);
}

public double getUpdateChance()

@Override
public boolean canModify()
{
return ModConfig.iceandfire.myrmexUpdateChanceForage;
return ModConfig.iceandfire.myrmexModifyForage;
}

@Override
public int getRunDelay()
{
return ModConfig.iceandfire.myrmexRunDelayForage;
}

@Override
public void updateTask()
public double getUpdateChance()
{
if(entity.getRNG().nextDouble() < this.getUpdateChance())
task.updateTask();
return ModConfig.iceandfire.myrmexUpdateChanceForage;
}
}
Original file line number Diff line number Diff line change
@@ -1,96 +1,32 @@
package com.charles445.aireducer.ai.myrmex;

import com.charles445.aireducer.config.ModConfig;
import com.charles445.aireducer.debug.DebugUtil;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIBase;

public class WrappedTaskMyrmexAILeaveHive extends WrappedTaskMyrmex
public class WrappedTaskMyrmexAILeaveHive extends WrappedTaskMyrmexRunDelay
{
public WrappedTaskMyrmexAILeaveHive(EntityLiving entity, EntityAIBase task)
{
super(entity, task);
}

@Override
public void resetTask()
public boolean canModify()
{

return ModConfig.iceandfire.myrmexModifyLeaveHive;
}

@Override
public boolean shouldExecute()
public int getRunDelay()
{
if(!ModConfig.iceandfire.myrmexModifyLeaveHive)
return super.shouldExecute();

//Follow later versions' code to use shouldEnterHive early on

if(reflector.c_EntityMyrmexQueen.isInstance(entity))
return false;

if(entity.isChild())
return false;

if(!reflector.canMove(entity))
return false;

if(!reflector.shouldLeaveHive(entity))
return false;

//The change
if(reflector.shouldEnterHive(entity))
return false;

//Go back to normal
boolean shouldExecute = super.shouldExecute();

/*
if(shouldExecute)
{
//Show the path with fire
Path path = reflector.getMyrmexAILeaveHive_path(task);
DebugUtil.dotPathPoints(entity.getEntityWorld(), path);
BlockPos nextEntrance = reflector.getMyrmexAILeaveHive_nextEntrance(task);
DebugUtil.sendParticle(entity.getEntityWorld(), EnumParticleTypes.BARRIER, nextEntrance.getX(), nextEntrance.getY(), nextEntrance.getZ());
}
*/

return shouldExecute;
return ModConfig.iceandfire.myrmexRunDelayLeaveHive;
}


@Override
public boolean shouldContinueExecuting()
public double getUpdateChance()
{
//Complete override

if(!ModConfig.iceandfire.myrmexModifyLeaveHive)
return super.shouldContinueExecuting();

//Rearranged a little bit

if(!reflector.shouldLeaveHive(entity))
return false;

if(entity.getNavigator().noPath())
{
return false;
}

double distanceCheck = entity.getDistanceSq(reflector.getMyrmexAILeaveHive_nextEntrance(task));

if(distanceCheck <= 3.0)
{
return false;
}

if(reflector.shouldEnterHive(entity))
return false;



return true;
return ModConfig.iceandfire.myrmexUpdateChanceLeaveHive;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package com.charles445.aireducer.ai.myrmex;

import com.charles445.aireducer.config.ModConfig;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIBase;

public class WrappedTaskMyrmexAIMoveThroughHive extends WrappedTaskMyrmex
public class WrappedTaskMyrmexAIMoveThroughHive extends WrappedTaskMyrmexRunDelay
{

public WrappedTaskMyrmexAIMoveThroughHive(EntityLiving entity, EntityAIBase task)
{
super(entity, task);
}

@Override
public void resetTask()
public boolean canModify()
{
return ModConfig.iceandfire.myrmexModifyMoveThroughHive;
}

@Override
public int getRunDelay()
{
return ModConfig.iceandfire.myrmexRunDelayMoveThroughHive;
}

@Override
public double getUpdateChance()
{

return ModConfig.iceandfire.myrmexUpdateChanceMoveThroughHive;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.charles445.aireducer.ai.myrmex;

import com.charles445.aireducer.config.ModConfig;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIBase;

public class WrappedTaskMyrmexAIWanderHiveCenter extends WrappedTaskMyrmexRunDelay
{
public WrappedTaskMyrmexAIWanderHiveCenter(EntityLiving entity, EntityAIBase task)
{
super(entity, task);
}

@Override
public boolean canModify()
{
return ModConfig.iceandfire.myrmexModifyWanderHiveCenter;
}

@Override
public int getRunDelay()
{
return ModConfig.iceandfire.myrmexRunDelayWanderHiveCenter;
}

@Override
public double getUpdateChance()
{
return ModConfig.iceandfire.myrmexUpdateChanceWanderHiveCenter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.charles445.aireducer.ai.myrmex;

import com.charles445.aireducer.config.ModConfig;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIBase;

public abstract class WrappedTaskMyrmexRunDelay extends WrappedTaskMyrmex
{
int lastRun = -10000;

public WrappedTaskMyrmexRunDelay(EntityLiving entity, EntityAIBase task)
{
super(entity, task);
}

public abstract boolean canModify();
public abstract int getRunDelay();
public abstract double getUpdateChance();

@Override
public boolean shouldExecute()
{
if(!this.canModify())
return super.shouldExecute();

if(lastRun < (entity.ticksExisted - this.getRunDelay()))
{
return super.shouldExecute();
}

return false;
}

@Override
public void startExecuting()
{
if(!this.canModify())
{
super.startExecuting();
return;
}

lastRun = entity.ticksExisted;

super.startExecuting();
}

@Override
public void updateTask()
{
if(!this.canModify())
{
super.updateTask();
return;
}

double updateChance = this.getUpdateChance();

if(updateChance <= 0.0d)
return;

if(updateChance >= 1.0d)
{
super.updateTask();
return;
}

if(entity.getRNG().nextDouble() < updateChance)
{
super.updateTask();
return;
}
}
}
Loading

0 comments on commit fcb17a8

Please sign in to comment.