Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brandon/equip equips #437

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@
import io.netty.buffer.ByteBuf;

import com.microsoft.Malmo.MalmoMod;
import com.microsoft.Malmo.MissionHandlerInterfaces.ICommandHandler;
import com.microsoft.Malmo.Schemas.*;
import com.microsoft.Malmo.Schemas.MissionInit;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;

import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
Expand Down Expand Up @@ -75,7 +73,6 @@ public IMessage onMessage(EquipMessage message, MessageContext ctx) {
if (player == null)
return null;


Item item = Item.getByNameOrId(message.parameters);
if (item == null || item.getRegistryName() == null)
return null;
Expand All @@ -95,16 +92,21 @@ public IMessage onMessage(EquipMessage message, MessageContext ctx) {

// We don't have that item in our inventories
if (!itemInInventory)
return null; // Returning true here as this handler should capture the place command
return null;

// Equip the item to the item's 'best' slot rather than always using mainhand
EntityEquipmentSlot equipmentSlot = EntityLiving.getSlotForItemStack(new ItemStack(item));

// Hard-coded hack to allow agents to hold pumpkins and skulls which are otherwise seen as helmets
if (item == Item.getItemFromBlock(Blocks.PUMPKIN) || item == Items.SKULL) {
equipmentSlot = EntityEquipmentSlot.MAINHAND;
}

// Swap current hotbar item with found inventory item (if not the same)
int hotbarIdx = player.inventory.currentItem;
System.out.println("got harbar " + hotbarIdx);
System.out.println("got slot " + stackIndex);
// Swap the items between the destination slot and the slot with the matching item
ItemStack prev = player.getItemStackFromSlot(equipmentSlot);
player.setItemStackToSlot(equipmentSlot, stackInInventory);
player.inventory.setInventorySlotContents(stackIndex, prev);

ItemStack prevEquip = inv.getStackInSlot(hotbarIdx).copy();
inv.setInventorySlotContents(hotbarIdx, stackInInventory);
inv.setInventorySlotContents(stackIndex, prevEquip);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"package": "com.microsoft.Malmo.Mixins",
"mixins": [
"MixinEntityRandom",
"MixinLargeInventory",
"MixinMinecraftGameloop",
"MixinMinecraftServerRun",
"MixinNoGuiInteract",
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup_intellij.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cd $DIR
echo "Openining IntelliJ - Please select import gradle project on the bottom right"
echo "Then import the ../Malmo module:"
echo "1) file -> project structure -> modules"
echo "2) + -> Module name: Malmo, Module dir: ../Malmo"
echo "2) + -> new module -> <next, keep defaults> -> Module name: Malmo, Module dir: ~/minerl/minerl/Malmo/"
sleep 1
./gradlew openIdea