use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class NetherPortalBlockMixin method arclight$portalEnter.
@Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPortal(Lnet/minecraft/util/math/BlockPos;)V"))
public void arclight$portalEnter(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) {
EntityPortalEnterEvent event = new EntityPortalEnterEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), new Location(((WorldBridge) worldIn).bridge$getWorld(), pos.getX(), pos.getY(), pos.getZ()));
Bukkit.getPluginManager().callEvent(event);
}
use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class SlimeEntityMixin method remove.
// @formatter:on
/**
* @author IzzelAliz
* @reason
*/
@Overwrite(remap = false)
@Override
public void remove(boolean keepData) {
int i = this.getSlimeSize();
if (!this.world.isRemote && i > 1 && this.getHealth() <= 0.0f) {
int j = 2 + this.rand.nextInt(3);
SlimeSplitEvent event = new SlimeSplitEvent((Slime) this.getBukkitEntity(), j);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled() || event.getCount() <= 0) {
super.remove(keepData);
return;
}
j = event.getCount();
List<LivingEntity> slimes = new ArrayList<>(j);
for (int k = 0; k < j; ++k) {
float f = (k % 2 - 0.5f) * i / 4.0f;
float f2 = (k / 2 - 0.5f) * i / 4.0f;
SlimeEntity entityslime = this.getType().create(this.world);
if (this.hasCustomName()) {
entityslime.setCustomName(this.getCustomName());
}
if (this.isNoDespawnRequired()) {
entityslime.enablePersistence();
}
entityslime.setInvulnerable(this.isInvulnerable());
entityslime.setSlimeSize(i / 2, true);
entityslime.setLocationAndAngles(this.posX + f, this.posY + 0.5, this.posZ + f2, this.rand.nextFloat() * 360.0f, 0.0f);
slimes.add(entityslime);
}
if (CraftEventFactory.callEntityTransformEvent((SlimeEntity) (Object) this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) {
return;
}
for (LivingEntity living : slimes) {
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SLIME_SPLIT);
this.world.addEntity(living);
}
}
super.remove(keepData);
}
use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class PlayerEntityMixin_1_15 method arclight$wakeup.
@Inject(method = "stopSleepInBed", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;sleepTimer:I"))
private void arclight$wakeup(boolean flag, boolean flag1, CallbackInfo ci) {
BlockPos blockPos = this.getBedPosition().orElse(null);
if (this.bridge$getBukkitEntity() instanceof Player) {
Player player = (Player) this.bridge$getBukkitEntity();
Block bed;
if (blockPos != null) {
bed = CraftBlock.at(this.world, blockPos);
} else {
bed = ((WorldBridge) this.world).bridge$getWorld().getBlockAt(player.getLocation());
}
PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed, true);
Bukkit.getPluginManager().callEvent(event);
}
}
use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class EggEntityMixin method onImpact.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
protected void onImpact(final RayTraceResult movingobjectposition) {
if (movingobjectposition.getType() == RayTraceResult.Type.ENTITY) {
((EntityRayTraceResult) movingobjectposition).getEntity().attackEntityFrom(DamageSource.causeThrownDamage((EggEntity) (Object) this, this.getThrower()), 0.0f);
}
if (!this.world.isRemote) {
boolean hatching = this.rand.nextInt(8) == 0;
byte b0 = 1;
if (this.rand.nextInt(32) == 0) {
b0 = 4;
}
if (!hatching) {
b0 = 0;
}
org.bukkit.entity.EntityType hatchingType = org.bukkit.entity.EntityType.CHICKEN;
final Entity shooter = this.getThrower();
if (shooter instanceof ServerPlayerEntity) {
final PlayerEggThrowEvent event = new PlayerEggThrowEvent(((ServerPlayerEntityBridge) shooter).bridge$getBukkitEntity(), (Egg) this.getBukkitEntity(), hatching, b0, hatchingType);
Bukkit.getPluginManager().callEvent(event);
b0 = event.getNumHatches();
hatching = event.isHatching();
hatchingType = event.getHatchingType();
}
if (hatching) {
for (int i = 0; i < b0; ++i) {
Entity entity = ((CraftEntity) ((WorldBridge) this.world).bridge$getWorld().spawnEntity(new Location(((WorldBridge) this.world).bridge$getWorld(), this.posX, this.posY, this.posZ, this.rotationYaw, 0.0f), hatchingType)).getHandle();
if (((EntityBridge) entity).bridge$getBukkitEntity() instanceof Ageable) {
((Ageable) ((EntityBridge) entity).bridge$getBukkitEntity()).setBaby();
}
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.EGG);
this.world.getWorld().addEntity(entity);
}
}
this.world.setEntityState((EggEntity) (Object) this, (byte) 3);
this.remove();
}
}
use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class ServerChunkProviderMixin method tickChunks.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private void tickChunks() {
long i = this.world.getGameTime();
long j = i - this.lastGameTime;
this.lastGameTime = i;
WorldInfo worldinfo = this.world.getWorldInfo();
boolean flag = worldinfo.getGenerator() == WorldType.DEBUG_ALL_BLOCK_STATES;
boolean flag1 = this.world.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING) && !this.world.getPlayers().isEmpty();
if (!flag) {
this.world.getProfiler().startSection("pollingChunks");
int k = this.world.getGameRules().getInt(GameRules.RANDOM_TICK_SPEED);
BlockPos blockpos = this.world.getSpawnPoint();
boolean spawnAnimal = ((WorldBridge) this.world).bridge$ticksPerAnimalSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerAnimalSpawns() == 0;
boolean spawnMonster = ((WorldBridge) this.world).bridge$ticksPerMonsterSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerMonsterSpawns() == 0;
boolean spawnWater = ((WorldBridge) this.world).bridge$ticksPerWaterSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerWaterSpawns() == 0;
boolean spawnAmbient = ((WorldBridge) this.world).bridge$ticksPerAmbientSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerAmbientSpawns() == 0;
boolean flag2 = spawnAnimal;
this.world.getProfiler().startSection("naturalSpawnCount");
int l = this.ticketManager.getSpawningChunksCount();
EntityClassification[] aentityclassification = EntityClassification.values();
Object2IntMap<EntityClassification> object2intmap = this.world.countEntities();
this.world.getProfiler().endSection();
((ChunkManagerBridge) this.chunkManager).bridge$getLoadedChunksIterable().forEach((p_223434_10_) -> {
Optional<Chunk> optional = p_223434_10_.getEntityTickingFuture().getNow(ChunkHolder.UNLOADED_CHUNK).left();
if (optional.isPresent()) {
Chunk chunk = optional.get();
this.world.getProfiler().startSection("broadcast");
p_223434_10_.sendChanges(chunk);
this.world.getProfiler().endSection();
ChunkPos chunkpos = p_223434_10_.getPosition();
if (!((ChunkManagerBridge) this.chunkManager).bridge$isOutsideSpawningRadius(chunkpos)) {
chunk.setInhabitedTime(chunk.getInhabitedTime() + j);
if (flag1 && (this.spawnHostiles || this.spawnPassives) && this.world.getWorldBorder().contains(chunk.getPos())) {
this.world.getProfiler().startSection("spawner");
for (EntityClassification entityclassification : aentityclassification) {
boolean spawnThisTick = true;
int limit = entityclassification.getMaxNumberOfCreature();
switch(entityclassification) {
case MONSTER:
spawnThisTick = spawnMonster;
limit = ((WorldBridge) world).bridge$getWorld().getMonsterSpawnLimit();
break;
case CREATURE:
spawnThisTick = spawnAnimal;
limit = ((WorldBridge) world).bridge$getWorld().getAnimalSpawnLimit();
break;
case WATER_CREATURE:
spawnThisTick = spawnWater;
limit = ((WorldBridge) world).bridge$getWorld().getWaterAnimalSpawnLimit();
break;
case AMBIENT:
spawnThisTick = spawnAmbient;
limit = ((WorldBridge) world).bridge$getWorld().getAmbientSpawnLimit();
break;
}
if (!spawnThisTick || limit == 0) {
continue;
}
if (entityclassification != EntityClassification.MISC && (!entityclassification.getPeacefulCreature() || this.spawnPassives) && (entityclassification.getPeacefulCreature() || this.spawnHostiles) && (!entityclassification.getAnimal() || flag2)) {
int i1 = limit * l / field_217238_b;
if (object2intmap.getInt(entityclassification) <= i1) {
this.bridge$worldNaturalSpawn(entityclassification, this.world, chunk, blockpos);
}
}
}
this.world.getProfiler().endSection();
}
this.world.tickEnvironment(chunk, k);
}
}
});
this.world.getProfiler().startSection("customSpawners");
if (flag1) {
this.generator.spawnMobs(this.world, this.spawnHostiles, this.spawnPassives);
}
this.world.getProfiler().endSection();
this.world.getProfiler().endSection();
}
((ChunkManagerBridge) this.chunkManager).bridge$tickEntityTracker();
}
Aggregations