mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-16 01:55:15 +00:00
Rod of the Shifting Crust and a bunch of other tweaks to go along with it.
This commit is contained in:
1 parent
8989a12835
commit
4eeec9bd49
16 files changed
+693
-12
No files matched your search
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [Aug 20, 2015, 10:31:54 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.item;
|
||||
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* An Item that implements this can provide blocks to other items that use them.
|
||||
* For example, the Black Hole Talisman implements this in order to allow for
|
||||
* the Rod of the Shifting Crust to pull blocks from it.
|
||||
*/
|
||||
public interface IBlockProvider {
|
||||
|
||||
/**
|
||||
* Provides the requested item. The doit paremeter specifies whether this is
|
||||
* just a test (false) or if the item should actually be removed (true).
|
||||
* If you need to use calls to ManaItemHandler.requestMana[Exact], use
|
||||
* the requestor as the ItemStack passed in.
|
||||
*/
|
||||
public boolean provideBlock(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta, boolean doit);
|
||||
|
||||
/**
|
||||
* Gets the amount of blocks of the type passed stored in this item. You must
|
||||
* check for the block passed in to not give the counter for a wrong block. Returning
|
||||
* -1 states that the item can provide infinite of the item passed in (for example,
|
||||
* the Rod of the Lands would return -1 if the block is dirt).
|
||||
*/
|
||||
public int getBlockCount(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta);
|
||||
|
||||
}
|
||||
@@ -12,6 +12,8 @@ package vazkii.botania.api.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
@@ -27,6 +29,7 @@ public interface IWireframeCoordinateListProvider {
|
||||
* Returns a list of ChunkCoordinates for the wireframes to draw.
|
||||
* Can be null.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<ChunkCoordinates> getWireframesToDraw(EntityPlayer player, ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -70,8 +70,9 @@ public final class ItemsRemainingRenderHandler {
|
||||
|
||||
if(stacks == 0)
|
||||
text = "" + count;
|
||||
else text = count + " (" + stacks + "*" + max + "+" + rem + ")";
|
||||
}
|
||||
else text = count + " (" + EnumChatFormatting.AQUA + stacks + EnumChatFormatting.RESET + "*" + EnumChatFormatting.GRAY + max + EnumChatFormatting.RESET + "+" + EnumChatFormatting.YELLOW + rem + EnumChatFormatting.RESET + ")";
|
||||
} else if(count == -1)
|
||||
text = "\u221E";
|
||||
|
||||
int color = 0x00FFFFFF | (int) (alpha * 0xFF) << 24;
|
||||
mc.fontRenderer.drawStringWithShadow(text, x + 20, y + 6, color);
|
||||
|
||||
@@ -43,14 +43,18 @@ public abstract class BlockCamo extends BlockModContainer<TileCamo> {
|
||||
if(tile instanceof TileCamo) {
|
||||
TileCamo camo = (TileCamo) tile;
|
||||
Block block = camo.camo;
|
||||
if(block != null && (block.isOpaqueCube() || isValidRenderType(block.getRenderType())))
|
||||
if(block != null && isValidBlock(block))
|
||||
return block.getIcon(side, camo.camoMeta);
|
||||
}
|
||||
|
||||
return getIconFromSideAfterCheck(tile, meta, side);
|
||||
}
|
||||
|
||||
public boolean isValidRenderType(int type) {
|
||||
public static boolean isValidBlock(Block block) {
|
||||
return block.isOpaqueCube() || isValidRenderType(block.getRenderType());
|
||||
}
|
||||
|
||||
public static boolean isValidRenderType(int type) {
|
||||
return validRenderTypes.contains(type);
|
||||
}
|
||||
|
||||
@@ -75,7 +79,7 @@ public abstract class BlockCamo extends BlockModContainer<TileCamo> {
|
||||
}
|
||||
|
||||
block = Block.getBlockFromItem(currentStack.getItem());
|
||||
if(block == null || !(isValidRenderType(block.getRenderType()) || block.isOpaqueCube()) || block instanceof BlockCamo || block.getMaterial() == Material.air)
|
||||
if(block == null || !isValidBlock(block) || block instanceof BlockCamo || block.getMaterial() == Material.air)
|
||||
doChange = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
|
||||
addItem(ModItems.tornadoRod);
|
||||
addItem(ModItems.fireRod);
|
||||
addItem(ModItems.smeltRod);
|
||||
addItem(ModItems.exchangeRod);
|
||||
addItem(ModItems.diviningRod);
|
||||
addItem(ModItems.gravityRod);
|
||||
addItem(ModItems.missileRod);
|
||||
|
||||
@@ -32,6 +32,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
import net.minecraftforge.oredict.RecipeSorter.Category;
|
||||
import vazkii.botania.api.item.IBlockProvider;
|
||||
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.core.helper.InventoryHelper;
|
||||
@@ -42,7 +43,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBlackHoleTalisman extends ItemMod {
|
||||
public class ItemBlackHoleTalisman extends ItemMod implements IBlockProvider {
|
||||
|
||||
private static final String TAG_BLOCK_NAME = "blockName";
|
||||
private static final String TAG_BLOCK_META = "blockMeta";
|
||||
@@ -189,7 +190,7 @@ public class ItemBlackHoleTalisman extends ItemMod {
|
||||
public String getItemStackDisplayName(ItemStack par1ItemStack) {
|
||||
Block block = getBlock(par1ItemStack);
|
||||
int meta = getBlockMeta(par1ItemStack);
|
||||
return super.getItemStackDisplayName(par1ItemStack) + (block == null ? "" : " (" + EnumChatFormatting.GREEN + new ItemStack(block, meta).getDisplayName() + EnumChatFormatting.RESET + ")");
|
||||
return super.getItemStackDisplayName(par1ItemStack) + (block == null ? "" : " (" + EnumChatFormatting.GREEN + new ItemStack(block, 1, meta).getDisplayName() + EnumChatFormatting.RESET + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -292,4 +293,29 @@ public class ItemBlackHoleTalisman extends ItemMod {
|
||||
return ItemNBTHelper.getInt(stack, TAG_BLOCK_COUNT, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean provideBlock(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta, boolean doit) {
|
||||
Block stored = getBlock(stack);
|
||||
int storedMeta = getBlockMeta(stack);
|
||||
if(stored == block && storedMeta == meta) {
|
||||
int count = getBlockCount(stack);
|
||||
if(count > 0) {
|
||||
if(doit)
|
||||
setCount(stack, count - 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCount(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta) {
|
||||
Block stored = getBlock(stack);
|
||||
int storedMeta = getBlockMeta(stack);
|
||||
if(stored == block && storedMeta == meta)
|
||||
return getBlockCount(stack);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,22 +10,26 @@
|
||||
*/
|
||||
package vazkii.botania.common.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.item.IBlockProvider;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.item.rod.ItemExchangeRod;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
public class ItemEnderHand extends ItemMod implements IManaUsingItem {
|
||||
public class ItemEnderHand extends ItemMod implements IManaUsingItem, IBlockProvider {
|
||||
|
||||
private static final int COST_PROVIDE = 5;
|
||||
private static final int COST_SELF = 250;
|
||||
private static final int COST_OTHER = 5000;
|
||||
|
||||
public ItemEnderHand() {
|
||||
setMaxDamage(1);
|
||||
setMaxStackSize(1);
|
||||
setUnlocalizedName(LibItemNames.ENDER_HAND);
|
||||
}
|
||||
|
||||
@@ -56,4 +60,33 @@ public class ItemEnderHand extends ItemMod implements IManaUsingItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean provideBlock(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta, boolean doit) {
|
||||
if(requestor != null && requestor.getItem() == this)
|
||||
return false;
|
||||
|
||||
ItemStack istack = ItemExchangeRod.removeFromInventory(player, player.getInventoryEnderChest(), stack, block, meta, false);
|
||||
if(istack != null) {
|
||||
boolean mana = ManaItemHandler.requestManaExact(stack, player, COST_PROVIDE, false);
|
||||
if(mana) {
|
||||
if(doit) {
|
||||
ManaItemHandler.requestManaExact(stack, player, COST_PROVIDE, true);
|
||||
ItemExchangeRod.removeFromInventory(player, player.getInventoryEnderChest(), stack, block, meta, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCount(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta) {
|
||||
if(requestor != null && requestor.getItem() == this)
|
||||
return 0;
|
||||
|
||||
return ItemExchangeRod.getInventoryItemCount(player, player.getInventoryEnderChest(), stack, block, meta);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,6 +100,7 @@ import vazkii.botania.common.item.relic.ItemThorRing;
|
||||
import vazkii.botania.common.item.rod.ItemCobbleRod;
|
||||
import vazkii.botania.common.item.rod.ItemDirtRod;
|
||||
import vazkii.botania.common.item.rod.ItemDiviningRod;
|
||||
import vazkii.botania.common.item.rod.ItemExchangeRod;
|
||||
import vazkii.botania.common.item.rod.ItemFireRod;
|
||||
import vazkii.botania.common.item.rod.ItemGravityRod;
|
||||
import vazkii.botania.common.item.rod.ItemMissileRod;
|
||||
@@ -249,6 +250,7 @@ public final class ModItems {
|
||||
public static Item cacophonium;
|
||||
public static Item slimeBottle;
|
||||
public static Item starSword;
|
||||
public static Item exchangeRod;
|
||||
|
||||
public static void init() {
|
||||
lexicon = new ItemLexicon();
|
||||
@@ -387,6 +389,7 @@ public final class ModItems {
|
||||
cacophonium = new ItemCacophonium();
|
||||
slimeBottle = new ItemSlimeBottle();
|
||||
starSword = new ItemStarSword();
|
||||
exchangeRod = new ItemExchangeRod();
|
||||
|
||||
OreDictionary.registerOre(LibOreDict.LEXICON, lexicon);
|
||||
for(int i = 0; i < 16; i++) {
|
||||
|
||||
@@ -10,15 +10,18 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.rod;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.item.IBlockProvider;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.common.item.ItemMod;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
public class ItemCobbleRod extends ItemMod implements IManaUsingItem {
|
||||
public class ItemCobbleRod extends ItemMod implements IManaUsingItem, IBlockProvider {
|
||||
|
||||
static final int COST = 150;
|
||||
|
||||
@@ -42,4 +45,18 @@ public class ItemCobbleRod extends ItemMod implements IManaUsingItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean provideBlock(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta, boolean doit) {
|
||||
if(block == Blocks.cobblestone && meta == 0)
|
||||
return !doit || ManaItemHandler.requestManaExact(requestor, player, COST, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCount(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta) {
|
||||
if(block == Blocks.dirt && meta == 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import vazkii.botania.api.item.IBlockProvider;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.common.Botania;
|
||||
@@ -28,7 +29,7 @@ import vazkii.botania.common.achievement.ModAchievements;
|
||||
import vazkii.botania.common.item.ItemMod;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
public class ItemDirtRod extends ItemMod implements IManaUsingItem, ICraftAchievement {
|
||||
public class ItemDirtRod extends ItemMod implements IManaUsingItem, ICraftAchievement, IBlockProvider {
|
||||
|
||||
static final int COST = 75;
|
||||
|
||||
@@ -82,4 +83,19 @@ public class ItemDirtRod extends ItemMod implements IManaUsingItem, ICraftAchiev
|
||||
return ModAchievements.dirtRodCraft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean provideBlock(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta, boolean doit) {
|
||||
if(block == Blocks.dirt && meta == 0)
|
||||
return !doit || ManaItemHandler.requestManaExact(requestor, player, COST, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCount(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta) {
|
||||
if(block == Blocks.dirt && meta == 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
/**
|
||||
* 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 the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [Aug 20, 2015, 8:08:34 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.item.rod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import vazkii.botania.api.item.IBlockProvider;
|
||||
import vazkii.botania.api.item.IWireframeCoordinateListProvider;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
|
||||
import vazkii.botania.common.block.BlockCamo;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.item.ItemMod;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWireframeCoordinateListProvider {
|
||||
|
||||
private static final int RANGE = 3;
|
||||
private static final int COST = 40;
|
||||
|
||||
private static final String TAG_BLOCK_NAME = "blockName";
|
||||
private static final String TAG_BLOCK_META = "blockMeta";
|
||||
private static final String TAG_TARGET_BLOCK_NAME = "targetBlockName";
|
||||
private static final String TAG_TARGET_BLOCK_META = "targetBlockMeta";
|
||||
private static final String TAG_SWAPPING = "swapping";
|
||||
private static final String TAG_SELECT_X = "selectX";
|
||||
private static final String TAG_SELECT_Y = "selectY";
|
||||
private static final String TAG_SELECT_Z = "selectZ";
|
||||
|
||||
public ItemExchangeRod() {
|
||||
setMaxStackSize(1);
|
||||
setUnlocalizedName(LibItemNames.EXCHANGE_ROD);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) {
|
||||
Block wblock = par3World.getBlock(par4, par5, par6);
|
||||
int wmeta = par3World.getBlockMetadata(par4, par5, par6);
|
||||
|
||||
if(par2EntityPlayer.isSneaking()) {
|
||||
TileEntity tile = par3World.getTileEntity(par4, par5, par6);
|
||||
if(tile == null) {
|
||||
if(BlockCamo.isValidBlock(wblock)) {
|
||||
Item item = Item.getItemFromBlock(wblock);
|
||||
if(!item.getHasSubtypes())
|
||||
wmeta = 0;
|
||||
|
||||
boolean set = setBlock(par1ItemStack, wblock, wmeta);
|
||||
par2EntityPlayer.setCurrentItemOrArmor(0, par1ItemStack);
|
||||
|
||||
displayRemainderCounter(par2EntityPlayer, par1ItemStack);
|
||||
return set;
|
||||
}
|
||||
}
|
||||
} else if(canExchange(par1ItemStack) && !ItemNBTHelper.getBoolean(par1ItemStack, TAG_SWAPPING, false)) {
|
||||
Block block = getBlock(par1ItemStack);
|
||||
int meta = getBlockMeta(par1ItemStack);
|
||||
List<ChunkCoordinates> swap = getBlocksToSwap(par3World, par1ItemStack, block, meta, par4, par5, par6, null, 0);
|
||||
if(swap.size() > 0) {
|
||||
ItemNBTHelper.setBoolean(par1ItemStack, TAG_SWAPPING, true);
|
||||
ItemNBTHelper.setInt(par1ItemStack, TAG_SELECT_X, par4);
|
||||
ItemNBTHelper.setInt(par1ItemStack, TAG_SELECT_Y, par5);
|
||||
ItemNBTHelper.setInt(par1ItemStack, TAG_SELECT_Z, par6);
|
||||
setTargetBlock(par1ItemStack, wblock, wmeta);
|
||||
if(par3World.isRemote)
|
||||
par2EntityPlayer.swingItem();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLeftClick(PlayerInteractEvent event) {
|
||||
if(event.action == Action.LEFT_CLICK_BLOCK) {
|
||||
ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
|
||||
if(stack != null && stack.getItem() == this && canExchange(stack))
|
||||
exchange(event.world, event.entityPlayer, event.x, event.y, event.z, stack, getBlock(stack), getBlockMeta(stack));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int something, boolean somethingelse) {
|
||||
if(!canExchange(stack) || !(entity instanceof EntityPlayer))
|
||||
return;
|
||||
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
Block block = getBlock(stack);
|
||||
int meta = getBlockMeta(stack);
|
||||
if(ItemNBTHelper.getBoolean(stack, TAG_SWAPPING, false)) {
|
||||
if(!ManaItemHandler.requestManaExact(stack, player, COST, false)) {
|
||||
ItemNBTHelper.setBoolean(stack, TAG_SWAPPING, false);
|
||||
return;
|
||||
}
|
||||
|
||||
int x = ItemNBTHelper.getInt(stack, TAG_SELECT_X, 0);
|
||||
int y = ItemNBTHelper.getInt(stack, TAG_SELECT_Y, 0);
|
||||
int z = ItemNBTHelper.getInt(stack, TAG_SELECT_Z, 0);
|
||||
Block targetBlock = getTargetBlock(stack);
|
||||
int targetMeta = getTargetBlockMeta(stack);
|
||||
List<ChunkCoordinates> swap = getBlocksToSwap(world, stack, block, meta, x, y, z, targetBlock, targetMeta);
|
||||
if(swap.size() == 0) {
|
||||
ItemNBTHelper.setBoolean(stack, TAG_SWAPPING, false);
|
||||
return;
|
||||
}
|
||||
|
||||
ChunkCoordinates coords = swap.get(world.rand.nextInt(swap.size()));
|
||||
boolean exchange = exchange(world, player, coords.posX, coords.posY, coords.posZ, stack, block, meta);
|
||||
if(exchange)
|
||||
ManaItemHandler.requestManaExact(stack, player, COST, true);
|
||||
else ItemNBTHelper.setBoolean(stack, TAG_SWAPPING, false);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean[][][] createMatrix(World world, ItemStack stack, Block blockToSwap, int metaToSwap, int xc, int yc, int zc, Block targetBlock, int targetMeta) {
|
||||
if(targetBlock == null) {
|
||||
targetBlock = world.getBlock(xc, yc, zc);
|
||||
targetMeta = world.getBlockMetadata(xc, yc, zc);
|
||||
}
|
||||
|
||||
int effrange = RANGE + 1;
|
||||
int diameter = effrange * 2 + 1;
|
||||
Boolean[][][] matrix = new Boolean[diameter][diameter][diameter];
|
||||
for(int i = 0; i < diameter; i++)
|
||||
for(int j = 0; j < diameter; j++)
|
||||
for(int k = 0; k < diameter; k++) {
|
||||
int x = xc + i - effrange;
|
||||
int y = yc + j - effrange;
|
||||
int z = zc + k - effrange;
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
boolean invalid = !BlockCamo.isValidBlock(block);
|
||||
if(invalid)
|
||||
matrix[i][j][k] = true;
|
||||
else if((block == blockToSwap && meta == metaToSwap) || block != targetBlock || meta != targetMeta)
|
||||
matrix[i][j][k] = null;
|
||||
else matrix[i][j][k] = false;
|
||||
}
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public List<ChunkCoordinates> getBlocksToSwap(World world, ItemStack stack, Block blockToSwap, int metaToSwap, int xc, int yc, int zc, Block targetBlock, int targetMeta) {
|
||||
List<ChunkCoordinates> coordsList = new ArrayList();
|
||||
Boolean[][][] matrix = createMatrix(world, stack, blockToSwap, metaToSwap, xc, yc, zc, targetBlock, targetMeta);
|
||||
|
||||
int effrange = RANGE + 1;
|
||||
int diameter = effrange * 2;
|
||||
for(int i = 1; i < diameter; i++)
|
||||
for(int j = 1; j < diameter; j++)
|
||||
for(int k = 1; k < diameter; k++) {
|
||||
int x = xc + i - effrange;
|
||||
int y = yc + j - effrange;
|
||||
int z = zc + k - effrange;
|
||||
|
||||
Boolean bool = matrix[i][j][k];
|
||||
if(bool != null && !bool)
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
Boolean obool = matrix[i + dir.offsetX][j + dir.offsetY][k + dir.offsetZ];
|
||||
if(obool != null && obool) {
|
||||
coordsList.add(new ChunkCoordinates(x, y, z));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return coordsList;
|
||||
}
|
||||
|
||||
public boolean exchange(World world, EntityPlayer player, int x, int y, int z, ItemStack stack, Block blockToSet, int metaToSet) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if(tile != null)
|
||||
return false;
|
||||
|
||||
ItemStack placeStack = removeFromInventory(player, stack, blockToSet, metaToSet, false);
|
||||
if(placeStack != null) {
|
||||
Block blockAt = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if(!blockAt.isAir(world, x, y, z) && blockAt.getPlayerRelativeBlockHardness(player, world, x, y, z) > 0 && (blockAt != blockToSet || meta != metaToSet)) {
|
||||
if(!world.isRemote) {
|
||||
if(!player.capabilities.isCreativeMode) {
|
||||
List<ItemStack> drops = blockAt.getDrops(world, x, y, z, meta, 0);
|
||||
for(ItemStack drop : drops)
|
||||
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, drop));
|
||||
removeFromInventory(player, stack, blockToSet, metaToSet, true);
|
||||
}
|
||||
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(blockAt) + (meta << 12));
|
||||
}
|
||||
world.setBlock(x, y, z, blockToSet, metaToSet, 1 | 2);
|
||||
blockToSet.onBlockPlacedBy(world, x, y, z, player, placeStack);
|
||||
displayRemainderCounter(player, stack);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canExchange(ItemStack stack) {
|
||||
Block block = getBlock(stack);
|
||||
return block != null && block != Blocks.air;
|
||||
}
|
||||
|
||||
public static ItemStack removeFromInventory(EntityPlayer player, IInventory inv, ItemStack stack, Block block, int meta, boolean doit) {
|
||||
List<ItemStack> providers = new ArrayList();
|
||||
for(int i = inv.getSizeInventory() - 1; i >= 0; i--) {
|
||||
ItemStack invStack = inv.getStackInSlot(i);
|
||||
if(invStack == null)
|
||||
continue;
|
||||
|
||||
Item item = invStack.getItem();
|
||||
if(item == Item.getItemFromBlock(block) && invStack.getItemDamage() == meta) {
|
||||
ItemStack retStack = invStack.copy();
|
||||
if(doit) {
|
||||
invStack.stackSize--;
|
||||
if(invStack.stackSize == 0)
|
||||
inv.setInventorySlotContents(i, null);
|
||||
}
|
||||
return retStack;
|
||||
}
|
||||
|
||||
if(item instanceof IBlockProvider)
|
||||
providers.add(invStack);
|
||||
}
|
||||
|
||||
for(ItemStack provStack : providers) {
|
||||
IBlockProvider prov = (IBlockProvider) provStack.getItem();
|
||||
if(prov.provideBlock(player, stack, provStack, block, meta, doit))
|
||||
return new ItemStack(block, 1, meta);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack removeFromInventory(EntityPlayer player, ItemStack stack, Block block, int meta, boolean doit) {
|
||||
if(player.capabilities.isCreativeMode)
|
||||
return new ItemStack(block, 1, meta);
|
||||
|
||||
return removeFromInventory(player, player.inventory, stack, block, meta, doit);
|
||||
}
|
||||
|
||||
public static int getInventoryItemCount(EntityPlayer player, ItemStack stack, Block block, int meta) {
|
||||
if(player.capabilities.isCreativeMode)
|
||||
return -1;
|
||||
return getInventoryItemCount(player, player.inventory, stack, block, meta);
|
||||
}
|
||||
|
||||
public static int getInventoryItemCount(EntityPlayer player, IInventory inv, ItemStack stack, Block block, int meta) {
|
||||
if(player.capabilities.isCreativeMode)
|
||||
return -1;
|
||||
|
||||
int count = 0;
|
||||
for(int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack invStack = inv.getStackInSlot(i);
|
||||
if(invStack == null)
|
||||
continue;
|
||||
|
||||
Item item = invStack.getItem();
|
||||
if(item == Item.getItemFromBlock(block) && invStack.getItemDamage() == meta)
|
||||
count += invStack.stackSize;
|
||||
|
||||
if(item instanceof IBlockProvider) {
|
||||
IBlockProvider prov = (IBlockProvider) item;
|
||||
int provCount = prov.getBlockCount(player, stack, invStack, block, meta);
|
||||
if(provCount == -1)
|
||||
return -1;
|
||||
count += provCount;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public void displayRemainderCounter(EntityPlayer player, ItemStack stack) {
|
||||
Block block = getBlock(stack);
|
||||
int meta = getBlockMeta(stack);
|
||||
int count = getInventoryItemCount(player, stack, block, meta);
|
||||
if(!player.worldObj.isRemote)
|
||||
ItemsRemainingRenderHandler.set(new ItemStack(block, 1, meta), count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull3D() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesMana(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean setBlock(ItemStack stack, Block block, int meta) {
|
||||
ItemNBTHelper.setString(stack, TAG_BLOCK_NAME, Block.blockRegistry.getNameForObject(block));
|
||||
ItemNBTHelper.setInt(stack, TAG_BLOCK_META, meta);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack par1ItemStack) {
|
||||
Block block = getBlock(par1ItemStack);
|
||||
int meta = getBlockMeta(par1ItemStack);
|
||||
return super.getItemStackDisplayName(par1ItemStack) + (block == null ? "" : " (" + EnumChatFormatting.GREEN + new ItemStack(block, 1, meta).getDisplayName() + EnumChatFormatting.RESET + ")");
|
||||
}
|
||||
|
||||
public static String getBlockName(ItemStack stack) {
|
||||
return ItemNBTHelper.getString(stack, TAG_BLOCK_NAME, "");
|
||||
}
|
||||
|
||||
public static Block getBlock(ItemStack stack) {
|
||||
Block block = Block.getBlockFromName(getBlockName(stack));
|
||||
return block;
|
||||
}
|
||||
|
||||
public static int getBlockMeta(ItemStack stack) {
|
||||
return ItemNBTHelper.getInt(stack, TAG_BLOCK_META, 0);
|
||||
}
|
||||
|
||||
private boolean setTargetBlock(ItemStack stack, Block block, int meta) {
|
||||
ItemNBTHelper.setString(stack, TAG_TARGET_BLOCK_NAME, Block.blockRegistry.getNameForObject(block));
|
||||
ItemNBTHelper.setInt(stack, TAG_TARGET_BLOCK_META, meta);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getTargetBlockName(ItemStack stack) {
|
||||
return ItemNBTHelper.getString(stack, TAG_TARGET_BLOCK_NAME, "");
|
||||
}
|
||||
|
||||
public static Block getTargetBlock(ItemStack stack) {
|
||||
Block block = Block.getBlockFromName(getTargetBlockName(stack));
|
||||
return block;
|
||||
}
|
||||
|
||||
public static int getTargetBlockMeta(ItemStack stack) {
|
||||
return ItemNBTHelper.getInt(stack, TAG_TARGET_BLOCK_META, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<ChunkCoordinates> getWireframesToDraw(EntityPlayer player, ItemStack stack) {
|
||||
ItemStack holding = player.getCurrentEquippedItem();
|
||||
if(holding != stack || !canExchange(stack))
|
||||
return null;
|
||||
|
||||
Block block = getBlock(stack);
|
||||
int meta = getBlockMeta(stack);
|
||||
|
||||
MovingObjectPosition pos = Minecraft.getMinecraft().objectMouseOver;
|
||||
if(pos != null) {
|
||||
int x = pos.blockX;
|
||||
int y = pos.blockY;
|
||||
int z = pos.blockZ;
|
||||
Block targetBlock = null;
|
||||
int targetMeta = 0;
|
||||
if(ItemNBTHelper.getBoolean(stack, TAG_SWAPPING, false)) {
|
||||
x = ItemNBTHelper.getInt(stack, TAG_SELECT_X, 0);
|
||||
y = ItemNBTHelper.getInt(stack, TAG_SELECT_Y, 0);
|
||||
z = ItemNBTHelper.getInt(stack, TAG_SELECT_Z, 0);
|
||||
targetBlock = getTargetBlock(stack);
|
||||
targetMeta = getTargetBlockMeta(stack);
|
||||
}
|
||||
|
||||
if(!player.worldObj.isAirBlock(x, y, z)) {
|
||||
List<ChunkCoordinates> coordsList = getBlocksToSwap(player.worldObj, stack, block, meta, x, y, z, targetBlock, targetMeta);
|
||||
for(ChunkCoordinates coords : coordsList)
|
||||
if(coords.posX == x && coords.posY == y && coords.posZ == z) {
|
||||
coordsList.remove(coords);
|
||||
break;
|
||||
}
|
||||
return coordsList;
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import vazkii.botania.api.item.IBlockProvider;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.api.subtile.ISpecialFlower;
|
||||
@@ -32,7 +33,7 @@ import vazkii.botania.common.item.ItemMod;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
public class ItemTerraformRod extends ItemMod implements IManaUsingItem {
|
||||
public class ItemTerraformRod extends ItemMod implements IManaUsingItem, IBlockProvider {
|
||||
|
||||
private static final int COST_PER = 55;
|
||||
|
||||
@@ -174,4 +175,19 @@ public class ItemTerraformRod extends ItemMod implements IManaUsingItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean provideBlock(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta, boolean doit) {
|
||||
if(block == Blocks.dirt && meta == 0)
|
||||
return !doit || ManaItemHandler.requestManaExact(requestor, player, ItemDirtRod.COST, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCount(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta) {
|
||||
if(block == Blocks.dirt && meta == 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -149,6 +149,7 @@ public final class LibItemNames {
|
||||
public static final String CACOPHONIUM = "cacophonium";
|
||||
public static final String SLIME_BOTTLE = "slimeBottle";
|
||||
public static final String STAR_SWORD = "starSword";
|
||||
public static final String EXCHANGE_ROD = "exchangeRod";
|
||||
|
||||
public static final String[] LENS_NAMES = new String[] {
|
||||
"lensNormal",
|
||||
|
||||
@@ -1431,6 +1431,7 @@ item.botania:obedienceStick.name=Floral Obedience Stick
|
||||
item.botania:cacophonium.name=Cacophonium
|
||||
item.botania:slimeBottle.name=Slime in a Bottle
|
||||
item.botania:starSword.name=Starcaller
|
||||
item.botania:exchangeRod.name=Rod of the Shifting Crust
|
||||
|
||||
# BREW NAMES
|
||||
botania.brew.fallback=Fallback
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"animation": {
|
||||
"frames": [
|
||||
{
|
||||
"index": 0,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 6,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 5,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 4,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 3,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 2,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 1,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 0,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 6,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 5,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 4,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 3,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 4,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 5,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 6,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 0,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 1,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 2,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 3,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 4,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 5,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 6,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 0,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 1,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 2,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 3,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 4,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 5,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 6,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 5,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 4,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 3,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 2,
|
||||
"time": 2
|
||||
}, {
|
||||
"index": 1,
|
||||
"time": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user