Search in sources :

Example 1 with StringTextComponent

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

the class ItemLinkingCard method appendHoverText.

@OnlyIn(Dist.CLIENT)
@Override
public void appendHoverText(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
    CompoundNBT tag = stack.getTag();
    if (tag != null && tag.contains("TYPE")) {
        String type = tag.getString("TYPE");
        int x = tag.getInt("X");
        int y = tag.getInt("Y");
        int z = tag.getInt("Z");
        String worldID = tag.getString("WORLD");
        tooltip.add(new StringTextComponent(String.format("Bound to %s at %s: %d,%d,%d", type, worldID, x, y, z)));
    }
    super.appendHoverText(stack, worldIn, tooltip, flagIn);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) StringTextComponent(net.minecraft.util.text.StringTextComponent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 2 with StringTextComponent

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

the class ItemMultiTool method leftClickOnBlockServer.

public static void leftClickOnBlockServer(@Nonnull ServerPlayerEntity player, LeftClickBlockMessage message) {
    BlockPos pos = message.getPos();
    ServerWorld world = player.getLevel();
    ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
    if (itemStack.getItem() != ModItems.multiTool || world.isEmptyBlock(pos)) {
        return;
    }
    player.startUsingItem(Hand.MAIN_HAND);
    if (player.isShiftKeyDown()) {
        CompoundNBT tag = itemStack.getTag();
        if (tag == null) {
            tag = new CompoundNBT();
        }
        BlockState state = world.getBlockState(pos);
        Item item = Item.byBlock(state.getBlock());
        ItemStack stackToPlace = new ItemStack(() -> item, 1);
        CompoundNBT blockTag = new CompoundNBT();
        stackToPlace.save(blockTag);
        tag.put("Item", blockTag);
        itemStack.setTag(tag);
        ITextComponent component = stackToPlace.getDisplayName();
        player.displayClientMessage(new StringTextComponent("Bound tool to ").append(component), true);
    } else {
        LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
        if (!opEnergy.isPresent()) {
            Overloaded.logger.warn("MultiTool has no Energy Capability? NBT: " + itemStack.getTag());
            return;
        }
        // Used to catch item spawn to teleport
        RegistryKey<World> worldId = world.dimension();
        CommonSideEvents.enabled = true;
        CommonSideEvents.world = worldId;
        CommonSideEvents.pos = pos;
        CommonSideEvents.uuid = player.getUUID();
        IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Error"));
        int efficiency = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY, itemStack);
        int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, itemStack);
        switch(breakAndUseEnergy(world, pos, energy, player, efficiency, unbreaking)) {
            case FAIL_REMOVE:
                player.displayClientMessage(new StringTextComponent("Unable to break block, reason unknown"), true);
                break;
            case FAIL_ENERGY:
                player.displayClientMessage(new StringTextComponent("Unable to break block, not enough energy"), true);
                break;
            case FAIL_UNBREAKABLE:
                player.displayClientMessage(new StringTextComponent("Block is unbreakable"), true);
                break;
            case FAIL_RANGE:
                player.displayClientMessage(new StringTextComponent("Block is out of range."), true);
                break;
            case SUCCESS:
                break;
        }
        CommonSideEvents.enabled = false;
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ITextComponent(net.minecraft.util.text.ITextComponent) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) ServerWorld(net.minecraft.world.server.ServerWorld) Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) BlockState(net.minecraft.block.BlockState) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack)

Example 3 with StringTextComponent

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

the class ItemRayGun method handleMessage.

