use of net.minecraft.entity.projectile.EntityThrowable in project SpongeCommon by SpongePowered.
the class PhaseTracker method spawnEntity.
/**
* This is the replacement of {@link WorldServer#spawnEntity(net.minecraft.entity.Entity)}
* where it captures into phases. The causes and relations are processed by the phases.
*
* The difference between {@link #spawnEntityWithCause(World, Entity)} is that it bypasses
* any phases and directly throws a spawn entity event.
*
* @param world The world
* @param entity The entity
* @return True if the entity spawn was successful
*/
public boolean spawnEntity(World world, Entity entity) {
checkNotNull(entity, "Entity cannot be null!");
// Sponge Start - handle construction phases
if (((IMixinEntity) entity).isInConstructPhase()) {
((IMixinEntity) entity).firePostConstructEvents();
}
final net.minecraft.entity.Entity minecraftEntity = EntityUtil.toNative(entity);
final WorldServer minecraftWorld = (WorldServer) world;
final IMixinWorldServer mixinWorldServer = (IMixinWorldServer) minecraftWorld;
final PhaseData phaseData = this.stack.peek();
final IPhaseState<?> phaseState = phaseData.state;
final PhaseContext<?> context = phaseData.context;
final boolean isForced = minecraftEntity.forceSpawn || minecraftEntity instanceof EntityPlayer;
// Certain phases disallow entity spawns (such as block restoration)
if (!isForced && !phaseState.allowEntitySpawns()) {
return false;
}
// Sponge End - continue with vanilla mechanics
final int chunkX = MathHelper.floor(minecraftEntity.posX / 16.0D);
final int chunkZ = MathHelper.floor(minecraftEntity.posZ / 16.0D);
if (!isForced && !mixinWorldServer.isMinecraftChunkLoaded(chunkX, chunkZ, true)) {
return false;
}
if (minecraftEntity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) minecraftEntity;
minecraftWorld.playerEntities.add(entityplayer);
minecraftWorld.updateAllPlayersSleepingFlag();
SpongeImplHooks.firePlayerJoinSpawnEvent((EntityPlayerMP) entityplayer);
} else {
// Sponge start - check for vanilla owner
if (minecraftEntity instanceof IEntityOwnable) {
IEntityOwnable ownable = (IEntityOwnable) entity;
net.minecraft.entity.Entity owner = ownable.getOwner();
if (owner != null && owner instanceof EntityPlayer) {
context.owner = (User) owner;
entity.setCreator(ownable.getOwnerId());
}
} else if (minecraftEntity instanceof EntityThrowable) {
EntityThrowable throwable = (EntityThrowable) minecraftEntity;
EntityLivingBase thrower = throwable.getThrower();
if (thrower != null) {
User user = null;
if (!(thrower instanceof EntityPlayer)) {
user = ((IMixinEntity) thrower).getCreatorUser().orElse(null);
} else {
user = (User) thrower;
}
if (user != null) {
context.owner = user;
entity.setCreator(user.getUniqueId());
}
}
}
// Sponge end
}
// capture all entities until the phase is marked for completion.
if (!isForced) {
try {
return ((IPhaseState) phaseState).spawnEntityOrCapture(context, entity, chunkX, chunkZ);
} catch (Exception | NoClassDefFoundError e) {
// Just in case something really happened, we should print a nice exception for people to
// paste us
this.printExceptionSpawningEntity(context, e);
return false;
}
}
// Sponge end - continue on with the checks.
minecraftWorld.getChunkFromChunkCoords(chunkX, chunkZ).addEntity(minecraftEntity);
minecraftWorld.loadedEntityList.add(minecraftEntity);
// Sponge - Cannot add onEntityAdded to the access transformer because forge makes it public
mixinWorldServer.onSpongeEntityAdded(minecraftEntity);
return true;
}
use of net.minecraft.entity.projectile.EntityThrowable in project SpongeCommon by SpongePowered.
the class EntityActivationRange method initializeEntityActivationState.
/**
* These entities are excluded from Activation range checks.
*
* @param entity Entity to check
* @return boolean If it should always tick.
*/
public static boolean initializeEntityActivationState(Entity entity) {
if (((IMixinWorld) entity.world).isFake()) {
return true;
}
// types that should always be active
if (entity instanceof EntityPlayer && !SpongeImplHooks.isFakePlayer(entity) || entity instanceof EntityThrowable || entity instanceof EntityDragon || entity instanceof MultiPartEntityPart || entity instanceof EntityWither || entity instanceof EntityFireball || entity instanceof EntityWeatherEffect || entity instanceof EntityTNTPrimed || entity instanceof EntityEnderCrystal || entity instanceof EntityFireworkRocket || // Always tick falling blocks
entity instanceof EntityFallingBlock) {
return true;
}
EntityActivationRangeCategory config = ((IMixinWorldServer) entity.world).getActiveConfig().getConfig().getEntityActivationRange();
EntityType type = ((org.spongepowered.api.entity.Entity) entity).getType();
IModData_Activation spongeEntity = (IModData_Activation) entity;
if (type == EntityTypes.UNKNOWN || !(type instanceof SpongeEntityType)) {
return false;
}
final SpongeEntityType spongeType = (SpongeEntityType) type;
final byte activationType = spongeEntity.getActivationType();
if (!spongeType.isActivationRangeInitialized()) {
addEntityToConfig(entity.world, spongeType, activationType);
spongeType.setActivationRangeInitialized(true);
}
EntityActivationModCategory entityMod = config.getModList().get(spongeType.getModId().toLowerCase());
int defaultActivationRange = config.getDefaultRanges().get(activationTypeMappings.get(activationType));
if (entityMod == null) {
// use default activation range
spongeEntity.setActivationRange(defaultActivationRange);
if (defaultActivationRange <= 0) {
return true;
}
return false;
} else if (!entityMod.isEnabled()) {
spongeEntity.setActivationRange(defaultActivationRange);
return true;
}
Integer defaultModActivationRange = entityMod.getDefaultRanges().get(activationTypeMappings.get(activationType));
Integer entityActivationRange = entityMod.getEntityList().get(type.getName().toLowerCase());
if (defaultModActivationRange != null && entityActivationRange == null) {
spongeEntity.setActivationRange(defaultModActivationRange);
if (defaultModActivationRange <= 0) {
return true;
}
return false;
} else if (entityActivationRange != null) {
spongeEntity.setActivationRange(entityActivationRange);
if (entityActivationRange <= 0) {
return true;
}
}
return false;
}
use of net.minecraft.entity.projectile.EntityThrowable in project ClaySoldiersMod by SanAndreasP.
the class EntityClayMan method throwSomethingAtEnemy.
public void throwSomethingAtEnemy(EntityLivingBase entity, Class<? extends ISoldierProjectile<? extends EntityThrowable>> projClass, boolean homing) {
double d = entity.posX - posX;
double d1 = entity.posZ - posZ;
try {
ISoldierProjectile<? extends EntityThrowable> projectile = projClass.getConstructor(World.class, EntityLivingBase.class).newInstance(this.worldObj, this);
projectile.initProjectile(entity, homing, this.getClayTeam());
EntityThrowable throwable = projectile.getProjectileEntity();
throwable.posY += 0.1D;
double d2 = (entity.posY + entity.getEyeHeight()) - 0.10000000298023224D - throwable.posY;
float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
this.worldObj.spawnEntityInWorld(throwable);
throwable.setThrowableHeading(d, d2 + f1, d1, 0.6F, 12.0F);
this.attackTime = 30;
this.hasAttacked = true;
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
FMLLog.log(ClaySoldiersMod.MOD_LOG, Level.ERROR, "%1$s cannot be instantiated! %1$s is not thrown to target!", projClass.getName());
e.printStackTrace();
}
}
use of net.minecraft.entity.projectile.EntityThrowable in project Kingdom-Keys-Re-Coded by Wehavecookies56.
the class ItemChakram method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
Entity entity;
switch(weapon) {
case Strings.Ashes:
entity = new EntityAshes(world, player);
break;
case Strings.BlazeofGlory:
entity = new EntityBlazeofGlory(world, player);
break;
case Strings.EternalFlames:
entity = new EntityEternalFlames(world, player);
break;
case Strings.Ifrit:
entity = new EntityIfrit(world, player);
break;
case Strings.Prometheus:
entity = new EntityPrometheus(world, player);
break;
case Strings.Prominence:
entity = new EntityProminence(world, player);
break;
case Strings.MoulinRouge:
entity = new EntityMoulinRouge(world, player);
break;
case Strings.FerrisWheel:
entity = new EntityFerrisWheels(world, player);
break;
case Strings.Combustion:
entity = new EntityCombustion(world, player);
break;
case Strings.Burnout:
entity = new EntityBurnout(world, player);
break;
case Strings.OmegaTrinity:
entity = new EntityOmegaTrinity(world, player);
break;
case Strings.Doldrums:
entity = new EntityDoledrum(world, player);
break;
case Strings.Outbreak:
entity = new EntityOutbreak(world, player);
break;
case Strings.Inferno:
entity = new EntityInferno(world, player);
break;
case Strings.SizzlingEdge:
entity = new EntitySizzlingEdge(world, player);
break;
case Strings.DoubleEdge:
entity = new EntityDoubleEdge(world, player);
break;
default:
entity = new EntityEternalFlames(world, player);
break;
}
if (!player.getCapability(ModCapabilities.PLAYER_STATS, null).getRecharge()) {
if (!player.isSneaking()) {
world.playSound(player.posX, player.posY, player.posZ, SoundEvents.ENTITY_GHAST_SHOOT, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F), false);
world.spawnEntity(entity);
((EntityThrowable) entity).setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0, 1f, 1);
if (!player.getCapability(ModCapabilities.CHEAT_MODE, null).getCheatMode())
player.getCapability(ModCapabilities.PLAYER_STATS, null).remMP(7);
player.swingArm(hand);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, player.getHeldItemMainhand());
}
return ActionResult.newResult(EnumActionResult.FAIL, player.getHeldItemMainhand());
}
Aggregations