file_name
stringlengths 6
86
| file_path
stringlengths 45
249
| content
stringlengths 47
6.26M
| file_size
int64 47
6.26M
| language
stringclasses 1
value | extension
stringclasses 1
value | repo_name
stringclasses 767
values | repo_stars
int64 8
14.4k
| repo_forks
int64 0
1.17k
| repo_open_issues
int64 0
788
| repo_created_at
stringclasses 767
values | repo_pushed_at
stringclasses 767
values |
---|---|---|---|---|---|---|---|---|---|---|---|
BlockFallable.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFallable.java | package cn.nukkit.block;
import cn.nukkit.entity.item.EntityFallingBlock;
import cn.nukkit.level.Level;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.DoubleTag;
import cn.nukkit.nbt.tag.FloatTag;
import cn.nukkit.nbt.tag.ListTag;
/**
* author: rcsuperman
* Nukkit Project
*/
public abstract class BlockFallable extends BlockSolid {
protected BlockFallable() {};
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
Block down = this.down();
if (down.getId() == AIR || down instanceof BlockLiquid) {
this.level.setBlock(this, Block.get(Block.AIR), true, true);
CompoundTag nbt = new CompoundTag()
.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("", this.x + 0.5))
.add(new DoubleTag("", this.y))
.add(new DoubleTag("", this.z + 0.5)))
.putList(new ListTag<DoubleTag>("Motion")
.add(new DoubleTag("", 0))
.add(new DoubleTag("", 0))
.add(new DoubleTag("", 0)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("", 0))
.add(new FloatTag("", 0)))
.putInt("TileID", this.getId())
.putByte("Data", this.getDamage());
EntityFallingBlock fall = new EntityFallingBlock(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
fall.spawnToAll();
}
}
return type;
}
}
| 1,751 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockStairs.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockStairs.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.SimpleAxisAlignedBB;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class BlockStairs extends BlockTransparentMeta {
protected BlockStairs(int meta) {
super(meta);
}
@Override
public double getMinY() {
// TODO: this seems wrong
return this.y + (getDamage() & 0x04) > 0 ? 0.5 : 0;
}
@Override
public double getMaxY() {
// TODO: this seems wrong
return this.y + (getDamage() & 0x04) > 0 ? 1 : 0.5;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
return this.place(item, block, target, face, fx, fy, fz, null);
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
int[] faces = new int[]{2, 1, 3, 0};
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
if ((fy > 0.5 && face != BlockFace.UP) || face == BlockFace.DOWN) {
this.setDamage(this.getDamage() | 0x04); //Upside-down stairs
}
this.getLevel().setBlock(block, this, true, true);
return true;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
Item item = super.toItem();
item.setDamage(0);
return item;
}
@Override
public boolean collidesWithBB(AxisAlignedBB bb) {
int damage = this.getDamage();
int side = damage & 0x03;
double f = 0;
double f1 = 0.5;
double f2 = 0.5;
double f3 = 1;
if ((damage & 0x04) > 0) {
f = 0.5;
f1 = 1;
f2 = 0;
f3 = 0.5;
}
if (bb.intersectsWith(new SimpleAxisAlignedBB(
this.x,
this.y + f,
this.z,
this.x + 1,
this.y + f1,
this.z + 1
))) {
return true;
}
if (side == 0) {
if (bb.intersectsWith(new SimpleAxisAlignedBB(
this.x + 0.5,
this.y + f2,
this.z,
this.x + 1,
this.y + f3,
this.z + 1
))) {
return true;
}
} else if (side == 1) {
if (bb.intersectsWith(new SimpleAxisAlignedBB(
this.x,
this.y + f2,
this.z,
this.x + 0.5,
this.y + f3,
this.z + 1
))) {
return true;
}
} else if (side == 2) {
if (bb.intersectsWith(new SimpleAxisAlignedBB(
this.x,
this.y + f2,
this.z + 0.5,
this.x + 1,
this.y + f3,
this.z + 1
))) {
return true;
}
} else if (side == 3) {
if (bb.intersectsWith(new SimpleAxisAlignedBB(
this.x,
this.y + f2,
this.z,
this.x + 1,
this.y + f3,
this.z + 0.5
))) {
return true;
}
}
return false;
}
}
| 3,865 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPressurePlateBase.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPressurePlateBase.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.entity.Entity;
import cn.nukkit.event.Event;
import cn.nukkit.event.block.BlockRedstoneEvent;
import cn.nukkit.event.entity.EntityInteractEvent;
import cn.nukkit.event.player.PlayerInteractEvent;
import cn.nukkit.event.player.PlayerInteractEvent.Action;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.level.Level;
import cn.nukkit.level.Sound;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.SimpleAxisAlignedBB;
/**
* Created by Snake1999 on 2016/1/11.
* Package cn.nukkit.block in project nukkit
*/
public abstract class BlockPressurePlateBase extends BlockFlowable {
protected float onPitch;
protected float offPitch;
protected BlockPressurePlateBase() {
this(0);
}
protected BlockPressurePlateBase(int meta) {
super(meta);
}
@Override
public boolean canPassThrough() {
return true;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
@Override
public double getMinX() {
return this.x + 0.625;
}
@Override
public double getMinZ() {
return this.z + 0.625;
}
@Override
public double getMinY() {
return this.y + 0;
}
@Override
public double getMaxX() {
return this.x + 0.9375;
}
@Override
public double getMaxZ() {
return this.z + 0.9375;
}
@Override
public double getMaxY() {
return isActivated() ? this.y + 0.03125 : this.y + 0.0625;
}
@Override
public boolean isPowerSource() {
return true;
}
public boolean isActivated() {
return this.getDamage() == 0;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.down().isTransparent()) {
this.level.useBreakOn(this);
}
} else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
int power = this.getRedstonePower();
if (power > 0) {
this.updateState(power);
}
}
return 0;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
// System.out.println("place");
if (block.down().isTransparent()) {
return false;
}
this.level.setBlock(block, this, true, true);
return true;
}
@Override
protected AxisAlignedBB recalculateCollisionBoundingBox() {
return new SimpleAxisAlignedBB(this.x + 0.125, this.y, this.z + 0.125, this.x + 0.875, this.y + 0.25, this.z + 0.875D);
}
@Override
public void onEntityCollide(Entity entity) {
int power = getRedstonePower();
if (power == 0) {
Event ev;
if (entity instanceof Player) {
ev = new PlayerInteractEvent((Player) entity, null, this, null, Action.PHYSICAL);
} else {
ev = new EntityInteractEvent(entity, this);
}
this.level.getServer().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
updateState(power);
}
}
}
protected void updateState(int oldStrength) {
int strength = this.computeRedstoneStrength();
boolean wasPowered = oldStrength > 0;
boolean isPowered = strength > 0;
if (oldStrength != strength) {
this.setRedstonePower(strength);
this.level.setBlock(this, this, false, false);
this.level.updateAroundRedstone(this, null);
this.level.updateAroundRedstone(this.getLocation().down(), null);
if (!isPowered && wasPowered) {
this.playOffSound();
this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));
} else if (isPowered && !wasPowered) {
this.playOnSound();
this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 0, 15));
}
}
if (isPowered) {
this.level.scheduleUpdate(this, 20);
}
}
@Override
public boolean onBreak(Item item) {
this.level.setBlock(this, new BlockAir(), true, true);
if (this.getRedstonePower() > 0) {
this.level.updateAroundRedstone(this, null);
this.level.updateAroundRedstone(this.getLocation().down(), null);
}
return true;
}
@Override
public int getWeakPower(BlockFace side) {
return getRedstonePower();
}
@Override
public int getStrongPower(BlockFace side) {
return side == BlockFace.UP ? this.getRedstonePower() : 0;
}
public int getRedstonePower() {
return this.getDamage();
}
public void setRedstonePower(int power) {
this.setDamage(power);
}
protected void playOnSound() {
this.level.addSound(this, Sound.RANDOM_CLICK, 0.6f, onPitch);
}
protected void playOffSound() {
this.level.addSound(this, Sound.RANDOM_CLICK, 0.6f, offPitch);
}
protected abstract int computeRedstoneStrength();
@Override
public Item toItem() {
return new ItemBlock(this, 0, 1);
}
} | 5,386 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDaylightDetector.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDaylightDetector.java | package cn.nukkit.block;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/11/22 by CreeperFace.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockDaylightDetector extends BlockTransparent {
public BlockDaylightDetector() {
}
@Override
public int getId() {
return DAYLIGHT_DETECTOR;
}
@Override
public String getName() {
return "Daylight Detector";
}
@Override
public double getHardness() {
return 0.2;
}
@Override
public BlockColor getColor() {
return BlockColor.WOOD_BLOCK_COLOR;
}
//这个函数提供一个结构的建议,可重命名也可删
protected boolean invertDetect() {
return false;
}
//todo redstone
}
| 768 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockGold.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockGold.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockGold extends BlockSolid {
public BlockGold() {
}
@Override
public int getId() {
return GOLD_BLOCK;
}
@Override
public String getName() {
return "Gold Block";
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 30;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_IRON) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.GOLD_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,092 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockMonsterEgg.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockMonsterEgg.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
public class BlockMonsterEgg extends BlockSolidMeta {
public static final int STONE = 0;
public static final int COBBLESTONE = 1;
public static final int STONE_BRICK = 2;
public static final int MOSSY_BRICK = 3;
public static final int CRACKED_BRICK = 4;
public static final int CHISELED_BRICK = 5;
public BlockMonsterEgg() {
this(0);
}
public BlockMonsterEgg(int meta) {
super(meta);
}
@Override
public int getId() {
return MONSTER_EGG;
}
@Override
public double getHardness() {
return 0.75;
}
@Override
public double getResistance() {
return 3.75;
}
@Override
public String getName() {
String[] names = new String[]{
"Stone",
"Cobblestone",
"Stone Brick",
"Mossy Stone Brick",
"Cracked Stone Brick",
"Chiseled Stone Brick"
};
return names[this.getDamage() & 0x07] + " Monster Egg";
}
@Override
public Item[] getDrops(Item item) {
return new Item[0];
}
}
| 1,187 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSandstone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSandstone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockSandstone extends BlockSolidMeta {
public static final int NORMAL = 0;
public static final int CHISELED = 1;
public static final int SMOOTH = 2;
public BlockSandstone() {
this(0);
}
public BlockSandstone(int meta) {
super(meta);
}
@Override
public int getId() {
return SANDSTONE;
}
@Override
public double getHardness() {
return 0.8;
}
@Override
public double getResistance() {
return 4;
}
@Override
public String getName() {
String[] names = new String[]{
"Sandstone",
"Chiseled Sandstone",
"Smooth Sandstone",
""
};
return names[this.getDamage() & 0x03];
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(this, this.getDamage() & 0x03);
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public BlockColor getColor() {
return BlockColor.SAND_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,647 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockWallSign.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockWallSign.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
/**
* Created by Pub4Game on 26.12.2015.
*/
public class BlockWallSign extends BlockSignPost {
public BlockWallSign() {
this(0);
}
public BlockWallSign(int meta) {
super(meta);
}
@Override
public int getId() {
return WALL_SIGN;
}
@Override
public String getName() {
return "Wall Sign";
}
@Override
public int onUpdate(int type) {
int[] faces = {
3,
2,
5,
4,
};
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.getDamage() >= 2 && this.getDamage() <= 5) {
if (this.getSide(BlockFace.fromIndex(faces[this.getDamage() - 2])).getId() == Item.AIR) {
this.getLevel().useBreakOn(this);
}
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
}
| 1,039 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSolidMeta.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSolidMeta.java | package cn.nukkit.block;
import cn.nukkit.utils.BlockColor;
public abstract class BlockSolidMeta extends BlockMeta {
protected BlockSolidMeta(int meta) {
super(meta);
}
@Override
public boolean isSolid() {
return true;
}
@Override
public BlockColor getColor() {
return BlockColor.STONE_BLOCK_COLOR;
}
}
| 363 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockCarrot.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockCarrot.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemCarrot;
import java.util.Random;
/**
* @author Nukkit Project Team
*/
public class BlockCarrot extends BlockCrops {
public BlockCarrot(int meta) {
super(meta);
}
public BlockCarrot() {
this(0);
}
@Override
public String getName() {
return "Carrot Block";
}
@Override
public int getId() {
return CARROT_BLOCK;
}
@Override
public Item[] getDrops(Item item) {
if (getDamage() >= 0x07) {
return new Item[]{
new ItemCarrot(0, new Random().nextInt(3) + 1)
};
}
return new Item[]{
new ItemCarrot()
};
}
@Override
public Item toItem() {
return new ItemCarrot();
}
}
| 844 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockOreCoal.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockOreCoal.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemCoal;
import cn.nukkit.item.ItemTool;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.math.NukkitRandom;
import java.util.concurrent.ThreadLocalRandom;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockOreCoal extends BlockSolid {
public BlockOreCoal() {
}
@Override
public int getId() {
return COAL_ORE;
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 15;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
return "Coal Ore";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
int count = 1;
Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
if (fortune != null && fortune.getLevel() >= 1) {
int i = ThreadLocalRandom.current().nextInt(fortune.getLevel() + 2) - 1;
if (i < 0) {
i = 0;
}
count = i + 1;
}
return new Item[]{
new ItemCoal(0, count)
};
} else {
return new Item[0];
}
}
@Override
public int getDropExp() {
return new NukkitRandom().nextRange(0, 2);
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,628 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDoubleSlab.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDoubleSlab.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockDoubleSlab extends BlockSolidMeta {
public static final int STONE = 0;
public static final int SANDSTONE = 1;
public static final int WOODEN = 2;
public static final int COBBLESTONE = 3;
public static final int BRICK = 4;
public static final int STONE_BRICK = 5;
public static final int QUARTZ = 6;
public static final int NETHER_BRICK = 7;
public BlockDoubleSlab() {
this(0);
}
public BlockDoubleSlab(int meta) {
super(meta);
}
@Override
public int getId() {
return DOUBLE_SLAB;
}
//todo hardness and residence
@Override
public double getHardness() {
return 2;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
String[] names = new String[]{
"Stone",
"Sandstone",
"Wooden",
"Cobblestone",
"Brick",
"Stone Brick",
"Quartz",
"Nether Brick"
};
return "Double " + names[this.getDamage() & 0x07] + " Slab";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
Item.get(Item.SLAB, this.getDamage() & 0x07, 2)
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
switch (this.getDamage() & 0x07) {
case BlockDoubleSlab.STONE:
return BlockColor.STONE_BLOCK_COLOR;
case BlockDoubleSlab.SANDSTONE:
return BlockColor.SAND_BLOCK_COLOR;
case BlockDoubleSlab.WOODEN:
return BlockColor.WOOD_BLOCK_COLOR;
case BlockDoubleSlab.COBBLESTONE:
return BlockColor.STONE_BLOCK_COLOR;
case BlockDoubleSlab.BRICK:
return BlockColor.STONE_BLOCK_COLOR;
case BlockDoubleSlab.STONE_BRICK:
return BlockColor.STONE_BLOCK_COLOR;
case BlockDoubleSlab.QUARTZ:
return BlockColor.QUARTZ_BLOCK_COLOR;
case BlockDoubleSlab.NETHER_BRICK:
return BlockColor.NETHERRACK_BLOCK_COLOR;
default:
return BlockColor.STONE_BLOCK_COLOR; //unreachable
}
}
}
| 2,635 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockLava.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockLava.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.entity.Entity;
import cn.nukkit.event.block.BlockIgniteEvent;
import cn.nukkit.event.entity.EntityCombustByBlockEvent;
import cn.nukkit.event.entity.EntityDamageByBlockEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
import cn.nukkit.item.Item;
import cn.nukkit.level.GameRule;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
import cn.nukkit.potion.Effect;
import cn.nukkit.utils.BlockColor;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockLava extends BlockLiquid {
public BlockLava() {
this(0);
}
public BlockLava(int meta) {
super(meta);
}
@Override
public int getId() {
return LAVA;
}
@Override
public int getLightLevel() {
return 15;
}
@Override
public String getName() {
return "Lava";
}
@Override
public void onEntityCollide(Entity entity) {
entity.highestPosition -= (entity.highestPosition - entity.y) * 0.5;
if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.LAVA, 4));
}
// Always setting the duration to 15 seconds? TODO
EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 15);
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled()
// Making sure the entity is acutally alive and not invulnerable.
&& entity.isAlive()
&& entity.noDamageTicks == 0) {
entity.setOnFire(ev.getDuration());
}
super.onEntityCollide(entity);
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
return this.place(item, block, target, face, fx, fy, fz, null);
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
boolean ret = this.getLevel().setBlock(this, this, true, false);
this.getLevel().scheduleUpdate(this, this.tickRate());
return ret;
}
@Override
public int onUpdate(int type) {
int result = super.onUpdate(type);
if (type == Level.BLOCK_UPDATE_RANDOM && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) {
Random random = ThreadLocalRandom.current();
int i = random.nextInt(3);
if (i > 0) {
for (int k = 0; k < i; ++k) {
Vector3 v = this.add(random.nextInt(3) - 1, 1, random.nextInt(3) - 1);
Block block = this.getLevel().getBlock(v);
if (block.getId() == AIR) {
if (this.isSurroundingBlockFlammable(block)) {
BlockIgniteEvent e = new BlockIgniteEvent(block, this, null, BlockIgniteEvent.BlockIgniteCause.LAVA);
this.level.getServer().getPluginManager().callEvent(e);
if (!e.isCancelled()) {
BlockFire fire = new BlockFire();
this.getLevel().setBlock(v, fire, true);
this.getLevel().scheduleUpdate(fire, fire.tickRate());
return Level.BLOCK_UPDATE_RANDOM;
}
return 0;
}
} else if (block.isSolid()) {
return Level.BLOCK_UPDATE_RANDOM;
}
}
} else {
for (int k = 0; k < 3; ++k) {
Vector3 v = this.add(random.nextInt(3) - 1, 0, random.nextInt(3) - 1);
Block block = this.getLevel().getBlock(v);
if (block.up().getId() == AIR && block.getBurnChance() > 0) {
BlockIgniteEvent e = new BlockIgniteEvent(block, this, null, BlockIgniteEvent.BlockIgniteCause.LAVA);
this.level.getServer().getPluginManager().callEvent(e);
if (!e.isCancelled()) {
BlockFire fire = new BlockFire();
this.getLevel().setBlock(v, fire, true);
this.getLevel().scheduleUpdate(fire, fire.tickRate());
}
}
}
}
}
return result;
}
protected boolean isSurroundingBlockFlammable(Block block) {
for (BlockFace face : BlockFace.values()) {
if (block.getSide(face).getBurnChance() > 0) {
return true;
}
}
return false;
}
@Override
public BlockColor getColor() {
return BlockColor.LAVA_BLOCK_COLOR;
}
@Override
public BlockLiquid getBlock(int meta) {
return new BlockLava(meta);
}
}
| 5,171 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockNetherPortal.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockNetherPortal.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2016/1/5 by xtypr.
* Package cn.nukkit.block in project nukkit .
* The name NetherPortalBlock comes from minecraft wiki.
*/
public class BlockNetherPortal extends BlockFlowable {
public BlockNetherPortal() {
this(0);
}
public BlockNetherPortal(int meta) {
super(0);
}
@Override
public String getName() {
return "Nether Portal Block";
}
@Override
public int getId() {
return NETHER_PORTAL;
}
@Override
public boolean canPassThrough() {
return true;
}
@Override
public boolean isBreakable(Item item) {
return false;
}
@Override
public double getHardness() {
return -1;
}
@Override
public int getLightLevel() {
return 11;
}
@Override
public boolean onBreak(Item item) {
boolean result = super.onBreak(item);
for (BlockFace face : BlockFace.values()) {
Block b = this.getSide(face);
if (b != null) {
if (b instanceof BlockNetherPortal) {
result &= b.onBreak(item);
}
}
}
return result;
}
@Override
public boolean hasEntityCollision() {
return true;
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
@Override
public boolean canBePushed() {
return false;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
@Override
protected AxisAlignedBB recalculateBoundingBox() {
return this;
}
}
| 1,803 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPiston.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPiston.java | package cn.nukkit.block;
/**
* @author CreeperFace
*/
public class BlockPiston extends BlockPistonBase {
public BlockPiston() {
this(0);
}
public BlockPiston(int meta) {
super(meta);
}
@Override
public int getId() {
return PISTON;
}
@Override
public String getName() {
return "Piston";
}
}
| 369 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockMushroomRed.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockMushroomRed.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.level.generator.object.mushroom.BigMushroom;
import cn.nukkit.level.particle.BoneMealParticle;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.DyeColor;
import java.util.concurrent.ThreadLocalRandom;
/**
* Created by Pub4Game on 03.01.2015.
*/
public class BlockMushroomRed extends BlockFlowable {
public BlockMushroomRed() {
this(0);
}
public BlockMushroomRed(int meta) {
super(0);
}
@Override
public String getName() {
return "Red Mushroom";
}
@Override
public int getId() {
return RED_MUSHROOM;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (!canStay()) {
getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
// System.out.println("light: " + this.level.getFullLight(this));
if (canStay()) {
getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public boolean onActivate(Item item, Player player) {
if (item.getId() == Item.DYE && item.getDamage() == DyeColor.WHITE.getDyeData()) {
if (ThreadLocalRandom.current().nextFloat() < 0.4) {
this.grow();
}
this.level.addParticle(new BoneMealParticle(this));
return true;
}
return false;
}
public boolean grow() {
this.level.setBlock(this, new BlockAir(), true, false);
BigMushroom generator = new BigMushroom(1);
if (generator.generate(this.level, new NukkitRandom(), this)) {
return true;
} else {
this.level.setBlock(this, this, true, false);
return false;
}
}
public boolean canStay() {
Block block = this.down();
return block.getId() == MYCELIUM || block.getId() == PODZOL || (!block.isTransparent() && this.level.getFullLight(this) < 13);
}
@Override
public BlockColor getColor() {
return BlockColor.FOLIAGE_BLOCK_COLOR;
}
}
| 2,576 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedSandstone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedSandstone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
/**
* Created by CreeperFace on 26. 11. 2016.
*/
public class BlockRedSandstone extends BlockSandstone {
public BlockRedSandstone() {
this(0);
}
public BlockRedSandstone(int meta) {
super(meta);
}
@Override
public int getId() {
return RED_SANDSTONE;
}
@Override
public String getName() {
String[] names = new String[]{
"Red Sandstone",
"Chiseled Red Sandstone",
"Smooth Red Sandstone",
""
};
return names[this.getDamage() & 0x03];
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(this, this.getDamage() & 0x03);
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,177 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazedBlue.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazedBlue.java | package cn.nukkit.block;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockTerracottaGlazedBlue extends BlockTerracottaGlazed {
public BlockTerracottaGlazedBlue() {
this(0);
}
public BlockTerracottaGlazedBlue(int meta) {
super(meta);
}
@Override
public int getId() {
return BLUE_GLAZED_TERRACOTTA;
}
@Override
public String getName() {
return "Blue Glazed Terracotta";
}
}
| 465 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTrapdoor.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTrapdoor.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.event.block.BlockRedstoneEvent;
import cn.nukkit.event.block.DoorToggleEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.level.Sound;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.SimpleAxisAlignedBB;
import cn.nukkit.utils.BlockColor;
/**
* Created by Pub4Game on 26.12.2015.
*/
public class BlockTrapdoor extends BlockTransparentMeta {
public BlockTrapdoor() {
this(0);
}
public BlockTrapdoor(int meta) {
super(meta);
}
@Override
public int getId() {
return TRAPDOOR;
}
@Override
public String getName() {
return "Wooden Trapdoor";
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 15;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
private static final AxisAlignedBB[] boundingBoxDamage = new AxisAlignedBB[16];
static {
for (int damage = 0; damage < 16; damage++) {
AxisAlignedBB bb;
double f = 0.1875;
if ((damage & 0x08) > 0) {
bb = new SimpleAxisAlignedBB(
0,
0 + 1 - f,
0,
0 + 1,
0 + 1,
0 + 1
);
} else {
bb = new SimpleAxisAlignedBB(
0,
0,
0,
0 + 1,
0 + f,
0 + 1
);
}
if ((damage & 0x04) > 0) {
if ((damage & 0x03) == 0) {
bb.setBounds(
0,
0,
0 + 1 - f,
0 + 1,
0 + 1,
0 + 1
);
} else if ((damage & 0x03) == 1) {
bb.setBounds(
0,
0,
0,
0 + 1,
0 + 1,
0 + f
);
}
if ((damage & 0x03) == 2) {
bb.setBounds(
0 + 1 - f,
0,
0,
0 + 1,
0 + 1,
0 + 1
);
}
if ((damage & 0x03) == 3) {
bb.setBounds(
0,
0,
0,
0 + f,
0 + 1,
0 + 1
);
}
}
boundingBoxDamage[damage] = bb;
}
}
private AxisAlignedBB getRelativeBoundingBox() {
return boundingBoxDamage[this.getDamage()];
}
@Override
public double getMinX() {
return this.x + getRelativeBoundingBox().getMinX();
}
@Override
public double getMaxX() {
return this.x + getRelativeBoundingBox().getMaxX();
}
@Override
public double getMinY() {
return this.y + getRelativeBoundingBox().getMinY();
}
@Override
public double getMaxY() {
return this.y + getRelativeBoundingBox().getMaxY();
}
@Override
public double getMinZ() {
return this.z + getRelativeBoundingBox().getMinZ();
}
@Override
public double getMaxZ() {
return this.z + getRelativeBoundingBox().getMaxZ();
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_REDSTONE || type == Level.BLOCK_UPDATE_NORMAL) {
if ((!isOpen() && this.level.isBlockPowered(this)) || (isOpen() && !this.level.isBlockPowered(this))) {
this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isOpen() ? 15 : 0, isOpen() ? 0 : 15));
this.toggle(null);
return type;
}
}
return 0;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
BlockFace facing;
boolean top;
if (face.getAxis().isHorizontal() || player == null) {
facing = face;
top = fy > 0.5;
} else {
facing = player.getDirection().getOpposite();
top = face != BlockFace.UP;
}
int[] faces = {2, 1, 3, 0};
int faceBit = faces[facing.getHorizontalIndex()];
this.setDamage(this.getDamage() | faceBit);
if (top) {
this.setDamage(this.getDamage() | 0x04);
}
this.getLevel().setBlock(block, this, true, true);
return true;
}
@Override
public Item toItem() {
return new ItemBlock(this, 0);
}
@Override
public boolean onActivate(Item item, Player player) {
if (!this.toggle(player)) {
return false;
}
this.level.addSound(this, isOpen() ? Sound.RANDOM_DOOR_OPEN : Sound.RANDOM_DOOR_CLOSE);
return true;
}
@Override
public BlockColor getColor() {
return BlockColor.WOOD_BLOCK_COLOR;
}
public boolean toggle(Player player) {
DoorToggleEvent event = new DoorToggleEvent(this, player);
this.getLevel().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
int sideBit = this.getDamage() & 0x07;
boolean open = isOpen();
this.setDamage(sideBit);
if (open) {
this.setDamage(this.getDamage() | 0x08);
}
this.level.setBlock(this, this, false, false);
return true;
}
public BlockFace getFacing() {
int[] faces = {3, 1, 0, 2};
return BlockFace.fromHorizontalIndex(faces[this.getDamage() & 0x03]);
}
public boolean isOpen() {
return (this.getDamage() & 0x08) != 0;
}
public boolean isTop() {
return (this.getDamage() & 0x04) != 0;
}
}
| 6,651 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockObsidianGlowing.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockObsidianGlowing.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
/**
* Created on 2015/11/22 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockObsidianGlowing extends BlockSolid {
public BlockObsidianGlowing() {
}
@Override
public int getId() {
return GLOWING_OBSIDIAN;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
return "Glowing Obsidian";
}
@Override
public double getHardness() {
return 50;
}
@Override
public double getResistance() {
return 6000;
}
@Override
public int getLightLevel() {
return 12;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() > ItemTool.DIAMOND_PICKAXE) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public boolean canBePushed() {
return false;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,192 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockWeightedPressurePlateLight.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockWeightedPressurePlateLight.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.NukkitMath;
import cn.nukkit.utils.BlockColor;
/**
* @author CreeperFace
*/
public class BlockWeightedPressurePlateLight extends BlockPressurePlateBase {
public BlockWeightedPressurePlateLight() {
this(0);
}
public BlockWeightedPressurePlateLight(int meta) {
super(meta);
this.onPitch = 0.90000004f;
this.offPitch = 0.75f;
}
@Override
public int getId() {
return LIGHT_WEIGHTED_PRESSURE_PLATE;
}
@Override
public String getName() {
return "Weighted Pressure Plate (Light)";
}
@Override
public double getHardness() {
return 0.5D;
}
@Override
public double getResistance() {
return 2.5D;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(this, 0);
}
@Override
public BlockColor getColor() {
return BlockColor.GOLD_BLOCK_COLOR;
}
@Override
protected int computeRedstoneStrength() {
int count = Math.min(this.level.getCollidingEntities(getCollisionBoundingBox()).length, this.getMaxWeight());
if (count > 0) {
float f = (float) Math.min(this.getMaxWeight(), count) / (float) this.getMaxWeight();
return NukkitMath.ceilFloat(f * 15.0F);
} else {
return 0;
}
}
public int getMaxWeight() {
return 15;
}
} | 1,881 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockStairsJungle.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockStairsJungle.java | package cn.nukkit.block;
/**
* Created on 2015/11/25 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockStairsJungle extends BlockStairsWood {
public BlockStairsJungle() {
this(0);
}
public BlockStairsJungle(int meta) {
super(meta);
}
@Override
public int getId() {
return JUNGLE_WOOD_STAIRS;
}
@Override
public String getName() {
return "Jungle Wood Stairs";
}
}
| 471 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstoneLamp.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstoneLamp.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
/**
* @author Nukkit Project Team
*/
public class BlockRedstoneLamp extends BlockSolid {
public BlockRedstoneLamp() {
}
@Override
public String getName() {
return "Redstone Lamp";
}
@Override
public int getId() {
return REDSTONE_LAMP;
}
@Override
public double getHardness() {
return 0.3D;
}
@Override
public double getResistance() {
return 1.5D;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (this.level.isBlockPowered(this)) {
this.level.setBlock(this, new BlockRedstoneLampLit(), false, true);
} else {
this.level.setBlock(this, this, false, true);
}
return true;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
if (this.level.isBlockPowered(this)) {
this.level.setBlock(this, new BlockRedstoneLampLit(), false, false);
return 1;
}
}
return 0;
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{
new ItemBlock(new BlockRedstoneLamp())
};
}
}
| 1,632 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSand.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSand.java | package cn.nukkit.block;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockSand extends BlockFallable {
public static final int DEFAULT = 0;
public static final int RED = 1;
private int meta;
public BlockSand() {
this(0);
}
public BlockSand(int meta) {
this.meta = meta;
}
@Override
public int getFullId() {
return (getId() << 4) + getDamage();
}
@Override
public final int getDamage() {
return this.meta;
}
@Override
public final void setDamage(int meta) {
this.meta = meta;
}
@Override
public int getId() {
return SAND;
}
@Override
public double getHardness() {
return 0.5;
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public String getName() {
if (this.getDamage() == 0x01) {
return "Red Sand";
}
return "Sand";
}
@Override
public BlockColor getColor() {
return BlockColor.SAND_BLOCK_COLOR;
}
}
| 1,241 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockCake.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockCake.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemCake;
import cn.nukkit.item.food.Food;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/**
* @author Nukkit Project Team
*/
public class BlockCake extends BlockTransparentMeta {
public BlockCake(int meta) {
super(meta);
}
public BlockCake() {
this(0);
}
@Override
public String getName() {
return "Cake Block";
}
@Override
public int getId() {
return CAKE_BLOCK;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public double getHardness() {
return 0.5;
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public double getMinX() {
return this.x + (1 + getDamage() * 2) / 16;
}
@Override
public double getMinY() {
return this.y;
}
@Override
public double getMinZ() {
return this.z + 0.0625;
}
@Override
public double getMaxX() {
return this.x - 0.0625 + 1;
}
@Override
public double getMaxY() {
return this.y + 0.5;
}
@Override
public double getMaxZ() {
return this.z - 0.0625 + 1;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (down().getId() != Block.AIR) {
getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (down().getId() == Block.AIR) {
getLevel().setBlock(this, new BlockAir(), true);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public Item[] getDrops(Item item) {
return new Item[0];
}
@Override
public Item toItem() {
return new ItemCake();
}
@Override
public boolean onActivate(Item item, Player player) {
if (player != null && player.getFoodData().getLevel() < player.getFoodData().getMaxLevel()) {
if (getDamage() <= 0x06) setDamage(getDamage() + 1);
if (getDamage() >= 0x06) {
getLevel().setBlock(this, new BlockAir(), true);
} else {
Food.getByRelative(this).eatenBy(player);
getLevel().setBlock(this, this, true);
}
return true;
}
return false;
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
public int getComparatorInputOverride() {
return (7 - this.getDamage()) * 2;
}
public boolean hasComparatorInputOverride() {
return true;
}
}
| 2,964 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockIron.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockIron.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockIron extends BlockSolid {
public BlockIron() {
}
@Override
public int getId() {
return IRON_BLOCK;
}
@Override
public String getName() {
return "Iron Block";
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public double getHardness() {
return 5;
}
@Override
public double getResistance() {
return 10;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_STONE) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.IRON_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,093 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDirt.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDirt.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockDirt extends BlockSolid {
public BlockDirt() {
}
@Override
public int getId() {
return DIRT;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public double getHardness() {
return 0.5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public String getName() {
return "Dirt";
}
@Override
public boolean onActivate(Item item) {
return this.onActivate(item, null);
}
@Override
public boolean onActivate(Item item, Player player) {
if (item.isHoe()) {
item.useOn(this);
this.getLevel().setBlock(this, new BlockFarmland(), true);
return true;
}
return false;
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{new ItemBlock(new BlockDirt())};
}
@Override
public BlockColor getColor() {
return BlockColor.DIRT_BLOCK_COLOR;
}
}
| 1,365 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFurnaceBurning.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFurnaceBurning.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityFurnace;
import cn.nukkit.inventory.ContainerInventory;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.BlockFace;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.nbt.tag.StringTag;
import cn.nukkit.nbt.tag.Tag;
import java.util.Map;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockFurnaceBurning extends BlockSolidMeta {
public BlockFurnaceBurning() {
this(0);
}
public BlockFurnaceBurning(int meta) {
super(meta);
}
@Override
public int getId() {
return BURNING_FURNACE;
}
@Override
public String getName() {
return "Burning Furnace";
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public double getHardness() {
return 3.5;
}
@Override
public double getResistance() {
return 17.5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public int getLightLevel() {
return 13;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
int faces[] = {2, 5, 3, 4};
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag()
.putList(new ListTag<>("Items"))
.putString("id", BlockEntity.FURNACE)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z);
if (item.hasCustomName()) {
nbt.putString("CustomName", item.getCustomName());
}
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
return true;
}
@Override
public boolean onBreak(Item item) {
this.getLevel().setBlock(this, new BlockAir(), true, true);
return true;
}
@Override
public boolean onActivate(Item item, Player player) {
if (player != null) {
BlockEntity t = this.getLevel().getBlockEntity(this);
BlockEntityFurnace furnace;
if (t instanceof BlockEntityFurnace) {
furnace = (BlockEntityFurnace) t;
} else {
CompoundTag nbt = new CompoundTag()
.putList(new ListTag<>("Items"))
.putString("id", BlockEntity.FURNACE)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z);
furnace = new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
}
if (furnace.namedTag.contains("Lock") && furnace.namedTag.get("Lock") instanceof StringTag) {
if (!furnace.namedTag.getString("Lock").equals(item.getCustomName())) {
return true;
}
}
player.addWindow(furnace.getInventory());
}
return true;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
new ItemBlock(new BlockFurnace())
};
} else {
return new Item[0];
}
}
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride() {
BlockEntity blockEntity = this.level.getBlockEntity(this);
if (blockEntity instanceof BlockEntityFurnace) {
return ContainerInventory.calculateRedstone(((BlockEntityFurnace) blockEntity).getInventory());
}
return super.getComparatorInputOverride();
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 4,515 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFence.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFence.java | package cn.nukkit.block;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.SimpleAxisAlignedBB;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/7 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockFence extends BlockTransparentMeta {
public static final int FENCE_OAK = 0;
public static final int FENCE_SPRUCE = 1;
public static final int FENCE_BIRCH = 2;
public static final int FENCE_JUNGLE = 3;
public static final int FENCE_ACACIA = 4;
public static final int FENCE_DARK_OAK = 5;
public BlockFence() {
this(0);
}
public BlockFence(int meta) {
super(meta);
}
@Override
public int getId() {
return FENCE;
}
@Override
public double getHardness() {
return 2;
}
@Override
public double getResistance() {
return 15;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
@Override
public String getName() {
String[] names = new String[]{
"Oak Fence",
"Spruce Fence",
"Birch Fence",
"Jungle Fence",
"Acacia Fence",
"Dark Oak Fence",
"",
""
};
return names[this.getDamage() & 0x07];
}
@Override
protected AxisAlignedBB recalculateBoundingBox() {
boolean north = this.canConnect(this.north());
boolean south = this.canConnect(this.south());
boolean west = this.canConnect(this.west());
boolean east = this.canConnect(this.east());
double n = north ? 0 : 0.375;
double s = south ? 1 : 0.625;
double w = west ? 0 : 0.375;
double e = east ? 1 : 0.625;
return new SimpleAxisAlignedBB(
this.x + w,
this.y,
this.z + n,
this.x + e,
this.y + 1.5,
this.z + s
);
}
@Override
public int getBurnChance() {
return 5;
}
@Override
public int getBurnAbility() {
return 20;
}
public boolean canConnect(Block block) {
return (block instanceof BlockFence || block instanceof BlockFenceGate) || block.isSolid() && !block.isTransparent();
}
@Override
public BlockColor getColor() {
return BlockColor.WOOD_BLOCK_COLOR;
}
}
| 2,469 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockMycelium.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockMycelium.java | package cn.nukkit.block;
import cn.nukkit.Server;
import cn.nukkit.event.block.BlockSpreadEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.math.Vector3;
import cn.nukkit.utils.BlockColor;
/**
* Created by Pub4Game on 03.01.2016.
*/
public class BlockMycelium extends BlockSolid {
public BlockMycelium() {
}
@Override
public String getName() {
return "Mycelium";
}
@Override
public int getId() {
return MYCELIUM;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public double getHardness() {
return 0.6;
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{
new ItemBlock(new BlockDirt())
};
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_RANDOM) {
//TODO: light levels
NukkitRandom random = new NukkitRandom();
x = random.nextRange((int) x - 1, (int) x + 1);
y = random.nextRange((int) y - 1, (int) y + 1);
z = random.nextRange((int) z - 1, (int) z + 1);
Block block = this.getLevel().getBlock(new Vector3(x, y, z));
if (block.getId() == Block.DIRT) {
if (block.up().isTransparent()) {
BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockMycelium());
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(block, ev.getNewState());
}
}
}
}
return 0;
}
@Override
public BlockColor getColor() {
return BlockColor.GRASS_BLOCK_COLOR;
}
}
| 2,012 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPurpur.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPurpur.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.BlockFace;
public class BlockPurpur extends BlockSolidMeta {
public static final int PURPUR_NORMAL = 0;
public static final int PURPUR_PILLAR = 2;
public BlockPurpur() {
this(0);
}
public BlockPurpur(int meta) {
super(meta);
}
@Override
public String getName() {
String[] names = new String[]{
"Purpur Block",
"",
"Purpur Pillar",
""
};
return names[this.getDamage() & 0x03];
}
@Override
public int getId() {
return PURPUR_BLOCK;
}
@Override
public double getHardness() {
return 1.5;
}
@Override
public double getResistance() {
return 30;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (this.getDamage() != PURPUR_NORMAL) {
short[] faces = new short[]{
0,
0,
0b1000,
0b1000,
0b0100,
0b0100
};
this.setDamage(((this.getDamage() & 0x03) | faces[face.getIndex()]));
}
this.getLevel().setBlock(block, this, true, true);
return true;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(new BlockPurpur(), this.getDamage() & 0x03, 1);
}
}
| 1,988 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFlowable.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFlowable.java | package cn.nukkit.block;
import cn.nukkit.math.AxisAlignedBB;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class BlockFlowable extends BlockTransparentMeta {
protected BlockFlowable(int meta) {
super(meta);
}
@Override
public boolean canBeFlowedInto() {
return true;
}
@Override
public boolean canPassThrough() {
return true;
}
@Override
public double getHardness() {
return 0;
}
@Override
public double getResistance() {
return 0;
}
@Override
public boolean isSolid() {
return false;
}
@Override
protected AxisAlignedBB recalculateBoundingBox() {
return null;
}
}
| 730 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockEnchantingTable.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockEnchantingTable.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityEnchantTable;
import cn.nukkit.inventory.EnchantInventory;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.BlockFace;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.nbt.tag.StringTag;
import cn.nukkit.nbt.tag.Tag;
import java.util.Map;
/**
* Created on 2015/11/22 by CreeperFace.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockEnchantingTable extends BlockTransparent {
public BlockEnchantingTable() {
}
@Override
public int getId() {
return ENCHANTING_TABLE;
}
@Override
public String getName() {
return "Enchanting Table";
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public double getHardness() {
return 5;
}
@Override
public double getResistance() {
return 6000;
}
@Override
public int getLightLevel() {
return 12;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag()
.putString("id", BlockEntity.ENCHANT_TABLE)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z);
if (item.hasCustomName()) {
nbt.putString("CustomName", item.getCustomName());
}
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
BlockEntity.createBlockEntity(BlockEntity.ENCHANT_TABLE, getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
return true;
}
@Override
public boolean onActivate(Item item, Player player) {
if (player != null) {
BlockEntity t = this.getLevel().getBlockEntity(this);
BlockEntityEnchantTable enchantTable;
if (t instanceof BlockEntityEnchantTable) {
enchantTable = (BlockEntityEnchantTable) t;
} else {
CompoundTag nbt = new CompoundTag()
.putList(new ListTag<>("Items"))
.putString("id", BlockEntity.ENCHANT_TABLE)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z);
enchantTable = new BlockEntityEnchantTable(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
}
if (enchantTable.namedTag.contains("Lock") && enchantTable.namedTag.get("Lock") instanceof StringTag) {
if (!enchantTable.namedTag.getString("Lock").equals(item.getCustomName())) {
return true;
}
}
player.addWindow(new EnchantInventory(this.getLocation()), Player.ENCHANT_WINDOW_ID);
}
return true;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 3,785 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockLeaves.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockLeaves.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.event.block.LeavesDecayEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemApple;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
import java.util.ArrayList;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockLeaves extends BlockTransparentMeta {
public static final int OAK = 0;
public static final int SPRUCE = 1;
public static final int BRICH = 2;
public static final int JUNGLE = 3;
public static final int ACACIA = 4;
public static final int DARK_OAK = 5;
public BlockLeaves() {
this(0);
}
public BlockLeaves(int meta) {
super(meta);
}
@Override
public int getId() {
return LEAVES;
}
@Override
public double getHardness() {
return 0.2;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHEARS;
}
@Override
public String getName() {
String[] names = new String[]{
"Oak Leaves",
"Spruce Leaves",
"Birch Leaves",
"Jungle Leaves"
};
return names[this.getDamage() & 0x03];
}
@Override
public int getBurnChance() {
return 30;
}
@Override
public int getBurnAbility() {
return 60;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
this.setDamage(this.getDamage() | 0x04);
this.getLevel().setBlock(this, this, true);
return true;
}
@Override
public Item toItem() {
return new ItemBlock(this, 0, 1);
}
@Override
public Item[] getDrops(Item item) {
if (item.isShears()) {
return new Item[]{
toItem()
};
} else {
if ((int) ((Math.random()) * 200) == 0 && (this.getDamage() & 0x03) == OAK) {
return new Item[]{
new ItemApple()
};
}
if ((int) ((Math.random()) * 20) == 0) {
return new Item[]{
new ItemBlock(new BlockSapling(), this.getDamage() & 0x03, 1)
};
}
}
return new Item[0];
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_RANDOM && (getDamage() & 0b00001100) == 0x00) {
setDamage(getDamage() | 0x08);
getLevel().setBlock(this, this, false, false);
} else if (type == Level.BLOCK_UPDATE_RANDOM) {
if ((getDamage() & 0b00001100) == 0x08) {
setDamage(getDamage() & 0x03);
ArrayList<String> visited = new ArrayList<>();
int check = 0;
LeavesDecayEvent ev = new LeavesDecayEvent(this);
Server.getInstance().getPluginManager().callEvent(ev);
if (ev.isCancelled() || findLog(this, visited, 0, check)) {
getLevel().setBlock(this, this, false, false);
} else {
getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
}
return 0;
}
private Boolean findLog(Block pos, ArrayList<String> visited, Integer distance, Integer check) {
return findLog(pos, visited, distance, check, null);
}
private Boolean findLog(Block pos, ArrayList<String> visited, Integer distance, Integer check, BlockFace fromSide) {
++check;
String index = pos.x + "." + pos.y + "." + pos.z;
if (visited.contains(index)) return false;
if (pos.getId() == Block.WOOD) return true;
if (pos.getId() == Block.LEAVES && distance < 4) {
visited.add(index);
Integer down = pos.down().getId();
if (down == Item.WOOD) {
return true;
}
if (fromSide == null) {
//North, East, South, West
for (Integer side = 2; side <= 5; ++side) {
if (this.findLog(pos.getSide(BlockFace.fromIndex(side)), visited, distance + 1, check, BlockFace.fromIndex(side)))
return true;
}
} else { //No more loops
switch (fromSide) {
case NORTH:
if (this.findLog(pos.getSide(BlockFace.NORTH), visited, distance + 1, check, fromSide))
return true;
if (this.findLog(pos.getSide(BlockFace.WEST), visited, distance + 1, check, fromSide))
return true;
if (this.findLog(pos.getSide(BlockFace.EAST), visited, distance + 1, check, fromSide))
return true;
break;
case SOUTH:
if (this.findLog(pos.getSide(BlockFace.SOUTH), visited, distance + 1, check, fromSide))
return true;
if (this.findLog(pos.getSide(BlockFace.WEST), visited, distance + 1, check, fromSide))
return true;
if (this.findLog(pos.getSide(BlockFace.EAST), visited, distance + 1, check, fromSide))
return true;
break;
case WEST:
if (this.findLog(pos.getSide(BlockFace.NORTH), visited, distance + 1, check, fromSide))
return true;
if (this.findLog(pos.getSide(BlockFace.SOUTH), visited, distance + 1, check, fromSide))
return true;
if (this.findLog(pos.getSide(BlockFace.WEST), visited, distance + 1, check, fromSide))
return true;
case EAST:
if (this.findLog(pos.getSide(BlockFace.NORTH), visited, distance + 1, check, fromSide))
return true;
if (this.findLog(pos.getSide(BlockFace.SOUTH), visited, distance + 1, check, fromSide))
return true;
if (this.findLog(pos.getSide(BlockFace.EAST), visited, distance + 1, check, fromSide))
return true;
break;
}
}
}
return false;
}
public boolean isChechDecay() {
return (this.getDamage() & 0x08) > 0;
}
public boolean isDecayable() {
return (this.getDamage() & 0x04) == 0;
}
@Override
public BlockColor getColor() {
return BlockColor.FOLIAGE_BLOCK_COLOR;
}
} | 6,933 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockCobweb.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockCobweb.java | package cn.nukkit.block;
import cn.nukkit.entity.Entity;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemString;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockCobweb extends BlockFlowable {
public BlockCobweb() {
this(0);
}
public BlockCobweb(int meta) {
super(0);
}
@Override
public String getName() {
return "Cobweb";
}
@Override
public int getId() {
return COBWEB;
}
@Override
public double getHardness() {
return 4;
}
@Override
public double getResistance() {
return 20;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SWORD;
}
@Override
public void onEntityCollide(Entity entity) {
entity.resetFallDistance();
}
@Override
public Item[] getDrops(Item item) {
if (item.isShears() || item.isSword()) {
return new Item[]{
new ItemString()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.CLOTH_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,364 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPistonBase.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPistonBase.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityPistonArm;
import cn.nukkit.event.block.BlockPistonChangeEvent;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.level.Sound;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
import cn.nukkit.nbt.tag.CompoundTag;
import java.util.ArrayList;
import java.util.List;
/**
* @author CreeperFace
*/
public abstract class BlockPistonBase extends BlockSolidMeta {
public boolean sticky;
public BlockPistonBase() {
this(0);
}
public BlockPistonBase(int meta) {
super(meta);
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public double getHardness() {
return 0.5;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (Math.abs(player.x - this.x) < 2 && Math.abs(player.z - this.z) < 2) {
double y = player.y + player.getEyeHeight();
if (y - this.y > 2) {
this.setDamage(BlockFace.UP.getIndex());
} else if (this.y - y > 0) {
this.setDamage(BlockFace.DOWN.getIndex());
} else {
this.setDamage(player.getHorizontalFacing().getIndex());
}
} else {
this.setDamage(player.getHorizontalFacing().getIndex());
}
this.level.setBlock(block, this, true, false);
CompoundTag nbt = new CompoundTag("")
.putString("id", BlockEntity.PISTON_ARM)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z)
.putBoolean("Sticky", this.sticky);
BlockEntityPistonArm be = new BlockEntityPistonArm(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
//this.checkState();
return true;
}
@Override
public boolean onBreak(Item item) {
this.level.setBlock(this, new BlockAir(), true, true);
Block block = this.getSide(getFacing());
if (block instanceof BlockPistonHead && ((BlockPistonHead) block).getFacing() == this.getFacing()) {
block.onBreak(item);
}
return true;
}
public boolean isExtended() {
BlockFace face = getFacing();
Block block = getSide(face);
return block instanceof BlockPistonHead && ((BlockPistonHead) block).getFacing() == face;
}
@Override
public int onUpdate(int type) {
if (type != 6 && type != 1) {
return 0;
} else {
BlockEntity blockEntity = this.level.getBlockEntity(this);
if (blockEntity instanceof BlockEntityPistonArm) {
BlockEntityPistonArm arm = (BlockEntityPistonArm) blockEntity;
boolean powered = this.isPowered();
if (arm.powered != powered) {
this.level.getServer().getPluginManager().callEvent(new BlockPistonChangeEvent(this, powered ? 0 : 15, powered ? 15 : 0));
arm.powered = !arm.powered;
if (arm.chunk != null) {
arm.chunk.setChanged();
}
}
}
return type;
}
}
private void checkState() {
BlockFace facing = getFacing();
boolean isPowered = this.isPowered();
if (isPowered && !isExtended()) {
if ((new BlocksCalculator(this.level, this, facing, true)).canMove()) {
if (!this.doMove(true)) {
return;
}
this.level.addSound(this, Sound.TILE_PISTON_OUT);
} else {
}
} else if (!isPowered && isExtended()) {
//this.level.setBlock() TODO: set piston extension?
if (this.sticky) {
Vector3 pos = this.add(facing.getXOffset() * 2, facing.getYOffset() * 2, facing.getZOffset() * 2);
Block block = this.level.getBlock(pos);
if (block.getId() == AIR) {
this.level.setBlock(this.getLocation().getSide(facing), new BlockAir(), true, true);
}
if (canPush(block, facing.getOpposite(), false) && (!(block instanceof BlockFlowable) || block.getId() == PISTON || block.getId() == STICKY_PISTON)) {
this.doMove(false);
}
} else {
this.level.setBlock(getLocation().getSide(facing), new BlockAir(), true, false);
}
this.level.addSound(this, Sound.TILE_PISTON_IN);
}
}
public BlockFace getFacing() {
return BlockFace.fromIndex(this.getDamage()).getOpposite();
}
private boolean isPowered() {
BlockFace face = getFacing();
for (BlockFace side : BlockFace.values()) {
if (side != face && this.level.isSidePowered(this.getLocation().getSide(side), side)) {
return true;
}
}
if (this.level.isSidePowered(this, BlockFace.DOWN)) {
return true;
} else {
Vector3 pos = this.getLocation().up();
for (BlockFace side : BlockFace.values()) {
if (side != BlockFace.DOWN && this.level.isSidePowered(pos.getSide(side), side)) {
return true;
}
}
return false;
}
}
private boolean doMove(boolean extending) {
Vector3 pos = this.getLocation();
BlockFace direction = getFacing();
if (!extending) {
this.level.setBlock(pos.getSide(direction), new BlockAir(), true, false);
}
BlocksCalculator calculator = new BlocksCalculator(this.level, this, direction, extending);
if (!calculator.canMove()) {
return false;
} else {
List<Block> blocks = calculator.getBlocksToMove();
List<Block> newBlocks = new ArrayList<>();
for (int i = 0; i < blocks.size(); ++i) {
Block block = blocks.get(i);
newBlocks.add(block);
}
List<Block> destroyBlocks = calculator.getBlocksToDestroy();
BlockFace side = extending ? direction : direction.getOpposite();
for (int i = destroyBlocks.size() - 1; i >= 0; --i) {
Block block = destroyBlocks.get(i);
this.level.useBreakOn(block);
}
for (int i = blocks.size() - 1; i >= 0; --i) {
Block block = blocks.get(i);
this.level.setBlock(block, new BlockAir());
Vector3 newPos = block.getLocation().getSide(side);
//TODO: change this to block entity
this.level.setBlock(newPos, newBlocks.get(i));
}
Vector3 pistonHead = pos.getSide(direction);
if (extending) {
//extension block entity
this.level.setBlock(pistonHead, new BlockPistonHead(this.getDamage()));
}
return true;
}
}
public static boolean canPush(Block block, BlockFace face, boolean destroyBlocks) {
if (!block.canBePushed()) {
return false;
} else if (block.getY() >= 0 && (face != BlockFace.DOWN || block.getY() != 0)) {
if (block.getY() <= 255 && (face != BlockFace.UP || block.getY() != 255)) {
if (!(block instanceof BlockPistonBase)) {
if (block instanceof BlockFlowable) {
return destroyBlocks;
}
} else if (((BlockPistonBase) block).isExtended()) {
return false;
}
return true;
} else {
return false;
}
} else {
return false;
}
}
public class BlocksCalculator {
private final Level level;
private final Vector3 pistonPos;
private final Block blockToMove;
private final BlockFace moveDirection;
private final List<Block> toMove = new ArrayList<>();
private final List<Block> toDestroy = new ArrayList<>();
public BlocksCalculator(Level level, Block pos, BlockFace facing, boolean extending) {
this.level = level;
this.pistonPos = pos.getLocation();
if (extending) {
this.moveDirection = facing;
this.blockToMove = pos.getSide(facing);
} else {
this.moveDirection = facing.getOpposite();
this.blockToMove = pos.getSide(facing, 2);
}
}
public boolean canMove() {
this.toMove.clear();
this.toDestroy.clear();
Block block = this.blockToMove;
if (!canPush(block, this.moveDirection, false)) {
if (block instanceof BlockFlowable) {
this.toDestroy.add(this.blockToMove);
return true;
} else {
return false;
}
} else if (!this.addBlockLine(this.blockToMove)) {
return false;
} else {
for (int i = 0; i < this.toMove.size(); ++i) {
Block b = this.toMove.get(i);
if (b.getId() == SLIME_BLOCK && !this.addBranchingBlocks(b)) {
return false;
}
}
return true;
}
}
private boolean addBlockLine(Block origin) {
Block block = origin.clone();
if (block.getId() == AIR) {
return true;
} else if (!canPush(origin, this.moveDirection, false)) {
return true;
} else if (origin.equals(this.pistonPos)) {
return true;
} else if (this.toMove.contains(origin)) {
return true;
} else {
int count = 1;
if (count + this.toMove.size() > 12) {
return false;
} else {
while (block.getId() == SLIME_BLOCK) {
block = origin.getSide(this.moveDirection.getOpposite(), count);
if (block.getId() == AIR || !canPush(block, this.moveDirection, false) || block.equals(this.pistonPos)) {
break;
}
++count;
if (count + this.toMove.size() > 12) {
return false;
}
}
int blockCount = 0;
for (int step = count - 1; step >= 0; --step) {
this.toMove.add(block.getSide(this.moveDirection.getOpposite(), step));
++blockCount;
}
int steps = 1;
while (true) {
Block nextBlock = block.getSide(this.moveDirection, steps);
int index = this.toMove.indexOf(nextBlock);
if (index > -1) {
this.reorderListAtCollision(blockCount, index);
for (int l = 0; l <= index + blockCount; ++l) {
Block b = this.toMove.get(l);
if (b.getId() == SLIME_BLOCK && !this.addBranchingBlocks(b)) {
return false;
}
}
return true;
}
if (nextBlock.getId() == AIR) {
return true;
}
if (!canPush(nextBlock, this.moveDirection, true) || nextBlock.equals(this.pistonPos)) {
return false;
}
if (nextBlock instanceof BlockFlowable) {
this.toDestroy.add(nextBlock);
return true;
}
if (this.toMove.size() >= 12) {
return false;
}
this.toMove.add(nextBlock);
++blockCount;
++steps;
}
}
}
}
private void reorderListAtCollision(int count, int index) {
List<Block> list = new ArrayList<>();
List<Block> list1 = new ArrayList<>();
List<Block> list2 = new ArrayList<>();
list.addAll(this.toMove.subList(0, index));
list1.addAll(this.toMove.subList(this.toMove.size() - count, this.toMove.size()));
list2.addAll(this.toMove.subList(index, this.toMove.size() - count));
this.toMove.clear();
this.toMove.addAll(list);
this.toMove.addAll(list1);
this.toMove.addAll(list2);
}
private boolean addBranchingBlocks(Block block) {
for (BlockFace face : BlockFace.values()) {
if (face.getAxis() != this.moveDirection.getAxis() && !this.addBlockLine(block.getSide(face))) {
return false;
}
}
return true;
}
public List<Block> getBlocksToMove() {
return this.toMove;
}
public List<Block> getBlocksToDestroy() {
return this.toDestroy;
}
}
} | 13,828 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockLapis.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockLapis.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockLapis extends BlockSolid {
public BlockLapis() {
}
@Override
public int getId() {
return LAPIS_BLOCK;
}
@Override
public String getName() {
return "Lapis Lazuli Block";
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 5;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_STONE) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.LAPIS_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,105 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstoneTorch.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstoneTorch.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockRedstoneTorch extends BlockTorch {
public BlockRedstoneTorch() {
this(0);
}
public BlockRedstoneTorch(int meta) {
super(meta);
}
@Override
public String getName() {
return "Redstone Torch";
}
@Override
public int getId() {
return REDSTONE_TORCH;
}
@Override
public int getLightLevel() {
return 7;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block below = this.down();
Vector3 pos = getLocation();
if (!target.isTransparent() && face != BlockFace.DOWN) {
this.setDamage(getFacing(face.getIndex()).getIndex());
this.getLevel().setBlock(block, this, true, true);
for (BlockFace side : BlockFace.values()) {
this.level.updateAround(pos.getSide(side));
}
return true;
} else if (!below.isTransparent() || below instanceof BlockFence || below.getId() == COBBLE_WALL) {
this.setDamage(0);
this.getLevel().setBlock(block, this, true, true);
for (BlockFace side : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(side), null);
}
return true;
}
return false;
}
@Override
public int getWeakPower(BlockFace side) {
//return BlockFace.getFront(this.meta).getOpposite() != side ? 15 : 0;
return 15;
}
@Override
public int getStrongPower(BlockFace side) {
return side == BlockFace.DOWN ? this.getWeakPower(side) : 0;
}
@Override
public boolean onBreak(Item item) {
this.getLevel().setBlock(this, new BlockAir(), true, true);
Vector3 pos = getLocation();
for (BlockFace side : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(side), null);
}
return true;
}
@Override
public boolean isPowerSource() {
return true;
}
}
| 2,287 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockChest.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockChest.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityChest;
import cn.nukkit.inventory.ContainerInventory;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.BlockFace;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.nbt.tag.StringTag;
import cn.nukkit.nbt.tag.Tag;
import cn.nukkit.utils.BlockColor;
import java.util.Map;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockChest extends BlockTransparentMeta {
public BlockChest() {
this(0);
}
public BlockChest(int meta) {
super(meta);
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public int getId() {
return CHEST;
}
@Override
public String getName() {
return "Chest";
}
@Override
public double getHardness() {
return 2.5;
}
@Override
public double getResistance() {
return 12.5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
@Override
public double getMinX() {
return this.x + 0.0625;
}
@Override
public double getMinY() {
return this.y;
}
@Override
public double getMinZ() {
return this.z + 0.0625;
}
@Override
public double getMaxX() {
return this.x + 0.9375;
}
@Override
public double getMaxY() {
return this.y + 0.9475;
}
@Override
public double getMaxZ() {
return this.z + 0.9375;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
BlockEntityChest chest = null;
int[] faces = {2, 5, 3, 4};
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
for (int side = 2; side <= 5; ++side) {
if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == 4 || side == 5)) {
continue;
} else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == 2 || side == 3)) {
continue;
}
Block c = this.getSide(BlockFace.fromIndex(side));
if (c instanceof BlockChest && c.getDamage() == this.getDamage()) {
BlockEntity blockEntity = this.getLevel().getBlockEntity(c);
if (blockEntity instanceof BlockEntityChest && !((BlockEntityChest) blockEntity).isPaired()) {
chest = (BlockEntityChest) blockEntity;
break;
}
}
}
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag("")
.putList(new ListTag<>("Items"))
.putString("id", BlockEntity.CHEST)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z);
if (item.hasCustomName()) {
nbt.putString("CustomName", item.getCustomName());
}
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
BlockEntity blockEntity = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
if (chest != null) {
chest.pairWith(((BlockEntityChest) blockEntity));
((BlockEntityChest) blockEntity).pairWith(chest);
}
return true;
}
@Override
public boolean onBreak(Item item) {
BlockEntity t = this.getLevel().getBlockEntity(this);
if (t instanceof BlockEntityChest) {
((BlockEntityChest) t).unpair();
}
this.getLevel().setBlock(this, new BlockAir(), true, true);
return true;
}
@Override
public boolean onActivate(Item item, Player player) {
if (player != null) {
Block top = up();
if (!top.isTransparent()) {
return true;
}
BlockEntity t = this.getLevel().getBlockEntity(this);
BlockEntityChest chest;
if (t instanceof BlockEntityChest) {
chest = (BlockEntityChest) t;
} else {
CompoundTag nbt = new CompoundTag("")
.putList(new ListTag<>("Items"))
.putString("id", BlockEntity.CHEST)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z);
chest = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
}
if (chest.namedTag.contains("Lock") && chest.namedTag.get("Lock") instanceof StringTag) {
if (!chest.namedTag.getString("Lock").equals(item.getCustomName())) {
return true;
}
}
player.addWindow(chest.getInventory());
}
return true;
}
@Override
public BlockColor getColor() {
return BlockColor.WOOD_BLOCK_COLOR;
}
public boolean hasComparatorInputOverride() {
return true;
}
public int getComparatorInputOverride() {
BlockEntity blockEntity = this.level.getBlockEntity(this);
if (blockEntity instanceof BlockEntityChest) {
return ContainerInventory.calculateRedstone(((BlockEntityChest) blockEntity).getInventory());
}
return super.getComparatorInputOverride();
}
}
| 5,846 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockGrassPath.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockGrassPath.java | package cn.nukkit.block;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/11/22 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockGrassPath extends BlockGrass {
public BlockGrassPath() {
}
@Override
public int getId() {
return GRASS_PATH;
}
@Override
public String getName() {
return "Grass Path";
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public double getMaxY() {
return this.y + 0.9375;
}
@Override
public double getResistance() {
return 3.25;
}
@Override
public BlockColor getColor() {
//todo edit this after minecraft pc 1.9 come out
return BlockColor.GRASS_BLOCK_COLOR;
}
}
| 834 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazedSilver.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazedSilver.java | package cn.nukkit.block;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockTerracottaGlazedSilver extends BlockTerracottaGlazed {
public BlockTerracottaGlazedSilver() {
this(0);
}
public BlockTerracottaGlazedSilver(int meta) {
super(meta);
}
@Override
public int getId() {
return SILVER_GLAZED_TERRACOTTA;
}
@Override
public String getName() {
return "Light Gray Glazed Terracotta";
}
}
| 479 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSnow.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSnow.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemSnowball;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
public class BlockSnow extends BlockSolid {
public BlockSnow() {
}
@Override
public String getName() {
return "Snow Block";
}
@Override
public int getId() {
return SNOW_BLOCK;
}
@Override
public double getHardness() {
return 0.2;
}
@Override
public double getResistance() {
return 1;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public Item[] getDrops(Item item) {
if (item.isShovel() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
new ItemSnowball(0, 4)
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.SNOW_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,096 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRail.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRail.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.Rail;
import cn.nukkit.utils.Rail.Orientation;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static cn.nukkit.math.BlockFace.EAST;
import static cn.nukkit.math.BlockFace.NORTH;
import static cn.nukkit.math.BlockFace.SOUTH;
import static cn.nukkit.math.BlockFace.WEST;
import static cn.nukkit.utils.Rail.Orientation.*;
/**
* Created by Snake1999 on 2016/1/11.
* Package cn.nukkit.block in project nukkit
*/
public class BlockRail extends BlockFlowable {
// 0x8: Set the block active
// 0x7: Reset the block to normal
// If the rail can be powered. So its a complex rail!
protected boolean canBePowered = false;
public BlockRail() {
this(0);
}
public BlockRail(int meta) {
super(meta);
}
@Override
public String getName() {
return "Rail";
}
@Override
public int getId() {
return RAIL;
}
@Override
public double getHardness() {
return 0.7;
}
@Override
public double getResistance() {
return 3.5;
}
@Override
public boolean canPassThrough() {
return true;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
Optional<BlockFace> ascendingDirection = this.getOrientation().ascendingDirection();
if (this.down().isTransparent() || (ascendingDirection.isPresent() && this.getSide(ascendingDirection.get()).isTransparent())) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public double getMaxY() {
return this.y + 0.125;
}
@Override
public AxisAlignedBB recalculateBoundingBox() {
return this;
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
//Information from http://minecraft.gamepedia.com/Rail
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (down == null || down.isTransparent()) {
return false;
}
Map<BlockRail, BlockFace> railsAround = this.checkRailsAroundAffected();
List<BlockRail> rails = new ArrayList<>(railsAround.keySet());
List<BlockFace> faces = new ArrayList<>(railsAround.values());
if (railsAround.size() == 1) {
BlockRail other = rails.get(0);
this.setDamage(this.connect(other, railsAround.get(other)).metadata());
} else if (railsAround.size() == 4) {
if (this.isAbstract()) {
this.setDamage(this.connect(rails.get(faces.indexOf(SOUTH)), SOUTH, rails.get(faces.indexOf(EAST)), EAST).metadata());
} else {
this.setDamage(this.connect(rails.get(faces.indexOf(EAST)), EAST, rails.get(faces.indexOf(WEST)), WEST).metadata());
}
} else if (!railsAround.isEmpty()) {
if (this.isAbstract()) {
if (railsAround.size() == 2) {
BlockRail rail1 = rails.get(0);
BlockRail rail2 = rails.get(1);
this.setDamage(this.connect(rail1, railsAround.get(rail1), rail2, railsAround.get(rail2)).metadata());
} else {
List<BlockFace> cd = Stream.of(CURVED_SOUTH_EAST, CURVED_NORTH_EAST, CURVED_SOUTH_WEST)
.filter(o -> o.connectingDirections().stream().allMatch(faces::contains))
.findFirst().get().connectingDirections();
BlockFace f1 = cd.get(0);
BlockFace f2 = cd.get(1);
this.setDamage(this.connect(rails.get(faces.indexOf(f1)), f1, rails.get(faces.indexOf(f2)), f2).metadata());
}
} else {
BlockFace f = faces.stream()
.sorted((f1, f2) -> (f1.getIndex() < f2.getIndex()) ? 1 : ((x == y) ? 0 : -1))
.findFirst().get();
BlockFace fo = f.getOpposite();
if (faces.contains(fo)) { //Opposite connectable
this.setDamage(this.connect(rails.get(faces.indexOf(f)), f, rails.get(faces.indexOf(fo)), fo).metadata());
} else {
this.setDamage(this.connect(rails.get(faces.indexOf(f)), f).metadata());
}
}
}
this.level.setBlock(this, this, true, true);
if (!isAbstract()) {
level.scheduleUpdate(this, this, 0);
}
return true;
}
private Orientation connect(BlockRail rail1, BlockFace face1, BlockRail rail2, BlockFace face2) {
this.connect(rail1, face1);
this.connect(rail2, face2);
if (face1.getOpposite() == face2) {
int delta1 = (int) (this.y - rail1.y);
int delta2 = (int) (this.y - rail2.y);
if (delta1 == -1) {
return Orientation.ascending(face1);
} else if (delta2 == -1) {
return Orientation.ascending(face2);
}
}
return straightOrCurved(face1, face2);
}
private Orientation connect(BlockRail other, BlockFace face) {
int delta = (int) (this.y - other.y);
Map<BlockRail, BlockFace> rails = other.checkRailsConnected();
if (rails.isEmpty()) { //Only one
other.setOrientation(delta == 1 ? ascending(face.getOpposite()) : straight(face));
return delta == -1 ? ascending(face) : straight(face);
} else if (rails.size() == 1) { //Already connected
BlockFace faceConnected = rails.values().iterator().next();
if (other.isAbstract() && faceConnected != face) { //Curve!
other.setOrientation(curved(face.getOpposite(), faceConnected));
return delta == -1 ? ascending(face) : straight(face);
} else if (faceConnected == face) { //Turn!
if (!other.getOrientation().isAscending()) {
other.setOrientation(delta == 1 ? ascending(face.getOpposite()) : straight(face));
}
return delta == -1 ? ascending(face) : straight(face);
} else if (other.getOrientation().hasConnectingDirections(NORTH, SOUTH)) { //North-south
other.setOrientation(delta == 1 ? ascending(face.getOpposite()) : straight(face));
return delta == -1 ? ascending(face) : straight(face);
}
}
return STRAIGHT_NORTH_SOUTH;
}
private Map<BlockRail, BlockFace> checkRailsAroundAffected() {
Map<BlockRail, BlockFace> railsAround = this.checkRailsAround(Arrays.asList(SOUTH, EAST, WEST, NORTH));
return railsAround.keySet().stream()
.filter(r -> r.checkRailsConnected().size() != 2)
.collect(Collectors.toMap(r -> r, railsAround::get));
}
private Map<BlockRail, BlockFace> checkRailsAround(Collection<BlockFace> faces) {
Map<BlockRail, BlockFace> result = new HashMap<>();
faces.forEach(f -> {
Block b = this.getSide(f);
Stream.of(b, b.up(), b.down())
.filter(Rail::isRailBlock)
.forEach(block -> result.put((BlockRail) block, f));
});
return result;
}
protected Map<BlockRail, BlockFace> checkRailsConnected() {
Map<BlockRail, BlockFace> railsAround = this.checkRailsAround(this.getOrientation().connectingDirections());
return railsAround.keySet().stream()
.filter(r -> r.getOrientation().hasConnectingDirections(railsAround.get(r).getOpposite()))
.collect(Collectors.toMap(r -> r, railsAround::get));
}
public boolean isAbstract() {
return this.getId() == RAIL;
}
public boolean canPowered() {
return this.canBePowered;
}
public Orientation getOrientation() {
return byMetadata(this.getRealMeta());
}
public void setOrientation(Orientation o) {
if (o.metadata() != this.getRealMeta()) {
this.setDamage(o.metadata());
this.level.setBlock(this, this, false, true);
}
}
public int getRealMeta() {
// Check if this can be powered
// Avoid modifying the value from meta (The rail orientation may be false)
// Reason: When the rail is curved, the meta will return STRAIGHT_NORTH_SOUTH.
// OR Null Pointer Exception
if (!isAbstract()) {
return getDamage() & 0x7;
}
// Return the default: This meta
return getDamage();
}
public boolean isActive() {
return (getDamage() & 0x8) != 0;
}
public void setActive(boolean active) {
if (active) {
setDamage(getDamage() | 0x8);
} else {
setDamage(getDamage() & 0x7);
}
level.setBlock(this, this, true, true);
}
}
| 9,443 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/*
* Created on 2015/12/11 by Pub4Game.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockRedstone extends BlockSolidMeta {
public BlockRedstone() {
this(0);
}
public BlockRedstone(int meta) {
super(0);
}
@Override
public int getId() {
return REDSTONE_BLOCK;
}
@Override
public double getResistance() {
return 10;
}
@Override
public double getHardness() {
return 5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
return "Redstone Block";
}
//TODO: redstone
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.REDSTONE_BLOCK_COLOR;
}
@Override
public boolean isPowerSource() {
return true;
}
@Override
public int getWeakPower(BlockFace face) {
return 15;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
} | 1,460 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazedPink.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazedPink.java | package cn.nukkit.block;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockTerracottaGlazedPink extends BlockTerracottaGlazed {
public BlockTerracottaGlazedPink() {
this(0);
}
public BlockTerracottaGlazedPink(int meta) {
super(meta);
}
@Override
public int getId() {
return PINK_GLAZED_TERRACOTTA;
}
@Override
public String getName() {
return "Pink Glazed Terracotta";
}
}
| 465 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockConcrete.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockConcrete.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockConcrete extends BlockSolidMeta {
public BlockConcrete() {
this(0);
}
public BlockConcrete(int meta) {
super(meta);
}
@Override
public int getId() {
return CONCRETE;
}
@Override
public double getResistance() {
return 9;
}
@Override
public double getHardness() {
return 1.8;
}
@Override
public String getName() {
return "Concrete";
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
return item.getTier() >= ItemTool.TIER_WOODEN ? new Item[]{toItem()} : new Item[0];
}
}
| 848 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockObsidian.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockObsidian.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockObsidian extends BlockSolid {
public BlockObsidian() {
}
@Override
public String getName() {
return "Obsidian";
}
@Override
public int getId() {
return OBSIDIAN;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public double getHardness() {
return 50;
}
@Override
public double getResistance() {
return 6000;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_DIAMOND) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public boolean onBreak(Item item) {
//destroy the nether portal
Block[] nearby = new Block[]{
this.up(), this.down(),
this.north(), south(),
this.west(), this.east(),
};
for (Block aNearby : nearby) {
if (aNearby != null) if (aNearby.getId() == NETHER_PORTAL) {
aNearby.onBreak(item);
}
}
return super.onBreak(item);
}
@Override
public BlockColor getColor() {
return BlockColor.OBSIDIAN_BLOCK_COLOR;
}
@Override
public boolean canBePushed() {
return false;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,703 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockCauldron.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockCauldron.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityCauldron;
import cn.nukkit.event.player.PlayerBucketEmptyEvent;
import cn.nukkit.event.player.PlayerBucketFillEvent;
import cn.nukkit.item.*;
import cn.nukkit.level.Sound;
import cn.nukkit.math.BlockFace;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.Tag;
import java.util.Map;
/**
* author: CreeperFace
* Nukkit Project
*/
public class BlockCauldron extends BlockSolidMeta {
public BlockCauldron() {
super(0);
}
public BlockCauldron(int meta) {
super(meta);
}
@Override
public int getId() {
return CAULDRON_BLOCK;
}
public String getName() {
return "Cauldron Block";
}
@Override
public double getResistance() {
return 10;
}
@Override
public double getHardness() {
return 2;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public boolean canBeActivated() {
return true;
}
public boolean isFull() {
return this.getDamage() == 0x06;
}
public boolean isEmpty() {
return this.getDamage() == 0x00;
}
@Override
public boolean onActivate(Item item, Player player) {
BlockEntity be = this.level.getBlockEntity(this);
if (!(be instanceof BlockEntityCauldron)) {
return false;
}
BlockEntityCauldron cauldron = (BlockEntityCauldron) be;
switch (item.getId()) {
case Item.BUCKET:
if (item.getDamage() == 0) {//empty bucket
if (!isFull() || cauldron.isCustomColor() || cauldron.hasPotion()) {
break;
}
ItemBucket bucket = (ItemBucket) item.clone();
bucket.setDamage(8);//water bucket
PlayerBucketFillEvent ev = new PlayerBucketFillEvent(player, this, null, item, bucket);
this.level.getServer().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
if (player.isSurvival()) {
player.getInventory().setItemInHand(ev.getItem());
}
this.setDamage(0);//empty
this.level.setBlock(this, this, true);
cauldron.clearCustomColor();
this.getLevel().addSound(this.add(0.5, 1, 0.5), Sound.CAULDRON_TAKEWATER);
}
} else if (item.getDamage() == 8) {//water bucket
if (isFull() && !cauldron.isCustomColor() && !cauldron.hasPotion()) {
break;
}
ItemBucket bucket = (ItemBucket) item.clone();
bucket.setDamage(0);//empty bucket
PlayerBucketEmptyEvent ev = new PlayerBucketEmptyEvent(player, this, null, item, bucket);
this.level.getServer().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
if (player.isSurvival()) {
player.getInventory().setItemInHand(ev.getItem());
}
if (cauldron.hasPotion()) {//if has potion
this.setDamage(0);//empty
cauldron.setPotionId(0xffff);//reset potion
cauldron.setSplashPotion(false);
cauldron.clearCustomColor();
this.level.setBlock(this, this, true);
this.level.addSound(this.add(0.5, 0, 0.5), Sound.CAULDRON_EXPLODE);
} else {
this.setDamage(6);//fill
cauldron.clearCustomColor();
this.level.setBlock(this, this, true);
this.level.addSound(this.add(0.5, 1, 0.5), Sound.BUCKET_FILL_WATER);
}
//this.update();
}
}
break;
case Item.DYE: //TODO
break;
case Item.LEATHER_CAP:
case Item.LEATHER_TUNIC:
case Item.LEATHER_PANTS:
case Item.LEATHER_BOOTS:
break;
case Item.POTION:
if (isFull()) {
break;
}
this.setDamage(this.getDamage() + 1);
if (this.getDamage() > 0x06)
this.setDamage(0x06);
if (item.getCount() == 1) {
player.getInventory().setItemInHand(new ItemBlock(new BlockAir()));
} else if (item.getCount() > 1) {
item.setCount(item.getCount() - 1);
player.getInventory().setItemInHand(item);
Item bottle = new ItemGlassBottle();
if (player.getInventory().canAddItem(bottle)) {
player.getInventory().addItem(bottle);
} else {
player.getLevel().dropItem(player.add(0, 1.3, 0), bottle, player.getDirectionVector().multiply(0.4));
}
}
this.level.addSound(this.add(0.5, 0.5, 0.5), Sound.CAULDRON_FILLPOTION);
break;
case Item.GLASS_BOTTLE:
if (isEmpty()) {
break;
}
this.setDamage(this.getDamage() - 1);
if (this.getDamage() < 0x00)
this.setDamage(0x00);
if (item.getCount() == 1) {
player.getInventory().setItemInHand(new ItemPotion());
} else if (item.getCount() > 1) {
item.setCount(item.getCount() - 1);
player.getInventory().setItemInHand(item);
Item potion = new ItemPotion();
if (player.getInventory().canAddItem(potion)) {
player.getInventory().addItem(potion);
} else {
player.getLevel().dropItem(player.add(0, 1.3, 0), potion, player.getDirectionVector().multiply(0.4));
}
}
this.level.addSound(this.add(0.5, 0.5, 0.5), Sound.CAULDRON_TAKEPOTION);
break;
default:
return true;
}
this.level.updateComparatorOutputLevel(this);
return true;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
CompoundTag nbt = new CompoundTag("")
.putString("id", BlockEntity.CHEST)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z)
.putShort("PotionId", 0xffff)
.putByte("SplashPotion", 0);
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
new BlockEntityCauldron(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
this.getLevel().setBlock(block, this, true, true);
return true;
}
@Override
public Item[] getDrops(Item item) {
if (item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{new ItemCauldron()};
}
return new Item[0];
}
@Override
public Item toItem() {
return new ItemCauldron();
}
public boolean hasComparatorInputOverride() {
return true;
}
public int getComparatorInputOverride() {
return this.getDamage();
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 8,161 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockOreRedstoneGlowing.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockOreRedstoneGlowing.java | package cn.nukkit.block;
import cn.nukkit.level.Level;
//和pm源码有点出入,这里参考了wiki
/**
* Created on 2015/12/6 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockOreRedstoneGlowing extends BlockOreRedstone {
public BlockOreRedstoneGlowing() {
}
@Override
public String getName() {
return "Glowing Redstone Ore";
}
@Override
public int getId() {
return GLOWING_REDSTONE_ORE;
}
@Override
public int getLightLevel() {
return 9;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_SCHEDULED || type == Level.BLOCK_UPDATE_RANDOM) {
this.getLevel().setBlock(this, new BlockOreRedstone(), false, false);
return Level.BLOCK_UPDATE_WEAK;
}
return 0;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 939 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstoneTorchUnlit.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstoneTorchUnlit.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.math.BlockFace;
/**
* Created by CreeperFace on 10.4.2017.
*/
public class BlockRedstoneTorchUnlit extends BlockTorch {
public BlockRedstoneTorchUnlit() {
this(0);
}
public BlockRedstoneTorchUnlit(int meta) {
super(meta);
}
@Override
public String getName() {
return "Redstone Torch";
}
@Override
public int getId() {
return REDSTONE_TORCH;
}
@Override
public int getLightLevel() {
return 7;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block below = this.down();
if (!target.isTransparent() && face != BlockFace.DOWN) {
int[] faces = new int[]{
0, //0, nerver used
5, //1
4, //2
3, //3
2, //4
1, //5
};
this.setDamage(faces[face.getIndex()]);
this.getLevel().setBlock(block, this, true, true);
//Redstone.active(this);
return true;
} else if (!below.isTransparent() || below instanceof BlockFence || below.getId() == COBBLE_WALL) {
this.setDamage(0);
this.getLevel().setBlock(block, this, true, true);
//Redstone.active(this);
return true;
}
return false;
}
@Override
public int getWeakPower(BlockFace side) {
return 0;
}
@Override
public int getStrongPower(BlockFace side) {
return 0;
}
@Override
public boolean onBreak(Item item) {
this.getLevel().setBlock(this, new BlockAir(), true, true);
//TODO: redstone
return true;
}
}
| 1,892 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockLavaStill.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockLavaStill.java | package cn.nukkit.block;
import cn.nukkit.level.Level;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockLavaStill extends BlockLava {
public BlockLavaStill() {
super(0);
}
public BlockLavaStill(int meta) {
super(meta);
}
@Override
public int getId() {
return STILL_LAVA;
}
@Override
public String getName() {
return "Still Lava";
}
@Override
public BlockLiquid getBlock(int meta) {
return new BlockLavaStill(meta);
}
@Override
public int onUpdate(int type) {
if (type != Level.BLOCK_UPDATE_SCHEDULED) {
return super.onUpdate(type);
}
return 0;
}
}
| 712 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockMushroomBrown.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockMushroomBrown.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.level.generator.object.mushroom.BigMushroom;
import cn.nukkit.level.particle.BoneMealParticle;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.DyeColor;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author Nukkit Project Team
*/
public class BlockMushroomBrown extends BlockFlowable {
public BlockMushroomBrown() {
this(0);
}
public BlockMushroomBrown(int meta) {
super(0);
}
@Override
public String getName() {
return "Brown Mushroom";
}
@Override
public int getId() {
return BROWN_MUSHROOM;
}
@Override
public int getLightLevel() {
return 1;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (!canStay()) {
getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (canStay()) {
getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public boolean onActivate(Item item, Player player) {
if (item.getId() == Item.DYE && item.getDamage() == DyeColor.WHITE.getDyeData()) {
if (ThreadLocalRandom.current().nextFloat() < 0.4) {
this.grow();
}
this.level.addParticle(new BoneMealParticle(this));
return true;
}
return false;
}
public boolean grow() {
this.level.setBlock(this, new BlockAir(), true, false);
BigMushroom generator = new BigMushroom(0);
if (generator.generate(this.level, new NukkitRandom(), this)) {
return true;
} else {
this.level.setBlock(this, this, true, false);
return false;
}
}
public boolean canStay() {
Block block = this.down();
return block.getId() == MYCELIUM || block.getId() == PODZOL || (!block.isTransparent() && this.level.getFullLight(this) < 13);
}
@Override
public BlockColor getColor() {
return BlockColor.FOLIAGE_BLOCK_COLOR;
}
}
| 2,577 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockHopper.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockHopper.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityHopper;
import cn.nukkit.inventory.ContainerInventory;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemHopper;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.ListTag;
/**
* @author CreeperFace
*/
public class BlockHopper extends BlockTransparentMeta {
public BlockHopper() {
this(0);
}
public BlockHopper(int meta) {
super(meta);
}
@Override
public int getId() {
return HOPPER_BLOCK;
}
@Override
public String getName() {
return "Hopper Block";
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 24;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
BlockFace facing = face.getOpposite();
if (facing == BlockFace.UP) {
facing = BlockFace.DOWN;
}
this.setDamage(facing.getIndex());
boolean powered = this.level.isBlockPowered(this);
if (powered == this.isEnabled()) {
this.setEnabled(!powered);
}
this.level.setBlock(this, this);
CompoundTag nbt = new CompoundTag()
.putList(new ListTag<>("Items"))
.putString("id", BlockEntity.HOPPER)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z);
new BlockEntityHopper(this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
return true;
}
@Override
public boolean onActivate(Item item, Player player) {
BlockEntity blockEntity = this.level.getBlockEntity(this);
if (blockEntity instanceof BlockEntityHopper) {
return player.addWindow(((BlockEntityHopper) blockEntity).getInventory()) != -1;
}
return false;
}
@Override
public boolean canBeActivated() {
return true;
}
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride() {
BlockEntity blockEntity = this.level.getBlockEntity(this);
if (blockEntity instanceof BlockEntityHopper) {
return ContainerInventory.calculateRedstone(((BlockEntityHopper) blockEntity).getInventory());
}
return super.getComparatorInputOverride();
}
public BlockFace getFacing() {
return BlockFace.fromIndex(this.getDamage() & 7);
}
public boolean isEnabled() {
return (this.getDamage() & 0x08) != 8;
}
public void setEnabled(boolean enabled) {
if (isEnabled() != enabled) {
this.setDamage(this.getDamage() ^ 0x08);
}
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
boolean powered = this.level.isBlockPowered(this);
if (powered == this.isEnabled()) {
this.setEnabled(!powered);
this.level.setBlock(this, this, true, false);
}
return type;
}
return 0;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
if (item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{toItem()};
}
return new Item[0];
}
@Override
public Item toItem() {
return new ItemHopper();
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 3,881 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockMobSpawner.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockMobSpawner.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
/**
* Created by Pub4Game on 27.12.2015.
*/
public class BlockMobSpawner extends BlockSolid {
public BlockMobSpawner() {
}
@Override
public String getName() {
return "Monster Spawner";
}
@Override
public int getId() {
return MONSTER_SPAWNER;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public double getHardness() {
return 5;
}
@Override
public double getResistance() {
return 25;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public boolean canBePushed() {
return false;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,058 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDoubleSlabWood.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDoubleSlabWood.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockDoubleSlabWood extends BlockSolidMeta {
public BlockDoubleSlabWood() {
this(0);
}
public BlockDoubleSlabWood(int meta) {
super(meta);
}
@Override
public int getId() {
return DOUBLE_WOOD_SLAB;
}
@Override
public double getHardness() {
return 2;
}
@Override
public double getResistance() {
return 15;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
@Override
public String getName() {
String[] names = new String[]{
"Oak",
"Spruce",
"Birch",
"Jungle",
"Acacia",
"Dark Oak",
"",
""
};
return "Double " + names[this.getDamage() & 0x07] + " Slab";
}
public Item[] getDrops(Item item) {
return new Item[]{
Item.get(Item.WOOD_SLAB, this.getDamage() & 0x07, 2)
};
}
@Override
public BlockColor getColor() {
return BlockColor.WOOD_BLOCK_COLOR;
}
}
| 1,332 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDoorDarkOak.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDoorDarkOak.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemDoorDarkOak;
public class BlockDoorDarkOak extends BlockDoorWood {
public BlockDoorDarkOak() {
this(0);
}
public BlockDoorDarkOak(int meta) {
super(meta);
}
@Override
public String getName() {
return "Dark Oak Door Block";
}
@Override
public int getId() {
return DARK_OAK_DOOR_BLOCK;
}
@Override
public Item toItem() {
return new ItemDoorDarkOak();
}
}
| 531 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockStemPumpkin.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockStemPumpkin.java | package cn.nukkit.block;
import cn.nukkit.Server;
import cn.nukkit.event.block.BlockGrowEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemSeedsPumpkin;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.BlockFace.Plane;
import cn.nukkit.math.NukkitRandom;
/**
* Created by Pub4Game on 15.01.2016.
*/
public class BlockStemPumpkin extends BlockCrops {
public BlockStemPumpkin() {
this(0);
}
public BlockStemPumpkin(int meta) {
super(meta);
}
@Override
public int getId() {
return PUMPKIN_STEM;
}
@Override
public String getName() {
return "Pumpkin Stem";
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.down().getId() != FARMLAND) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
} else if (type == Level.BLOCK_UPDATE_RANDOM) {
NukkitRandom random = new NukkitRandom();
if (random.nextRange(1, 2) == 1) {
if (this.getDamage() < 0x07) {
Block block = this.clone();
block.setDamage(block.getDamage() + 1);
BlockGrowEvent ev = new BlockGrowEvent(this, block);
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(this, ev.getNewState(), true);
}
return Level.BLOCK_UPDATE_RANDOM;
} else {
for (BlockFace face : Plane.HORIZONTAL) {
Block b = this.getSide(face);
if (b.getId() == PUMPKIN) {
return Level.BLOCK_UPDATE_RANDOM;
}
}
Block side = this.getSide(Plane.HORIZONTAL.random(random));
Block d = side.down();
if (side.getId() == AIR && (d.getId() == FARMLAND || d.getId() == GRASS || d.getId() == DIRT)) {
BlockGrowEvent ev = new BlockGrowEvent(side, new BlockPumpkin());
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(side, ev.getNewState(), true);
}
}
}
}
return Level.BLOCK_UPDATE_RANDOM;
}
return 0;
}
@Override
public Item[] getDrops(Item item) {
NukkitRandom random = new NukkitRandom();
return new Item[]{
new ItemSeedsPumpkin(0, random.nextRange(0, 3))
};
}
}
| 2,827 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSlabRedSandstone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSlabRedSandstone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
/**
* Created by CreeperFace on 26. 11. 2016.
*/
public class BlockSlabRedSandstone extends BlockSlab {
public static final int RED_SANDSTONE = 0;
public static final int PURPUR = 1; //WHY THIS
public BlockSlabRedSandstone() {
this(0);
}
public BlockSlabRedSandstone(int meta) {
super(meta, DOUBLE_RED_SANDSTONE_SLAB);
}
@Override
public int getId() {
return RED_SANDSTONE_SLAB;
}
@Override
public String getName() {
String[] names = new String[]{
"Red Sandstone",
"Purpur",
"",
"",
"",
"",
"",
""
};
return ((this.getDamage() & 0x08) > 0 ? "Upper " : "") + names[this.getDamage() & 0x07] + " Slab";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(this, this.getDamage() & 0x07);
}
@Override
public boolean canHarvestWithHand() {
return false;
}
} | 1,418 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockWall.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockWall.java | package cn.nukkit.block;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.SimpleAxisAlignedBB;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockWall extends BlockTransparentMeta {
public static final int NONE_MOSSY_WALL = 0;
public static final int MOSSY_WALL = 1;
public BlockWall() {
this(0);
}
public BlockWall(int meta) {
super(meta);
}
@Override
public int getId() {
return STONE_WALL;
}
@Override
public boolean isSolid() {
return false;
}
@Override
public double getHardness() {
return 2;
}
@Override
public double getResistance() {
return 30;
}
@Override
public String getName() {
if (this.getDamage() == 0x01) {
return "Mossy Cobblestone Wall";
}
return "Cobblestone Wall";
}
@Override
protected AxisAlignedBB recalculateBoundingBox() {
boolean north = this.canConnect(this.getSide(BlockFace.NORTH));
boolean south = this.canConnect(this.getSide(BlockFace.SOUTH));
boolean west = this.canConnect(this.getSide(BlockFace.WEST));
boolean east = this.canConnect(this.getSide(BlockFace.EAST));
double n = north ? 0 : 0.25;
double s = south ? 1 : 0.75;
double w = west ? 0 : 0.25;
double e = east ? 1 : 0.75;
if (north && south && !west && !east) {
w = 0.3125;
e = 0.6875;
} else if (!north && !south && west && east) {
n = 0.3125;
s = 0.6875;
}
return new SimpleAxisAlignedBB(
this.x + w,
this.y,
this.z + n,
this.x + e,
this.y + 1.5,
this.z + s
);
}
public boolean canConnect(Block block) {
return (!(block.getId() != COBBLE_WALL && block.getId() != FENCE_GATE)) || block.isSolid() && !block.isTransparent();
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 2,247 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstoneLampLit.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstoneLampLit.java | package cn.nukkit.block;
import cn.nukkit.level.Level;
/**
* @author Pub4Game
*/
public class BlockRedstoneLampLit extends BlockRedstoneLamp {
public BlockRedstoneLampLit() {
}
@Override
public String getName() {
return "Lit Redstone Lamp";
}
@Override
public int getId() {
return LIT_REDSTONE_LAMP;
}
@Override
public int getLightLevel() {
return 15;
}
@Override
public int onUpdate(int type) {
if ((type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) && !this.level.isBlockPowered(this)) {
this.level.scheduleUpdate(this, 4);
return 1;
}
if (type == Level.BLOCK_UPDATE_SCHEDULED && !this.level.isBlockPowered(this)) {
this.level.setBlock(this, new BlockRedstoneLamp(), false, false);
}
return 0;
}
}
| 890 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazedYellow.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazedYellow.java | package cn.nukkit.block;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockTerracottaGlazedYellow extends BlockTerracottaGlazed {
public BlockTerracottaGlazedYellow() {
this(0);
}
public BlockTerracottaGlazedYellow(int meta) {
super(meta);
}
@Override
public int getId() {
return YELLOW_GLAZED_TERRACOTTA;
}
@Override
public String getName() {
return "Yellow Glazed Terracotta";
}
}
| 475 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockGravel.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockGravel.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemFlint;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
import java.util.Random;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockGravel extends BlockFallable {
public BlockGravel() {
}
@Override
public int getId() {
return GRAVEL;
}
@Override
public double getHardness() {
return 0.6;
}
@Override
public double getResistance() {
return 3;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public String getName() {
return "Gravel";
}
@Override
public Item[] getDrops(Item item) {
if (new Random().nextInt(9) == 0) {
return new Item[]{
new ItemFlint()
};
} else {
return new Item[]{
toItem()
};
}
}
@Override
public BlockColor getColor() {
return BlockColor.SAND_BLOCK_COLOR;
}
}
| 1,090 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPumpkinLit.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPumpkinLit.java | package cn.nukkit.block;
/**
* Created on 2015/12/8 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockPumpkinLit extends BlockPumpkin {
public BlockPumpkinLit() {
this(0);
}
public BlockPumpkinLit(int meta) {
super(0);
}
@Override
public String getName() {
return "Jack o'Lantern";
}
@Override
public int getId() {
return LIT_PUMPKIN;
}
@Override
public int getLightLevel() {
return 15;
}
}
| 519 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSponge.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSponge.java | package cn.nukkit.block;
import cn.nukkit.utils.BlockColor;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockSponge extends BlockSolidMeta {
public static final int DRY = 0;
public static final int WET = 1;
public BlockSponge() {
this(0);
}
public BlockSponge(int meta) {
super(meta);
}
@Override
public int getId() {
return SPONGE;
}
@Override
public double getHardness() {
return 0.6;
}
@Override
public double getResistance() {
return 3;
}
@Override
public String getName() {
String[] names = new String[]{
"Sponge",
"Wet sponge"
};
return names[this.getDamage() & 0x07];
}
@Override
public BlockColor getColor() {
return BlockColor.CLOTH_BLOCK_COLOR;
}
}
| 873 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockStairsDarkOak.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockStairsDarkOak.java | package cn.nukkit.block;
/**
* Created on 2015/11/25 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockStairsDarkOak extends BlockStairsWood {
public BlockStairsDarkOak() {
this(0);
}
public BlockStairsDarkOak(int meta) {
super(meta);
}
@Override
public int getId() {
return DARK_OAK_WOOD_STAIRS;
}
@Override
public String getName() {
return "Dark Oak Wood Stairs";
}
}
| 478 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockEmerald.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockEmerald.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/1 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockEmerald extends BlockSolid {
public BlockEmerald() {
}
@Override
public String getName() {
return "Emerald Block";
}
@Override
public int getId() {
return EMERALD_BLOCK;
}
@Override
public double getHardness() {
return 5;
}
@Override
public double getResistance() {
return 30;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.EMERALD_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,150 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPistonHead.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPistonHead.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.math.BlockFace;
/**
* @author CreeperFace
*/
public class BlockPistonHead extends BlockTransparentMeta {
public BlockPistonHead() {
this(0);
}
public BlockPistonHead(int meta) {
super(meta);
}
@Override
public int getId() {
return PISTON_HEAD;
}
@Override
public String getName() {
return "Piston Head";
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public double getHardness() {
return 0.5;
}
@Override
public Item[] getDrops(Item item) {
return new Item[0];
}
@Override
public boolean onBreak(Item item) {
this.level.setBlock(this, new BlockAir(), true, true);
Block piston = getSide(getFacing().getOpposite());
if (piston instanceof BlockPistonBase && ((BlockPistonBase) piston).getFacing() == this.getFacing()) {
piston.onBreak(item);
}
return true;
}
public BlockFace getFacing() {
return BlockFace.fromIndex(this.getDamage()).getOpposite();
}
@Override
public boolean canBePushed() {
return false;
}
}
| 1,247 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDoorSpruce.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDoorSpruce.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemDoorSpruce;
public class BlockDoorSpruce extends BlockDoorWood {
public BlockDoorSpruce() {
this(0);
}
public BlockDoorSpruce(int meta) {
super(meta);
}
@Override
public String getName() {
return "Spruce Door Block";
}
@Override
public int getId() {
return SPRUCE_DOOR_BLOCK;
}
@Override
public Item toItem() {
return new ItemDoorSpruce();
}
}
| 522 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockMossStone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockMossStone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockMossStone extends BlockSolid {
public BlockMossStone() {
}
@Override
public String getName() {
return "Moss Stone";
}
@Override
public int getId() {
return MOSS_STONE;
}
@Override
public double getHardness() {
return 2;
}
@Override
public double getResistance() {
return 10;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,010 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstoneDiode.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstoneDiode.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
/**
* @author CreeperFace
*/
public abstract class BlockRedstoneDiode extends BlockFlowable {
protected boolean isPowered = false;
public BlockRedstoneDiode() {
this(0);
}
public BlockRedstoneDiode(int meta) {
super(meta);
}
@Override
public boolean onBreak(Item item) {
Vector3 pos = getLocation();
this.level.setBlock(this, new BlockAir(), true, true);
for (BlockFace face : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(face), null);
}
return true;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (block.getSide(BlockFace.DOWN).isTransparent()) {
return false;
}
this.setDamage(player != null ? player.getDirection().getOpposite().getHorizontalIndex() : 0);
this.level.setBlock(block, this, true, true);
if (shouldBePowered()) {
this.level.scheduleUpdate(this, 1);
}
return true;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_SCHEDULED) {
if (!this.isLocked()) {
Vector3 pos = getLocation();
boolean shouldBePowered = this.shouldBePowered();
if (this.isPowered && !shouldBePowered) {
this.level.setBlock(pos, this.getUnpowered(), true, true);
this.level.updateAroundRedstone(this.getLocation().getSide(getFacing().getOpposite()), null);
} else if (!this.isPowered) {
this.level.setBlock(pos, this.getPowered(), true, true);
this.level.updateAroundRedstone(this.getLocation().getSide(getFacing().getOpposite()), null);
if (!shouldBePowered) {
// System.out.println("schedule update 2");
level.scheduleUpdate(getPowered(), this, this.getDelay());
}
}
}
} else if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
if (type == Level.BLOCK_UPDATE_NORMAL && this.getSide(BlockFace.DOWN).isTransparent()) {
this.level.useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
} else {
this.updateState();
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
public void updateState() {
if (!this.isLocked()) {
boolean shouldPowered = this.shouldBePowered();
if ((this.isPowered && !shouldPowered || !this.isPowered && shouldPowered) && !this.level.isBlockTickPending(this, this)) {
/*int priority = -1;
if (this.isFacingTowardsRepeater()) {
priority = -3;
} else if (this.isPowered) {
priority = -2;
}*/
this.level.scheduleUpdate(this, this, this.getDelay());
}
}
}
public boolean isLocked() {
return false;
}
protected int calculateInputStrength() {
BlockFace face = getFacing();
Vector3 pos = this.getLocation().getSide(face);
int power = this.level.getRedstonePower(pos, face);
if (power >= 15) {
return power;
} else {
Block block = this.level.getBlock(pos);
return Math.max(power, block.getId() == Block.REDSTONE_WIRE ? block.getDamage() : 0);
}
}
protected int getPowerOnSides() {
Vector3 pos = getLocation();
BlockFace face = getFacing();
BlockFace face1 = face.rotateY();
BlockFace face2 = face.rotateYCCW();
return Math.max(this.getPowerOnSide(pos.getSide(face1), face1), this.getPowerOnSide(pos.getSide(face2), face2));
}
protected int getPowerOnSide(Vector3 pos, BlockFace side) {
Block block = this.level.getBlock(pos);
return isAlternateInput(block) ? (block.getId() == Block.REDSTONE_BLOCK ? 15 : (block.getId() == Block.REDSTONE_WIRE ? block.getDamage() : this.level.getStrongPower(pos, side))) : 0;
}
@Override
public boolean isPowerSource() {
return true;
}
protected boolean shouldBePowered() {
return this.calculateInputStrength() > 0;
}
public abstract BlockFace getFacing();
protected abstract int getDelay();
protected abstract Block getUnpowered();
protected abstract Block getPowered();
@Override
public double getMaxY() {
return this.y + 0.125;
}
@Override
public boolean canPassThrough() {
return false;
}
protected boolean isAlternateInput(Block block) {
return block.isPowerSource();
}
public static boolean isDiode(Block block) {
return block instanceof BlockRedstoneDiode;
}
protected int getRedstoneSignal() {
return 15;
}
public int getStrongPower(BlockFace side) {
return getWeakPower(side);
}
public int getWeakPower(BlockFace side) {
return !this.isPowered() ? 0 : (getFacing() == side ? this.getRedstoneSignal() : 0);
}
@Override
public boolean canBeActivated() {
return true;
}
public boolean isPowered() {
return isPowered;
}
public boolean isFacingTowardsRepeater() {
BlockFace side = getFacing().getOpposite();
Block block = this.getSide(side);
return block instanceof BlockRedstoneDiode && ((BlockRedstoneDiode) block).getFacing() != side;
}
}
| 5,861 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockCoal.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockCoal.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
/**
* Created on 2015/11/24 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockCoal extends BlockSolid {
public BlockCoal() {
}
@Override
public int getId() {
return COAL_BLOCK;
}
@Override
public double getHardness() {
return 5;
}
@Override
public double getResistance() {
return 30;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public int getBurnChance() {
return 5;
}
@Override
public int getBurnAbility() {
return 5;
}
@Override
public String getName() {
return "Block of Coal";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,148 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFenceGateAcacia.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFenceGateAcacia.java | package cn.nukkit.block;
/**
* Created on 2015/11/23 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockFenceGateAcacia extends BlockFenceGate {
public BlockFenceGateAcacia() {
this(0);
}
public BlockFenceGateAcacia(int meta) {
super(meta);
}
@Override
public int getId() {
return FENCE_GATE_ACACIA;
}
@Override
public String getName() {
return "Acacia Fence Gate";
}
}
| 475 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDandelion.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDandelion.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockDandelion extends BlockFlowable {
public BlockDandelion() {
this(0);
}
public BlockDandelion(int meta) {
super(0);
}
@Override
public String getName() {
return "Dandelion";
}
@Override
public int getId() {
return DANDELION;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (down.getId() == 2 || down.getId() == 3 || down.getId() == 60) {
this.getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.down().isTransparent()) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public BlockColor getColor() {
return BlockColor.FOLIAGE_BLOCK_COLOR;
}
}
| 1,368 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockBeetroot.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockBeetroot.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
/**
* Created on 2015/11/22 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockBeetroot extends BlockCrops {
public BlockBeetroot() {
this(0);
}
public BlockBeetroot(int meta) {
super(meta);
}
@Override
public int getId() {
return BEETROOT_BLOCK;
}
@Override
public String getName() {
return "Beetroot Block";
}
@Override
public Item[] getDrops(Item item) {
if (this.getDamage() >= 0x07) {
return new Item[]{
Item.get(Item.BEETROOT, 0, 1),
Item.get(Item.BEETROOT_SEEDS, 0, (int) (4d * Math.random()))
};
} else {
return new Item[]{
Item.get(Item.BEETROOT_SEEDS, 0, 1)
};
}
}
}
| 881 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazedGray.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazedGray.java | package cn.nukkit.block;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockTerracottaGlazedGray extends BlockTerracottaGlazed {
public BlockTerracottaGlazedGray() {
this(0);
}
public BlockTerracottaGlazedGray(int meta) {
super(meta);
}
@Override
public int getId() {
return GRAY_GLAZED_TERRACOTTA;
}
@Override
public String getName() {
return "Gray Glazed Terracotta";
}
}
| 465 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockUnknown.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockUnknown.java | package cn.nukkit.block;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockUnknown extends BlockMeta {
private final int id;
public BlockUnknown(int id) {
this(id, 0);
}
public BlockUnknown(int id, Integer meta) {
super(meta);
this.id = id;
}
@Override
public int getId() {
return id;
}
@Override
public String getName() {
return "Unknown";
}
}
| 452 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockLadder.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockLadder.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.entity.Entity;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/8 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockLadder extends BlockTransparentMeta {
public BlockLadder() {
this(0);
}
public BlockLadder(int meta) {
super(meta);
calculateOffsets();
}
@Override
public String getName() {
return "Ladder";
}
@Override
public int getId() {
return LADDER;
}
@Override
public boolean hasEntityCollision() {
return true;
}
@Override
public boolean canBeClimbed() {
return true;
}
@Override
public boolean isSolid() {
return false;
}
@Override
public double getHardness() {
return 0.4;
}
@Override
public double getResistance() {
return 2;
}
@Override
public void onEntityCollide(Entity entity) {
entity.resetFallDistance();
}
private double offMinX;
private double offMinZ;
private double offMaxX;
private double offMaxZ;
private void calculateOffsets() {
double f = 0.1875;
switch (this.getDamage()) {
case 2:
this.offMinX = 0;
this.offMinZ = 1 - f;
this.offMaxX = 1;
this.offMaxZ = 1;
break;
case 3:
this.offMinX = 0;
this.offMinZ = 0;
this.offMaxX = 1;
this.offMaxZ = f;
break;
case 4:
this.offMinX = 1 - f;
this.offMinZ = 0;
this.offMaxX = 1;
this.offMaxZ = 1;
break;
case 5:
this.offMinX = 0;
this.offMinZ = 0;
this.offMaxX = f;
this.offMaxZ = 1;
break;
default:
this.offMinX = 0;
this.offMinZ = 1 ;
this.offMaxX = 1;
this.offMaxZ = 1;
break;
}
}
@Override
public void setDamage(int meta) {
super.setDamage(meta);
calculateOffsets();
}
@Override
public double getMinX() {
return this.x + offMinX;
}
@Override
public double getMinZ() {
return this.z + offMinZ;
}
@Override
public double getMaxX() {
return this.x + offMaxX;
}
@Override
public double getMaxZ() {
return this.z + offMaxZ;
}
@Override
protected AxisAlignedBB recalculateCollisionBoundingBox() {
return super.recalculateBoundingBox();
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (!target.isTransparent()) {
if (face.getIndex() >= 2 && face.getIndex() <= 5) {
this.setDamage(face.getIndex());
this.getLevel().setBlock(block, this, true, true);
return true;
}
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
int[] faces = {
0, //never use
1, //never use
3,
2,
5,
4
};
if (!this.getSide(BlockFace.fromIndex(faces[this.getDamage()])).isSolid()) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
}
| 4,098 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockOreRedstone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockOreRedstone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemRedstone;
import cn.nukkit.item.ItemTool;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.level.Level;
import cn.nukkit.math.NukkitRandom;
import java.util.Random;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockOreRedstone extends BlockSolid {
public BlockOreRedstone() {
}
@Override
public int getId() {
return REDSTONE_ORE;
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 15;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
return "Redstone Ore";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_IRON) {
int count = new Random().nextInt(2) + 4;
Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
if (fortune != null && fortune.getLevel() >= 1) {
count += new Random().nextInt(fortune.getLevel() + 1);
}
return new Item[]{
new ItemRedstone(0, count)
};
} else {
return new Item[0];
}
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_TOUCH) { //type == Level.BLOCK_UPDATE_NORMAL ||
this.getLevel().setBlock(this, new BlockOreRedstoneGlowing(), false, false);
return Level.BLOCK_UPDATE_WEAK;
}
return 0;
}
@Override
public int getDropExp() {
return new NukkitRandom().nextRange(1, 5);
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,867 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPressurePlateStone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPressurePlateStone.java | package cn.nukkit.block;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.EntityLiving;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.utils.BlockColor;
/**
* @author Nukkit Project Team
*/
public class BlockPressurePlateStone extends BlockPressurePlateBase {
public BlockPressurePlateStone(int meta) {
super(meta);
this.onPitch = 0.6f;
this.offPitch = 0.5f;
}
public BlockPressurePlateStone() {
this(0);
}
@Override
public String getName() {
return "Stone Pressure Plate";
}
@Override
public int getId() {
return STONE_PRESSURE_PLATE;
}
@Override
public double getHardness() {
return 0.5D;
}
@Override
public double getResistance() {
return 2.5D;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.STONE_BLOCK_COLOR;
}
@Override
protected int computeRedstoneStrength() {
AxisAlignedBB bb = getCollisionBoundingBox();
for (Entity entity : this.level.getCollidingEntities(bb)) {
if (entity instanceof EntityLiving && entity.doesTriggerPressurePlate()) {
return 15;
}
}
return 0;
}
}
| 1,671 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTorch.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTorch.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockTorch extends BlockFlowable {
public BlockTorch() {
this(0);
}
public BlockTorch(int meta) {
super(meta);
}
@Override
public String getName() {
return "Torch";
}
@Override
public int getId() {
return TORCH;
}
@Override
public int getLightLevel() {
return 15;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
Block below = this.down();
int side = this.getDamage();
int[] faces = new int[]{
0, //0
4, //1
5, //2
2, //3
3, //4
0, //5
0 //6
};
if (this.getSide(BlockFace.fromIndex(faces[side])).isTransparent() && !(side == 0 && (below instanceof BlockFence || below.getId() == COBBLE_WALL))) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block below = this.down();
if (!target.isTransparent() && face != BlockFace.DOWN) {
int[] faces = new int[]{
0, //0, nerver used
5, //1
4, //2
3, //3
2, //4
1, //5
};
this.setDamage(faces[face.getIndex()]);
this.getLevel().setBlock(block, this, true, true);
return true;
} else if (!below.isTransparent() || below instanceof BlockFence || below.getId() == COBBLE_WALL) {
this.setDamage(0);
this.getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public Item toItem() {
return new ItemBlock(this, 0);
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
public BlockFace getFacing() {
return getFacing(this.getDamage());
}
public BlockFace getFacing(int meta) {
switch (meta) {
case 1:
return BlockFace.EAST;
case 2:
return BlockFace.WEST;
case 3:
return BlockFace.SOUTH;
case 4:
return BlockFace.NORTH;
case 5:
default:
return BlockFace.UP;
}
}
}
| 2,964 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstoneComparatorUnpowered.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstoneComparatorUnpowered.java | package cn.nukkit.block;
/**
* @author CreeperFace
*/
public class BlockRedstoneComparatorUnpowered extends BlockRedstoneComparator {
public BlockRedstoneComparatorUnpowered() {
this(0);
}
public BlockRedstoneComparatorUnpowered(int meta) {
super(meta);
}
@Override
public int getId() {
return UNPOWERED_COMPARATOR;
}
@Override
public String getName() {
return "Comparator Block Unpowered";
}
@Override
protected BlockRedstoneComparator getUnpowered() {
return this;
}
} | 570 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockWheat.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockWheat.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemSeedsWheat;
import cn.nukkit.item.ItemWheat;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockWheat extends BlockCrops {
public BlockWheat() {
this(0);
}
public BlockWheat(int meta) {
super(meta);
}
@Override
public String getName() {
return "Wheat Block";
}
@Override
public int getId() {
return WHEAT_BLOCK;
}
@Override
public Item[] getDrops(Item item) {
if (this.getDamage() >= 0x07) {
return new Item[]{
new ItemWheat(),
new ItemSeedsWheat(0, (int) (4d * Math.random()))
};
} else {
return new Item[]{
new ItemSeedsWheat()
};
}
}
}
| 897 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPotato.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPotato.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemPotato;
import java.util.Random;
/**
* Created by Pub4Game on 15.01.2016.
*/
public class BlockPotato extends BlockCrops {
public BlockPotato(int meta) {
super(meta);
}
public BlockPotato() {
this(0);
}
@Override
public String getName() {
return "Potato Block";
}
@Override
public int getId() {
return POTATO_BLOCK;
}
@Override
public Item[] getDrops(Item item) {
if (getDamage() >= 0x07) {
return new Item[]{
new ItemPotato(0, new Random().nextInt(3) + 1)
};
} else {
return new Item[]{
new ItemPotato()
};
}
}
}
| 799 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockIcePacked.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockIcePacked.java | package cn.nukkit.block;
import cn.nukkit.item.ItemTool;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockIcePacked extends BlockIce {
public BlockIcePacked() {
}
@Override
public int getId() {
return PACKED_ICE;
}
@Override
public String getName() {
return "Packed Ice";
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public int onUpdate(int type) {
return 0; //not being melted
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 616 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockWater.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockWater.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.entity.Entity;
import cn.nukkit.item.Item;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockWater extends BlockLiquid {
public BlockWater() {
this(0);
}
public BlockWater(int meta) {
super(meta);
}
@Override
public int getId() {
return WATER;
}
@Override
public String getName() {
return "Water";
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
return this.place(item, block, target, face, fx, fy, fz, null);
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
boolean ret = this.getLevel().setBlock(this, this, true, false);
this.getLevel().scheduleUpdate(this, this.tickRate());
return ret;
}
@Override
public BlockColor getColor() {
return BlockColor.WATER_BLOCK_COLOR;
}
@Override
public BlockLiquid getBlock(int meta) {
return new BlockWater(meta);
}
@Override
public void onEntityCollide(Entity entity) {
super.onEntityCollide(entity);
if (entity.fireTicks > 0) {
entity.extinguish();
}
}
}
| 1,439 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockCocoa.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockCocoa.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.event.block.BlockGrowEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemDye;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.level.particle.BoneMealParticle;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.SimpleAxisAlignedBB;
import java.util.Random;
/**
* Created by CreeperFace on 27. 10. 2016.
*/
public class BlockCocoa extends BlockTransparentMeta {
protected static final AxisAlignedBB[] EAST = new SimpleAxisAlignedBB[]{new SimpleAxisAlignedBB(0.6875D, 0.4375D, 0.375D, 0.9375D, 0.75D, 0.625D), new SimpleAxisAlignedBB(0.5625D, 0.3125D, 0.3125D, 0.9375D, 0.75D, 0.6875D), new SimpleAxisAlignedBB(0.5625D, 0.3125D, 0.3125D, 0.9375D, 0.75D, 0.6875D)};
protected static final AxisAlignedBB[] WEST = new SimpleAxisAlignedBB[]{new SimpleAxisAlignedBB(0.0625D, 0.4375D, 0.375D, 0.3125D, 0.75D, 0.625D), new SimpleAxisAlignedBB(0.0625D, 0.3125D, 0.3125D, 0.4375D, 0.75D, 0.6875D), new SimpleAxisAlignedBB(0.0625D, 0.3125D, 0.3125D, 0.4375D, 0.75D, 0.6875D)};
protected static final AxisAlignedBB[] NORTH = new SimpleAxisAlignedBB[]{new SimpleAxisAlignedBB(0.375D, 0.4375D, 0.0625D, 0.625D, 0.75D, 0.3125D), new SimpleAxisAlignedBB(0.3125D, 0.3125D, 0.0625D, 0.6875D, 0.75D, 0.4375D), new SimpleAxisAlignedBB(0.3125D, 0.3125D, 0.0625D, 0.6875D, 0.75D, 0.4375D)};
protected static final AxisAlignedBB[] SOUTH = new SimpleAxisAlignedBB[]{new SimpleAxisAlignedBB(0.375D, 0.4375D, 0.6875D, 0.625D, 0.75D, 0.9375D), new SimpleAxisAlignedBB(0.3125D, 0.3125D, 0.5625D, 0.6875D, 0.75D, 0.9375D), new SimpleAxisAlignedBB(0.3125D, 0.3125D, 0.5625D, 0.6875D, 0.75D, 0.9375D)};
protected static final AxisAlignedBB[] ALL = new AxisAlignedBB[12];
public BlockCocoa() {
this(0);
}
public BlockCocoa(int meta) {
super(meta);
}
@Override
public int getId() {
return COCOA;
}
@Override
public String getName() {
return "Cocoa";
}
@Override
public void setDamage(int meta) {
super.setDamage(meta);
}
@Override
public double getMinX() {
return this.x + getRelativeBoundingBox().getMinX();
}
@Override
public double getMaxX() {
return this.x + getRelativeBoundingBox().getMaxX();
}
@Override
public double getMinY() {
return this.y + getRelativeBoundingBox().getMinY();
}
@Override
public double getMaxY() {
return this.y + getRelativeBoundingBox().getMaxY();
}
@Override
public double getMinZ() {
return this.z + getRelativeBoundingBox().getMinZ();
}
@Override
public double getMaxZ() {
return this.z + getRelativeBoundingBox().getMaxZ();
}
private AxisAlignedBB getRelativeBoundingBox() {
int damage = this.getDamage();
if (damage > 11) {
this.setDamage(damage = 11);
}
AxisAlignedBB boundingBox = ALL[damage];
if (boundingBox != null) return boundingBox;
AxisAlignedBB[] bbs;
switch (getDamage()) {
case 0:
case 4:
case 8:
bbs = NORTH;
break;
case 1:
case 5:
case 9:
bbs = EAST;
break;
case 2:
case 6:
case 10:
bbs = SOUTH;
break;
case 3:
case 7:
case 11:
bbs = WEST;
break;
default:
bbs = NORTH;
break;
}
return ALL[damage] = bbs[this.getDamage() >> 2];
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
return this.place(item, block, target, face, fx, fy, fz, null);
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (target.getId() == Block.WOOD && target.getDamage() == BlockWood.JUNGLE) {
if (face != BlockFace.DOWN && face != BlockFace.UP) {
int[] faces = new int[]{
0,
0,
0,
2,
3,
1,
};
this.setDamage(faces[face.getIndex()]);
this.level.setBlock(block, this, true, true);
return true;
}
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
int[] faces = new int[]{
3, 4, 2, 5, 3, 4, 2, 5, 3, 4, 2, 5
};
Block side = this.getSide(BlockFace.fromIndex(faces[this.getDamage()]));
if (side.getId() != Block.WOOD && side.getDamage() != BlockWood.JUNGLE) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
} else if (type == Level.BLOCK_UPDATE_RANDOM) {
if (new Random().nextInt(2) == 1) {
if (this.getDamage() / 4 < 2) {
BlockCocoa block = (BlockCocoa) this.clone();
block.setDamage(block.getDamage() + 4);
BlockGrowEvent ev = new BlockGrowEvent(this, block);
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(this, ev.getNewState(), true, true);
} else {
return Level.BLOCK_UPDATE_RANDOM;
}
}
} else {
return Level.BLOCK_UPDATE_RANDOM;
}
}
return 0;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public boolean onActivate(Item item, Player player) {
if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
Block block = this.clone();
if (this.getDamage() / 4 < 2) {
block.setDamage(block.getDamage() + 4);
BlockGrowEvent ev = new BlockGrowEvent(this, block);
Server.getInstance().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
}
this.getLevel().setBlock(this, ev.getNewState(), true, true);
}
this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
item.count--;
return true;
}
return false;
}
@Override
public double getResistance() {
return 15;
}
@Override
public double getHardness() {
return 0.2;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
@Override
public Item[] getDrops(Item item) {
if (this.getDamage() >= 8) {
return new Item[]{
new ItemDye(3, 3)
};
} else {
return new Item[]{
new ItemDye(3, 1)
};
}
}
}
| 7,394 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockGlass.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockGlass.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockGlass extends BlockTransparent {
public BlockGlass() {
}
@Override
public int getId() {
return GLASS;
}
@Override
public String getName() {
return "Glass";
}
@Override
public double getResistance() {
return 1.5;
}
@Override
public double getHardness() {
return 0.3;
}
@Override
public Item[] getDrops(Item item) {
return new Item[0];
}
}
| 572 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazedWhite.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazedWhite.java | package cn.nukkit.block;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockTerracottaGlazedWhite extends BlockTerracottaGlazed {
public BlockTerracottaGlazedWhite() {
this(0);
}
public BlockTerracottaGlazedWhite(int meta) {
super(meta);
}
@Override
public int getId() {
return WHITE_GLAZED_TERRACOTTA;
}
@Override
public String getName() {
return "White Glazed Terracotta";
}
}
| 470 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockAir.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockAir.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.math.AxisAlignedBB;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockAir extends BlockTransparent {
public BlockAir() {}
@Override
public int getId() {
return AIR;
}
@Override
public String getName() {
return "Air";
}
@Override
public boolean canPassThrough() {
return true;
}
@Override
public boolean isBreakable(Item item) {
return false;
}
@Override
public boolean canBeFlowedInto() {
return true;
}
@Override
public boolean canBePlaced() {
return false;
}
@Override
public boolean canBeReplaced() {
return true;
}
@Override
public boolean isSolid() {
return false;
}
@Override
public AxisAlignedBB getBoundingBox() {
return null;
}
@Override
public double getHardness() {
return 0;
}
@Override
public double getResistance() {
return 0;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,155 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockGrass.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockGrass.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.event.block.BlockSpreadEvent;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.level.generator.object.ObjectTallGrass;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.math.Vector3;
import cn.nukkit.utils.BlockColor;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockGrass extends BlockDirt {
public BlockGrass() {
}
@Override
public int getId() {
return GRASS;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public double getHardness() {
return 0.6;
}
@Override
public double getResistance() {
return 3;
}
@Override
public String getName() {
return "Grass";
}
@Override
public boolean onActivate(Item item) {
return this.onActivate(item, null);
}
@Override
public boolean onActivate(Item item, Player player) {
if (item.getId() == Item.DYE && item.getDamage() == 0x0F) {
item.count--;
ObjectTallGrass.growGrass(this.getLevel(), this, new NukkitRandom(), 15, 10);
return true;
} else if (item.isHoe()) {
item.useOn(this);
this.getLevel().setBlock(this, new BlockFarmland());
return true;
} else if (item.isShovel()) {
item.useOn(this);
this.getLevel().setBlock(this, new BlockGrassPath());
return true;
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_RANDOM) {
Block block = this.getLevel().getBlock(new Vector3(this.x, this.y, this.z));
if (block.up().getLightLevel() < 4) {
BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockDirt());
Server.getInstance().getPluginManager().callEvent(ev);
} else if (block.up().getLightLevel() >= 9) {
for (int l = 0; l < 4; ++l) {
NukkitRandom random = new NukkitRandom();
int x = random.nextRange((int) this.x - 1, (int) this.x + 1);
int y = random.nextRange((int) this.y - 2, (int) this.y + 2);
int z = random.nextRange((int) this.z - 1, (int) this.z + 1);
Block blocks = this.getLevel().getBlock(new Vector3(x, y, z));
if (blocks.getId() == Block.DIRT && blocks.getDamage() == 0x0F && blocks.up().getLightLevel() >= 4 && blocks.z <= 2) {
BlockSpreadEvent ev = new BlockSpreadEvent(blocks, this, new BlockGrass());
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(blocks, ev.getNewState());
}
}
}
}
}
return 0;
}
@Override
public BlockColor getColor() {
return BlockColor.GRASS_BLOCK_COLOR;
}
}
| 3,140 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDoorIron.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDoorIron.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemDoorIron;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockDoorIron extends BlockDoor {
public BlockDoorIron() {
this(0);
}
public BlockDoorIron(int meta) {
super(meta);
}
@Override
public String getName() {
return "Iron Door Block";
}
@Override
public int getId() {
return IRON_DOOR_BLOCK;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public double getHardness() {
return 5;
}
@Override
public double getResistance() {
return 25;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemDoorIron();
}
@Override
public BlockColor getColor() {
return BlockColor.IRON_BLOCK_COLOR;
}
@Override
public boolean onActivate(Item item, Player player) {
return false;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,519 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockOreLapis.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockOreLapis.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemDye;
import cn.nukkit.item.ItemTool;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.math.NukkitRandom;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockOreLapis extends BlockSolid {
public BlockOreLapis() {
}
@Override
public int getId() {
return LAPIS_ORE;
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
return "Lapis Lazuli Ore";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_STONE) {
int count = 4 + ThreadLocalRandom.current().nextInt(5);
Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
if (fortune != null && fortune.getLevel() >= 1) {
int i = ThreadLocalRandom.current().nextInt(fortune.getLevel() + 2) - 1;
if (i < 0) {
i = 0;
}
count *= (i + 1);
}
return new Item[]{
new ItemDye(4, new Random().nextInt(4) + 4)
};
} else {
return new Item[0];
}
}
@Override
public int getDropExp() {
return new NukkitRandom().nextRange(2, 5);
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,727 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockWeightedPressurePlateHeavy.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockWeightedPressurePlateHeavy.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.NukkitMath;
import cn.nukkit.utils.BlockColor;
/**
* @author CreeperFace
*/
public class BlockWeightedPressurePlateHeavy extends BlockPressurePlateBase {
public BlockWeightedPressurePlateHeavy() {
this(0);
}
public BlockWeightedPressurePlateHeavy(int meta) {
super(meta);
this.onPitch = 0.90000004f;
this.offPitch = 0.75f;
}
@Override
public int getId() {
return HEAVY_WEIGHTED_PRESSURE_PLATE;
}
@Override
public String getName() {
return "Weighted Pressure Plate (Heavy)";
}
@Override
public double getHardness() {
return 0.5D;
}
@Override
public double getResistance() {
return 2.5D;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(this, 0);
}
@Override
public BlockColor getColor() {
return BlockColor.IRON_BLOCK_COLOR;
}
@Override
protected int computeRedstoneStrength() {
int count = Math.min(this.level.getCollidingEntities(getCollisionBoundingBox()).length, this.getMaxWeight());
if (count > 0) {
float f = (float) Math.min(this.getMaxWeight(), count) / (float) this.getMaxWeight();
return Math.max(1, NukkitMath.ceilFloat(f * 15.0F));
} else {
return 0;
}
}
public int getMaxWeight() {
return 150;
}
}
| 1,896 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDoubleSlabStone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDoubleSlabStone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockDoubleSlabStone extends BlockSolidMeta {
public static final int STONE = 0;
public static final int SANDSTONE = 1;
public static final int WOODEN = 2;
public static final int COBBLESTONE = 3;
public static final int BRICK = 4;
public static final int STONE_BRICK = 5;
public static final int QUARTZ = 6;
public static final int NETHER_BRICK = 7;
public BlockDoubleSlabStone() {
this(0);
}
public BlockDoubleSlabStone(int meta) {
super(meta);
}
@Override
public int getId() {
return DOUBLE_SLAB;
}
@Override
public double getResistance() {
return getToolType() > ItemTool.TIER_WOODEN ? 30 : 15;
}
@Override
public double getHardness() {
return 2;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
String[] names = new String[]{
"Stone",
"Sandstone",
"Wooden",
"Cobblestone",
"Brick",
"Stone Brick",
"Quartz",
"Nether Brick"
};
return "Double " + names[this.getDamage() & 0x07] + " Slab";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
Item.get(Item.SLAB, this.getDamage() & 0x07, 2)
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
switch (this.getDamage() & 0x07) {
case BlockDoubleSlabStone.STONE:
return BlockColor.STONE_BLOCK_COLOR;
case BlockDoubleSlabStone.SANDSTONE:
return BlockColor.SAND_BLOCK_COLOR;
case BlockDoubleSlabStone.WOODEN:
return BlockColor.WOOD_BLOCK_COLOR;
case BlockDoubleSlabStone.COBBLESTONE:
return BlockColor.STONE_BLOCK_COLOR;
case BlockDoubleSlabStone.BRICK:
return BlockColor.STONE_BLOCK_COLOR;
case BlockDoubleSlabStone.STONE_BRICK:
return BlockColor.STONE_BLOCK_COLOR;
case BlockDoubleSlabStone.QUARTZ:
return BlockColor.QUARTZ_BLOCK_COLOR;
case BlockDoubleSlabStone.NETHER_BRICK:
return BlockColor.NETHERRACK_BLOCK_COLOR;
default:
return BlockColor.STONE_BLOCK_COLOR; //unreachable
}
}
@Override
public boolean canHarvestWithHand() {
return false;
}
} | 2,859 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSlabWood.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSlabWood.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockSlabWood extends BlockSlab {
public BlockSlabWood() {
this(0);
}
public BlockSlabWood(int meta) {
super(meta, DOUBLE_WOODEN_SLAB);
}
@Override
public String getName() {
String[] names = new String[]{
"Oak",
"Spruce",
"Birch",
"Jungle",
"Acacia",
"Dark Oak",
"",
""
};
return (((this.getDamage() & 0x08) == 0x08) ? "Upper " : "") + names[this.getDamage() & 0x07] + " Wooden Slab";
}
@Override
public int getId() {
return WOOD_SLAB;
}
@Override
public int getBurnChance() {
return 5;
}
@Override
public int getBurnAbility() {
return 20;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{
toItem()
};
}
@Override
public Item toItem() {
return new ItemBlock(this, this.getDamage() & 0x07);
}
@Override
public BlockColor getColor() {
return BlockColor.WOOD_BLOCK_COLOR;
}
}
| 1,482 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockBed.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockBed.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityBed;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBed;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.DyeColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockBed extends BlockTransparentMeta {
public BlockBed() {
this(0);
}
public BlockBed(int meta) {
super(meta);
}
@Override
public int getId() {
return BED_BLOCK;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public double getResistance() {
return 1;
}
@Override
public double getHardness() {
return 0.2;
}
@Override
public String getName() {
return this.getDyeColor().getName() + " Bed Block";
}
@Override
public double getMaxY() {
return this.y + 0.5625;
}
@Override
public boolean onActivate(Item item) {
return this.onActivate(item, null);
}
@Override
public boolean onActivate(Item item, Player player) {
int time = this.getLevel().getTime() % Level.TIME_FULL;
boolean isNight = (time >= Level.TIME_NIGHT && time < Level.TIME_SUNRISE);
if (player != null && !isNight) {
player.sendMessage(new TranslationContainer("tile.bed.noSleep"));
return true;
}
Block blockNorth = this.north();
Block blockSouth = this.south();
Block blockEast = this.east();
Block blockWest = this.west();
Block b;
if ((this.getDamage() & 0x08) == 0x08) {
b = this;
} else {
if (blockNorth.getId() == this.getId() && (blockNorth.getDamage() & 0x08) == 0x08) {
b = blockNorth;
} else if (blockSouth.getId() == this.getId() && (blockSouth.getDamage() & 0x08) == 0x08) {
b = blockSouth;
} else if (blockEast.getId() == this.getId() && (blockEast.getDamage() & 0x08) == 0x08) {
b = blockEast;
} else if (blockWest.getId() == this.getId() && (blockWest.getDamage() & 0x08) == 0x08) {
b = blockWest;
} else {
if (player != null) {
player.sendMessage(new TranslationContainer("tile.bed.notValid"));
}
return true;
}
}
if (player != null && !player.sleepOn(b)) {
player.sendMessage(new TranslationContainer("tile.bed.occupied"));
}
return true;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
return this.place(item, block, target, face, fx, fy, fz, null);
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (!down.isTransparent()) {
Block next = this.getSide(player.getDirection());
Block downNext = next.down();
if (next.canBeReplaced() && !downNext.isTransparent()) {
int meta = player.getDirection().getHorizontalIndex();
this.getLevel().setBlock(block, Block.get(this.getId(), meta), true, true);
this.getLevel().setBlock(next, Block.get(this.getId(), meta | 0x08), true, true);
createBlockEntity(this, item.getDamage());
createBlockEntity(next, item.getDamage());
return true;
}
}
return false;
}
@Override
public boolean onBreak(Item item) {
Block blockNorth = this.north(); //Gets the blocks around them
Block blockSouth = this.south();
Block blockEast = this.east();
Block blockWest = this.west();
if ((this.getDamage() & 0x08) == 0x08) { //This is the Top part of bed
if (blockNorth.getId() == this.getId() && blockNorth.getDamage() != 0x08) { //Checks if the block ID&&meta are right
this.getLevel().setBlock(blockNorth, new BlockAir(), true, true);
} else if (blockSouth.getId() == this.getId() && blockSouth.getDamage() != 0x08) {
this.getLevel().setBlock(blockSouth, new BlockAir(), true, true);
} else if (blockEast.getId() == this.getId() && blockEast.getDamage() != 0x08) {
this.getLevel().setBlock(blockEast, new BlockAir(), true, true);
} else if (blockWest.getId() == this.getId() && blockWest.getDamage() != 0x08) {
this.getLevel().setBlock(blockWest, new BlockAir(), true, true);
}
} else { //Bottom Part of Bed
if (blockNorth.getId() == this.getId() && (blockNorth.getDamage() & 0x08) == 0x08) {
this.getLevel().setBlock(blockNorth, new BlockAir(), true, true);
} else if (blockSouth.getId() == this.getId() && (blockSouth.getDamage() & 0x08) == 0x08) {
this.getLevel().setBlock(blockSouth, new BlockAir(), true, true);
} else if (blockEast.getId() == this.getId() && (blockEast.getDamage() & 0x08) == 0x08) {
this.getLevel().setBlock(blockEast, new BlockAir(), true, true);
} else if (blockWest.getId() == this.getId() && (blockWest.getDamage() & 0x08) == 0x08) {
this.getLevel().setBlock(blockWest, new BlockAir(), true, true);
}
}
this.getLevel().setBlock(this, new BlockAir(), true, true);
return true;
}
private void createBlockEntity(Vector3 pos, int color) {
CompoundTag nbt = BlockEntity.getDefaultCompound(pos, BlockEntity.BED);
nbt.putByte("color", color);
BlockEntity.createBlockEntity(BlockEntity.BED, this.level.getChunk(pos.getFloorX() >> 4, pos.getFloorZ() >> 4), nbt);
}
@Override
public Item toItem() {
return new ItemBed(this.getDyeColor().getWoolData());
}
@Override
public BlockColor getColor() {
return this.getDyeColor().getColor();
}
public DyeColor getDyeColor() {
if (this.level != null) {
BlockEntity blockEntity = this.level.getBlockEntity(this);
if (blockEntity instanceof BlockEntityBed) {
return ((BlockEntityBed) blockEntity).getDyeColor();
}
}
return DyeColor.WHITE;
}
}
| 6,700 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockVine.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockVine.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.entity.Entity;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.SimpleAxisAlignedBB;
/**
* Created by Pub4Game on 15.01.2016.
*/
public class BlockVine extends BlockTransparentMeta {
public BlockVine(int meta) {
super(meta);
}
public BlockVine() {
this(0);
}
@Override
public String getName() {
return "Vines";
}
@Override
public int getId() {
return VINE;
}
@Override
public double getHardness() {
return 0.2;
}
@Override
public double getResistance() {
return 1;
}
@Override
public boolean canPassThrough() {
return true;
}
@Override
public boolean hasEntityCollision() {
return true;
}
@Override
public boolean canBeReplaced() {
return true;
}
@Override
public boolean canBeClimbed() {
return true;
}
@Override
public void onEntityCollide(Entity entity) {
entity.resetFallDistance();
entity.onGround = true;
}
@Override
public boolean isSolid() {
return false;
}
@Override
protected AxisAlignedBB recalculateBoundingBox() {
double f1 = 1;
double f2 = 1;
double f3 = 1;
double f4 = 0;
double f5 = 0;
double f6 = 0;
boolean flag = this.getDamage() > 0;
if ((this.getDamage() & 0x02) > 0) {
f4 = Math.max(f4, 0.0625);
f1 = 0;
f2 = 0;
f5 = 1;
f3 = 0;
f6 = 1;
flag = true;
}
if ((this.getDamage() & 0x08) > 0) {
f1 = Math.min(f1, 0.9375);
f4 = 1;
f2 = 0;
f5 = 1;
f3 = 0;
f6 = 1;
flag = true;
}
if ((this.getDamage() & 0x01) > 0) {
f3 = Math.min(f3, 0.9375);
f6 = 1;
f1 = 0;
f4 = 1;
f2 = 0;
f5 = 1;
flag = true;
}
if (!flag && this.up().isSolid()) {
f2 = Math.min(f2, 0.9375);
f5 = 1;
f1 = 0;
f4 = 1;
f3 = 0;
f6 = 1;
}
return new SimpleAxisAlignedBB(
this.x + f1,
this.y + f2,
this.z + f3,
this.x + f4,
this.y + f5,
this.z + f6
);
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (target.isSolid()) {
int[] faces = new int[]{
0,
0,
1,
4,
8,
2
};
this.setDamage(faces[face.getIndex()]);
this.getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public Item[] getDrops(Item item) {
if (item.isShears()) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(this, 0);
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
BlockFace[] faces = {
BlockFace.DOWN,
BlockFace.SOUTH,
BlockFace.WEST,
BlockFace.DOWN,
BlockFace.NORTH,
BlockFace.DOWN,
BlockFace.DOWN,
BlockFace.DOWN,
BlockFace.EAST
};
if (!this.getSide(faces[this.getDamage()]).isSolid()) {
Block up = this.up();
if (up.getId() != this.getId() || up.getDamage() != this.getDamage()) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
}
return 0;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHEARS;
}
}
| 4,477 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFlower.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFlower.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/11/23 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockFlower extends BlockFlowable {
public static final int TYPE_POPPY = 0;
public static final int TYPE_BLUE_ORCHID = 1;
public static final int TYPE_ALLIUM = 2;
public static final int TYPE_AZURE_BLUET = 3;
public static final int TYPE_RED_TULIP = 4;
public static final int TYPE_ORANGE_TULIP = 5;
public static final int TYPE_WHITE_TULIP = 6;
public static final int TYPE_PINK_TULIP = 7;
public static final int TYPE_OXEYE_DAISY = 8;
public BlockFlower() {
this(0);
}
public BlockFlower(int meta) {
super(meta);
}
@Override
public int getId() {
return FLOWER;
}
@Override
public String getName() {
String[] names = new String[]{
"Poppy",
"Blue Orchid",
"Allium",
"Azure Bluet",
"Red Tulip",
"Orange Tulip",
"White Tulip",
"Pink Tulip",
"Oxeye Daisy",
"Unknown",
"Unknown",
"Unknown",
"Unknown",
"Unknown",
"Unknown",
"Unknown"
};
return names[this.getDamage() & 0x0f];
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (down.getId() == Block.GRASS || down.getId() == Block.DIRT || down.getId() == Block.FARMLAND || down.getId() == Block.PODZOL) {
this.getLevel().setBlock(block, this, true);
return true;
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.down().isTransparent()) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{
toItem()
};
}
@Override
public BlockColor getColor() {
return BlockColor.FOLIAGE_BLOCK_COLOR;
}
}
| 2,503 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstoneWire.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstoneWire.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.event.block.BlockRedstoneEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemRedstone;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.BlockFace.Plane;
import cn.nukkit.math.Vector3;
import cn.nukkit.utils.BlockColor;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockRedstoneWire extends BlockFlowable {
private boolean canProvidePower = true;
private final Set<Vector3> blocksNeedingUpdate = new HashSet<>();
public BlockRedstoneWire() {
this(0);
}
public BlockRedstoneWire(int meta) {
super(meta);
}
@Override
public String getName() {
return "Redstone Wire";
}
@Override
public int getId() {
return REDSTONE_WIRE;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (face != BlockFace.UP || !canBePlacedOn(target)) {
return false;
}
this.getLevel().setBlock(block, this, true, false);
this.updateSurroundingRedstone(true);
Vector3 pos = getLocation();
for (BlockFace blockFace : Plane.VERTICAL) {
this.level.updateAroundRedstone(pos.getSide(blockFace), blockFace.getOpposite());
}
for (BlockFace blockFace : Plane.VERTICAL) {
this.updateAround(pos.getSide(blockFace), blockFace.getOpposite());
}
for (BlockFace blockFace : Plane.HORIZONTAL) {
Vector3 v = pos.getSide(blockFace);
if (this.level.getBlock(v).isNormalBlock()) {
this.updateAround(v.up(), BlockFace.DOWN);
} else {
this.updateAround(v.down(), BlockFace.UP);
}
}
return true;
}
private void updateAround(Vector3 pos, BlockFace face) {
if (this.level.getBlock(pos).getId() == Block.REDSTONE_WIRE) {
this.level.updateAroundRedstone(pos, face);
for (BlockFace side : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(side), side.getOpposite());
}
}
}
private void updateSurroundingRedstone(boolean force) {
this.calculateCurrentChanges(force);
}
private void calculateCurrentChanges(boolean force) {
Vector3 pos = this.getLocation();
int meta = this.getDamage();
int maxStrength = meta;
this.canProvidePower = false;
int power = this.getIndirectPower();
this.canProvidePower = true;
if (power > 0 && power > maxStrength - 1) {
maxStrength = power;
}
int strength = 0;
for (BlockFace face : Plane.HORIZONTAL) {
Vector3 v = pos.getSide(face);
boolean flag = v.getX() != this.getX() || v.getZ() != this.getZ();
if (flag) {
strength = this.getMaxCurrentStrength(v, strength);
}
if (this.level.getBlock(v).isNormalBlock() && !this.level.getBlock(pos.up()).isNormalBlock()) {
if (flag) {
strength = this.getMaxCurrentStrength(v.up(), strength);
}
} else if (flag && !this.level.getBlock(v).isNormalBlock()) {
strength = this.getMaxCurrentStrength(v.down(), strength);
}
}
if (strength > maxStrength) {
maxStrength = strength - 1;
} else if (maxStrength > 0) {
--maxStrength;
} else {
maxStrength = 0;
}
if (power > maxStrength - 1) {
maxStrength = power;
}
if (meta != maxStrength) {
this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, meta, maxStrength));
this.setDamage(maxStrength);
this.level.setBlock(this, this, false, false);
this.level.updateAroundRedstone(this, null);
for (BlockFace face : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(face), face.getOpposite());
}
} else if (force) {
for (BlockFace face : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(face), face.getOpposite());
}
}
}
private int getMaxCurrentStrength(Vector3 pos, int maxStrength) {
if (this.level.getBlockIdAt(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ()) != this.getId()) {
return maxStrength;
} else {
int strength = this.level.getBlockDataAt(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
return strength > maxStrength ? strength : maxStrength;
}
}
@Override
public boolean onBreak(Item item) {
this.getLevel().setBlock(this, new BlockAir(), true, true);
Vector3 pos = getLocation();
this.updateSurroundingRedstone(false);
for (BlockFace blockFace : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(blockFace), null);
}
for (BlockFace blockFace : Plane.HORIZONTAL) {
Vector3 v = pos.getSide(blockFace);
if (this.level.getBlock(v).isNormalBlock()) {
this.updateAround(v.up(), BlockFace.DOWN);
} else {
this.updateAround(v.down(), BlockFace.UP);
}
}
return true;
}
@Override
public Item toItem() {
return new ItemRedstone();
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
@Override
public int onUpdate(int type) {
if (type != Level.BLOCK_UPDATE_NORMAL && type != Level.BLOCK_UPDATE_REDSTONE) {
return 0;
}
if (type == Level.BLOCK_UPDATE_NORMAL && !this.canBePlacedOn(this.getLocation().down())) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
this.updateSurroundingRedstone(false);
return Level.BLOCK_UPDATE_NORMAL;
}
public boolean canBePlacedOn(Vector3 v) {
Block b = this.level.getBlock(v);
return b.isSolid() && !b.isTransparent() && b.getId() != Block.GLOWSTONE;
}
public int getStrongPower(BlockFace side) {
return !this.canProvidePower ? 0 : getWeakPower(side);
}
public int getWeakPower(BlockFace side) {
if (!this.canProvidePower) {
return 0;
} else {
int power = this.getDamage();
if (power == 0) {
return 0;
} else if (side == BlockFace.UP) {
return power;
} else {
EnumSet<BlockFace> enumset = EnumSet.noneOf(BlockFace.class);
for (BlockFace face : Plane.HORIZONTAL) {
if (this.isPowerSourceAt(face)) {
enumset.add(face);
}
}
if (side.getAxis().isHorizontal() && enumset.isEmpty()) {
return power;
} else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY())) {
return power;
} else {
return 0;
}
}
}
}
private boolean isPowerSourceAt(BlockFace side) {
Vector3 pos = getLocation();
Vector3 v = pos.getSide(side);
Block block = this.level.getBlock(v);
boolean flag = block.isNormalBlock();
boolean flag1 = this.level.getBlock(pos.up()).isNormalBlock();
return !flag1 && flag && canConnectUpwardsTo(this.level, v.up()) || (canConnectTo(block, side) || !flag && canConnectUpwardsTo(this.level, block.down()));
}
protected static boolean canConnectUpwardsTo(Level level, Vector3 pos) {
return canConnectUpwardsTo(level.getBlock(pos));
}
protected static boolean canConnectUpwardsTo(Block block) {
return canConnectTo(block, null);
}
protected static boolean canConnectTo(Block block, BlockFace side) {
if (block.getId() == Block.REDSTONE_WIRE) {
return true;
} else if (BlockRedstoneDiode.isDiode(block)) {
BlockFace face = ((BlockRedstoneDiode) block).getFacing();
return face == side || face.getOpposite() == side;
} else {
return block.isPowerSource() && side != null;
}
}
@Override
public boolean isPowerSource() {
return this.canProvidePower;
}
private int getIndirectPower() {
int power = 0;
Vector3 pos = getLocation();
for (BlockFace face : BlockFace.values()) {
int blockPower = this.getIndirectPower(pos.getSide(face), face);
if (blockPower >= 15) {
return 15;
}
if (blockPower > power) {
power = blockPower;
}
}
return power;
}
private int getIndirectPower(Vector3 pos, BlockFace face) {
Block block = this.level.getBlock(pos);
if (block.getId() == Block.REDSTONE_WIRE) {
return 0;
}
return block.isNormalBlock() ? getStrongPower(pos.getSide(face), face) : block.getWeakPower(face);
}
private int getStrongPower(Vector3 pos, BlockFace direction) {
Block block = this.level.getBlock(pos);
if (block.getId() == Block.REDSTONE_WIRE) {
return 0;
}
return block.getStrongPower(direction);
}
}
| 9,763 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockRedstoneComparatorPowered.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockRedstoneComparatorPowered.java | package cn.nukkit.block;
/**
* @author CreeperFace
*/
public class BlockRedstoneComparatorPowered extends BlockRedstoneComparator {
public BlockRedstoneComparatorPowered() {
this(0);
}
public BlockRedstoneComparatorPowered(int meta) {
super(meta);
this.isPowered = true;
}
@Override
public int getId() {
return POWERED_COMPARATOR;
}
@Override
public String getName() {
return "Comparator Block Powered";
}
@Override
protected BlockRedstoneComparator getPowered() {
return this;
}
}
| 590 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.