Search in sources :

Example 96 with WorldServer

use of net.minecraft.world.WorldServer in project MC-Prefab by Brian-Wuest.

the class StructureHandler method onMessage.

@Override
public IMessage onMessage(final StructureTagMessage message, final MessageContext ctx) {
    // Or Minecraft.getMinecraft() on the client.
    IThreadListener mainThread = (WorldServer) ctx.getServerHandler().player.world;
    mainThread.addScheduledTask(new Runnable() {

        @Override
        public void run() {
            // This is server side. Build the structure.
            EnumStructureConfiguration structureConfig = message.getStructureConfig();
            StructureConfiguration configuration = structureConfig.structureConfig.ReadFromNBTTagCompound(message.getMessageTag());
            configuration.BuildStructure(ctx.getServerHandler().player, ctx.getServerHandler().player.world);
        }
    });
    // no response in this case
    return null;
}
Also used : StructureConfiguration(com.wuest.prefab.Config.Structures.StructureConfiguration) EnumStructureConfiguration(com.wuest.prefab.Proxy.Messages.StructureTagMessage.EnumStructureConfiguration) IThreadListener(net.minecraft.util.IThreadListener) WorldServer(net.minecraft.world.WorldServer) EnumStructureConfiguration(com.wuest.prefab.Proxy.Messages.StructureTagMessage.EnumStructureConfiguration)

Example 97 with WorldServer

use of net.minecraft.world.WorldServer in project Galacticraft by micdoodle8.

the class EntityTieredRocket method onUpdate.

@Override
public void onUpdate() {
    if (this.getWaitForPlayer()) {
        if (this.riddenByEntity != null) {
            if (this.ticks >= 40) {
                if (!this.worldObj.isRemote) {
                    Entity e = this.riddenByEntity;
                    e.mountEntity(null);
                    e.mountEntity(this);
                    GCLog.debug("Remounting player in rocket.");
                }
                this.setWaitForPlayer(false);
                this.motionY = -0.5D;
            } else {
                this.motionX = this.motionY = this.motionZ = 0.0D;
                this.riddenByEntity.motionX = this.riddenByEntity.motionY = this.riddenByEntity.motionZ = 0;
            }
        } else {
            this.motionX = this.motionY = this.motionZ = 0.0D;
        }
    }
    super.onUpdate();
    if (!this.worldObj.isRemote) {
        if (this.launchCooldown > 0) {
            this.launchCooldown--;
        }
        if (this.preGenIterator != null) {
            if (this.preGenIterator.hasNext()) {
                MinecraftServer mcserver;
                if (this.worldObj instanceof WorldServer) {
                    mcserver = ((WorldServer) this.worldObj).getMinecraftServer();
                    BlockVec3 coords = this.preGenIterator.next();
                    World w = mcserver.worldServerForDimension(coords.y);
                    if (w != null) {
                        w.getChunkFromChunkCoords(coords.x, coords.z);
                        // Pregen a second chunk if still on launchpad (low strain on server)
                        if (this.launchPhase < EnumLaunchPhase.LAUNCHED.ordinal() && this.preGenIterator.hasNext()) {
                            coords = this.preGenIterator.next();
                            w = mcserver.worldServerForDimension(coords.y);
                            w.getChunkFromChunkCoords(coords.x, coords.z);
                        }
                    }
                }
            } else {
                this.preGenIterator = null;
                EntityTieredRocket.preGenInProgress = false;
            }
        }
    }
    if (this.rumble > 0) {
        this.rumble--;
    } else if (this.rumble < 0) {
        this.rumble++;
    }
    if (this.riddenByEntity != null) {
        final double rumbleAmount = this.rumble / (double) (37 - 5 * Math.max(this.getRocketTier(), 5));
        this.riddenByEntity.posX += rumbleAmount;
        this.riddenByEntity.posZ += rumbleAmount;
    }
    if (this.launchPhase >= EnumLaunchPhase.IGNITED.ordinal()) {
        this.performHurtAnimation();
        this.rumble = (float) this.rand.nextInt(3) - 3;
    }
    if (!this.worldObj.isRemote) {
        this.lastLastMotionY = this.lastMotionY;
        this.lastMotionY = this.motionY;
    }
}
Also used : ICameraZoomEntity(micdoodle8.mods.galacticraft.api.entity.ICameraZoomEntity) Entity(net.minecraft.entity.Entity) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 98 with WorldServer

use of net.minecraft.world.WorldServer in project Ceramics by KnightMiner.

the class TileFaucet method reset.

protected void reset() {
    isPouring = false;
    stopPouring = false;
    drained = null;
    // invalid direction
    direction = EnumFacing.DOWN;
    lastRedstoneState = false;
    // sync to clients
    if (getWorld() != null && !getWorld().isRemote && getWorld() instanceof WorldServer) {
        CeramicsNetwork.sendToClients((WorldServer) getWorld(), pos, new FluidUpdatePacket(pos, null));
    }
}
Also used : FluidUpdatePacket(knightminer.ceramics.network.FluidUpdatePacket) WorldServer(net.minecraft.world.WorldServer)

Example 99 with WorldServer

use of net.minecraft.world.WorldServer in project Wizardry by TeamWizardry.

the class BlockUtils method breakBlock.

/**
 * Tries breaking a block safely and fires an event for it.
 *
 * @return Whether the block was successfully broken
 */
public static boolean breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nullable IBlockState oldState, @Nullable EntityPlayerMP player, boolean drop) {
    if (!world.isBlockLoaded(pos))
        return false;
    EntityPlayerMP playerMP;
    if (player == null) {
        playerMP = new FakePlayer((WorldServer) world, breaker);
        playerMP.setPosition(pos.getX(), pos.getY(), pos.getZ());
    } else
        playerMP = player;
    if (player != null && !(player instanceof FakePlayer))
        if (!hasBreakPermission(world, pos, playerMP))
            return false;
    if (oldState == null)
        oldState = world.getBlockState(pos);
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, oldState, playerMP);
    MinecraftForge.EVENT_BUS.post(event);
    return !event.isCanceled() && (drop ? world.destroyBlock(pos, true) : world.setBlockToAir(pos));
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) BlockEvent(net.minecraftforge.event.world.BlockEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 100 with WorldServer

use of net.minecraft.world.WorldServer in project BuildCraft by BuildCraft.

the class BptBuilderBase method isBlockPlaceCanceled.

protected boolean isBlockPlaceCanceled(World world, BlockPos pos, SchematicBlockBase schematic) {
    IBlockState state = schematic instanceof SchematicBlock ? ((SchematicBlock) schematic).state : Blocks.STONE.getDefaultState();
    EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) world, pos).get();
    BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(new BlockSnapshot(world, pos, state), Blocks.AIR.getDefaultState(), player);
    MinecraftForge.EVENT_BUS.post(placeEvent);
    return placeEvent.isCanceled();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Aggregations

WorldServer (net.minecraft.world.WorldServer)338 BlockPos (net.minecraft.util.math.BlockPos)101 EntityPlayer (net.minecraft.entity.player.EntityPlayer)63 ItemStack (net.minecraft.item.ItemStack)55 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)51 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)47 Entity (net.minecraft.entity.Entity)44 TileEntity (net.minecraft.tileentity.TileEntity)42 IBlockState (net.minecraft.block.state.IBlockState)39 MinecraftServer (net.minecraft.server.MinecraftServer)36 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)32 World (net.minecraft.world.World)29 Block (net.minecraft.block.Block)28 EntityLivingBase (net.minecraft.entity.EntityLivingBase)28 ArrayList (java.util.ArrayList)20 PotionEffect (net.minecraft.potion.PotionEffect)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 Nullable (javax.annotation.Nullable)17 Chunk (net.minecraft.world.chunk.Chunk)16 World (org.spongepowered.api.world.World)14