diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index 177b4ba0..80d873a2 100644 --- a/src/main/java/net/minecraft/server/Block.java +++ b/src/main/java/net/minecraft/server/Block.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Optional; import java.util.Random; public class Block { @@ -309,28 +308,16 @@ public void dropNaturally(World world, int i, int j, int k, int l, float f) { for (int j1 = 0; j1 < i1; ++j1) { // CraftBukkit - <= to < to allow for plugins to completely disable block drops from explosions if (world.random.nextFloat() < f) { - //Project Poseidon Start - New way to handle block drops to allow for plugins to know what items a block will drop - Optional> items = getDrops(world, i, j, k, l); - if(items.isPresent()) { - for(ItemStack item : items.get()) { - this.a(world, i, j, k, item); - } + int k1 = this.a(l, world.random); + + if (k1 > 0) { + this.a(world, i, j, k, new ItemStack(k1, 1, this.a_(l))); } - //Project Poseidon End } } } } - //Project Poseidon - API to get the drops of a block - public Optional> getDrops(World world, int x, int y, int z, int data){ - if(this.a(data, world.random) <= 0){ - return Optional.empty(); - }else{ - return Optional.of(Arrays.asList(new ItemStack(this.a(data, world.random), 1, this.a_(data)))); - } - } - protected void a(World world, int i, int j, int k, ItemStack itemstack) { if (!world.isStatic) { float f = 0.7F; diff --git a/src/main/java/net/minecraft/server/BlockBed.java b/src/main/java/net/minecraft/server/BlockBed.java index 434c7468..236e4bf0 100644 --- a/src/main/java/net/minecraft/server/BlockBed.java +++ b/src/main/java/net/minecraft/server/BlockBed.java @@ -2,10 +2,7 @@ import org.bukkit.event.entity.EntityDamageEvent; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; -import java.util.Optional; import java.util.Random; public class BlockBed extends Block { @@ -192,11 +189,10 @@ public static ChunkCoordinates f(World world, int i, int j, int k, int l) { return null; } - public Optional> getDrops(World world, int x, int y, int z, int data){ - if(!d(data)){ - return super.getDrops(world, x, y, z, data); + public void dropNaturally(World world, int i, int j, int k, int l, float f) { + if (!d(l)) { + super.dropNaturally(world, i, j, k, l, f); } - return Optional.empty(); } public int e() { diff --git a/src/main/java/net/minecraft/server/BlockCrops.java b/src/main/java/net/minecraft/server/BlockCrops.java index 8ae34e7c..0025bc3d 100644 --- a/src/main/java/net/minecraft/server/BlockCrops.java +++ b/src/main/java/net/minecraft/server/BlockCrops.java @@ -1,8 +1,5 @@ package net.minecraft.server; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; import java.util.Random; public class BlockCrops extends BlockFlower { @@ -89,15 +86,22 @@ public int a(int i, int j) { return this.textureId + j; } - public Optional> getDrops(World world, int x, int y, int z, int data){ - Optional> ret = super.getDrops(world, x, y, z, data); - List stacks = ret.orElse(new ArrayList<>(3)); - for(int i = 0; i < 3; i++){ - if(world.random.nextInt(15) <= 1){ - stacks.add(new ItemStack(Item.SEEDS)); + public void dropNaturally(World world, int i, int j, int k, int l, float f) { + super.dropNaturally(world, i, j, k, l, f); + if (!world.isStatic) { + for (int i1 = 0; i1 < 3; ++i1) { + if (world.random.nextInt(15) <= l) { + float f1 = 0.7F; + float f2 = world.random.nextFloat() * f1 + (1.0F - f1) * 0.5F; + float f3 = world.random.nextFloat() * f1 + (1.0F - f1) * 0.5F; + float f4 = world.random.nextFloat() * f1 + (1.0F - f1) * 0.5F; + EntityItem entityitem = new EntityItem(world, (double) ((float) i + f2), (double) ((float) j + f3), (double) ((float) k + f4), new ItemStack(Item.SEEDS)); + + entityitem.pickupDelay = 10; + world.addEntity(entityitem); + } } } - return Optional.of(stacks); } public int a(int i, Random random) { diff --git a/src/main/java/net/minecraft/server/BlockJukeBox.java b/src/main/java/net/minecraft/server/BlockJukeBox.java index 9fff2cdb..67f857a4 100644 --- a/src/main/java/net/minecraft/server/BlockJukeBox.java +++ b/src/main/java/net/minecraft/server/BlockJukeBox.java @@ -58,6 +58,12 @@ public void remove(World world, int i, int j, int k) { super.remove(world, i, j, k); } + public void dropNaturally(World world, int i, int j, int k, int l, float f) { + if (!world.isStatic) { + super.dropNaturally(world, i, j, k, l, f); + } + } + protected TileEntity a_() { return new TileEntityRecordPlayer(); } diff --git a/src/main/java/net/minecraft/server/BlockPistonMoving.java b/src/main/java/net/minecraft/server/BlockPistonMoving.java index 9bdc25e3..03d9ca29 100644 --- a/src/main/java/net/minecraft/server/BlockPistonMoving.java +++ b/src/main/java/net/minecraft/server/BlockPistonMoving.java @@ -1,7 +1,5 @@ package net.minecraft.server; -import java.util.List; -import java.util.Optional; import java.util.Random; public class BlockPistonMoving extends BlockContainer { @@ -56,13 +54,13 @@ public int a(int i, Random random) { return 0; } + public void dropNaturally(World world, int i, int j, int k, int l, float f) { + if (!world.isStatic) { + TileEntityPiston tileentitypiston = this.b(world, i, j, k); - public Optional> getDrops(World world, int x, int y, int z, int data){ - TileEntityPiston tileentitypiston = this.b(world, x, y, z); - if(tileentitypiston != null){ - return Block.byId[tileentitypiston.a()].getDrops(world, x, y, z, tileentitypiston.e()); - }else{ - return Optional.empty(); + if (tileentitypiston != null) { + Block.byId[tileentitypiston.a()].g(world, i, j, k, tileentitypiston.e()); + } } } diff --git a/src/main/java/net/minecraft/server/BlockStairs.java b/src/main/java/net/minecraft/server/BlockStairs.java index f38f773e..67ca33cc 100644 --- a/src/main/java/net/minecraft/server/BlockStairs.java +++ b/src/main/java/net/minecraft/server/BlockStairs.java @@ -1,8 +1,6 @@ package net.minecraft.server; import java.util.ArrayList; -import java.util.List; -import java.util.Optional; import java.util.Random; public class BlockStairs extends Block { @@ -119,8 +117,8 @@ public void remove(World world, int i, int j, int k) { this.a.remove(world, i, j, k); } - public Optional> getDrops(World world, int x, int y, int z, int data){ - return this.a.getDrops(world, x, y, z, data); + public void dropNaturally(World world, int i, int j, int k, int l, float f) { + this.a.dropNaturally(world, i, j, k, l, f); } public void b(World world, int i, int j, int k, Entity entity) { diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java index 3017eb90..0cf844eb 100644 --- a/src/main/java/org/bukkit/block/Block.java +++ b/src/main/java/org/bukkit/block/Block.java @@ -1,12 +1,9 @@ package org.bukkit.block; -import java.util.Collection; - import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.inventory.ItemStack; /** * Represents a block. This is a live object, and only one Block may exist for @@ -280,30 +277,4 @@ public interface Block { * @return reaction */ PistonMoveReaction getPistonMoveReaction(); - - /** - * Returns a list of items which would drop by destroying this block - * @return a list of dropped items for this type of block - */ - Collection getDrops(); - - /** - * Returns a list of items which would drop by destroying this block with a specific tool - * @param tool The tool or item in hand used for digging - * @return a list of dropped items for this type of block - */ - Collection getDrops(ItemStack tool); - - /** - * Breaks the block and spawns items as if a player had digged it regardless of the tool - * @return true if the block was broken - */ - boolean breakNaturally(); - - /** - * Breaks the block and spawns items as if a player had digged it - * @param tool The tool or item in hand used for digging - * @return true if the block was broken - */ - boolean breakNaturally(ItemStack tool); } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index c23dd013..419d84f6 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -2,22 +2,13 @@ import net.minecraft.server.BiomeBase; import net.minecraft.server.BlockRedstoneWire; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.*; import org.bukkit.craftbukkit.CraftChunk; -import org.bukkit.inventory.ItemStack; import org.bukkit.util.BlockVector; -import org.bukkit.craftbukkit.CraftWorld; -import org.bukkit.craftbukkit.inventory.CraftItemStack; public class CraftBlock implements Block { private final CraftChunk chunk; @@ -318,50 +309,4 @@ public PistonMoveReaction getPistonMoveReaction() { return PistonMoveReaction.getById(net.minecraft.server.Block.byId[this.getTypeId()].material.j()); } - - @Override - public Collection getDrops() { - net.minecraft.server.Block block = net.minecraft.server.Block.byId[getTypeId()]; - if (block == null) { - return new ArrayList(); - }else if(block.material.i()) { - return Arrays.asList(block.getDrops(((CraftWorld) this.getWorld()).getHandle(), x, y, z, (int)getData()).map((list) -> list.stream().map(itemStack -> new CraftItemStack(itemStack)).toArray(ItemStack[]::new)).orElse(new ItemStack[0])); - }else { - return new ArrayList(); - } - } - - @Override - public Collection getDrops(ItemStack tool) { - net.minecraft.server.Block block = net.minecraft.server.Block.byId[getTypeId()]; - if (block == null) { - return new ArrayList(); - }else if(block.material.i() || ((CraftItemStack)tool).getHandle().b(block)) { - return Arrays.asList(block.getDrops(((CraftWorld) this.getWorld()).getHandle(), x, y, z, (int)getData()).map((list) -> list.stream().map(itemStack -> new CraftItemStack(itemStack)).toArray(ItemStack[]::new)).orElse(new ItemStack[0])); - }else { - return new ArrayList(); - } - } - - @Override - public boolean breakNaturally() { - return breakNaturally(new ItemStack(Material.AIR)); - } - - @Override - public boolean breakNaturally(ItemStack tool) { - net.minecraft.server.Block block = net.minecraft.server.Block.byId[getTypeId()]; - if (block == null) { - return false; - }else{ - Collection drops = getDrops(tool); - boolean flag = setTypeId(0); - if (flag) { - for (ItemStack drop : drops) { - getWorld().dropItemNaturally(getLocation(), drop); - } - } - return flag; - } - } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index 5e612993..dcebeade 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -123,8 +123,4 @@ public short getDurability() { public int getMaxStackSize() { return item.getItem().getMaxStackSize(); } - - public net.minecraft.server.ItemStack getHandle() { - return item; - } }