コード例 #1
0
ファイル: ZKeyEvent.java プロジェクト: Zeiyo/ZeiyoCraft
 public boolean hasRequiredKey(EntityPlayer player, TileEntityLockable tileEntityLockable) {
   for (ItemStack stack : player.inventory.mainInventory) {
     if (stack != null && stack.getItem() == ZeiyoItems.key) {
       if (tileEntityLockable.getLockCode().getLock().equals(stack.getDisplayName())) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #2
0
ファイル: ZKeyEvent.java プロジェクト: Zeiyo/ZeiyoCraft
  @SubscribeEvent
  public void onBreakBlock(BreakEvent event) {
    if (event.getWorld().isRemote) return;

    EntityPlayerMP player = (EntityPlayerMP) event.getPlayer();

    TileEntity tileEntity = event.getWorld().getTileEntity(event.getPos());
    if (tileEntity instanceof TileEntityLockable) {
      TileEntityLockable tileEntityLockable = (TileEntityLockable) tileEntity;
      if (tileEntityLockable.isLocked()) {
        if (!hasRequiredKey(event.getPlayer(), tileEntityLockable)) {
          player.addChatComponentMessage(
              new TextComponentTranslation("text.key.errorOnDestroyBlock", new Object[0]), true);

          event.setCanceled(true);
        }
      }
    }
  }
コード例 #3
0
  public void func_145839_a(NBTTagCompound p_145839_1_) {
    super.func_145839_a(p_145839_1_);
    NBTTagList var2 = p_145839_1_.func_150295_c("Items", 10);
    this.field_146022_i = new ItemStack[this.func_70302_i_()];

    for (int var3 = 0; var3 < var2.func_74745_c(); ++var3) {
      NBTTagCompound var4 = var2.func_150305_b(var3);
      int var5 = var4.func_74771_c("Slot") & 255;
      if (var5 >= 0 && var5 < this.field_146022_i.length) {
        this.field_146022_i[var5] = ItemStack.func_77949_a(var4);
      }
    }

    if (p_145839_1_.func_150297_b("CustomName", 8)) {
      this.field_146020_a = p_145839_1_.func_74779_i("CustomName");
    }
  }
コード例 #4
0
  public void func_145841_b(NBTTagCompound p_145841_1_) {
    super.func_145841_b(p_145841_1_);
    NBTTagList var2 = new NBTTagList();

    for (int var3 = 0; var3 < this.field_146022_i.length; ++var3) {
      if (this.field_146022_i[var3] != null) {
        NBTTagCompound var4 = new NBTTagCompound();
        var4.func_74774_a("Slot", (byte) var3);
        this.field_146022_i[var3].func_77955_b(var4);
        var2.func_74742_a(var4);
      }
    }

    p_145841_1_.func_74782_a("Items", var2);
    if (this.func_145818_k_()) {
      p_145841_1_.func_74778_a("CustomName", this.field_146020_a);
    }
  }
コード例 #5
0
  @Override
  public void writeToNBT(NBTTagCompound tagCompound) {
    super.writeToNBT(tagCompound);

    NBTTagList tagList = new NBTTagList();
    for (int slot = 0; slot < this.inventory.length; ++slot) {
      if (this.inventory[slot] != null) {
        NBTTagCompound nbt = new NBTTagCompound();
        nbt.setByte("Slot", (byte) slot);
        this.inventory[slot].writeToNBT(nbt);
        tagList.appendTag(nbt);
      }
    }
    tagCompound.setTag("Items", tagList);
    tagCompound.setBoolean("Freezing", freezing);
    tagCompound.setInteger("Progress", progress);
    tagCompound.setInteger("FuelTime", fuelTime);
    tagCompound.setInteger("Remaining", timeRemaining);
  }
コード例 #6
0
  @Override
  public void readFromNBT(NBTTagCompound tagCompound) {
    super.readFromNBT(tagCompound);

    NBTTagList tagList = (NBTTagList) tagCompound.getTag("Items");
    this.inventory = new ItemStack[this.getSizeInventory()];

    for (int i = 0; i < tagList.tagCount(); ++i) {
      NBTTagCompound nbt = (NBTTagCompound) tagList.getCompoundTagAt(i);
      byte slot = nbt.getByte("Slot");

      if (slot >= 0 && slot < this.inventory.length) {
        this.inventory[slot] = ItemStack.loadItemStackFromNBT(nbt);
      }
    }

    this.freezing = tagCompound.getBoolean("Freezing");
    this.progress = tagCompound.getInteger("Progress");
    this.fuelTime = tagCompound.getInteger("FuelTime");
    this.timeRemaining = tagCompound.getInteger("Remaining");
  }
コード例 #7
0
  @Override
  public void writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);
    compound.setShort("CrystalizeTime", (short) timeCanCrystalize);
    compound.setShort("SubmergeTime", (short) ticksCrystalizingItemSoFar);
    compound.setShort("SubmergeTimeTotal", (short) ticksPerItem);
    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < crystalizerItemStackArray.length; ++i) {
      if (crystalizerItemStackArray[i] != null) {
        NBTTagCompound nbtTagCompound = new NBTTagCompound();
        nbtTagCompound.setByte("Slot", (byte) i);
        crystalizerItemStackArray[i].writeToNBT(nbtTagCompound);
        nbttaglist.appendTag(nbtTagCompound);
      }
    }

    compound.setTag("Items", nbttaglist);

    if (hasCustomName()) {
      compound.setString("CustomName", crystalizerCustomName);
    }
  }
