Java Code Examples for net.minecraft.entity.player.PlayerEntity

The following examples show how to use net.minecraft.entity.player.PlayerEntity. These examples are extracted from open source projects. 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 Project: Galacticraft-Rewoven   Source File: OxygenCollectorBlock.java    License: MIT License 6 votes vote down vote up
@Override
public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) {
    super.onBreak(world, blockPos, blockState, playerEntity);
    BlockEntity blockEntity = world.getBlockEntity(blockPos);

    if (blockEntity != null) {
        if (blockEntity instanceof OxygenCollectorBlockEntity) {
            OxygenCollectorBlockEntity be = (OxygenCollectorBlockEntity) blockEntity;

            for (int i = 0; i < be.getInventory().getSize(); i++) {
                ItemStack itemStack = be.getInventory().getStack(i);

                if (itemStack != null) {
                    world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack));
                }
            }
        }
    }
}
 
Example 2
Source Project: fabric-carpet   Source File: LogCommand.java    License: MIT License 6 votes vote down vote up
private static int subscribePlayer(ServerCommandSource source, String player_name, String logname, String option)
{
    PlayerEntity player = source.getMinecraftServer().getPlayerManager().getPlayer(player_name);
    if (player == null)
    {
        Messenger.m(source, "r No player specified");
        return 0;
    }
    if (LoggerRegistry.getLogger(logname) == null)
    {
        Messenger.m(source, "r Unknown logger: ","rb "+logname);
        return 0;
    }
    LoggerRegistry.subscribePlayer(player_name, logname, option);
    if (option!=null)
    {
        Messenger.m(source, "gi Subscribed to " + logname + "(" + option + ")");
    }
    else
    {
        Messenger.m(source, "gi Subscribed to " + logname);
    }
        return 1;
}
 
Example 3
Source Project: Galacticraft-Rewoven   Source File: RefineryBlock.java    License: MIT License 6 votes vote down vote up
@Override
public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) {
    super.onBreak(world, blockPos, blockState, playerEntity);

    BlockEntity blockEntity = world.getBlockEntity(blockPos);

    if (blockEntity != null) {
        if (blockEntity instanceof RefineryBlockEntity) {
            RefineryBlockEntity refineryBlockEntity = (RefineryBlockEntity) blockEntity;

            for (int i = 0; i < refineryBlockEntity.getInventory().getSize(); i++) {
                ItemStack itemStack = refineryBlockEntity.getInventory().getStack(i);

                if (itemStack != null) {
                    world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack));
                }
            }
        }
    }
}
 
Example 4
Source Project: Galacticraft-Rewoven   Source File: EnergyStorageModuleBlock.java    License: MIT License 6 votes vote down vote up
@Override
public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) {
    super.onBreak(world, blockPos, blockState, playerEntity);
    BlockEntity blockEntity = world.getBlockEntity(blockPos);

    if (blockEntity != null) {
        if (blockEntity instanceof EnergyStorageModuleBlockEntity) {
            EnergyStorageModuleBlockEntity be = (EnergyStorageModuleBlockEntity) blockEntity;

            for (int i = 0; i < be.getInventory().getSize(); i++) {
                ItemStack itemStack = be.getInventory().getStack(i);

                if (itemStack != null) {
                    world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack));
                }
            }
        }
    }
}
 
Example 5
Source Project: EnderStorage   Source File: ContainerEnderItemStorage.java    License: MIT License 6 votes vote down vote up
@Override
public ItemStack transferStackInSlot(PlayerEntity par1EntityPlayer, int i) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = inventorySlots.get(i);

    if (slot != null && slot.getHasStack()) {
        ItemStack itemstack1 = slot.getStack();
        itemstack = itemstack1.copy();

        int chestSlots = EnderItemStorage.sizes[chestInv.getSize()];
        if (i < chestSlots) {
            if (!mergeItemStack(itemstack1, chestSlots, inventorySlots.size(), true)) {
                return ItemStack.EMPTY;
            }
        } else if (!mergeItemStack(itemstack1, 0, chestSlots, false)) {
            return ItemStack.EMPTY;
        }
        if (itemstack1.getCount() == 0) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }
    }
    return itemstack;
}
 
