Search in sources :

Example 61 with WorldServer

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;
}
Also used : IvTranslations(ivorius.ivtoolkit.tools.IvTranslations) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) java.util(java.util) RayMove(ivorius.reccomplex.world.gen.feature.structure.generic.placement.rays.RayMove) RayMatcher(ivorius.reccomplex.world.gen.feature.structure.generic.placement.rays.RayMatcher) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) TypeToken(com.google.common.reflect.TypeToken) WeightedSelector(ivorius.ivtoolkit.random.WeightedSelector) RayDynamicPosition(ivorius.reccomplex.world.gen.feature.structure.generic.placement.rays.RayDynamicPosition) StructureBoundingBoxes(ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes) Pair(org.apache.commons.lang3.tuple.Pair) Placer(ivorius.reccomplex.world.gen.feature.structure.Placer) LineSelections(ivorius.ivtoolkit.util.LineSelections) WorldServer(net.minecraft.world.WorldServer) Nonnull(javax.annotation.Nonnull) JsonUtils(ivorius.reccomplex.json.JsonUtils) Nullable(javax.annotation.Nullable) WorldCache(ivorius.ivtoolkit.world.WorldCache) RayAverageMatcher(ivorius.reccomplex.world.gen.feature.structure.generic.placement.rays.RayAverageMatcher) LineSelection(ivorius.ivtoolkit.util.LineSelection) SerializedName(com.google.gson.annotations.SerializedName) Collectors(java.util.stream.Collectors) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) GenericPlacerPresets(ivorius.reccomplex.world.gen.feature.structure.generic.presets.GenericPlacerPresets) Type(java.lang.reflect.Type) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) com.google.gson(com.google.gson) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) PresettedObject(ivorius.reccomplex.utils.presets.PresettedObject) LineSelection(ivorius.ivtoolkit.util.LineSelection) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) WorldServer(net.minecraft.world.WorldServer) WorldCache(ivorius.ivtoolkit.world.WorldCache) Pair(org.apache.commons.lang3.tuple.Pair)

Example 62 with WorldServer

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;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer)

Example 63 with WorldServer

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());
    }
}
Also used : WorldServer(net.minecraft.world.WorldServer) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity)

Example 64 with WorldServer

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);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 65 with WorldServer

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);
    }
}
Also used : WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

WorldServer (net.minecraft.world.WorldServer)67 BlockPos (net.minecraft.util.math.BlockPos)24 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 IBlockState (net.minecraft.block.state.IBlockState)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 Entity (net.minecraft.entity.Entity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 World (net.minecraft.world.World)8 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)8 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)7 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)7 Nullable (javax.annotation.Nullable)6 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)5 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)5 StructureSpawnContext (ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)5 Collectors (java.util.stream.Collectors)5 Block (net.minecraft.block.Block)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 Chunk (net.minecraft.world.chunk.Chunk)4 ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)4