コード例 #8
0
  @Override
  public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    NBTTagList nbttaglist = compound.getTagList("Items", 10);
    crystalizerItemStackArray = new ItemStack[getSizeInventory()];

    for (int i = 0; i < nbttaglist.tagCount(); ++i) {
      NBTTagCompound nbtTagCompound = nbttaglist.getCompoundTagAt(i);
      byte b0 = nbtTagCompound.getByte("Slot");

      if (b0 >= 0 && b0 < crystalizerItemStackArray.length) {
        crystalizerItemStackArray[b0] = ItemStack.loadItemStackFromNBT(nbtTagCompound);
      }
    }

    timeCanCrystalize = compound.getShort("CrystalizeTime");
    ticksCrystalizingItemSoFar = compound.getShort("SubmergeTime");
    ticksPerItem = compound.getShort("SubmergeTimeTotal");

    if (compound.hasKey("CustomName", 8)) {
      crystalizerCustomName = compound.getString("CustomName");
    }
  }
コード例 #9
0
ファイル: ZKeyEvent.java プロジェクト: Zeiyo/ZeiyoCraft
  @SubscribeEvent(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent.RightClickBlock event) {

    World world = event.getWorld();
    BlockPos pos = event.getPos();

    if (world.isRemote) return;

    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity instanceof TileEntityLockable) {
      TileEntityLockable tileEntityLockable = (TileEntityLockable) tileEntity;

      EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer();

      ItemStack current = player.getHeldItemMainhand();
      if (tileEntityLockable.isLocked()) {
        if (current != null && current.getItem() == ZeiyoItems.key) {
          String unlockPass = new StringBuilder(current.getDisplayName()).reverse().toString();

          if (tileEntityLockable.getLockCode().getLock().equals(unlockPass)) {
            tileEntityLockable.setLockCode(new LockCode(""));
            world.playSound(
                (EntityPlayer) null,
                player.posX,
                player.posY,
                player.posZ,
                SoundEvents.UI_BUTTON_CLICK,
                SoundCategory.BLOCKS,
                0.5F,
                world.rand.nextFloat() * 0.1F + 0.9F);
            player.addChatComponentMessage(
                new TextComponentTranslation("text.key.successOnUnlock", new Object[0]), true);

          } else if (!tileEntityLockable.getLockCode().getLock().equals(current.getDisplayName())) {
            world.playSound(
                (EntityPlayer) null,
                player.posX,
                player.posY,
                player.posZ,
                SoundEvents.UI_BUTTON_CLICK,
                SoundCategory.BLOCKS,
                0.5F,
                world.rand.nextFloat() * 0.1F + 0.9F);
            player.addChatComponentMessage(
                new TextComponentTranslation("text.key.errorOnKey", new Object[0]), true);
            event.setCanceled(true);
          }
        } else {
          world.playSound(
              (EntityPlayer) null,
              player.posX,
              player.posY,
              player.posZ,
              SoundEvents.UI_BUTTON_CLICK,
              SoundCategory.BLOCKS,
              0.5F,
              world.rand.nextFloat() * 0.1F + 0.9F);
          player.addChatComponentMessage(
              new TextComponentTranslation("text.key.errorOnBlock", new Object[0]), true);
          event.setCanceled(true);
        }
      } else {
        if (current != null && current.getItem() == ZeiyoItems.key) {
          if (!current
              .getDisplayName()
              .equals(I18n.translateToLocal(current.getItem().getUnlocalizedName() + ".name"))) {
            tileEntityLockable.setLockCode(new LockCode(current.getDisplayName()));
            world.playSound(
                (EntityPlayer) null,
                player.posX,
                player.posY,
                player.posZ,
                SoundEvents.UI_BUTTON_CLICK,
                SoundCategory.BLOCKS,
                0.5F,
                world.rand.nextFloat() * 0.1F + 0.9F);
            player.addChatComponentMessage(
                new TextComponentTranslation("text.key.successOnLock", new Object[0]), true);

          } else {

            player.addChatComponentMessage(
                new TextComponentTranslation("text.key.errorOnKeyName", new Object[0]), true);
          }
          event.setCanceled(true);
        }
      }
    }
  }
コード例 #10
0
 @Override
 protected Optional<String> getVal(TileEntityLockable container) {
   return Optional.of(container.getLockCode().getLock());
 }
コード例 #11
0
 @Override
 protected boolean set(TileEntityLockable container, String value) {
   container.setLockCode(value.length() == 0 ? LockCode.EMPTY_CODE : new LockCode(value));
   return true;
 }