public void handleMessage(ServerPlayerEntity player, RayGunMessage message) {
    ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
    if (itemStack.getItem() != this) {
        return;
    }
    LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
    if (!opEnergy.isPresent()) {
        Overloaded.logger.warn("Railgun has no Energy Capability? NBT: " + itemStack.getTag());
        return;
    }
    IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    if (energy.getEnergyStored() < OverloadedConfig.INSTANCE.rayGun.energyPerShot) {
        player.displayClientMessage(new StringTextComponent("Not enough power to fire."), true);
        return;
    }
    Vector3d eyePos = player.getEyePosition(1);
    if (eyePos.distanceTo(message.vector) > OverloadedConfig.INSTANCE.rayGun.maxRange) {
        player.displayClientMessage(new StringTextComponent("Target out of range."), true);
        return;
    }
    BlockRayTraceResult sanityCheckVec = player.level.clip(new RayTraceContext(eyePos, message.vector, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, player));
    if (sanityCheckVec.getType() != RayTraceResult.Type.MISS) {
        player.displayClientMessage(new StringTextComponent("Target no longer in sight."), true);
        return;
    }
    energy.extractEnergy(OverloadedConfig.INSTANCE.rayGun.energyPerShot, false);
    LightningBoltEntity entity = new LightningBoltEntity(EntityType.LIGHTNING_BOLT, player.level);
    entity.moveTo(message.vector.x, message.vector.y, message.vector.z, 0, 0);
    player.level.addFreshEntity(entity);
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceContext(net.minecraft.util.math.RayTraceContext) LightningBoltEntity(net.minecraft.entity.effect.LightningBoltEntity) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) StringTextComponent(net.minecraft.util.text.StringTextComponent) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack)

Example 4 with StringTextComponent

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

the class ItemRailGun method appendHoverText.

@Override
public void appendHoverText(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
    stack.getCapability(GENERIC_DATA_STORAGE).ifPresent(cap -> {
        cap.suggestUpdate();
        int energyRequirement = cap.getIntegerMap().getOrDefault(RAILGUN_POWER_KEY, OverloadedConfig.INSTANCE.railGun.minEnergy);
        tooltip.add(new StringTextComponent(String.format("Power Usage: %s", NumberFormat.getInstance().format(energyRequirement))));
    });
    super.appendHoverText(stack, worldIn, tooltip, flagIn);
}
Also used : StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 5 with StringTextComponent

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

the class ItemRailGun method handleFireMessage.

public void handleFireMessage(@Nonnull ServerPlayerEntity player, @Nonnull RailGunFireMessage message) {
    ItemStack itemStack = player.getItemInHand(message.hand);
    if (itemStack.getItem() != this) {
        return;
    }
    LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
    if (!opEnergy.isPresent()) {
        Overloaded.logger.warn("RailGun has no Energy Capability? NBT: " + itemStack.getTag());
        return;
    }
    IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    LazyOptional<IGenericDataStorage> opSettingCapability = itemStack.getCapability(GENERIC_DATA_STORAGE);
    if (!opSettingCapability.isPresent()) {
        Overloaded.logger.warn("RailGun has no GenericData Capability? NBT: " + itemStack.getTag());
        return;
    }
    IGenericDataStorage settingCapability = opSettingCapability.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    settingCapability.suggestUpdate();
    int energyRequired = settingCapability.getIntegerMap().getOrDefault(RAILGUN_POWER_KEY, OverloadedConfig.INSTANCE.railGun.minEnergy);
    if (energy.getEnergyStored() < energyRequired) {
        player.displayClientMessage(new StringTextComponent("Not enough power to fire."), true);
        return;
    }
    int energyExtracted = energy.extractEnergy(energyRequired, false);
    @Nullable Entity entity = player.level.getEntity(message.id);
    if (entity == null || !entity.isAlive()) {
        return;
    } else if (player.distanceTo(entity) > OverloadedConfig.INSTANCE.rayGun.maxRange) {
        player.displayClientMessage(new StringTextComponent("Target out of range."), true);
    } else if (entity.hurt(DamageSource.playerAttack(player), (float) (OverloadedConfig.INSTANCE.railGun.damagePerRF * energyExtracted))) {
        Vector3d knockback = message.moveVector.scale(energyExtracted * OverloadedConfig.INSTANCE.railGun.knockbackPerRF);
        entity.push(knockback.x, knockback.y, knockback.z);
    }
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

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