Last active
August 29, 2015 14:04
-
-
Save MultiMote/c51cf126cf00fa4b9a36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.multimote.microz.item.admin; | |
import com.multimote.microz.utils.OtherUtils; | |
import net.minecraft.block.Block; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.util.ChatComponentText; | |
import net.minecraft.world.World; | |
import java.util.List; | |
/** | |
* Created by multimote on 31.07.14. | |
*/ | |
public class RecursiveCleaner extends AdminItem { | |
public RecursiveCleaner(){ | |
setUnlocalizedName("recleaner"); | |
setTextureName("microz:recleaner"); | |
} | |
public void onUpdate(ItemStack is, World world, Entity en, int par4, boolean par5) { | |
checkCompound(is); | |
} | |
public void add(ItemStack is) { | |
incrementIntIfNotNull(is, "BlockLimit"); | |
} | |
public void rem(ItemStack is) { | |
int current = getIntIfNotNull(is, "BlockLimit"); | |
if(current-1>1)decrementIntIfNotNull(is, "BlockLimit"); | |
} | |
public void breakblocks(World world, ItemStack is, int x, int y, int z, Block block){ | |
if(world.getBlock(x , y, z)!=block || getIntIfNotNull(is, "BlocksDone") > getIntIfNotNull(is, "BlockLimit")) return; | |
world.setBlockToAir(x, y, z); | |
incrementIntIfNotNull(is, "BlocksDone"); | |
breakblocks(world, is, x+1, y, z, block); | |
breakblocks(world, is, x-1, y, z, block); | |
breakblocks(world, is, x, y+1, z, block); | |
breakblocks(world, is, x, y-1, z, block); | |
breakblocks(world, is, x, y, z+1, block); | |
breakblocks(world, is, x, y, z-1, block); | |
} | |
@Override | |
public boolean onItemUse(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { | |
if(!world.isRemote && OtherUtils.checkPermsAndSendMsg(player)){ | |
setIntIfNotNull(is, "BlocksDone", 0); | |
setIntIfNotNull(is, "BlockLimit", 30); | |
try { | |
breakblocks(world, is, x, y, z, world.getBlock(x, y, z)); | |
}catch (StackOverflowError err){ | |
player.addChatMessage(new ChatComponentText("Oops, StackOverflow.")); | |
} | |
} | |
return true; | |
} | |
@Override | |
public void addInformation(ItemStack is, EntityPlayer par2EntityPlayer, List list, boolean par4) { | |
list.add("Limit: " + getIntIfNotNull(is, "BlockLimit")); | |
list.add("Last broken: " + getIntIfNotNull(is, "BlocksDone")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment