From f25e25b972b3c0c2bdd56b2bf1439d9b67e163bd Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Sun, 26 Jan 2014 00:20:39 +0000 Subject: [PATCH] Rotation, rotation. --- .../vazkii/botania/api/IWandRotateable.java | 42 ------------------- .../client/render/block/RenderSpreader.java | 4 +- .../render/tile/RenderTileSpreader.java | 5 +++ .../common/block/tile/TileSpreader.java | 37 +++++++--------- .../botania/common/item/ItemTwigWand.java | 38 ++++++++++------- 5 files changed, 46 insertions(+), 80 deletions(-) delete mode 100644 MODSRC/vazkii/botania/api/IWandRotateable.java diff --git a/MODSRC/vazkii/botania/api/IWandRotateable.java b/MODSRC/vazkii/botania/api/IWandRotateable.java deleted file mode 100644 index 667ba771c..000000000 --- a/MODSRC/vazkii/botania/api/IWandRotateable.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * This class was created by . 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 @ [Jan 22, 2014, 5:14:05 PM (GMT)] - */ -package vazkii.botania.api; - -/** - * A TileEntity that implements this can be rotated using the wand's rotation function. - */ -public interface IWandRotateable { - - /** - * Gets the horizontal rotation of this Tile, in degrees. - */ - public int getHorizontalRotation(); - - /** - * Gets the vertical rotation of this Tile, in degrees. - */ - public int getVerticalRotation(); - - /** - * Called when the rotation of this TileEntity should be changed. - * @param horizontal The change in the rotation setting player's horizontal rotation. - * @param vertical The change in the rotation setting player's vertical rotation. - */ - public void changeRotation(float horizontal, float vertical); - - /** - * Called (on the client of the rotation setting player) per tick. Generally - * used to display the vector being pointed at. - */ - public void onClientTick(); - -} diff --git a/MODSRC/vazkii/botania/client/render/block/RenderSpreader.java b/MODSRC/vazkii/botania/client/render/block/RenderSpreader.java index 6b9004c1c..d28056dfd 100644 --- a/MODSRC/vazkii/botania/client/render/block/RenderSpreader.java +++ b/MODSRC/vazkii/botania/client/render/block/RenderSpreader.java @@ -29,7 +29,9 @@ public class RenderSpreader implements ISimpleBlockRenderingHandler { public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { GL11.glPushMatrix(); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - TileEntityRenderer.instance.renderTileEntityAt(new TileSpreader(), 0.0D, 0.0D, 0.0D, 0.0F); + TileSpreader spreader = new TileSpreader(); + spreader.rotationX = -180F; + TileEntityRenderer.instance.renderTileEntityAt(spreader, 0.0D, 0.0D, 0.0D, 0.0F); GL11.glPopMatrix(); } diff --git a/MODSRC/vazkii/botania/client/render/tile/RenderTileSpreader.java b/MODSRC/vazkii/botania/client/render/tile/RenderTileSpreader.java index 27051c390..e18449889 100644 --- a/MODSRC/vazkii/botania/client/render/tile/RenderTileSpreader.java +++ b/MODSRC/vazkii/botania/client/render/tile/RenderTileSpreader.java @@ -38,6 +38,11 @@ public class RenderTileSpreader extends TileEntitySpecialRenderer { Minecraft.getMinecraft().renderEngine.bindTexture(texture); GL11.glTranslatef(0.5F, 1.5F, 0.5F); + GL11.glRotatef(spreader.rotationX, 0F, 1F, 0F); + GL11.glTranslatef(0F, -1F, 0F); + GL11.glRotatef(spreader.rotationY, 1F, 0F, 0F); + GL11.glTranslatef(0F, 1F, 0F); + GL11.glScalef(1F, -1F, -1F); model.render(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); diff --git a/MODSRC/vazkii/botania/common/block/tile/TileSpreader.java b/MODSRC/vazkii/botania/common/block/tile/TileSpreader.java index 906444a1b..da15c3572 100644 --- a/MODSRC/vazkii/botania/common/block/tile/TileSpreader.java +++ b/MODSRC/vazkii/botania/common/block/tile/TileSpreader.java @@ -17,25 +17,29 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet132TileEntityData; +import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.StatCollector; import org.lwjgl.opengl.GL11; -import vazkii.botania.api.IWandRotateable; import vazkii.botania.api.internal.ManaNetworkEvent; import vazkii.botania.api.mana.IManaCollector; import vazkii.botania.common.block.ModBlocks; +import vazkii.botania.common.item.ItemTwigWand; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; -public class TileSpreader extends TileMod implements IWandRotateable, IManaCollector { +public class TileSpreader extends TileMod implements IManaCollector { private static final int MAX_MANA = 1000; private static final String TAG_MANA = "mana"; private static final String TAG_KNOWN_MANA = "knownMana"; + private static final String TAG_ROTATION_X = "rotationX"; + private static final String TAG_ROTATION_Y = "rotationY"; int mana; int knownMana = -1; + public float rotationX, rotationY; boolean added = false; @Override @@ -71,11 +75,16 @@ public class TileSpreader extends TileMod implements IWandRotateable, IManaColle @Override public void writeCustomNBT(NBTTagCompound cmp) { cmp.setInteger(TAG_MANA, mana); + cmp.setFloat(TAG_ROTATION_X, rotationX); + cmp.setFloat(TAG_ROTATION_Y, rotationY); } @Override public void readCustomNBT(NBTTagCompound cmp) { mana = cmp.getInteger(TAG_MANA); + rotationX = cmp.getFloat(TAG_ROTATION_X); + rotationY = cmp.getFloat(TAG_ROTATION_Y); + if(cmp.hasKey(TAG_KNOWN_MANA)) knownMana = cmp.getInteger(TAG_KNOWN_MANA); } @@ -90,24 +99,6 @@ public class TileSpreader extends TileMod implements IWandRotateable, IManaColle return mana; } - @Override - public int getHorizontalRotation() { - return 0; - } - - @Override - public int getVerticalRotation() { - return 0; - } - - @Override - public void changeRotation(float horizontal, float vertical) { - } - - @Override - public void onClientTick() { - } - public void onWanded(EntityPlayer player, ItemStack wand) { if(!player.isSneaking()) { if(!worldObj.isRemote) { @@ -118,14 +109,16 @@ public class TileSpreader extends TileMod implements IWandRotateable, IManaColle } worldObj.playSoundAtEntity(player, "random.orb", 1F, 1F); } else { - + rotationX = -player.rotationYaw; + rotationY = player.rotationPitch; + PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId); } } public void renderHUD(Minecraft mc, ScaledResolution res) { String name = ModBlocks.spreader.getLocalizedName(); int type = 0; - if(mana >= 0) { + if(knownMana >= 0) { type = 1; double percentage = (double) knownMana / (double) MAX_MANA * 100; if(percentage == 100) diff --git a/MODSRC/vazkii/botania/common/item/ItemTwigWand.java b/MODSRC/vazkii/botania/common/item/ItemTwigWand.java index 6b501f156..05670b938 100644 --- a/MODSRC/vazkii/botania/common/item/ItemTwigWand.java +++ b/MODSRC/vazkii/botania/common/item/ItemTwigWand.java @@ -12,17 +12,23 @@ package vazkii.botania.common.item; import java.awt.Color; +import java.util.HashMap; import java.util.List; +import java.util.Map; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; import net.minecraft.entity.passive.EntitySheep; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.Icon; import net.minecraft.world.World; +import net.minecraftforge.common.FakePlayer; import vazkii.botania.api.IWandable; import vazkii.botania.client.core.helper.IconHelper; import vazkii.botania.common.core.helper.ItemNBTHelper; @@ -30,17 +36,18 @@ import vazkii.botania.common.lib.LibItemIDs; import vazkii.botania.common.lib.LibItemNames; public class ItemTwigWand extends Item16Colors { - + Icon[] icons; - + private static final String TAG_COLOR1 = "color1"; private static final String TAG_COLOR2 = "color2"; + public ItemTwigWand() { super(LibItemIDs.idTwigWand, LibItemNames.TWIG_WAND); setMaxStackSize(1); } - + @Override public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { int id = par3World.getBlockId(par4, par5, par6); @@ -48,7 +55,7 @@ public class ItemTwigWand extends Item16Colors { return ((IWandable) Block.blocksList[id]).onUsedByWand(par2EntityPlayer, par1ItemStack, par3World, par4, par5, par6, par7); return false; } - + @Override public boolean shouldPassSneakingClickToBlock(World par2World, int par4, int par5, int par6) { int id = par2World.getBlockId(par4, par5, par6); @@ -56,38 +63,38 @@ public class ItemTwigWand extends Item16Colors { return false; return true; } - + @Override public void registerIcons(IconRegister par1IconRegister) { icons = new Icon[3]; for(int i = 0; i < icons.length; i++) icons[i] = IconHelper.forItem(par1IconRegister, this, i); } - + @Override public Icon getIcon(ItemStack stack, int pass) { return icons[Math.min(2, pass)]; } - + @Override public int getColorFromItemStack(ItemStack par1ItemStack, int par2) { if(par2 == 0) return 0xFFFFFF; - + float[] color = EntitySheep.fleeceColorTable[par2 == 1 ? getColor1(par1ItemStack) : getColor2(par1ItemStack)]; return new Color(color[0], color[1], color[2]).getRGB(); } - + @Override public boolean requiresMultipleRenderPasses() { return true; } - + @Override public int getRenderPasses(int metadata) { return 3; } - + @Override public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) { for(int i = 0; i < 16; i++) @@ -98,20 +105,20 @@ public class ItemTwigWand extends Item16Colors { public String getUnlocalizedName(ItemStack par1ItemStack) { return getUnlocalizedNameLazy(par1ItemStack); } - + @Override public EnumRarity getRarity(ItemStack par1ItemStack) { return EnumRarity.rare; } - + public static ItemStack forColors(int color1, int color2) { ItemStack stack = new ItemStack(ModItems.twigWand); ItemNBTHelper.setInt(stack, TAG_COLOR1, color1); ItemNBTHelper.setInt(stack, TAG_COLOR2, color2); - + return stack; } - + public static int getColor1(ItemStack stack) { return ItemNBTHelper.getInt(stack, TAG_COLOR1, 0xFFFFFF); } @@ -119,4 +126,5 @@ public class ItemTwigWand extends Item16Colors { public static int getColor2(ItemStack stack) { return ItemNBTHelper.getInt(stack, TAG_COLOR2, 0xFFFFFF); } + }