mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-22 13:09:42 +00:00
Added dispenser behaviours.
This commit is contained in:
1 parent
3e9f2145d5
commit
65e1f3862f
17 files changed
+159
-3
No files matched your search
@@ -16,6 +16,10 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Item.ToolMaterial;
|
||||
import net.minecraft.item.ItemArmor.ArmorMaterial;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -48,6 +52,8 @@ public final class BotaniaAPI {
|
||||
|
||||
public static Map<String, Integer> oreWeights = new HashMap<String, Integer>();
|
||||
|
||||
public static Map<Item, Block> seeds = new HashMap();
|
||||
|
||||
public static ArmorMaterial manasteelArmorMaterial = EnumHelper.addArmorMaterial("MANASTEEL", 16, new int[] { 2, 6, 5, 2 }, 18);
|
||||
public static ToolMaterial manasteelToolMaterial = EnumHelper.addToolMaterial("MANASTEEL", 3, 300, 6.2F, 2F, 20);
|
||||
|
||||
@@ -99,6 +105,13 @@ public final class BotaniaAPI {
|
||||
addOreWeight("oreUranium", 1337); // IC2
|
||||
addOreWeight("oreVinteum", 5925); // Ars Magica
|
||||
addOreWeight("oreYellorite", 3520); // Big Reactors
|
||||
|
||||
addSeed(Items.wheat_seeds, Blocks.wheat);
|
||||
addSeed(Items.potato, Blocks.potatoes);
|
||||
addSeed(Items.carrot, Blocks.carrots);
|
||||
addSeed(Items.nether_wart, Blocks.nether_wart);
|
||||
addSeed(Items.pumpkin_seeds, Blocks.pumpkin_stem);
|
||||
addSeed(Items.melon_seeds, Blocks.melon_stem);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,6 +211,14 @@ public final class BotaniaAPI {
|
||||
public static int getOreWeight(String ore) {
|
||||
return oreWeights.get(ore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows an item to be counted as a seed. Any item in this list can be
|
||||
* dispensed by a dispenser, the block is the block to be placed.
|
||||
*/
|
||||
public static void addSeed(Item item, Block block) {
|
||||
seeds.put(item, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last recipe to have been added to the recipe list.
|
||||
|
||||
@@ -77,7 +77,8 @@ public class SubTileEntity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Wand of the Forest is used on this sub tile.
|
||||
* Called when a Wand of the Forest is used on this sub tile. Note that the
|
||||
* player parameter can be null if this is called from a dispenser.
|
||||
*/
|
||||
public boolean onWanded(EntityPlayer player, ItemStack wand) {
|
||||
return false;
|
||||
|
||||
@@ -133,6 +133,9 @@ public class SubTileFunctional extends SubTileEntity {
|
||||
|
||||
@Override
|
||||
public boolean onWanded(EntityPlayer player, ItemStack wand) {
|
||||
if(player == null)
|
||||
return false;
|
||||
|
||||
knownMana = mana;
|
||||
player.worldObj.playSoundAtEntity(player, "random.orb", 0.1F, 1F);
|
||||
|
||||
|
||||
@@ -141,6 +141,9 @@ public class SubTileGenerating extends SubTileEntity {
|
||||
|
||||
@Override
|
||||
public boolean onWanded(EntityPlayer player, ItemStack wand) {
|
||||
if(player == null)
|
||||
return false;
|
||||
|
||||
if(!player.worldObj.isRemote)
|
||||
sync();
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ import net.minecraft.world.World;
|
||||
*/
|
||||
public interface IWandable {
|
||||
|
||||
/**
|
||||
* Called when the item is used by a wand. Note that the player parameter can be null
|
||||
* if this function is called from a dispenser.
|
||||
*/
|
||||
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int side);
|
||||
|
||||
}
|
||||
@@ -122,6 +122,9 @@ public class BlockPistonRelay extends BlockMod implements IWandable, ILexiconabl
|
||||
|
||||
@Override
|
||||
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int side) {
|
||||
if(player == null)
|
||||
return false;
|
||||
|
||||
if(!player.isSneaking()) {
|
||||
playerPositions.put(player.getCommandSenderName(), getCoordsAsString(world.provider.dimensionId, x, y, z));
|
||||
world.playSoundEffect(x, y, z, "random.orb", 0.5F, 1F);
|
||||
|
||||
@@ -12,9 +12,13 @@
|
||||
package vazkii.botania.common.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.common.block.dispenser.BehaviourSeeds;
|
||||
import vazkii.botania.common.block.dispenser.BehaviourWand;
|
||||
import vazkii.botania.common.block.subtile.SubTilePureDaisy;
|
||||
import vazkii.botania.common.block.subtile.functional.SubTileAgricarnation;
|
||||
import vazkii.botania.common.block.subtile.functional.SubTileBellethorn;
|
||||
@@ -53,6 +57,7 @@ import vazkii.botania.common.block.tile.TileSpecialFlower;
|
||||
import vazkii.botania.common.block.tile.TileSpreader;
|
||||
import vazkii.botania.common.block.tile.TileTinyPlanet;
|
||||
import vazkii.botania.common.block.tile.TileTurntable;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import vazkii.botania.common.lib.LibOreDict;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
@@ -116,7 +121,13 @@ public final class ModBlocks {
|
||||
|
||||
initTileEntities();
|
||||
}
|
||||
|
||||
|
||||
public static void addDispenserBehaviours() {
|
||||
for(Item seed : BotaniaAPI.seeds.keySet())
|
||||
BlockDispenser.dispenseBehaviorRegistry.putObject(seed, new BehaviourSeeds(BotaniaAPI.seeds.get(seed)));
|
||||
BlockDispenser.dispenseBehaviorRegistry.putObject(ModItems.twigWand, new BehaviourWand());
|
||||
}
|
||||
|
||||
private static void initTileEntities() {
|
||||
GameRegistry.registerTileEntity(TileAltar.class, LibBlockNames.ALTAR);
|
||||
GameRegistry.registerTileEntity(TileSpecialFlower.class, LibBlockNames.SPECIAL_FLOWER);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [May 16, 2014, 10:36:05 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.block.dispenser;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BehaviourSeeds extends BehaviorDefaultDispenseItem {
|
||||
|
||||
Block block;
|
||||
|
||||
public BehaviourSeeds(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) {
|
||||
EnumFacing facing = BlockDispenser.func_149937_b(par1IBlockSource.getBlockMetadata());
|
||||
int x = par1IBlockSource.getXInt() + facing.getFrontOffsetX();
|
||||
int y = par1IBlockSource.getYInt() + facing.getFrontOffsetY();
|
||||
int z = par1IBlockSource.getZInt() + facing.getFrontOffsetZ();
|
||||
World world = par1IBlockSource.getWorld();
|
||||
|
||||
if(world.getBlock(x, y, z).isAir(world, x, y, z) && block.canBlockStay(world, x, y, z)) {
|
||||
world.setBlock(x, y, z, block);
|
||||
par2ItemStack.stackSize--;
|
||||
return par2ItemStack;
|
||||
}
|
||||
|
||||
return super.dispenseStack(par1IBlockSource, par2ItemStack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [May 16, 2014, 11:11:31 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.block.dispenser;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import vazkii.botania.api.wand.IWandable;
|
||||
|
||||
public class BehaviourWand extends BehaviorDefaultDispenseItem {
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) {
|
||||
ForgeDirection facing = ForgeDirection.getOrientation(BlockDispenser.func_149937_b(par1IBlockSource.getBlockMetadata()).ordinal());
|
||||
int x = par1IBlockSource.getXInt() + facing.offsetX;
|
||||
int y = par1IBlockSource.getYInt() + facing.offsetY;
|
||||
int z = par1IBlockSource.getZInt() + facing.offsetZ;
|
||||
World world = par1IBlockSource.getWorld();
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if(block instanceof IWandable) {
|
||||
((IWandable) block).onUsedByWand(null, par2ItemStack, world, x, y, z, facing.getOpposite().ordinal());
|
||||
return par2ItemStack;
|
||||
}
|
||||
|
||||
return super.dispenseStack(par1IBlockSource, par2ItemStack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -173,6 +173,9 @@ public class SubTileHopperhock extends SubTileFunctional {
|
||||
|
||||
@Override
|
||||
public boolean onWanded(EntityPlayer player, ItemStack wand) {
|
||||
if(player == null)
|
||||
return false;
|
||||
|
||||
if(player.isSneaking()) {
|
||||
filterType = filterType == 2 ? 0 : filterType + 1;
|
||||
sync();
|
||||
|
||||
@@ -197,6 +197,9 @@ public class TilePool extends TileMod implements IManaPool {
|
||||
}
|
||||
|
||||
public void onWanded(EntityPlayer player, ItemStack wand) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
if(player.isSneaking()) {
|
||||
outputting = !outputting;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
|
||||
@@ -203,6 +203,9 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
|
||||
}
|
||||
|
||||
public void onWanded(EntityPlayer player, ItemStack wand) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
if(!player.isSneaking()) {
|
||||
if(!worldObj.isRemote) {
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
|
||||
@@ -65,6 +65,9 @@ public class TileTurntable extends TileMod {
|
||||
}
|
||||
|
||||
public void onWanded(EntityPlayer player, ItemStack wand) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
if(player.isSneaking())
|
||||
backwards = !backwards;
|
||||
else speed = speed == 6 ? 1 : speed + 1;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CommonProxy {
|
||||
}
|
||||
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
|
||||
ModBlocks.addDispenserBehaviours();
|
||||
}
|
||||
|
||||
public void setEntryToOpen(LexiconEntry entry) {
|
||||
|
||||
@@ -128,6 +128,7 @@ public final class LexiconData {
|
||||
|
||||
public static LexiconEntry unstableBlocks;
|
||||
public static LexiconEntry decorativeBlocks;
|
||||
public static LexiconEntry dispenserTweaks;
|
||||
|
||||
public static void init() {
|
||||
BotaniaAPI.addCategory(categoryBasics = new LexiconCategory(LibLexicon.CATEGORY_BASICS));
|
||||
@@ -395,5 +396,8 @@ public final class LexiconData {
|
||||
decorativeBlocks = new BLexiconEntry(LibLexicon.MISC_DECORATIVE_BLOCKS, categoryMisc);
|
||||
decorativeBlocks.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModCrafingRecipes.recipeLivingrockDecor1), new PageCraftingRecipe("2", ModCrafingRecipes.recipeLivingrockDecor2), new PageCraftingRecipe("3", ModCrafingRecipes.recipeLivingrockDecor3), new PageCraftingRecipe("4", ModCrafingRecipes.recipeLivingrockDecor4),
|
||||
new PageCraftingRecipe("5", ModCrafingRecipes.recipeLivingwoodDecor1), new PageCraftingRecipe("6", ModCrafingRecipes.recipeLivingwoodDecor2), new PageCraftingRecipe("7", ModCrafingRecipes.recipeLivingwoodDecor3), new PageCraftingRecipe("8", ModCrafingRecipes.recipeLivingwoodDecor4), new PageCraftingRecipe("9", ModCrafingRecipes.recipeLivingwoodDecor5));
|
||||
|
||||
dispenserTweaks = new BLexiconEntry(LibLexicon.MISC_DISPENSER_TWEAKS, categoryMisc);
|
||||
dispenserTweaks.setLexiconPages(new PageText("0"));
|
||||
}
|
||||
}
|
||||
@@ -109,5 +109,6 @@ public final class LibLexicon {
|
||||
|
||||
public static final String MISC_UNSTABLE_BLOCKS = "unstableBlocks";
|
||||
public static final String MISC_DECORATIVE_BLOCKS = "decorativeBlocks";
|
||||
public static final String MISC_DISPENSER_TWEAKS = "dispenserTweaks";
|
||||
|
||||
}
|
||||
@@ -855,3 +855,7 @@ botania.page.decorativeBlocks6=Mossing the planks
|
||||
botania.page.decorativeBlocks7=Framing the planks
|
||||
botania.page.decorativeBlocks8=Pattern planks
|
||||
botania.page.decorativeBlocks9=Glimmering livingwood
|
||||
|
||||
# -- DISPENSER TWEAKS
|
||||
botania.entry.dispenserTweaks=Dispenser Tweaks
|
||||
botania.page.dispenserTweaks0=&1Dispensers&0, among their normal abilities, can also plant all sorts of crops, from &1Seeds&0, &1Potatos&0 or &1Carrots&0 to even &1Nether Wart&0. The crop is planted in the block right in front of the dispenser.<br>The &1Dispensers&0 can also use the &1Wand of the Forest&0 for some specific tasks such as triggering a &1Runic Altar&0.
|
||||
Reference in new issue
Block a user