<commit_before>package ethanjones.cubes.item;

import ethanjones.cubes.block.Block;
import ethanjones.cubes.core.util.BlockFace;
import ethanjones.cubes.entity.living.player.Player;
import ethanjones.cubes.graphics.world.RayTracing;
import ethanjones.cubes.item.inv.InventoryHelper;
import ethanjones.cubes.side.Side;
import ethanjones.cubes.side.Sided;
import ethanjones.cubes.side.common.Cubes;
import ethanjones.cubes.world.reference.BlockReference;

import com.badlogic.gdx.Input;

public class ItemBlock extends Item {
  public final Block block;

  public ItemBlock(Block block) {
    super(block.id);
    this.block = block;
  }

  public void loadGraphics() {
    this.texture = block.getTextureHandler().getSide(BlockFace.posX);
  }

  @Override
  public void onButtonPress(int button, ItemStack itemStack, Player player, int stack) {
    if (Sided.getSide() == Side.Server && button == Input.Buttons.RIGHT) {
      RayTracing.BlockIntersection blockIntersection = RayTracing.getBlockIntersection(player.position, player.angle, Cubes.getServer().world);
      if (blockIntersection != null) {
        BlockReference blockReference = blockIntersection.getBlockReference();
        switch (blockIntersection.getBlockFace()) {
          case posX:
            blockReference.blockX++;
            break;
          case negX:
            blockReference.blockX--;
            break;
          case posY:
            blockReference.blockY++;
            break;
          case negY:
            blockReference.blockY--;
            break;
          case posZ:
            blockReference.blockZ++;
            break;
          case negZ:
            blockReference.blockZ--;
            break;
        }
        Cubes.getServer().world.setBlock(block, blockReference.blockX, blockReference.blockY, blockReference.blockZ);

        InventoryHelper.reduceCount(player.getInventory(), stack);
      }<commit_msg>Prevent crash when block face of intersection is unknown<commit_after>package ethanjones.cubes.item;

import ethanjones.cubes.block.Block;
import ethanjones.cubes.core.util.BlockFace;
import ethanjones.cubes.entity.living.player.Player;
import ethanjones.cubes.graphics.world.RayTracing;
import ethanjones.cubes.item.inv.InventoryHelper;
import ethanjones.cubes.side.Side;
import ethanjones.cubes.side.Sided;
import ethanjones.cubes.side.common.Cubes;
import ethanjones.cubes.world.reference.BlockReference;

import com.badlogic.gdx.Input;

public class ItemBlock extends Item {
  public final Block block;

  public ItemBlock(Block block) {
    super(block.id);
    this.block = block;
  }

  public void loadGraphics() {
    this.texture = block.getTextureHandler().getSide(BlockFace.posX);
  }

  @Override
  public void onButtonPress(int button, ItemStack itemStack, Player player, int stack) {
    if (Sided.getSide() == Side.Server && button == Input.Buttons.RIGHT) {
      RayTracing.BlockIntersection blockIntersection = RayTracing.getBlockIntersection(player.position, player.angle, Cubes.getServer().world);
      if (blockIntersection == null || blockIntersection.getBlockFace() == null) return;
      BlockReference blockReference = blockIntersection.getBlockReference();
      switch (blockIntersection.getBlockFace()) {
        case posX:
          blockReference.blockX++;
          break;
        case negX:
          blockReference.blockX--;
          break;
        case posY:
          blockReference.blockY++;
          break;
        case negY:
          blockReference.blockY--;
          break;
        case posZ:
          blockReference.blockZ++;
          break;
        case negZ:
          blockReference.blockZ--;
          break;
      }
      Cubes.getServer().world.setBlock(block, blockReference.blockX, blockReference.blockY, blockReference.blockZ);

      InventoryHelper.reduceCount(player.getInventory(), stack);
{'fraction_non_alphanumeric': 0.10106245141228297, 'fraction_numerical': 0.0, 'mean_word_length': 3.0588853838065195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4759830', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1119, 'n_words': 213}