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