use of net.minecraft.server.v1_14_R1.World in project RoseStacker by Rosewood-Development.
the class StackedSpawnerTileImpl method c.
@Override
public void c() {
World level = this.a();
if (level == null)
return;
// Only tick the spawner if a player is nearby
this.playersTimeSinceLastCheck = (this.playersTimeSinceLastCheck + 1) % Setting.SPAWNER_PLAYER_CHECK_FREQUENCY.getInt();
if (this.playersTimeSinceLastCheck == 0)
this.playersNearby = this.isNearPlayer(level, this.blockPos);
if (!this.playersNearby)
return;
SpawnerStackSettings stackSettings = this.stackedSpawner.getStackSettings();
// Handle redstone deactivation if enabled
if (Setting.SPAWNER_DEACTIVATE_WHEN_POWERED.getBoolean()) {
if (this.redstoneTimeSinceLastCheck == 0) {
boolean hasSignal = level.isBlockIndirectlyPowered(this.blockPos);
if (this.redstoneDeactivated && !hasSignal) {
this.redstoneDeactivated = false;
this.requiredPlayerRange = stackSettings.getPlayerActivationRange();
this.updateTile();
} else if (!this.redstoneDeactivated && hasSignal) {
this.redstoneDeactivated = true;
this.requiredPlayerRange = 0;
this.updateTile();
}
if (this.redstoneDeactivated)
return;
}
this.redstoneTimeSinceLastCheck = (this.redstoneTimeSinceLastCheck + 1) % Setting.SPAWNER_POWERED_CHECK_FREQUENCY.getInt();
}
// Count down spawn timer unless we are ready to spawn
if (this.spawnDelay > 0) {
this.spawnDelay--;
return;
}
// Reset spawn delay
this.spawnDelay = level.getRandom().nextInt(this.maxSpawnDelay - this.minSpawnDelay + 1) + this.minSpawnDelay;
this.updateTile();
// Execute spawning method
try {
if (this.spawnData != null) {
MinecraftKey resourceLocation = MinecraftKey.a(this.spawnData.getEntity().getString("id"));
if (resourceLocation != null) {
NamespacedKey namespacedKey = CraftNamespacedKey.fromMinecraft(resourceLocation);
EntityType entityType = this.fromKey(namespacedKey);
if (entityType != null)
new MobSpawningMethod(entityType).spawn(this.stackedSpawner);
}
}
} catch (Exception e) {
e.printStackTrace();
}
// Randomize spawn potentials
if (!this.mobs.isEmpty())
this.setSpawnData(WeightedRandom.a(this.a().random, this.mobs));
}
use of net.minecraft.server.v1_14_R1.World in project RoseStacker by Rosewood-Development.
the class StackedSpawnerTileImpl method updateTile.
private void updateTile() {
World level = this.a();
if (level != null) {
level.b(this.blockPos, this.blockEntity);
IBlockData var1 = this.a().getType(this.b());
this.a().notify(this.blockPos, var1, var1, 3);
}
}
use of net.minecraft.server.v1_14_R1.World in project SSB-OneBlock by BG-Software-LLC.
the class NMSAdapter_v1_8_R3 method setChestName.
@Override
public void setChestName(Location chest, String name) {
World world = ((CraftWorld) chest.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(chest.getBlockX(), chest.getBlockY(), chest.getBlockZ());
TileEntityChest tileEntityChest = (TileEntityChest) world.getTileEntity(blockPosition);
tileEntityChest.a(name);
}
use of net.minecraft.server.v1_14_R1.World in project Frequency by ElevatedDev.
the class InvalidD method process.
@Override
public void process(final Object object) {
if (object instanceof WrappedPlayInFlying) {
final WrappedPlayInFlying wrapper = (WrappedPlayInFlying) object;
if (wrapper.hasPos()) {
// Get position values from wrapper
final double posX = wrapper.getX();
final double posZ = wrapper.getZ();
// Calculate the basic horizontal distance and the acceleration
final double horizontalDistance = MathUtil.magnitude(posX - lastPosX, posZ - lastPosZ);
final double acceleration = Math.abs(horizontalDistance - lastHorizontalDistance);
/*
* The theory is, when the player attacks an entity they get slowed down by 0.6. Here we're simply checking
* if the player had any sort of slowdown when attacking a player. If not, that means that the player's
* motion was not messed with. When that happens, increase a buffer to reduce possible false positives.
*/
motion: {
final Entity target = playerData.getTarget().get();
/*
* The player only gets slowed down in Minecraft when he's hitting another player. Not if
* he is hitting a mob. Thus, we need to make sure that the entity attacked is surely a
* player, and not a mob or this check is going to false to bits since the theory is wrong then,
*/
final boolean exists = target instanceof Player;
final boolean exempt = this.isExempt(ExemptType.TPS, ExemptType.TELEPORTING);
/*
* We don't want to run the check if the player has not attacked or if the entity attacked
* was not a player of if the player did not attack at all. Thus, we're breaking on these scenarios.
*/
if (exempt || !exists || !attacked)
break motion;
/*
* The check only is valid if the player is sprinting, so we also need to make sure that the player'ss
* sprinting status are true, or the check again is not going to work as expected.
*/
final boolean accelerated = acceleration < 1e-04 && horizontalDistance > lastHorizontalDistance * 0.99;
final boolean sprinting = playerData.getSprinting().get();
if (accelerated && sprinting) {
buffer += 0.25;
if (buffer > 1.25)
fail();
} else {
buffer = Math.max(buffer - 0.25, 0);
}
attacked = false;
}
lastHorizontalDistance = horizontalDistance;
lastPosX = posX;
lastPosZ = posZ;
}
} else if (object instanceof WrappedPlayInUseEntity) {
final WrappedPlayInUseEntity wrapper = (WrappedPlayInUseEntity) object;
final EntityPlayer entityPlayer = NmsUtil.getEntityPlayer(playerData);
final World world = entityPlayer.world;
attacked: {
if (wrapper.getAction() != PacketPlayInUseEntity.EnumEntityUseAction.ATTACK)
break attacked;
if (wrapper.getTarget(world) instanceof Player) {
attacked = true;
}
}
}
}
use of net.minecraft.server.v1_14_R1.World in project Citizens2 by CitizensDev.
the class EntityHumanNPC method initialise.
private void initialise(MinecraftServer minecraftServer) {
Socket socket = new EmptySocket();
NetworkManager conn = null;
try {
conn = new EmptyNetworkManager(EnumProtocolDirection.CLIENTBOUND);
playerConnection = new EmptyNetHandler(minecraftServer, conn, this);
conn.setPacketListener(playerConnection);
socket.close();
} catch (IOException e) {
// swallow
}
AttributeInstance range = getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
if (range == null) {
range = getAttributeMap().b(GenericAttributes.FOLLOW_RANGE);
}
range.setValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble());
controllerJump = new PlayerControllerJump(this);
controllerMove = new PlayerControllerMove(this);
navigation = new PlayerNavigation(this, world);
invulnerableTicks = 0;
// the default (0) breaks step climbing
NMS.setStepHeight(getBukkitEntity(), 1);
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancementData());
NMSImpl.setAdvancement(this.getBukkitEntity(), new EmptyAdvancementDataPlayer(minecraftServer, CitizensAPI.getDataFolder().getParentFile(), this));
}
Aggregations