Don't drop multiparts for creative players

This commit is contained in:
Shadowfacts 2019-01-06 10:28:36 -05:00
parent b601cdb516
commit 4ca4c47ec1
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 7 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
@ -151,17 +152,16 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
} }
@Override @Override
public boolean breakPart(MultipartView view) { public boolean breakPart(MultipartView view, PlayerEntity player) {
if (view.getContainer() != this || !(view instanceof Entry)) { if (view.getContainer() != this || !(view instanceof Entry)) {
return false; return false;
} }
Entry e = (Entry)view; Entry e = (Entry)view;
if (world instanceof ServerWorld) { if (world instanceof ServerWorld && !player.isCreative()) {
List<ItemStack> drops = getDroppedStacks(e, (ServerWorld)world, pos); List<ItemStack> drops = getDroppedStacks(e, (ServerWorld)world, pos);
drops.forEach(stack -> Block.dropStack(world, pos, stack)); drops.forEach(stack -> Block.dropStack(world, pos, stack));
// TODO: don't drop if player is creative
} }
remove(e); remove(e);

View File

@ -41,7 +41,7 @@ public class ContainerEventHandler {
return ActionResult.FAILURE; return ActionResult.FAILURE;
} }
boolean success = container.breakPart(hit.view); boolean success = container.breakPart(hit.view, player);
return success ? ActionResult.SUCCESS : ActionResult.FAILURE; return success ? ActionResult.SUCCESS : ActionResult.FAILURE;
} }

View File

@ -1,5 +1,6 @@
package net.shadowfacts.simplemultipart.container; package net.shadowfacts.simplemultipart.container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -99,7 +100,7 @@ public interface MultipartContainer {
* @param view The part to break. * @param view The part to break.
* @return If the part has been successfully broken. * @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. * Indicates that something about a multipart in this container has changed and it should be saved to disk.

View File

@ -116,7 +116,7 @@ public class MultipartItem extends Item {
if (context.getContainer().canInsert(placementState)) { if (context.getContainer().canInsert(placementState)) {
context.getContainer().insert(placementState); context.getContainer().insert(placementState);
context.getItemStack().addAmount(-1); context.getItemStack().subtractAmount(1);
return true; return true;
} }
return false; return false;