net.minecraft.world.server.ServerWorld Java Examples

The following examples show how to use net.minecraft.world.server.ServerWorld. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenderBlockTileEntity.java    From MiningGadgets with MIT License 6 votes vote down vote up
public void setBlockAllowed() {
    if (!UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.VOID_JUNK)) {
        this.blockAllowed = true;
        return;
    }
    PlayerEntity player = world.getPlayerByUuid(playerUUID);
    if (player == null) return;
    int silk = 0;
    int fortune = 0;

    ItemStack tempTool = new ItemStack(ModItems.MININGGADGET.get());

    // If silk is in the upgrades, apply it without a tier.
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.SILK)) {
        tempTool.addEnchantment(Enchantments.SILK_TOUCH, 1);
        silk = 1;
    }

    // FORTUNE_1 is eval'd against the basename so this'll support all fortune upgrades
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1)) {
        Optional<Upgrade> upgrade = UpgradeTools.getUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1);
        if (upgrade.isPresent()) {
            fortune = upgrade.get().getTier();
            tempTool.addEnchantment(Enchantments.FORTUNE, fortune);
        }
    }

    List<ItemStack> drops = Block.getDrops(renderBlock, (ServerWorld) world, this.pos, null, player, tempTool);

    this.blockAllowed = blockAllowed(drops, getGadgetFilters(), isGadgetIsWhitelist());
}
 
Example #2
Source File: ForgeMod.java    From BlueMap with MIT License 5 votes vote down vote up
private void onBlockChange(BlockEvent evt) {
	if (!(evt.getWorld() instanceof ServerWorld)) return;
	
	try {
		UUID world = getUUIDForWorld((ServerWorld) evt.getWorld());
		Vector3i position = new Vector3i(
				evt.getPos().getX(),
				evt.getPos().getY(),
				evt.getPos().getZ()
			);
		
		for (ServerEventListener listener : eventListeners) listener.onBlockChange(world, position);
		
	} catch (IOException ignore) {}
}
 
Example #3
Source File: ForgeMod.java    From BlueMap with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldSave(WorldEvent.Save evt) {
	if (!(evt.getWorld() instanceof ServerWorld)) return;
	
	try {
		UUID world = getUUIDForWorld((ServerWorld) evt.getWorld());
		
		for (ServerEventListener listener : eventListeners) listener.onWorldSaveToDisk(world);
		
	} catch (IOException ignore) {}
}
 
Example #4
Source File: ForgeMod.java    From BlueMap with MIT License 5 votes vote down vote up
public UUID getUUIDForWorld(ServerWorld world) throws IOException {
	synchronized (worldUUIDs) {
		String key = getFolderForWorld(world).getPath();
		
		UUID uuid = worldUUIDs.get(key);
		if (uuid == null) {
			uuid = UUID.randomUUID();
			worldUUIDs.put(key, uuid);
		}
		
		return uuid;
	}
}
 
Example #5
Source File: ForgeCommandSource.java    From BlueMap with MIT License 5 votes vote down vote up
@Override
public Optional<World> getWorld() {
	try {
		ServerWorld world = delegate.getWorld();
		if (world != null) {
			return Optional.ofNullable(plugin.getWorld(mod.getUUIDForWorld(world)));
		}
	} catch (IOException ignore) {}
	
	return Optional.empty();
}
 
Example #6
Source File: RenderBlockTileEntity.java    From MiningGadgets with MIT License 5 votes vote down vote up
private void removeBlock() {
    if(world == null || world.isRemote)
        return;

    PlayerEntity player = world.getPlayerByUuid(playerUUID);
    if (player == null)
        return;

    int silk = 0;
    int fortune = 0;

    ItemStack tempTool = new ItemStack(ModItems.MININGGADGET.get());

    // If silk is in the upgrades, apply it without a tier.
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.SILK)) {
        tempTool.addEnchantment(Enchantments.SILK_TOUCH, 1);
        silk = 1;
    }

    // FORTUNE_1 is eval'd against the basename so this'll support all fortune upgrades
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1)) {
        Optional<Upgrade> upgrade = UpgradeTools.getUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1);
        if (upgrade.isPresent()) {
            fortune = upgrade.get().getTier();
            tempTool.addEnchantment(Enchantments.FORTUNE, fortune);
        }
    }

    List<ItemStack> drops = Block.getDrops(renderBlock, (ServerWorld) world, this.pos, null, player, tempTool);

    if ( blockAllowed ) {
        int exp = renderBlock.getExpDrop(world, pos, fortune, silk);
        boolean magnetMode = (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.MAGNET));
        for (ItemStack drop : drops) {
            if (drop != null) {
                if (magnetMode) {
                    int wasPickedUp = ForgeEventFactory.onItemPickup(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), drop), player);
                    // 1  = someone allowed the event meaning it's handled,
                    // -1 = someone blocked the event and thus we shouldn't drop it nor insert it
                    // 0  = no body captured the event and we should handle it by hand.
                    if( wasPickedUp == 0 ) {
                        if (!player.addItemStackToInventory(drop))
                            Block.spawnAsEntity(world, pos, drop);
                    }
                } else {
                    Block.spawnAsEntity(world, pos, drop);
                }
            }
        }
        if (magnetMode) {
            if (exp > 0)
                player.giveExperiencePoints(exp);
        } else {
            if (exp > 0)
                renderBlock.getBlock().dropXpOnBlockBreak(world, pos, exp);
        }

        renderBlock.spawnAdditionalDrops(world, pos, tempTool); // Fixes silver fish basically...
    }

    world.removeTileEntity(this.pos);
    world.setBlockState(this.pos, Blocks.AIR.getDefaultState());

    // Add to the break stats
    player.addStat(Stats.BLOCK_MINED.get(renderBlock.getBlock()));

    // Handle special cases
    if(SpecialBlockActions.getRegister().containsKey(renderBlock.getBlock()))
        SpecialBlockActions.getRegister().get(renderBlock.getBlock()).accept(world, pos, renderBlock);
}
 
Example #7
Source File: ForgeMod.java    From BlueMap with MIT License 4 votes vote down vote up
private void registerWorld(ServerWorld world) throws IOException {
	getUUIDForWorld(world);
}
 
Example #8
Source File: ICustomParticleBlock.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
default boolean addLandingEffects(BlockState state1, ServerWorld worldserver, BlockPos pos, BlockState state2, LivingEntity entity, int numberOfParticles) {
    CustomParticleHandler.handleLandingEffects(worldserver, pos, entity, numberOfParticles);
    return true;
}
 
Example #9
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void sendToChunk(IPacket<?> packet, World world, ChunkPos pos) {
    ServerWorld serverWorld = (ServerWorld) world;
    serverWorld.getChunkProvider().chunkManager.getTrackingPlayers(pos, false).forEach(e -> e.connection.sendPacket(packet));
}
 
Example #10
Source File: ChoppingBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private boolean interceptClick(World worldIn, BlockPos pos, BlockState state, PlayerEntity playerIn)
{
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (!(tileentity instanceof ChoppingBlockTileEntity))
        return false;

    ChoppingBlockTileEntity chopper = (ChoppingBlockTileEntity) tileentity;
    if (chopper.getSlotInventory().getStackInSlot(0).getCount() <= 0)
        return false;

    if (worldIn.isRemote)
        return true;

    ItemStack heldItem = playerIn.getHeldItem(Hand.MAIN_HAND);

    int harvestLevel = heldItem.getItem().getHarvestLevel(heldItem, ToolType.AXE, playerIn, null);
    ActionResult<ItemStack> result = chopper.chop(playerIn, harvestLevel, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, heldItem));
    if (result.getType() == ActionResultType.SUCCESS)
    {
        if (worldIn.rand.nextFloat() < ConfigManager.SERVER.choppingDegradeChance.get())
        {
            worldIn.setBlockState(pos, breaksInto.get());
        }

        if (ConfigManager.SERVER.choppingExhaustion.get() > 0)
            playerIn.addExhaustion(ConfigManager.SERVER.choppingExhaustion.get().floatValue());

        if (heldItem.getCount() > 0 && !playerIn.abilities.isCreativeMode)
        {
            heldItem.damageItem(1, playerIn, (stack) -> {
                stack.sendBreakAnimation(Hand.MAIN_HAND);
            });
        }
    }
    if (result.getType() != ActionResultType.PASS)
    {
        ((ServerWorld) worldIn).spawnParticle(new ItemParticleData(ParticleTypes.ITEM, result.getResult()),
                pos.getX() + 0.5, pos.getY() + 0.6, pos.getZ() + 0.5, 8,
                0, 0.1, 0, 0.02);
    }

    return true;
}
 
Example #11
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Call from {@link Block#addLandingEffects}
 * Provided the model bound is an instance of IModelParticleProvider, you will have landing particles just handled for you.
 *
 * @param world        The world.
 * @param pos          The position of the block.
 * @param entity       The entity.
 * @param numParticles The number of particles to spawn.
 * @return Always true for this, basically just return the result of this method inside {@link Block#addLandingEffects}
 */
public static boolean handleLandingEffects(ServerWorld world, BlockPos pos, LivingEntity entity, int numParticles) {
    PacketCustom packet = new PacketCustom(CCLNetwork.NET_CHANNEL, C_ADD_LANDING_EFFECTS);
    packet.writePos(pos);
    packet.writeVector(Vector3.fromEntity(entity));
    packet.writeVarInt(numParticles);
    packet.sendToPlayer((ServerPlayerEntity) entity);
    return true;
}