User Tools

Site Tools


voxel.class

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
voxel.class [2016/12/21 15:37]
127.0.0.1 external edit
voxel.class [2017/02/13 09:23]
gobrosse
Line 1: Line 1:
 ====== Voxel.class ====== ====== Voxel.class ======
  
-The Voxel class in the code is an abstract class that defines what Voxel should answer ​to : solidity, collisions, rendering etcTo make custom Voxel object with custom ​properties ​you have to override this class, ie :+The Voxel.class is user-extendable and provides ​way for users to define custom behaviours for their voxelsIt takes into argument ​'​type'​ variable, that contains the properties ​defined in the [[voxels_format|.voxels file]]
  
 <​Code>​ <​Code>​
Line 9: Line 9:
 public class MyVoxelType extends Voxel public class MyVoxelType extends Voxel
 { {
-    ​//Hundreds of lines of boilerplate code +    ​int configured;
-+
-</​Code>​+
  
-The issue with that is that you'd have to redefine all the methods and you probably are not interested in doing that, also the voxel parameters in the .voxels files can't be applied to such custom voxels since they don't have the relevant fields. A better alternative is to override ​the VoxelDefault class, that already provides a barebone ​voxel implentation,​ and only rewrite the methods you want your custom behavior to happen in : +    public MyVoxelType(VoxelType type) 
- +    { 
-<​Code>​ + super(type);​ 
-package demo.voxel +        //We can use the type variable ​to access stuff defined in the voxel file definition 
-import io.xol.chunkstories.voxel+        ​configured = Integer.parseInt(type.resolveProperty("​some_value_we_need",​ "​0"​))
- +    } 
-public class MyVoxelType extends VoxelDefault +     
-{ +    ​@Override 
-    //Blah+    //Custom behaviour goes here
 } }
 </​Code>​ </​Code>​
Line 27: Line 25:
 Reminder : to tell the game to use a custom voxel class for a certain id, you have to write  Reminder : to tell the game to use a custom voxel class for a certain id, you have to write 
 <​Code>​ <​Code>​
-voxel myVoxel 666 demo.voxel.MyVoxelType+voxel myVoxel 666 
 + customClass: ​demo.voxel.MyVoxelType
 </​Code>​ </​Code>​
  
 in your .voxels file. in your .voxels file.
voxel.class.txt · Last modified: 2017/02/13 10:11 by gobrosse