Don't drop multiparts for creative players
This commit is contained in:
parent
b601cdb516
commit
4ca4c47ec1
|
@ -8,6 +8,7 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
|
@ -151,17 +152,16 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean breakPart(MultipartView view) {
|
||||
public boolean breakPart(MultipartView view, PlayerEntity player) {
|
||||
if (view.getContainer() != this || !(view instanceof Entry)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Entry e = (Entry)view;
|
||||
|
||||
if (world instanceof ServerWorld) {
|
||||
if (world instanceof ServerWorld && !player.isCreative()) {
|
||||
List<ItemStack> drops = getDroppedStacks(e, (ServerWorld)world, pos);
|
||||
drops.forEach(stack -> Block.dropStack(world, pos, stack));
|
||||
// TODO: don't drop if player is creative
|
||||
}
|
||||
|
||||
remove(e);
|
||||
|
|
|
@ -41,7 +41,7 @@ public class ContainerEventHandler {
|
|||
return ActionResult.FAILURE;
|
||||
}
|
||||
|
||||
boolean success = container.breakPart(hit.view);
|
||||
boolean success = container.breakPart(hit.view, player);
|
||||
return success ? ActionResult.SUCCESS : ActionResult.FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.shadowfacts.simplemultipart.container;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -99,7 +100,7 @@ public interface MultipartContainer {
|
|||
* @param view The part to break.
|
||||
* @return If the part has been successfully broken.
|
||||
*/
|
||||
boolean breakPart(MultipartView view);
|
||||
boolean breakPart(MultipartView view, PlayerEntity player);
|
||||
|
||||
/**
|
||||
* Indicates that something about a multipart in this container has changed and it should be saved to disk.
|
||||
|
|
|
@ -116,7 +116,7 @@ public class MultipartItem extends Item {
|
|||
|
||||
if (context.getContainer().canInsert(placementState)) {
|
||||
context.getContainer().insert(placementState);
|
||||
context.getItemStack().addAmount(-1);
|
||||
context.getItemStack().subtractAmount(1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue