Skip to content

Commit

Permalink
Added support for block metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
falkirks committed Aug 18, 2015
1 parent c1a3a8a commit 7510778
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: MineReset
main: minereset\MineReset
version: 2.0.3
version: 2.1
author: Falk
api: [1.0.0]
load: POSTWORLD
Expand All @@ -23,4 +23,4 @@ permissions:
minereset.command.reset:
description: Reset mines
minereset.command.destroy:
description: Remove old mines
description: Remove mines
7 changes: 6 additions & 1 deletion src/minereset/MineReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
$save = [];
foreach ($sets as $key => $item) {
if ( $key & 1 ) {
$save[$sets[$key-1]] = $item;
if(isset($save[$sets[$key-1]])){
$save[$sets[$key-1]] += $item;
}
else {
$save[$sets[$key - 1]] = $item;
}
}
}
$this->mines[$args[1]]->setData($save);
Expand Down
12 changes: 11 additions & 1 deletion src/minereset/MineResetTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public function onRun(){
}
$sum = [];
$id = array_keys(unserialize($this->ratioData));
for($i = 0; $i < count($id); $i++){
$blockId = explode(":", $id[$i]);
if(!isset($blockId[1])){
$blockId[1] = 0;
}
$id[$i] = $blockId;
}

$m = array_values(unserialize($this->ratioData));
$sum[0] = $m[0];

This comment has been minimized.

Copy link
@karpovichv

karpovichv Nov 9, 2015

Could you please explain what is going on in this method (specifically, at this line and further)? The code is quite not self-explanatory. :)

This comment has been minimized.

Copy link
@falkirks

falkirks Nov 10, 2015

Author Owner

I am just going to be upfront about this, that code is really old and I don't touch it anymore. Here is my best explanation. We need to create a way to map random values to specific blocks (so we know what block to insert where). We do this simply by creating ranges for each block, let's say we have 10% iron and 90% wood. Then we generate a number from 1 to 100 and anything beween 0 and 10 is iron and anything between 10 and 100 is wood. The line below generates an array that represents the ranges needed. There is nothing hardwiring this to percentages out of a hundred, I just say that to make things easy, they really are just proper ratios (S(n)/sum of S). Is there anything else that is confusing?

This comment has been minimized.

Copy link
@karpovichv

karpovichv Nov 10, 2015

Yes, this seems to be pointless:
$y & 0x7f, $id[$l][0] & 0xff, $id[$l][1] & 0xff

This comment has been minimized.

Copy link
@falkirks

falkirks Nov 10, 2015

Author Owner

That makes sure the values don't exceed 128 for $y and 255 for the id and metadata. It could be removed I supposed.

for ($l = 1; $l < count($m); $l++) $sum[$l] = $sum[$l - 1] + $m[$l];
Expand All @@ -48,7 +56,9 @@ public function onRun(){
for ($l = 0; $l < count($sum); $l++) {
if ($a <= $sum[$l]) {
$hash = Level::chunkHash($x >> 4, $z >> 4);
if(isset($chunks[$hash])) $chunks[$hash]->setBlock($x & 0x0f, $y & 0x7f, $z & 0x0f, $id[$l] & 0xff, 0);
if(isset($chunks[$hash])){
$chunks[$hash]->setBlock($x & 0x0f, $y & 0x7f, $z & 0x0f, $id[$l][0] & 0xff, $id[$l][1] & 0xff);
}
$l = count($sum);
}
}
Expand Down

0 comments on commit 7510778

Please sign in to comment.