diff --git a/src/api/java/mods/railcraft/api/core/items/IMinecartItem.java b/src/api/java/mods/railcraft/api/core/items/IMinecartItem.java new file mode 100644 index 000000000..8f8652022 --- /dev/null +++ b/src/api/java/mods/railcraft/api/core/items/IMinecartItem.java @@ -0,0 +1,49 @@ +/* + * ****************************************************************************** + * Copyright 2011-2015 CovertJaguar + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.md for details. + * *************************************************************************** + */ + +package mods.railcraft.api.core.items; + +import com.mojang.authlib.GameProfile; +import net.minecraft.entity.item.EntityMinecart; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +/** + * This interface should be implemented by any cart item, + * but it is generally optional. + * + * @author CovertJaguar + */ +public interface IMinecartItem +{ + + /** + * Controls whether this cart item can be placed by the Cart and Train Dispensers. + * + * Generally, you can ignore the placeCart() function if this returns false. + * + * @param cart + * @return true if it can be placed, false otherwise + */ + public boolean canBePlacedByNonPlayer(ItemStack cart); + + /** + * Places a cart at the specified location. + * + * Implementing this function is optional. + * + * @param owner the name of the player placing the cart or "[MyMod]" with the brackets + * @param cart An ItemStack that contains the cart + * @param world The World + * @param i x-Coord + * @param j y-Coord + * @param k z-Coord + * @return the cart placed or null if failed + */ + public EntityMinecart placeCart(GameProfile owner, ItemStack cart, World world, int i, int j, int k); +} \ No newline at end of file diff --git a/src/main/java/vazkii/botania/common/item/ItemPoolMinecart.java b/src/main/java/vazkii/botania/common/item/ItemPoolMinecart.java index 3e4648c03..4c9240293 100644 --- a/src/main/java/vazkii/botania/common/item/ItemPoolMinecart.java +++ b/src/main/java/vazkii/botania/common/item/ItemPoolMinecart.java @@ -10,6 +10,10 @@ */ package vazkii.botania.common.item; +import com.mojang.authlib.GameProfile; + +import cpw.mods.fml.common.Optional; +import mods.railcraft.api.core.items.IMinecartItem; import net.minecraft.block.BlockRailBase; import net.minecraft.entity.item.EntityMinecart; import net.minecraft.entity.player.EntityPlayer; @@ -22,7 +26,8 @@ import vazkii.botania.common.achievement.ModAchievements; import vazkii.botania.common.entity.EntityPoolMinecart; import vazkii.botania.common.lib.LibItemNames; -public class ItemPoolMinecart extends ItemMod implements ICraftAchievement { +@Optional.Interface(modid = "Railcraft", iface = "mods.railcraft.api.core.items.IMinecartItem", striprefs = true) +public class ItemPoolMinecart extends ItemMod implements ICraftAchievement, IMinecartItem { public ItemPoolMinecart() { setMaxStackSize(1); @@ -53,4 +58,25 @@ public class ItemPoolMinecart extends ItemMod implements ICraftAchievement { return ModAchievements.manaCartCraft; } + @Override + public boolean canBePlacedByNonPlayer(ItemStack cart) { + return true; + } + + @Override + public EntityMinecart placeCart(GameProfile owner, ItemStack cart, World world, int i, int j, int k) { + if(BlockRailBase.func_150051_a(world.getBlock(i, j, k))) { + if(!world.isRemote) { + EntityMinecart entityminecart = new EntityPoolMinecart(world, i + 0.5,j + 0.5, k + 0.5); + + if(cart.hasDisplayName()) + entityminecart.setMinecartName(cart.getDisplayName()); + + if(world.spawnEntityInWorld(entityminecart)) + return entityminecart; + } + } + return null; + } + }