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);
}
}
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;
}
}
}
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);
}
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);
}
}
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();
}
Aggregations