Created
June 29, 2015 04:41
-
-
Save StillManic/cbbf31de220ae13b03a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Mod(modid = ModelLoaderRegistryDebug.MODID, version = ModelLoaderRegistryDebug.VERSION) | |
public class ModelLoaderRegistryDebug | |
{ | |
public static final String MODID = "ForgeDebugModelLoaderRegistry"; | |
public static final String VERSION = "1.0"; | |
@EventHandler | |
public void preInit(FMLPreInitializationEvent event) | |
{ | |
GameRegistry.registerBlock(CustomModelBlock4.instance, CustomModelBlock4.name); | |
if (event.getSide() == Side.CLIENT) | |
clientPreInit(); | |
} | |
private void clientPreInit() | |
{ | |
OBJLoader.instance.addDomain(MODID.toLowerCase()); | |
Item item4 = Item.getItemFromBlock(CustomModelBlock4.instance); | |
ModelLoader.setCustomModelResourceLocation(item4, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + CustomModelBlock4.name, "inventory")); | |
} | |
public static class CustomModelBlock4 extends Block | |
{ | |
// public static EnumFacing facing = EnumFacing.NORTH; | |
public static final PropertyDirection FACING = PropertyDirection.create("facing"); | |
public static final CustomModelBlock4 instance = new CustomModelBlock4(); | |
public static final String name = "CustomModelBlock4"; | |
private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[] {FACING}, new IUnlistedProperty[]{OBJModel.OBJProperty.instance}); | |
// private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[] {FACING}, new IUnlistedProperty[0]); | |
// private BlockState state = new BlockState(this, new IProperty[] {FACING}); | |
private CustomModelBlock4() | |
{ | |
super(Material.iron); | |
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); | |
setCreativeTab(CreativeTabs.tabBlock); | |
setUnlocalizedName(name); | |
} | |
@Override | |
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) | |
{ | |
return this.getDefaultState().withProperty(FACING, getFacingFromEntity(world, pos, placer)); | |
} | |
@Override | |
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) | |
{ | |
world.setBlockState(pos, state.withProperty(FACING, getFacingFromEntity(world, pos, placer)), 2); | |
} | |
public static EnumFacing getFacing(int meta) | |
{ | |
return EnumFacing.getFront(meta & 7); | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
public IBlockState getStateForEntityRender(IBlockState state) | |
{ | |
return this.getDefaultState().withProperty(FACING, EnumFacing.SOUTH); | |
} | |
@Override | |
public IBlockState getStateFromMeta(int meta) | |
{ | |
return this.getDefaultState().withProperty(FACING, getFacing(meta)); | |
} | |
@Override | |
public int getMetaFromState(IBlockState state) | |
{ | |
return ((EnumFacing) state.getValue(FACING)).getIndex(); | |
} | |
@Override | |
public BlockState createBlockState() | |
{ | |
return this.state; | |
} | |
@Override | |
public boolean isOpaqueCube() { return false; } | |
@Override | |
public boolean isFullCube() { return false; } | |
@Override | |
public boolean isVisuallyOpaque() { return false; } | |
@Override | |
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) | |
{ | |
try | |
{ | |
IModel model = ModelLoaderRegistry.getModel(new ResourceLocation(MODID.toLowerCase() + ":" + "block/eye.obj")); | |
if (((OBJModel) model).getModelState() != null && ((OBJModel) model).getModelState() instanceof OBJModel.OBJState) | |
{ | |
FMLLog.info("CustomModelBlock4: Model state passed", new Object[0]); | |
// OBJModel.OBJState modelState = (OBJModel.OBJState) ((OBJModel) model).getModelState(); | |
OBJModel.OBJState retState = new OBJModel.OBJState(null, (OBJModel) model); | |
return ((IExtendedBlockState) this.state.getBaseState()).withProperty(OBJModel.OBJProperty.instance, retState).withProperty(FACING, state.getValue(FACING)); | |
} | |
} | |
catch (IOException e) | |
{ | |
FMLLog.info("CustomModelBlock4: failed to load block/eye.obj", new Object[0]); | |
} | |
return state; | |
} | |
private void setElementTransforms(TRSRTransformation input) | |
{ | |
try | |
{ | |
IModel model = ModelLoaderRegistry.getModel(new ResourceLocation(MODID.toLowerCase(), "block/tesseract.obj")); | |
TRSRTransformation transform = input == null ? TRSRTransformation.identity() : input; | |
for (Map.Entry<String, OBJModel.Element> e : ((OBJModel) model).getMatLib().getElements().entrySet()) | |
{ | |
OBJModel.Element element = e.getValue(); | |
element.setTransform(transform); | |
} | |
} | |
catch (IOException e) | |
{ | |
FMLLog.info("CustomModelBlock4: failed to find build/tesseract.obj", new Object[0]); | |
} | |
} | |
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn) | |
{ | |
if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F) | |
{ | |
double d0 = entityIn.posY + (double)entityIn.getEyeHeight(); | |
if (d0 - (double)clickedBlock.getY() > 2.0D) | |
{ | |
return EnumFacing.UP; | |
} | |
if ((double)clickedBlock.getY() - d0 > 0.0D) | |
{ | |
return EnumFacing.DOWN; | |
} | |
} | |
return entityIn.getHorizontalFacing().getOpposite(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment