mirror of
https://github.com/GTNewHorizons/Draconic-Evolution.git
synced 2026-11-18 03:25:03 +00:00
Item Dislocators will work from baubles slots (#47)
* Item Dislocators will work from baubles slots * fix typo * optional baubles
This commit is contained in:
1 parent
5252678a45
commit
d71e388119
7 files changed
+98
-8
No files matched your search
@@ -19,6 +19,9 @@ dependencies {
|
||||
compileOnly("com.github.GTNewHorizons:inventory-tweaks:1.6.2:dev") {
|
||||
transitive = false
|
||||
}
|
||||
compileOnly('com.github.GTNewHorizons:Baubles:1.0.4:dev') {
|
||||
transitive = false
|
||||
}
|
||||
|
||||
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {
|
||||
transitive = false
|
||||
|
||||
+7
-1
@@ -1,5 +1,7 @@
|
||||
package com.brandon3055.draconicevolution.client.keybinding;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
@@ -12,12 +14,14 @@ import org.lwjgl.input.Mouse;
|
||||
import com.brandon3055.brandonscore.common.utills.ItemNBTHelper;
|
||||
import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.common.ModItems;
|
||||
import com.brandon3055.draconicevolution.common.items.tools.Magnet;
|
||||
import com.brandon3055.draconicevolution.common.items.tools.baseclasses.ToolHandler;
|
||||
import com.brandon3055.draconicevolution.common.network.ButtonPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.MagnetTogglePacket;
|
||||
import com.brandon3055.draconicevolution.common.network.PlacedItemPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.TeleporterPacket;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.InventoryUtils;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
@@ -65,7 +69,9 @@ public class KeyInputHandler {
|
||||
}
|
||||
} else if (KeyBindings.toggleMagnet.isPressed()) {
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
if (player.inventory.hasItem(ModItems.magnet)) {
|
||||
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInAnyPlayerInventory(player, Magnet.class);
|
||||
|
||||
if (magnetOptional.isPresent()) {
|
||||
DraconicEvolution.network.sendToServer(new MagnetTogglePacket());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.item.EntityXPOrb;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -25,13 +26,18 @@ import com.brandon3055.draconicevolution.common.handler.ConfigHandler;
|
||||
import com.brandon3055.draconicevolution.common.items.ItemDE;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.IBauble;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Created by brandon3055 on 9/3/2016.
|
||||
*/
|
||||
public class Magnet extends ItemDE {
|
||||
|
||||
@Optional.Interface(iface = "baubles.api.IBauble", modid = "Baubles")
|
||||
public class Magnet extends ItemDE implements IBauble {
|
||||
|
||||
private IIcon draconium;
|
||||
private IIcon awakened;
|
||||
@@ -187,4 +193,41 @@ public class Magnet extends ItemDE {
|
||||
+ " "
|
||||
+ StatCollector.translateToLocal("info.de.blockRange.txt"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public BaubleType getBaubleType(ItemStack itemstack) {
|
||||
return BaubleType.UNIVERSAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
|
||||
World world = player.worldObj;
|
||||
onUpdate(itemstack, world, player, 0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public void onEquipped(ItemStack itemstack, EntityLivingBase player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.brandon3055.draconicevolution.common.lib;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
public final class References {
|
||||
|
||||
public static final String MODID = "DraconicEvolution";
|
||||
@@ -10,6 +12,7 @@ public final class References {
|
||||
public static final String SERVERPROXYLOCATION = "com.brandon3055.draconicevolution.common.CommonProxy";
|
||||
public static final String GUIFACTORY = "com.brandon3055.draconicevolution.client.gui.DEGUIFactory";
|
||||
public static final String RESOURCESPREFIX = MODID.toLowerCase() + ":";
|
||||
public static final boolean BAUBLES_MOD_IS_LOADED = Loader.isModLoaded("Baubles");
|
||||
|
||||
// ======================Render IDs========================//
|
||||
public static int idTeleporterStand = -1;
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public final class MagnetToggleAckPacket implements IMessage {
|
||||
@Override
|
||||
public IMessage onMessage(MagnetToggleAckPacket message, MessageContext ctx) {
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInPlayerInventory(player, Magnet.class);
|
||||
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInAnyPlayerInventory(player, Magnet.class);
|
||||
|
||||
if (magnetOptional.isPresent()) {
|
||||
ItemStack itemStack = magnetOptional.get().copy();
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ public final class MagnetTogglePacket implements IMessage {
|
||||
public IMessage onMessage(MagnetTogglePacket message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
|
||||
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInPlayerInventory(player, Magnet.class);
|
||||
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInAnyPlayerInventory(player, Magnet.class);
|
||||
magnetOptional.ifPresent(itemStack -> {
|
||||
Magnet.toggle(itemStack);
|
||||
DraconicEvolution.network.sendTo(new MagnetToggleAckPacket(Magnet.isEnabled(itemStack)), player);
|
||||
|
||||
@@ -1,18 +1,53 @@
|
||||
package com.brandon3055.draconicevolution.common.utills;
|
||||
|
||||
import java.util.Arrays;
|
||||
import static com.brandon3055.draconicevolution.common.lib.References.BAUBLES_MOD_IS_LOADED;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
|
||||
public final class InventoryUtils {
|
||||
|
||||
private InventoryUtils() {}
|
||||
|
||||
public static Optional<ItemStack> getItemInPlayerInventory(EntityPlayer player, Class<? extends Item> item) {
|
||||
return Arrays.stream(player.inventory.mainInventory)
|
||||
.filter(itemStack -> itemStack != null && item.isInstance(itemStack.getItem())).findAny();
|
||||
public static Optional<ItemStack> getItemInAnyPlayerInventory(EntityPlayer player,
|
||||
Class<? extends Item> itemClass) {
|
||||
if (BAUBLES_MOD_IS_LOADED) {
|
||||
Optional<ItemStack> itemInBaubles = getItemInPlayerBaublesInventory(player, itemClass);
|
||||
if (itemInBaubles.isPresent()) {
|
||||
return itemInBaubles;
|
||||
}
|
||||
}
|
||||
return getItemInPlayerInventory(player, itemClass);
|
||||
}
|
||||
|
||||
public static Optional<ItemStack> getItemInPlayerInventory(EntityPlayer player, Class<? extends Item> itemClass) {
|
||||
if (itemClass != null) {
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||
ItemStack itemStack = player.inventory.getStackInSlot(i);
|
||||
|
||||
if (itemStack != null && itemClass.isInstance(itemStack.getItem())) {
|
||||
return Optional.of(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static Optional<ItemStack> getItemInPlayerBaublesInventory(EntityPlayer player,
|
||||
Class<? extends Item> itemClass) {
|
||||
if (BAUBLES_MOD_IS_LOADED && itemClass != null) {
|
||||
for (int i = 0; i < PlayerHandler.getPlayerBaubles(player).getSizeInventory(); i++) {
|
||||
ItemStack itemStack = PlayerHandler.getPlayerBaubles(player).getStackInSlot(i);
|
||||
if (itemStack != null && itemClass.isInstance(itemStack.getItem())) {
|
||||
return Optional.of(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user