added options for drop command

This commit is contained in:
gnembon committed 2020-02-09 01:56:30 -04:00
1 parent 8ed56c1d81
commit 161b5d491d
2 files changed
+41

No files matched your search

@@ -53,7 +53,9 @@ public class PlayerCommand
.then(makeActionCommand("jump", EntityPlayerActionPack.ActionType.JUMP))
.then(makeActionCommand("attack", EntityPlayerActionPack.ActionType.ATTACK))
.then(makeActionCommand("drop", EntityPlayerActionPack.ActionType.DROP_ITEM))
.then(makeDropCommand("drop", false))
.then(makeActionCommand("dropStack", EntityPlayerActionPack.ActionType.DROP_STACK))
.then(makeDropCommand("dropStack", true))
.then(makeActionCommand("swapHands", EntityPlayerActionPack.ActionType.SWAP_HANDS))
.then(literal("kill").executes(PlayerCommand::kill))
.then(literal("shadow"). executes(PlayerCommand::shadow))
@@ -105,6 +107,19 @@ public class PlayerCommand
.executes(c -> action(c, type, EntityPlayerActionPack.Action.interval(IntegerArgumentType.getInteger(c, "ticks"))))));
}
private static LiteralArgumentBuilder<ServerCommandSource> makeDropCommand(String actionName, boolean dropAll)
{
return literal(actionName)
.then(literal("all").executes(c ->manipulate(c, ap -> ap.drop(-2,dropAll))))
.then(literal("mainhand").executes(c ->manipulate(c, ap -> ap.drop(-1,dropAll))))
.then(literal("offhand").executes(c ->manipulate(c, ap -> ap.drop(40,dropAll))))
.then(argument("slot", IntegerArgumentType.integer(0, 40)).
executes(c ->manipulate(c, ap -> ap.drop(
IntegerArgumentType.getInteger(c,"slot"),
dropAll
))));
}
private static Collection<String> getPlayers(ServerCommandSource source)
{
Set<String> players = Sets.newLinkedHashSet(Arrays.asList("Steve", "Alex"));
@@ -4,6 +4,7 @@ import carpet.fakes.ServerPlayerEntityInterface;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.HorseBaseEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.MinecartEntity;
import net.minecraft.item.ItemStack;
@@ -222,6 +223,31 @@ public class EntityPlayerActionPack
return Tracer.rayTrace(player, 1, reach, false);
}
private void dropItemFromSlot(int slot, boolean dropAll)
{
PlayerInventory inv = player.inventory;
if (!inv.getInvStack(slot).isEmpty())
player.dropItem(inv.takeInvStack(slot,
dropAll ? inv.getInvStack(slot).getCount() : 1
), false, true); // scatter, keep owner
}
public void drop(int selectedSlot, boolean dropAll)
{
PlayerInventory inv = player.inventory;
if (selectedSlot == -2) // all
{
for (int i = inv.getInvSize(); i >= 0; i--)
dropItemFromSlot(i, dropAll);
}
else // one slot
{
if (selectedSlot == -1)
selectedSlot = inv.selectedSlot;
dropItemFromSlot(selectedSlot, dropAll);
}
}
public enum ActionType
{
USE(true)