Skip to content

Commit

Permalink
Activating the new spider AI plugin (Part 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Oct 15, 2024
1 parent 53b76a2 commit 4594a3b
Show file tree
Hide file tree
Showing 28 changed files with 1,508 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent;
Expand All @@ -11,7 +10,13 @@
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppedEvent;

import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import org.imesense.dynamicspawncontrol.ai.spider.utils.event.EventHandler;
import org.imesense.dynamicspawncontrol.ai.spider.utils.attackweb.WebSlingerCapability;
import org.imesense.dynamicspawncontrol.debug.CheckDebugger;
import org.imesense.dynamicspawncontrol.gameplay.recipes.IRecipes;
import org.imesense.dynamicspawncontrol.gameplay.recipes.CraftItemWeb;
import org.imesense.dynamicspawncontrol.technical.eventprocessor.primitive.OnUpdateTimeWorld;
import org.imesense.dynamicspawncontrol.technical.eventprocessor.primitive.OnWindowTitle;
import org.imesense.dynamicspawncontrol.technical.initializer.RegisterCfgClasses;
Expand All @@ -21,6 +26,7 @@
import org.imesense.dynamicspawncontrol.technical.gamestructures.Structures;
import org.imesense.dynamicspawncontrol.technical.initializer.RegisterTechnicalClasses;
import org.imesense.dynamicspawncontrol.technical.network.MessageHandler;
import org.imesense.dynamicspawncontrol.technical.network.PlayerInWebMessage;
import org.imesense.dynamicspawncontrol.technical.parsers.GeneralStorageData;
import org.imesense.dynamicspawncontrol.technical.parsers.ParserGenericJsonScripts;
import org.imesense.dynamicspawncontrol.technical.parsers.ParserManager;
Expand All @@ -29,7 +35,6 @@
import org.imesense.dynamicspawncontrol.technical.worldcache.CacheStorage;

import java.io.File;
import java.io.IOException;

/**
* Main class of modification
Expand Down Expand Up @@ -144,6 +149,11 @@ public static File getGlobalPathToConfigs()
)
public static IProxy Proxy;

/**
*
*/
public static IRecipes Recipes;

/**
* Constructor
*/
Expand All @@ -158,12 +168,17 @@ public DynamicSpawnControl()
*/
public GeneralStorageData generalStorageData = null;

/**
*
*/
public static SimpleNetworkWrapper networkWrapper = null;

/**
* Preinitialize modification
*
* @param event Preinitialization event
*/
@EventHandler
@Mod.EventHandler
public synchronized void preInit(FMLPreInitializationEvent event)
{
//
Expand All @@ -179,6 +194,10 @@ public synchronized void preInit(FMLPreInitializationEvent event)
//
MessageHandler.init();

WebSlingerCapability.register();
networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("dynamicspawncontrol");
PlayerInWebMessage.register(networkWrapper);

//
RegisterCfgClasses.initializeConfigs();

Expand Down Expand Up @@ -212,11 +231,18 @@ public synchronized void preInit(FMLPreInitializationEvent event)
*
* @param event Initialization event
*/
@EventHandler
@Mod.EventHandler
public synchronized void init(FMLInitializationEvent event)
{
//
Proxy.init(event);

//
Recipes = new CraftItemWeb();

//
Recipes.registry();

MinecraftForge.EVENT_BUS.register(OnUpdateTimeWorld.INSTANCE);
}

Expand All @@ -225,19 +251,21 @@ public synchronized void init(FMLInitializationEvent event)
*
* @param event Postinitialization event
*/
@EventHandler
@Mod.EventHandler
public synchronized void postInit(FMLPostInitializationEvent event)
{
//
Proxy.postInit(event);

MinecraftForge.EVENT_BUS.register( new EventHandler());
}

/**
* Load complete action
*
* @param event Load complete event
*/
@EventHandler
@Mod.EventHandler
public synchronized void onLoadComplete(FMLLoadCompleteEvent event)
{
ParserGenericJsonScripts.readRules();
Expand All @@ -250,7 +278,7 @@ public synchronized void onLoadComplete(FMLLoadCompleteEvent event)
*
* @param event Server starting event
*/
@EventHandler
@Mod.EventHandler
public synchronized void serverLoad(FMLServerStartingEvent event)
{
RegisterCommandsClasses.registerCommands(event);
Expand All @@ -261,7 +289,7 @@ public synchronized void serverLoad(FMLServerStartingEvent event)
*
* @param event Server stopped action
*/
@EventHandler
@Mod.EventHandler
public synchronized void serverStopped(FMLServerStoppedEvent event)
{
Cache.instance.cleanActualCache();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.imesense.dynamicspawncontrol.ai.spider.task;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.world.World;
import org.imesense.dynamicspawncontrol.ai.spider.utils.attackweb.EntityThrowableWeb;
import org.imesense.dynamicspawncontrol.technical.config.spiderattackweb.DataSpiderAttackWeb;

public class AISpiderWebAttackTask extends EntityAIBase
{
private int attackTimer;
private final EntityLiving parentEntity;

public AISpiderWebAttackTask(EntityLiving entity)
{
this.parentEntity = entity;
}

public boolean shouldExecute()
{
EntityLivingBase entitylivingbase = this.parentEntity != null ? this.parentEntity.getAttackTarget() : null;
return entitylivingbase != null ? entitylivingbase.getDistanceSq(this.parentEntity) >= 4.0D : false;
}

public void startExecuting()
{
this.attackTimer = 0;
}

public void resetTask()
{
super.resetTask();
}

public void updateTask()
{
EntityLivingBase entitylivingbase = this.parentEntity != null ? this.parentEntity.getAttackTarget() : null;

if (this.parentEntity != null && entitylivingbase != null && entitylivingbase.getDistanceSq(this.parentEntity) < 256.0D && this.parentEntity.canEntityBeSeen(entitylivingbase))
{
World world = this.parentEntity.world;

++this.attackTimer;

if (this.attackTimer >= DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingCooldown())
{
EntityThrowableWeb.sling(world, this.parentEntity);

double cooldown =
(double)DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingCooldown() +
(double)((float)DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingCooldown() *
world.rand.nextFloat()) * DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingVariance();

this.attackTimer = (int)((double)this.attackTimer - cooldown);
}
}
else if (this.attackTimer > 0)
{
--this.attackTimer;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package org.imesense.dynamicspawncontrol.ai.spider.utils.attackweb;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.imesense.dynamicspawncontrol.DynamicSpawnControl;
import org.imesense.dynamicspawncontrol.technical.config.spiderattackweb.DataSpiderAttackWeb;
import org.imesense.dynamicspawncontrol.technical.customlibrary.ObjectHandler;
import org.imesense.dynamicspawncontrol.technical.network.PlayerInWebMessage;

public class EntityThrowableWeb extends EntityThrowable
{
public static final EnumParticleTypes particleType;

public EntityThrowableWeb(World worldIn)
{
super(worldIn);
this.init();
}

public EntityThrowableWeb(World worldIn, EntityLivingBase throwerIn)
{
super(worldIn, throwerIn);
this.init();
}

public EntityThrowableWeb(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
this.init();
}

public EntityThrowableWeb(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
super(worldIn);
this.setSize(1.0F, 1.0F);
this.setLocationAndAngles(x, y, z, this.rotationYaw, this.rotationPitch);
this.setPosition(x, y, z);
this.init();
}

protected void init()
{

}

public static void registerFixesWebbing(DataFixer fixer)
{
EntityThrowable.registerFixesThrowable(fixer, "webbing");
}

@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id)
{
if (id == 3)
{
for(int i = 0; i < 3; ++i)
{
this.world.spawnParticle(particleType, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
}
}

}

protected void onImpact(RayTraceResult result)
{
boolean doit = true;
EntityLivingBase thrower = this.getThrower();

if (result.entityHit != null && result.entityHit != thrower)
{
result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, thrower), 0.0F);
}

if (result.typeOfHit != RayTraceResult.Type.MISS)
{
BlockPos pos;

if (result.typeOfHit == RayTraceResult.Type.BLOCK)
{
if (!DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingWebbingOnWeb())
{
IBlockState state = this.world.getBlockState(result.getBlockPos());
Block oldBlock = state.getBlock();
doit &= oldBlock != Blocks.WEB;
}

pos = result.getBlockPos().offset(result.sideHit);
}
else
{
pos = result.entityHit.getPosition();
}

doit &= this.getThrower() != result.entityHit;

if (doit)
{
onHit(this.world, pos, thrower, result.entityHit);
}
}

if (doit && !this.world.isRemote)
{
this.world.setEntityState(this, (byte)3);
this.setDead();
}

}

public static EntityThrowableWeb sling(World worldIn, EntityLivingBase entityIn)
{
EntityThrowableWeb entity = null;
float pitch = 1.0F / (entityIn.getRNG().nextFloat() * 0.4F + 0.8F);

entityIn.playSound(ObjectHandler.WEBBING_SHOOT, 1.0F, pitch);

if (!worldIn.isRemote)
{
entity = new EntityThrowableWeb(worldIn, entityIn);
float inaccuracy = DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingInaccuracy();
entity.shoot(entityIn, entityIn.rotationPitch, entityIn.rotationYaw, 0.0F, 1.1F, inaccuracy);
worldIn.spawnEntity(entity);
}

return entity;
}

public static void onHit(World world, BlockPos pos, Entity source, Entity target)
{
IBlockState state = world.getBlockState(pos);
Block oldBlock = state.getBlock();
boolean stick = true;

if (!oldBlock.isReplaceable(world, pos) ||
!DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getBlockWebReplacement() && !oldBlock.isAir(state, world, pos))
{
stick = false;
}

if (!stick)
{
world.playSound((EntityPlayer)null, pos, ObjectHandler.WEBBING_NONSTICK,
SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F));
}
else
{
world.playSound((EntityPlayer)null, pos, ObjectHandler.WEBBING_STICK,
SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F));

if (!world.isRemote)
{
world.setBlockState(pos, Blocks.WEB.getDefaultState());

if (target != null)
{
target.setInWeb();

if (target instanceof EntityPlayerMP)
{
DynamicSpawnControl.networkWrapper.sendTo(new PlayerInWebMessage(pos), (EntityPlayerMP)target);
}
}

}
}
}

static
{
particleType = EnumParticleTypes.SNOWBALL;
}
}
Loading

0 comments on commit 4594a3b

Please sign in to comment.