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