Search in sources :

Example 1 with GameMode

use of net.minecraft.world.GameMode in project LuckPerms by lucko.

the class FabricPlayerCalculator method calculate.

@Override
public void calculate(@NonNull ServerPlayerEntity target, @NonNull ContextConsumer consumer) {
    GameMode mode = target.interactionManager.getGameMode();
    // GameMode.NOT_SET with ID -1 was removed in 1.17
    final int GAME_MODE_NOT_SET = -1;
    if (this.gamemode && mode != null && mode.getId() != GAME_MODE_NOT_SET) {
        consumer.accept(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
    }
    // TODO: figure out dimension type context too
    ServerWorld world = target.getWorld();
    if (this.world) {
        this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(getContextKey(world.getRegistryKey().getValue()), consumer);
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) GameMode(net.minecraft.world.GameMode)

Example 2 with GameMode

use of net.minecraft.world.GameMode in project VeinMining by TheIllusiveC4.

the class VeinMiningLogic method harvest.

public static boolean harvest(ServerPlayerEntity player, BlockPos pos, BlockPos originPos) {
    ServerWorld world = player.getWorld();
    BlockState blockState = world.getBlockState(pos);
    GameMode gameMode = player.interactionManager.getGameMode();
    if (!player.getMainHandStack().getItem().canMine(blockState, world, pos, player)) {
        return false;
    } else {
        BlockEntity blockEntity = world.getBlockEntity(pos);
        Block block = blockState.getBlock();
        if ((block instanceof CommandBlock || block instanceof StructureBlock || block instanceof JigsawBlock) && !player.isCreativeLevelTwoOp()) {
            world.updateListeners(pos, blockState, blockState, 3);
            return false;
        } else if (player.isBlockBreakingRestricted(world, pos, gameMode)) {
            return false;
        } else {
            block.onBreak(world, pos, blockState, player);
            boolean bl = world.removeBlock(pos, false);
            if (bl) {
                block.onBroken(world, pos, blockState);
            }
            if (gameMode != GameMode.CREATIVE) {
                ItemStack itemStack = player.getMainHandStack();
                ItemStack itemStack2 = itemStack.copy();
                boolean bl2 = player.canHarvest(blockState);
                if (VeinMiningConfig.VeinMining.addToolDamage) {
                    postMine(itemStack, world, blockState, pos, player);
                }
                BlockPos spawnPos = VeinMiningConfig.VeinMining.relocateDrops ? originPos : pos;
                if (bl && bl2) {
                    afterBreak(block, world, player, pos, spawnPos, blockState, blockEntity, itemStack2);
                }
            }
            return true;
        }
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) JigsawBlock(net.minecraft.block.JigsawBlock) GameMode(net.minecraft.world.GameMode) BlockState(net.minecraft.block.BlockState) StructureBlock(net.minecraft.block.StructureBlock) CommandBlock(net.minecraft.block.CommandBlock) Block(net.minecraft.block.Block) JigsawBlock(net.minecraft.block.JigsawBlock) StructureBlock(net.minecraft.block.StructureBlock) BlockPos(net.minecraft.util.math.BlockPos) CommandBlock(net.minecraft.block.CommandBlock) ItemStack(net.minecraft.item.ItemStack) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 3 with GameMode

use of net.minecraft.world.GameMode in project ImmersivePortalsMod by qouteall.

the class MyGameRenderer method renderPlayerItself.

private void renderPlayerItself(Vec3d playerPos, Vec3d playerLastTickPos, float patialTicks) {
    EntityRenderDispatcher entityRenderDispatcher = ((IEWorldRenderer) mc.worldRenderer).getEntityRenderDispatcher();
    PlayerListEntry playerListEntry = CHelper.getClientPlayerListEntry();
    GameMode originalGameMode = MyRenderHelper.originalGameMode;
    Entity player = mc.cameraEntity;
    assert player != null;
    Vec3d oldPos = player.getPos();
    Vec3d oldLastTickPos = McHelper.lastTickPosOf(player);
    GameMode oldGameMode = playerListEntry.getGameMode();
    Helper.setPosAndLastTickPos(player, playerPos, playerLastTickPos);
    ((IEPlayerListEntry) playerListEntry).setGameMode(originalGameMode);
    entityRenderDispatcher.render(player, patialTicks, false);
    Helper.setPosAndLastTickPos(player, oldPos, oldLastTickPos);
    ((IEPlayerListEntry) playerListEntry).setGameMode(oldGameMode);
}
Also used : GameMode(net.minecraft.world.GameMode) Entity(net.minecraft.entity.Entity) IEWorldRenderer(com.qouteall.immersive_portals.ducks.IEWorldRenderer) IEPlayerListEntry(com.qouteall.immersive_portals.ducks.IEPlayerListEntry) PlayerListEntry(net.minecraft.client.network.PlayerListEntry) IEPlayerListEntry(com.qouteall.immersive_portals.ducks.IEPlayerListEntry) Vec3d(net.minecraft.util.math.Vec3d) EntityRenderDispatcher(net.minecraft.client.render.entity.EntityRenderDispatcher) BlockEntityRenderDispatcher(net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher)

Example 4 with GameMode

use of net.minecraft.world.GameMode in project Moonfix by Kingdom-of-Moon.

the class MinecraftClientMixin method hasOutline.

@Inject(at = @At("RETURN"), method = "hasOutline", cancellable = true)
private void hasOutline(Entity entity, CallbackInfoReturnable<Boolean> cir) {
    // button not pressed or already true, return
    if (!this.options.spectatorOutlinesKey.isPressed() || cir.getReturnValue())
        return;
    // entity detection
    int config = (int) Config.HIGHLIGHT_ENTITY.value;
    if (config == 0 && entity.getType() != EntityType.PLAYER || config == 1 && !(entity instanceof LivingEntity))
        return;
    // gamemode detection and return
    config = (int) Config.HIGHLIGHT.value;
    GameMode gamemode = this.getNetworkHandler().getPlayerListEntry(this.player.getUuid()).getGameMode();
    if (config == 2 || (gamemode == GameMode.CREATIVE && config == 1) || gamemode == GameMode.SPECTATOR) {
        cir.setReturnValue(true);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) GameMode(net.minecraft.world.GameMode) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with GameMode

use of net.minecraft.world.GameMode in project LuckPerms by lucko.

the class FabricPlayerCalculator method estimatePotentialContexts.

@Override
@NotNull
@NonNull
public ContextSet estimatePotentialContexts() {
    ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
    if (this.gamemode) {
        for (GameMode mode : GameMode.values()) {
            builder.add(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
        }
    }
    // TODO: dimension type
    Optional<MinecraftServer> server = this.plugin.getBootstrap().getServer();
    if (this.world && server.isPresent()) {
        Iterable<ServerWorld> worlds = server.get().getWorlds();
        for (ServerWorld world : worlds) {
            String worldName = getContextKey(world.getRegistryKey().getValue());
            if (Context.isValidValue(worldName)) {
                builder.add(DefaultContextKeys.WORLD_KEY, worldName);
            }
        }
    }
    return builder.build();
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) GameMode(net.minecraft.world.GameMode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) MinecraftServer(net.minecraft.server.MinecraftServer) NonNull(org.checkerframework.checker.nullness.qual.NonNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GameMode (net.minecraft.world.GameMode)6 ServerWorld (net.minecraft.server.world.ServerWorld)3 IEPlayerListEntry (com.qouteall.immersive_portals.ducks.IEPlayerListEntry)2 IEWorldRenderer (com.qouteall.immersive_portals.ducks.IEWorldRenderer)2 PlayerListEntry (net.minecraft.client.network.PlayerListEntry)2 IEChunkRenderList (com.qouteall.immersive_portals.ducks.IEChunkRenderList)1 IEGameRenderer (com.qouteall.immersive_portals.ducks.IEGameRenderer)1 List (java.util.List)1 ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)1 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 CommandBlock (net.minecraft.block.CommandBlock)1 JigsawBlock (net.minecraft.block.JigsawBlock)1 StructureBlock (net.minecraft.block.StructureBlock)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 BlockEntityRenderDispatcher (net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher)1 EntityRenderDispatcher (net.minecraft.client.render.entity.EntityRenderDispatcher)1 ClientWorld (net.minecraft.client.world.ClientWorld)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1