Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a sample class for changing the block's texture

  • Loading branch information...
commit a81f610064f82e1645252f1182f1f49331726912 1 parent 245ed84
@Havvy authored
Showing with 44 additions and 0 deletions.
  1. +44 −0 tutorial/generic/samples/TextureChangingBlock.java
View
44 tutorial/generic/samples/TextureChangingBlock.java
@@ -0,0 +1,44 @@
+public class TextureChangingBlock extends Block implements ITickHandler {
+ // Wherever your texture starts in the texture file.
+ @SideOnly(Side.CLIENT)
+ private final int TEXTUREBASE = 32;
+
+ // Number of textures to use.
+ @SideOnly(Side.CLIENT)
+ private final int TEXTURECOUNT = 4;
+
+ // This value plus your TEXTUREBASE will determine which texture to show.
+ private static int texture = 0;
+
+ public TextureChangingBlock (int id) {
+ /* The rest of your constuctor */
+
+ FMLCommonHandler.instance().registerTickHandler(this, Side.CLIENT);
+ }
+
+ // Block Methods
+ @Override
+ getBlockTextureFromSideAndMetadata (int metadata, int side) {
+ // Not actually using metadata or side...
+ return TEXTUREBASE + texture;
+ }
+
+ // TickHandler Methods
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void tickStart (EnumSet<TickType> type, Object... tickData) {
+ texture = (texture + 1) % TEXTURECOUNT;
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public EnumSet<TickType> ticks () {
+ return EnumSet.of(TickType.CLIENT);
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public String getLabel () {
+ return null;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.