use of net.minecraft.world.WorldServer in project RecurrentComplex by Ivorforce.
the class GenericPlacer method place.
@Override
public int place(StructurePlaceContext context, @Nullable IvBlockCollection blockCollection) {
if (factors.isEmpty())
return DONT_GENERATE;
WorldServer world = context.environment.world;
WorldCache cache = new WorldCache(world, StructureBoundingBoxes.wholeHeightBoundingBox(world, context.boundingBox));
LineSelection considerable = LineSelection.fromRange(new IntegerRange(0, world.getHeight() - context.boundingBox.getYSize()), true);
List<Pair<LineSelection, Float>> considerations = new ArrayList<>();
factors.forEach(factor -> {
List<Pair<LineSelection, Float>> consideration = factor.consider(cache, considerable, blockCollection, context);
consideration.stream().filter(p -> p.getRight() <= 0).forEach(p -> considerable.set(p.getLeft(), true, false));
consideration = consideration.stream().filter(p -> p.getRight() > 0).collect(Collectors.toList());
considerable.set(LineSelections.combine(consideration.stream().map(Pair::getLeft), true), false, false);
considerations.addAll(consideration);
});
Set<Pair<Integer, Double>> applicable = considerable.streamElements(null, true).mapToObj(y -> Pair.of(y, considerations.stream().mapToDouble(pair -> pair.getLeft().isSectionAdditive(pair.getLeft().sectionForIndex(y)) ? pair.getRight() : 1).reduce(1f, (left, right) -> left * right))).filter(p -> p.getRight() > 0).collect(Collectors.toSet());
return applicable.size() > 0 ? WeightedSelector.select(context.random, applicable, Pair::getRight).getLeft() : DONT_GENERATE;
}
use of net.minecraft.world.WorldServer in project Railcraft by Railcraft.
the class TileFeedStation method feedAnimal.
private boolean feedAnimal(EntityAnimal animal) {
if (animal == null) {
return false;
}
try {
if (animal.getGrowingAge() == 0 && !animal.isInLove()) {
EntityPlayer player;
if (Game.isHost(worldObj)) {
EntityAIMateBreeding.modifyAI(animal);
player = RailcraftFakePlayer.get((WorldServer) worldObj, getPos());
} else {
player = null;
}
//noinspection ConstantConditions
animal.setInLove(player);
for (int i = 0; i < 7; i++) {
double d = rand.nextGaussian() * 0.02D;
double d1 = rand.nextGaussian() * 0.02D;
double d2 = rand.nextGaussian() * 0.02D;
worldObj.spawnParticle(HEART, (animal.posX + rand.nextFloat() * animal.width * 2.0F) - animal.width, animal.posY + 0.5D + rand.nextFloat() * animal.height, (animal.posZ + rand.nextFloat() * animal.width * 2.0F) - animal.width, d, d1, d2);
}
return true;
}
} catch (Throwable ex) {
Game.log(Level.ERROR, "Feed Station encountered error, {0}", ex);
}
return false;
}
use of net.minecraft.world.WorldServer in project Railcraft by Railcraft.
the class PacketBuilder method sendTileEntityPacket.
public void sendTileEntityPacket(TileEntity tile) {
if (tile.getWorld() instanceof WorldServer) {
WorldServer world = (WorldServer) tile.getWorld();
SPacketUpdateTileEntity packet = tile.getUpdatePacket();
if (packet != null)
PacketDispatcher.sendToWatchers(packet, world, tile.getPos().getX(), tile.getPos().getZ());
}
}
use of net.minecraft.world.WorldServer in project Railcraft by Railcraft.
the class SchematicMask method placeInWorld.
@Override
public void placeInWorld(IBuilderContext context, BlockPos pos, List<ItemStack> stacks) {
if (isConcrete) {
if (stacks.size() == 0 || !BuildCraftAPI.isSoftBlock(context.world(), pos)) {
return;
} else {
ItemStack stack = stacks.get(0);
EntityPlayer player = BuildCraftAPI.fakePlayerProvider.getBuildCraftPlayer((WorldServer) context.world()).get();
// force the block to be air block, in case it's just a soft
// block which replacement is not straightforward
context.world().setBlockToAir(pos);
// Find nearest solid surface to place on
EnumFacing solidFace = null;
for (EnumFacing face : EnumFacing.values()) {
BlockPos offset = pos.offset(face);
if (!BuildCraftAPI.isSoftBlock(context.world(), offset)) {
solidFace = face;
break;
}
}
ItemBlock itemBlock = (ItemBlock) stack.getItem();
IBlockState state = itemBlock.block.onBlockPlaced(context.world(), pos, solidFace, 0, 0, 0, stack.getMetadata(), player);
itemBlock.placeBlockAt(stack, player, context.world(), pos, solidFace, 0, 0, 0, state);
}
} else {
context.world().setBlockToAir(pos);
}
}
use of net.minecraft.world.WorldServer in project Witchworks by Um-Mitternacht.
the class TileFluidInventory method particleServerSide.
void particleServerSide(EnumParticleTypes particle, double x, double y, double z, double xOffset, double yOffset, double zOffset, int count) {
if (world instanceof WorldServer) {
BlockPos pos = getPos();
((WorldServer) world).spawnParticle(particle, pos.getX() + x, pos.getY() + y, pos.getZ() + z, count, xOffset, yOffset, zOffset, 0D);
}
}
Aggregations