Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: type=="foo" and type=="bar" #3

Open
professor opened this issue Jul 2, 2019 · 2 comments
Open

Idea: type=="foo" and type=="bar" #3

professor opened this issue Jul 2, 2019 · 2 comments

Comments

@professor
Copy link
Collaborator

There's an object or strategies waiting in every code base?

  • rollercoaster
  • IaaS
  • Minecraft mine(tool, block)
@professor
Copy link
Collaborator Author

professor commented Jul 2, 2019

@benchristel
Copy link
Owner

@professor something like this?

class Player
  def mine(tool, block)
    if Block.INDESTRUCTIBLE.include?(block.type)
      return
    end

    if tool.type == :pick && !Block.MINEABLE_BY_PICK.include?(block.type)
      # destroy the block without dropping anything
      block.destroy!
      return
    end

    if tool.type == :shovel && !Block.MINEABLE_BY_SHOVEL.include?(block.type)
      # destroy the block without dropping anything
      block.destroy!
      return
    end

    if tool.strength < Tool.STONE && block.hardness >= Block.IRON ||
       tool.strength < Tool.DIAMOND && block.hardness >= Block.OBSIDIAN
      # destroy block without dropping anything
      block.destroy!
      return
    end

    if block.type == :redstone
      # redstone drops multiple items
      block.drop_all([:redstone] * rand(4..6))
      block.destroy!
      return
    end

    if block.type == :lapis
      # lapis drops multiple items
      block.drop_all([:lapis] * rand(2..4))
      block.destroy!
      return
    end

    if block.type == :cracked_stone
      block.destroy!
      # cracked stone doesn't drop anything
      return
    end

    # default case: drop one item
    block.drop(block.type)
    block.destroy!
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants