Skip to content

Commit

Permalink
Minor adjustments last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Oct 15, 2024
1 parent 22c1d09 commit d987b93
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,89 @@
import org.imesense.dynamicspawncontrol.ai.spider.utils.attackweb.EntityThrowableWeb;
import org.imesense.dynamicspawncontrol.technical.config.spiderattackweb.DataSpiderAttackWeb;

public class AISpiderWebAttackTask extends EntityAIBase
/**
*
*/
public final class AISpiderWebAttackTask extends EntityAIBase
{
private int attackTimer;
/**
*
*/
private Double attackTimer;

/**
*
*/
private final EntityLiving parentEntity;

/**
*
* @param entity
*/
public AISpiderWebAttackTask(EntityLiving entity)
{
this.parentEntity = entity;
}

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

/**
*
*/
@Override
public void startExecuting()
{
this.attackTimer = 0;
this.attackTimer = 0.0;
}

/**
*
*/
@Override
public void resetTask()
{
super.resetTask();
}

/**
*
*/
@Override
public void updateTask()
{
EntityLivingBase entitylivingbase = this.parentEntity != null ? this.parentEntity.getAttackTarget() : null;
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))
if (this.parentEntity != null && entitylivingbase != null &&
entitylivingbase.getDistanceSq(this.parentEntity) < 256.0 &&
this.parentEntity.canEntityBeSeen(entitylivingbase))
{
World world = this.parentEntity.world;

++this.attackTimer;

if (this.attackTimer >= DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingCooldown())
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();
double coolDown =
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingCoolDown() +
(DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingCoolDown() *
world.rand.nextDouble()) * DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingVariance();

this.attackTimer = (int)((double)this.attackTimer - cooldown);
this.attackTimer = this.attackTimer - coolDown;
}
}
else if (this.attackTimer > 0)
else if (this.attackTimer > 0.0)
{
--this.attackTimer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,68 +22,95 @@
import org.imesense.dynamicspawncontrol.technical.customlibrary.ObjectHandler;
import org.imesense.dynamicspawncontrol.technical.network.PlayerInWebMessage;

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

/**
*
* @param worldIn
*/
public EntityThrowableWeb(World worldIn)
{
super(worldIn);
this.init();
}

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

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

/**
*
* @param worldIn
* @param x
* @param y
* @param z
* @param accelX
* @param accelY
* @param accelZ
*/
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.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");
}

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

}

/**
*
* @param result
*/
protected void onImpact(RayTraceResult result)
{
boolean doit = true;
boolean doIt = true;
EntityLivingBase thrower = this.getThrower();

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

if (result.typeOfHit != RayTraceResult.Type.MISS)
Expand All @@ -96,7 +123,7 @@ protected void onImpact(RayTraceResult result)
{
IBlockState state = this.world.getBlockState(result.getBlockPos());
Block oldBlock = state.getBlock();
doit &= oldBlock != Blocks.WEB;
doIt &= oldBlock != Blocks.WEB;
}

pos = result.getBlockPos().offset(result.sideHit);
Expand All @@ -106,61 +133,70 @@ protected void onImpact(RayTraceResult result)
pos = result.entityHit.getPosition();
}

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

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

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

}

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

entityIn.playSound(ObjectHandler.WEBBING_SHOOT, 1.0F, pitch);
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);
Float inaccuracy = DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingInaccuracy();
entity.shoot(entityIn, entityIn.rotationPitch, entityIn.rotationYaw, 0.0f, 1.1f, inaccuracy);
worldIn.spawnEntity(entity);
}

return entity;
}

/**
*
* @param world
* @param pos
* @param source
* @param target
*/
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;
}
boolean stick = oldBlock.isReplaceable(world, pos) &&
(DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getBlockWebReplacement() || oldBlock.isAir(state, world, pos));

if (!stick)
{
world.playSound((EntityPlayer)null, pos, ObjectHandler.WEBBING_NONSTICK,
SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F));
world.playSound(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));
world.playSound(null, pos, ObjectHandler.WEBBING_STICK,
SoundCategory.NEUTRAL, 0.5f, 0.4f / (world.rand.nextFloat() * 0.4f + 0.8f));

if (!world.isRemote)
{
Expand All @@ -175,11 +211,13 @@ public static void onHit(World world, BlockPos pos, Entity source, Entity target
DynamicSpawnControl.networkWrapper.sendTo(new PlayerInWebMessage(pos), (EntityPlayerMP)target);
}
}

}
}
}

/**
*
*/
static
{
particleType = EnumParticleTypes.SNOWBALL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.imesense.dynamicspawncontrol.technical.customlibrary.thing.IThing;

@Mod.EventBusSubscriber
public class WebSlingerCapability implements IWebSlinger
public final class WebSlingerCapability implements IWebSlinger
{
@CapabilityInject(IWebSlinger.class)
public static final Capability<IWebSlinger> CAPABILITY = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import javax.annotation.Nullable;

public class WebSlingerProvider extends SimpleCapabilityProvider<IWebSlinger>
public final class WebSlingerProvider extends SimpleCapabilityProvider<IWebSlinger>
{
IThing owner = null;
int taskPriority = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.Capability.IStorage;

public class WebSlingerStorage implements IStorage<IWebSlinger>
public final class WebSlingerStorage implements IStorage<IWebSlinger>
{
public NBTBase writeNBT(Capability<IWebSlinger> capability, IWebSlinger instance, EnumFacing side)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.imesense.dynamicspawncontrol.technical.customlibrary.thing.TileEntityThing;

@Mod.EventBusSubscriber
public class EventHandler
public final class EventHandler
{
@SubscribeEvent
public static void attachCapabilitiesTileEntity(AttachCapabilitiesEvent<TileEntity> event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.imesense.dynamicspawncontrol.ai.spider.utils.attackweb.EntityThrowableWeb;
import org.imesense.dynamicspawncontrol.technical.customlibrary.ObjectHandler;

public class DSCWeb extends Item
public final class DSCWeb extends Item
{
public DSCWeb()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraftforge.fml.common.registry.GameRegistry;
import org.imesense.dynamicspawncontrol.technical.customlibrary.ObjectHandler;

public class CraftItemWeb implements IRecipes
public final class CraftItemWeb implements IRecipes
{
@Override
public void registry()
Expand Down
Loading

0 comments on commit d987b93

Please sign in to comment.