Example 6
Source Project: Galacticraft-Rewoven   Source File: CoalGeneratorScreenHandler.java    License: MIT License 6 votes vote down vote up
public CoalGeneratorScreenHandler(int syncId, PlayerEntity playerEntity, CoalGeneratorBlockEntity generator) {
    super(syncId, playerEntity, generator, GalacticraftScreenHandlerTypes.COAL_GENERATOR_HANDLER);
    Inventory inventory = blockEntity.getInventory().asInventory();
    addProperty(status);
    // Coal Generator fuel slot
    this.addSlot(new ItemSpecificSlot(inventory, 0, 8, 72, fuel));
    this.addSlot(new ChargeSlot(inventory, 1, 8, 8));

    // Player inventory slots
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, 94 + i * 18));
        }
    }

    // Hotbar slots
    for (int i = 0; i < 9; ++i) {
        this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, 152));
    }

}
 
Example 7
Source Project: Better-Sprinting   Source File: ClientNetwork.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onPacket(LogicalSide side, ByteBuf data, PlayerEntity player){
	if (side == LogicalSide.SERVER){
		PacketPipeline.sendToPlayer(writeLanSettings(), player);
		return;
	}
	
	byte type = data.readByte();
	
	if (type == 0){
		ClientModManager.svSurvivalFlyBoost = data.readBoolean();
		ClientModManager.svRunInAllDirs = data.readBoolean();
	}
	else if (type == 1 && !ClientSettings.disableMod.get()){
		ClientModManager.svDisableMod = true;
		ClientEventHandler.showDisableWarningWhenPossible = true;
	}
	else if (type == 2 && !ClientSettings.disableMod.get()){
		ClientModManager.svDisableMod = false;
		ClientEventHandler.showDisableWarningWhenPossible = true;
	}
}
 
Example 8
Source Project: LibGui   Source File: SyncedGuiDescription.java    License: MIT License 6 votes vote down vote up
/** WILL MODIFY toInsert! Returns true if anything was inserted. */
private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) {
	ItemStack curSlotStack = slot.getStack();
	if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack) && slot.canTakeItems(player)) {
		int combinedAmount = curSlotStack.getCount() + toInsert.getCount();
		if (combinedAmount <= toInsert.getMaxCount()) {
			toInsert.setCount(0);
			curSlotStack.setCount(combinedAmount);
			slot.markDirty();
			return true;
		} else if (curSlotStack.getCount() < toInsert.getMaxCount()) {
			toInsert.decrement(toInsert.getMaxCount() - curSlotStack.getCount());
			curSlotStack.setCount(toInsert.getMaxCount());
			slot.markDirty();
			return true;
		}
	}
	return false;
}
 
Example 9
Source Project: MineLittlePony   Source File: HorseCam.java    License: MIT License 6 votes vote down vote up
/**
 * Transforms the client pony's pitch to the corresponding angle for a human character.
 */
public static float transformCameraAngle(float pitch) {

    if (!MineLittlePony.getInstance().getConfig().fillycam.get()) {
        return pitch;
    }

    PlayerEntity player = MinecraftClient.getInstance().player;
    IPony pony = MineLittlePony.getInstance().getManager().getPony(player);

    if (!pony.getRace(false).isHuman()) {
        float factor = pony.getMetadata().getSize().getEyeHeightFactor();
        return rescaleCameraPitch(player.getStandingEyeHeight() / factor, pitch);
    }

    return pitch;
}
 
Example 10
@Redirect(
    method = "tick",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/entity/player/PlayerEntity;sleepTimer:I",
        opcode = Opcodes.PUTFIELD
    ),
    slice = @Slice(
        from = @At(
            value = "INVOKE",
            target = "Lnet/minecraft/entity/player/PlayerEntity;wakeUp(ZZ)V"
        ),
        to = @At(
            value = "CONSTANT",
            args = "intValue=110"
        )
    )
)
private void realTimeImpl$adjustForRealTimeWakeTimer(final PlayerEntity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) self.getEntityWorld()).realTimeBridge$getRealTimeTicks();
    this.sleepTimer += ticks;
}
 
Example 11
Source Project: the-hallow   Source File: PumpkinPieBlock.java    License: MIT License 6 votes vote down vote up
private ActionResult tryEat(IWorld iWorld, BlockPos pos, BlockState state, PlayerEntity player) {
	if (!player.canConsume(false)) {
		return ActionResult.PASS;
	}
	float saturation = 0.1F;
	TrinketComponent trinketPlayer = TrinketsApi.getTrinketComponent(player);
	ItemStack mainHandStack = trinketPlayer.getStack("hand:ring");
	ItemStack offHandStack = trinketPlayer.getStack("offhand:ring");
	if (mainHandStack.getItem().equals(HallowedItems.PUMPKIN_RING) || offHandStack.getItem().equals(HallowedItems.PUMPKIN_RING)) {
		saturation = 0.3F;
	}
	player.getHungerManager().add(2, saturation);
	int bites = state.get(BITES);
	if (bites > 1) {
		iWorld.setBlockState(pos, state.with(BITES, bites - 1), 3);
	} else {
		iWorld.removeBlock(pos, false);
	}
	return ActionResult.SUCCESS;
}
 
Example 12
Source Project: the-hallow   Source File: ColoredPumpkinBlock.java    License: MIT License 6 votes vote down vote up
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	ItemStack stack = playerEntity.getStackInHand(hand);

	if (stack.getItem() == Items.SHEARS) {
		if (!world.isClient) {
			Direction side = blockHitResult.getSide();
			Direction facingTowardPlayer = side.getAxis() == Direction.Axis.Y ? playerEntity.getHorizontalFacing().getOpposite() : side;

			world.playSound(null, blockPos, SoundEvents.BLOCK_PUMPKIN_CARVE, SoundCategory.BLOCKS, 1.0F, 1.0F);
			world.setBlockState(blockPos, HallowedBlocks.CARVED_PUMPKIN_COLORS.get(this.color).getDefaultState().with(CarvedPumpkinBlock.FACING, facingTowardPlayer), 11);
			ItemEntity itemEntity = new ItemEntity(world, blockPos.getX() + 0.5D + facingTowardPlayer.getOffsetX() * 0.65D, blockPos.getY() + 0.1D, blockPos.getZ() + 0.5D + facingTowardPlayer.getOffsetZ() * 0.65D, new ItemStack(Items.PUMPKIN_SEEDS, 4));

			itemEntity.setVelocity(0.05D * (double) facingTowardPlayer.getOffsetX() + world.random.nextDouble() * 0.02D, 0.05D, 0.05D * (double) facingTowardPlayer.getOffsetZ() + world.random.nextDouble() * 0.02D);
			world.spawnEntity(itemEntity);
			stack.damage(1, playerEntity, (playerEntityVar) -> {
				playerEntityVar.sendToolBreakStatus(hand);
			});
		}

		return ActionResult.SUCCESS;
	}

	return super.onUse(blockState, world, blockPos, playerEntity, hand, blockHitResult);
}
 
Example 13
Source Project: fabric-carpet   Source File: SettingsManager.java    License: MIT License 5 votes vote down vote up
private int listAllSettings(ServerCommandSource source)
{
    //listSettings(source, "Current "+fancyName+" Settings", getNonDefault());
    listSettings(source, String.format(tr("ui.current_%(mod)s_settings","Current %s Settings"), fancyName), getNonDefault());

    if (version != null)
        //Messenger.m(source, "g "+fancyName+" version: "+ version);
        Messenger.m(source, "g "+fancyName+" "+ tr("ui.version",  "version") + ": "+ version);
    try
    {
        PlayerEntity player = source.getPlayer();
        List<Object> tags = new ArrayList<>();
        //tags.add("w Browse Categories:\n");
        tags.add("w " + tr("ui.browse_categories", "Browse Categories")  + ":\n");
        for (String t : getCategories())
        {
            String catKey = "category." + t;
            String translated = tr(catKey, t);
            String translatedPlus = Translations.hasTranslation(catKey) ? String.format("%s (%s)",tr(catKey, t), t) : t;
            tags.add("c [" + translated +"]");
            //tags.add("^g list all " + translated + " settings");
            tags.add("^g " + String.format(tr("ui.list_all_%(cat)s_settings","list all %s settings"), translatedPlus));
            tags.add("!/"+identifier+" list " + t);
            tags.add("w  ");
        }
        tags.remove(tags.size() - 1);
        Messenger.m(player, tags.toArray(new Object[0]));
    }
    catch (CommandSyntaxException ignored) { }
    return 1;
}
 
Example 14
Source Project: bleachhack-1.14   Source File: EntityUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void setGlowing(Entity entity, Formatting color, String teamName) {
	Team team = mc.world.getScoreboard().getTeamNames().contains(teamName) ?
			mc.world.getScoreboard().getTeam(teamName) :
			mc.world.getScoreboard().addTeam(teamName);
       
	mc.world.getScoreboard().addPlayerToTeam(
			entity instanceof PlayerEntity ? entity.getEntityName() : entity.getUuidAsString(), team);
	mc.world.getScoreboard().getTeam(teamName).setColor(color);
	
	entity.setGlowing(true);
}
 
Example 15
Source Project: Galacticraft-Rewoven   Source File: CavernousVineBlockPoisonous.java    License: MIT License 5 votes vote down vote up
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
    if (playerEntity.getStackInHand(hand).getItem() instanceof ShearsItem) {
        world.setBlockState(blockPos, GalacticraftBlocks.CAVERNOUS_VINE.getDefaultState().with(VINES, blockState.get(VINES)));
        world.playSound(blockPos.getX(), blockPos.getY(), blockPos.getZ(), SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1f, 1f, true);
        return ActionResult.SUCCESS;
    }
    return ActionResult.SUCCESS;
}
 
Example 16
Source Project: Galacticraft-Rewoven   Source File: UnlitWallTorchBlock.java    License: MIT License 5 votes vote down vote up
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (player.getStackInHand(hand).getItem() instanceof FlintAndSteelItem) {
        world.setBlockState(pos, Blocks.WALL_TORCH.getDefaultState().with(WallTorchBlock.FACING, state.get(WallTorchBlock.FACING)));
        ItemStack stack = player.getStackInHand(hand).copy();
        stack.damage(1, player, (playerEntity -> {
        }));
        player.setStackInHand(hand, stack);
    }

    return super.onUse(state, world, pos, player, hand, hit);
}
 
Example 17
Source Project: Galacticraft-Rewoven   Source File: UnlitTorchBlock.java    License: MIT License 5 votes vote down vote up
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (player.getStackInHand(hand).getItem() instanceof FlintAndSteelItem) {
        world.setBlockState(pos, Blocks.TORCH.getDefaultState());
        ItemStack stack = player.getStackInHand(hand).copy();
        stack.damage(1, player, (playerEntity -> {
        }));
        player.setStackInHand(hand, stack);
    }
    return super.onUse(state, world, pos, player, hand, hit);
}
 
Example 18
Source Project: fabric-carpet   Source File: PlayerCommand.java    License: MIT License 5 votes vote down vote up
private static boolean cantManipulate(CommandContext<ServerCommandSource> context)
{
    PlayerEntity player = getPlayer(context);
    if (player == null)
    {
        Messenger.m(context.getSource(), "r Can only manipulate existing players");
        return true;
    }
    PlayerEntity sendingPlayer;
    try
    {
        sendingPlayer = context.getSource().getPlayer();
    }
    catch (CommandSyntaxException e)
    {
        return false;
    }

    if (!context.getSource().getMinecraftServer().getPlayerManager().isOperator(sendingPlayer.getGameProfile()))
    {
        if (sendingPlayer != player && !(player instanceof EntityPlayerMPFake))
        {
            Messenger.m(context.getSource(), "r Non OP players can't control other real players");
            return true;
        }
    }
    return false;
}
 
Example 19
Source Project: bleachhack-1.14   Source File: Tracers.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
public void onRender(Event3DRender event) {
	final float thick = (float) getSettings().get(6).toSlider().getValue();
	
	for (Entity e: mc.world.getEntities()) {
		Vec3d vec = e.getPos();
		
		Vec3d vec2 = new Vec3d(0, 0, 75).rotateX(-(float) Math.toRadians(mc.cameraEntity.pitch))
				.rotateY(-(float) Math.toRadians(mc.cameraEntity.yaw))
				.add(mc.cameraEntity.getPos().add(0, mc.cameraEntity.getEyeHeight(mc.cameraEntity.getPose()), 0));
		
		if (e instanceof PlayerEntity && e != mc.player && e != mc.cameraEntity && getSettings().get(0).toToggle().state) {
			RenderUtils.drawLine(vec2.x,vec2.y,vec2.z,vec.x,vec.y,vec.z,1f,0f,0f,thick);
			RenderUtils.drawLine(vec.x,vec.y,vec.z, vec.x,vec.y+(e.getHeight()/1.1),vec.z,1f,0f,0f,thick);
		}
		else if (e instanceof Monster && getSettings().get(1).toToggle().state) {
			RenderUtils.drawLine(vec2.x,vec2.y,vec2.z,vec.x,vec.y,vec.z,0f,0f,0f,thick);
			RenderUtils.drawLine(vec.x,vec.y,vec.z, vec.x,vec.y+(e.getHeight()/1.1),vec.z,0f,0f,0f,thick);
		}
		else if (EntityUtils.isAnimal(e) && getSettings().get(2).toToggle().state) {
			RenderUtils.drawLine(vec2.x,vec2.y,vec2.z,vec.x,vec.y,vec.z,0f,1f,0f,thick);
			RenderUtils.drawLine(vec.x,vec.y,vec.z, vec.x,vec.y+(e.getHeight()/1.1),vec.z,0f,1f,0f,thick);
		}
		else if (e instanceof ItemEntity && getSettings().get(3).toToggle().state) {
			RenderUtils.drawLine(vec2.x,vec2.y,vec2.z,vec.x,vec.y,vec.z,1f,0.7f,0f,thick);
			RenderUtils.drawLine(vec.x,vec.y,vec.z, vec.x,vec.y+(e.getHeight()/1.1),vec.z,1f,0.7f,0f,thick);
		}
		else if (e instanceof EnderCrystalEntity && getSettings().get(4).toToggle().state) {
			RenderUtils.drawLine(vec2.x,vec2.y,vec2.z,vec.x,vec.y,vec.z,1f, 0f, 1f,thick);
			RenderUtils.drawLine(vec.x,vec.y,vec.z, vec.x,vec.y+(e.getHeight()/1.1),vec.z,1f, 0f, 1f,thick);
		}
		else if ((e instanceof BoatEntity || e instanceof AbstractMinecartEntity) && getSettings().get(5).toToggle().state) {
			RenderUtils.drawLine(vec2.x,vec2.y,vec2.z,vec.x,vec.y,vec.z,0.5f, 0.5f, 0.5f,thick);
			RenderUtils.drawLine(vec.x,vec.y,vec.z, vec.x,vec.y+(e.getHeight()/1.1),vec.z,0.5f, 0.5f, 0.5f,thick);
		}
	}
}
 
Example 20
Source Project: fabric-carpet   Source File: HUDController.java    License: MIT License 5 votes vote down vote up
public static void addMessage(PlayerEntity player, BaseText hudMessage)
{
    if (!player_huds.containsKey(player))
    {
        player_huds.put(player, new ArrayList<>());
    }
    else
    {
        player_huds.get(player).add(new LiteralText("\n"));
    }
    player_huds.get(player).add(hudMessage);
}
 
Example 21
Source Project: multiconnect   Source File: MixinFireworkItem.java    License: MIT License 5 votes vote down vote up
@Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isFallFlying()Z", ordinal = 0))
private boolean disableFireworkElytraBoost(PlayerEntity player) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_11) {
        return false;
    }
    return player.isFallFlying();
}
 
Example 22
public ElectricCompressorScreenHandler(int syncId, PlayerEntity player, ElectricCompressorBlockEntity blockEntity) {
    super(syncId, player, blockEntity, GalacticraftScreenHandlerTypes.ELECTRIC_COMPRESSOR_HANDLER);
    this.inventory = blockEntity.getInventory().asInventory();
    addProperty(status);
    addProperty(progress);

    // 3x3 comprerssor input grid
    int slot = 0;
    for (int y = 0; y < 3; y++) {
        for (int x = 0; x < 3; x++) {
            this.addSlot(new Slot(this.inventory, slot, x * 18 + 19, y * 18 + 18));
            slot++;
        }
    }

    // Output slot
    this.addSlot(new FurnaceOutputSlot(playerEntity, this.inventory, CompressorBlockEntity.OUTPUT_SLOT, getOutputSlotPos()[0], getOutputSlotPos()[1]));

    // Player inventory slots
    int playerInvYOffset = 117;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, playerInvYOffset + i * 18));
        }
    }

    // Hotbar slots
    for (int i = 0; i < 9; ++i) {
        this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, playerInvYOffset + 58));
    }

    addProperty(energy);
    addSlot(new FurnaceOutputSlot(player, this.inventory, ElectricCompressorBlockEntity.SECOND_OUTPUT_SLOT, getOutputSlotPos()[0], getOutputSlotPos()[1] + 18));
    addSlot(new ChargeSlot(this.inventory, CompressorBlockEntity.FUEL_INPUT_SLOT, 3 * 18 + 1, 75));
}
 
Example 23
/**
 * Drops all items from inv using removeStackFromSlot
 */
public static void dropOnClose(PlayerEntity player, IInventory inv) {
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.removeStackFromSlot(i);
        if (!stack.isEmpty()) {
            player.dropItem(stack, false);
        }
    }
}
 
Example 24
Source Project: Galacticraft-Rewoven   Source File: OxygenGearItem.java    License: MIT License 5 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    if (((GCPlayerAccessor) user).getGearInventory().getStack(5).isEmpty()) {
        ((GCPlayerAccessor) user).getGearInventory().setStack(5, user.getStackInHand(hand));
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return super.use(world, user, hand);
}
 
Example 25
@SubscribeEvent
public void onAttackEntity(AttackEntityEvent ev)
{
    if (!ConfigManager.SERVER.enableTorchFire.get())
        return;

    if (!ev.getTarget().func_230279_az_() && !ev.getTarget().world.isRemote)
    {
        PlayerEntity player = ev.getPlayer();
        ItemStack stack = player.getHeldItem(Hand.MAIN_HAND);
        if (stack.getCount() > 0 && stack.getItem() instanceof BlockItem)
        {
            BlockItem b = (BlockItem) stack.getItem();
            Block bl = b.getBlock();
            if (bl == Blocks.TORCH)
            {
                ev.getTarget().setFire(2);
                if (!ev.getPlayer().isCreative() && rnd.nextFloat() > 0.25)
                {
                    stack.grow(-1);
                    if (stack.getCount() <= 0)
                    {
                        player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
                    }
                }
            }
        }
    }
}
 
Example 26
Source Project: fabric-carpet   Source File: BlockRotator.java    License: MIT License 5 votes vote down vote up
public static boolean flipBlockWithCactus(BlockState state, World world, PlayerEntity player, Hand hand, BlockHitResult hit)
{
    if (!player.abilities.allowModifyWorld || !CarpetSettings.flippinCactus || !player_holds_cactus_mainhand(player))
    {
        return false;
    }
    CarpetSettings.impendingFillSkipUpdates = true;
    boolean retval = flip_block(state, world, player, hand, hit);
    CarpetSettings.impendingFillSkipUpdates = false;
    return retval;
}
 
Example 27
Source Project: the-hallow   Source File: HallowedFogColorCalculator.java    License: MIT License 5 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public Vec3d calculate(float v, float v1) {
	World world = MinecraftClient.getInstance().world;
	PlayerEntity player = MinecraftClient.getInstance().player;
	double totalR = 0;
	double totalG = 0;
	double totalB = 0;
	int count = 0;
	int radius = HallowedConfig.HallowedFog.fogSmoothingRadius;
	
	for (int x = 0; x < radius; x++) {
		for (int z = 0; z < radius; z++) {
			BlockPos pos = player.getBlockPos().add(x - (radius / 2), 0, z - (radius / 2));
			
			if (world.getBiomeAccess().getBiome(pos) instanceof HallowedBiomeInfo) {
				HallowedBiomeInfo biomeInfo = (HallowedBiomeInfo) world.getBiomeAccess().getBiome(pos);
				
				totalR += Math.pow(biomeInfo.getFogColor().x, 2);
				totalG += Math.pow(biomeInfo.getFogColor().y, 2);
				totalB += Math.pow(biomeInfo.getFogColor().z, 2);
			}
			count++;
		}
	}
	
	return new Vec3d(Math.sqrt(totalR / count), Math.sqrt(totalG / count), Math.sqrt(totalB / count));
}
 
Example 28
Source Project: fabric-carpet   Source File: LoggerRegistry.java    License: MIT License 5 votes vote down vote up
public static void playerDisconnected(PlayerEntity player)
{
    for(Logger log: loggerRegistry.values() )
    {
        log.onPlayerDisconnect(player);
    }
}
 
Example 29
Source Project: fabric-carpet   Source File: LoggerRegistry.java    License: MIT License 5 votes vote down vote up
public static void playerConnected(PlayerEntity player)
{
    boolean firstTime = false;
    if (!seenPlayers.contains(player.getName().getString()))
    {
        seenPlayers.add(player.getName().getString());
        firstTime = true;
        //subscribe them to the defualt loggers
    }
    for(Logger log: loggerRegistry.values() )
    {
        log.onPlayerConnect(player, firstTime);
    }
}
 
Example 30
Source Project: spark   Source File: ForgeCommandSender.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getName() {
    if (super.delegate instanceof PlayerEntity) {
        return ((PlayerEntity) super.delegate).getGameProfile().getName();
    } else if (super.delegate instanceof IServer) {
        return "Console";
    } else {
        return "unknown:" + super.delegate.getClass().getSimpleName();
    }
}