Skip to content

Commit

Permalink
Revert "Add Block.getDrops() and Block.breakNaturally() (#85)" (#90)
Browse files Browse the repository at this point in the history
This reverts commit 19db456.
  • Loading branch information
RhysB authored Apr 30, 2024
1 parent 8aabead commit d4eb7fd
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 134 deletions.
21 changes: 4 additions & 17 deletions src/main/java/net/minecraft/server/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<List<ItemStack>> 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<List<ItemStack>> 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;
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/net/minecraft/server/BlockBed.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -192,11 +189,10 @@ public static ChunkCoordinates f(World world, int i, int j, int k, int l) {
return null;
}

public Optional<List<ItemStack>> 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() {
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/net/minecraft/server/BlockCrops.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -89,15 +86,22 @@ public int a(int i, int j) {
return this.textureId + j;
}

public Optional<List<ItemStack>> getDrops(World world, int x, int y, int z, int data){
Optional<List<ItemStack>> ret = super.getDrops(world, x, y, z, data);
List<ItemStack> 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) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/minecraft/server/BlockJukeBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/net/minecraft/server/BlockPistonMoving.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<List<ItemStack>> 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());
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/minecraft/server/BlockStairs.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -119,8 +117,8 @@ public void remove(World world, int i, int j, int k) {
this.a.remove(world, i, j, k);
}

public Optional<List<ItemStack>> 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) {
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/org/bukkit/block/Block.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<ItemStack> 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<ItemStack> 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);
}
55 changes: 0 additions & 55 deletions src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -318,50 +309,4 @@ public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.getById(net.minecraft.server.Block.byId[this.getTypeId()].material.j());

}

@Override
public Collection<ItemStack> getDrops() {
net.minecraft.server.Block block = net.minecraft.server.Block.byId[getTypeId()];
if (block == null) {
return new ArrayList<ItemStack>();
}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<ItemStack>();
}
}

@Override
public Collection<ItemStack> getDrops(ItemStack tool) {
net.minecraft.server.Block block = net.minecraft.server.Block.byId[getTypeId()];
if (block == null) {
return new ArrayList<ItemStack>();
}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<ItemStack>();
}
}

@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<ItemStack> drops = getDrops(tool);
boolean flag = setTypeId(0);
if (flag) {
for (ItemStack drop : drops) {
getWorld().dropItemNaturally(getLocation(), drop);
}
}
return flag;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,4 @@ public short getDurability() {
public int getMaxStackSize() {
return item.getItem().getMaxStackSize();
}

public net.minecraft.server.ItemStack getHandle() {
return item;
}
}

0 comments on commit d4eb7fd

Please sign in to comment.