Search in sources :

Example 21 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class BlockPlayerInterface method use.

@Override
@Nonnull
public ActionResultType use(@Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult rayTraceResult) {
    if (!world.isClientSide && hand == Hand.MAIN_HAND) {
        TileEntity te = world.getBlockEntity(pos);
        if (te instanceof TilePlayerInterface) {
            UUID placer = ((TilePlayerInterface) te).getPlacer();
            if (placer == null) {
                player.sendMessage(new StringTextComponent("Not bound to anyone..... ghosts placed this."), player.getUUID());
            } else {
                String username = UsernameCache.getLastKnownUsername(placer);
                player.sendMessage(new StringTextComponent("Bound to player: " + (username == null ? placer.toString() : username)), player.getUUID());
            }
        }
        return ActionResultType.SUCCESS;
    }
    return super.use(state, world, pos, player, hand, rayTraceResult);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TilePlayerInterface(com.cjm721.overloaded.tile.functional.TilePlayerInterface) StringTextComponent(net.minecraft.util.text.StringTextComponent) UUID(java.util.UUID) Nonnull(javax.annotation.Nonnull)

Example 22 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class ItemRailGun method handleSettingsMessage.

public void handleSettingsMessage(@Nonnull ServerPlayerEntity player, @Nonnull RailGunSettingsMessage message) {
    ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
    if (itemStack.getItem() != this) {
        return;
    }
    LazyOptional<IGenericDataStorage> opCap = itemStack.getCapability(GENERIC_DATA_STORAGE);
    if (!opCap.isPresent()) {
        Overloaded.logger.warn("RailGun has no GenericData Capability? NBT: " + itemStack.getTag());
        return;
    }
    IGenericDataStorage cap = opCap.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    Map<String, Integer> integerMap = cap.getIntegerMap();
    int power = integerMap.getOrDefault(RAILGUN_POWER_KEY, 0) + message.powerDelta;
    power = Ints.constrainToRange(power, OverloadedConfig.INSTANCE.railGun.minEnergy, OverloadedConfig.INSTANCE.railGun.maxEnergy);
    integerMap.put(RAILGUN_POWER_KEY, power);
    cap.suggestSave();
    player.displayClientMessage(new StringTextComponent("Power usage set to: " + NumberFormat.getInstance().format(power)), true);
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack)

Example 23 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method rightClickWithItem.

public void rightClickWithItem(@Nonnull ServerPlayerEntity player, RightClickBlockMessage message) {
    BlockPos pos = message.getPos();
    Direction sideHit = message.getHitSide();
    float hitX = message.getHitX();
    float hitY = message.getHitY();
    float hitZ = message.getHitZ();
    ServerWorld worldIn = player.getLevel();
    ItemStack multiTool = player.getMainHandItem();
    if (multiTool.getItem() != this) {
        return;
    }
    ItemStack blockStack = getSelectedBlockItemStack(multiTool);
    if (blockStack.isEmpty()) {
        player.displayClientMessage(new StringTextComponent("No block type selected to place."), true);
        return;
    }
    if (!(blockStack.getItem() instanceof BlockItem)) {
        player.displayClientMessage(new StringTextComponent("No valid block type selected to place."), true);
        return;
    }
    LazyOptional<IEnergyStorage> opEnergy = multiTool.getCapability(ENERGY);
    if (!opEnergy.isPresent()) {
        Overloaded.logger.warn("MultiTool has no Energy Capability? NBT: " + multiTool.getTag());
        return;
    }
    IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    Vector3i sideVector = sideHit.getNormal();
    BlockPos.Mutable newPosition = pos.offset(sideVector).mutable();
    switch(placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ)) {
        case FAIL_PREREQUISITE:
            player.displayClientMessage(new StringTextComponent("Do not have the required items"), true);
            return;
        case FAIL_DENY:
            player.displayClientMessage(new StringTextComponent("Unable to place blocks"), true);
            return;
        case FAIL_RANGE:
            player.displayClientMessage(new StringTextComponent("To far away"), true);
            return;
        case FAIL_ENERGY:
            player.displayClientMessage(new StringTextComponent("Not enough energy"), true);
            return;
        case SUCCESS:
    }
    if (player.isShiftKeyDown()) {
        BlockPos playerPos = player.blockPosition();
        switch(sideHit) {
            case UP:
                while (newPosition.getY() < playerPos.getY()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case DOWN:
                while (newPosition.getY() > playerPos.getY()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case NORTH:
                while (newPosition.getZ() > playerPos.getZ()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case SOUTH:
                while (newPosition.getZ() < playerPos.getZ()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case EAST:
                while (newPosition.getX() < playerPos.getX()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case WEST:
                while (newPosition.getX() > playerPos.getX()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) Vector3i(net.minecraft.util.math.vector.Vector3i) BlockPos(net.minecraft.util.math.BlockPos) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem)

Example 24 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method appendHoverText.

@OnlyIn(Dist.CLIENT)
@Override
public void appendHoverText(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
    tooltip.add(new StringTextComponent("Assist Mode: " + getAssistMode().getName()));
    super.appendHoverText(stack, worldIn, tooltip, flagIn);
}
Also used : StringTextComponent(net.minecraft.util.text.StringTextComponent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 25 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class AbstractBlockHyperSender method use.

@Override
@Nonnull
public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult rayTraceResult) {
    if (hand == Hand.MAIN_HAND) {
        ItemStack heldItem = player.getItemInHand(hand);
        if (heldItem.isEmpty()) {
            // Should find a cleaner way of showing all of this
            if (!world.isClientSide) {
                String message = ((AbstractTileHyperSender) world.getBlockEntity(pos)).getRightClickMessage();
                player.displayClientMessage(new StringTextComponent(message), false);
            }
            return ActionResultType.SUCCESS;
        } else if (heldItem.getItem().equals(ModItems.linkingCard)) {
            CompoundNBT tag = heldItem.getTag();
            if (tag != null) {
                if (tag.getString("TYPE").equals(this.getType())) {
                    String worldID = tag.getString("WORLD");
                    int x = tag.getInt("X");
                    int y = tag.getInt("Y");
                    int z = tag.getInt("Z");
                    bindToPartner(world, pos, worldID, new BlockPos(x, y, z));
                    if (world.isClientSide) {
                        player.displayClientMessage(new StringTextComponent("Bound Hyper Nodes"), true);
                    }
                } else {
                    if (world.isClientSide) {
                        player.displayClientMessage(new StringTextComponent("Incorrect Hyper Node Type to bind."), true);
                    }
                }
            }
            return ActionResultType.SUCCESS;
        }
    }
    return super.use(state, world, pos, player, hand, rayTraceResult);
}
Also used : AbstractTileHyperSender(com.cjm721.overloaded.tile.hyperTransfer.base.AbstractTileHyperSender) CompoundNBT(net.minecraft.nbt.CompoundNBT) StringTextComponent(net.minecraft.util.text.StringTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

StringTextComponent (net.minecraft.util.text.StringTextComponent)31 ItemStack (net.minecraft.item.ItemStack)17 CompoundNBT (net.minecraft.nbt.CompoundNBT)7 TileEntity (net.minecraft.tileentity.TileEntity)5 Nonnull (javax.annotation.Nonnull)4 BlockPos (net.minecraft.util.math.BlockPos)4 ITextComponent (net.minecraft.util.text.ITextComponent)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)4 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)4 IGenericDataStorage (com.cjm721.overloaded.storage.IGenericDataStorage)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)3 TileBPMicroblock (com.bluepowermod.tile.TileBPMicroblock)2 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)2 ItemSeedBag (com.infinityraider.agricraft.content.tools.ItemSeedBag)2 BlockState (net.minecraft.block.BlockState)2 Minecraft (net.minecraft.client.Minecraft)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2