Skip to content

Commit

Permalink
updated to 1.11, fixed skill multiplier calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
RypoFalem committed Nov 17, 2016
1 parent f485d18 commit 9a674a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
5 changes: 2 additions & 3 deletions resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ softdepend: [Skills]
commands:
permissions:
growstick.use:
escription: Use the growstick.
default: true

description: Use the growstick.
default: true
6 changes: 3 additions & 3 deletions src/io/github/rypofalem/growstick/BlockUpdater.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package io.github.rypofalem.growstick;

import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_11_R1.util.CraftMagicNumbers;

import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.BlockPosition;


public abstract class BlockUpdater {

//schedules a "random tick" block update
//see https://minecraft.gamepedia.com/Tick#Block_tick
static void update(Location loc){
net.minecraft.server.v1_10_R1.World mcWorld = ((org.bukkit.craftbukkit.v1_10_R1.CraftWorld) loc.getWorld()).getHandle();
net.minecraft.server.v1_11_R1.World mcWorld = ((org.bukkit.craftbukkit.v1_11_R1.CraftWorld) loc.getWorld()).getHandle();
BlockPosition blockPos = new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
mcWorld.a(blockPos, CraftMagicNumbers.getBlock(loc.getBlock()), 1);
}
Expand Down
32 changes: 13 additions & 19 deletions src/io/github/rypofalem/growstick/GrowStickPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -44,7 +45,7 @@ void loadConfig(){
reloadConfig();
if(getConfig() == null) return;
doNotUpdateList = new ArrayList<Material>();

if(getConfig().contains("blacklist")){
List<String> blacklist = getConfig().getStringList("blacklist");
if(blacklist != null){
Expand All @@ -58,11 +59,11 @@ void loadConfig(){
}
}
}

if(getConfig().isDouble("baseMultiplier")){
baseMultiplier = (float) getConfig().getDouble("baseMultiplier");
}

if(getConfig().isDouble("skillMultiplier")){
skillMultiplier = (float) getConfig().getDouble("skillMultiplier");
}
Expand All @@ -82,9 +83,10 @@ public void onRightClick(PlayerInteractEvent event){

int range = getRange(event.getPlayer());
int length= 2*range + 1;
float updateBase = length * length * getMultiplier(event.getPlayer());
int updates = (int) Math.max(1, updateBase * baseMultiplier);
if((updateBase - (int)(updateBase)) * baseMultiplier <= rand.nextFloat()){
float updateBase = length * length * getMultiplier(event.getPlayer()) * baseMultiplier;

int updates = (int) Math.max(1, updateBase);
if((updateBase - (int)(updateBase)) <= rand.nextFloat()){
//TODO: optimize so this happens 1/x times without random number generation
updates++;
}
Expand All @@ -96,19 +98,11 @@ public void onRightClick(PlayerInteractEvent event){
for(int yOffset = 2; yOffset >= -1; yOffset--){
Block crop = world.getBlockAt(x, y + yOffset, z);
Material cropType = crop.getType();
boolean isBlacklisted = false;
for(Material mat : doNotUpdateList){
if(cropType.equals(mat)){
isBlacklisted = true;
break;
}
}
if(isBlacklisted) continue;
if(crop.getType() != Material.AIR){ //any other block is safe to schedule an update for
Location blockLoc = new Location(world, x + .5, y + yOffset + .99, z + .5);
BlockUpdater.update(blockLoc);
world.playEffect(blockLoc, Effect.FLYING_GLYPH, 1 );
}
if(doNotUpdateList.contains(cropType)) continue;
if(crop.getType() == Material.AIR) continue;
Location blockLoc = new Location(world, x + .5, y + yOffset + .99, z + .5);
BlockUpdater.update(blockLoc);
world.spawnParticle(Particle.ENCHANTMENT_TABLE, blockLoc, 1);
}
}

Expand Down

0 comments on commit 9a674a8

Please sign in to comment.