Rotation, rotation.

This commit is contained in:
Vasco Lavos committed 2014-01-26 00:20:39 +00:00
1 parent cda8e88160
commit f25e25b972
5 files changed
+46 -80

No files matched your search

@@ -1,42 +0,0 @@
/**
* 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 @ [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();
}
@@ -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();
}
@@ -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);
@@ -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)
@@ -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);
}
}