Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

UltraTechX

Forge Modder
  • Joined

  • Last visited

Everything posted by UltraTechX

  1. Thank you so much! After copying everything except the last switch statement into my block, it works perfectly.
  2. ok, so here is my code now: package tutorial.generic; import net.minecraft.block.Block; import net.minecraft.block.BlockRailBase; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.IStringSerializable; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import tutorial.generic.railControlBlock.EnumPartType; public class genericBlockTileEntity extends Block implements ITileEntityProvider { public static final PropertyEnum ROTATION = PropertyEnum.create("rotation", EnumFacing.class); private static String name = "genericBlockTileEntity"; private int rotation; public genericBlockTileEntity() { super(Material.iron); GameRegistry.registerTileEntity(genericTileEntity.class, name); GameRegistry.registerBlock(this, name); this.setCreativeTab(CreativeTabs.tabMisc); this.setUnlocalizedName(name); this.setDefaultState(this.blockState.getBaseState().withProperty(ROTATION, EnumFacing.NORTH)); this.rotation = 0; this.setHardness(2.0f); this.setResistance(6.0f); this.setHarvestLevel("pickaxe", 2); this.isBlockContainer = true; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new genericTileEntity(); } @Override public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) { super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam); TileEntity tileentity = worldIn.getTileEntity(pos); return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam); } public static String getName(){ return name; } public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(ROTATION)).getMetadata(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { ROTATION }); } public IProperty getRotationProperty() { return ROTATION; } public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(ROTATION, EnumFacing.byMetadata(meta)); } @Override public void breakBlock(World world, BlockPos pos, IBlockState blockstate) { genericTileEntity te = (genericTileEntity) world.getTileEntity(pos); this.rotation = 0; super.breakBlock(world, pos, blockstate); } @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state){ genericTileEntity te = new genericTileEntity(); for (EnumFacing direction : EnumFacing.VALUES){ // For each direction BlockPos neighbourPos = pos.offset(direction); // Offset the block's position by 1 block in the current direction IBlockState neighbourState = worldIn.getBlockState(neighbourPos); // Get the IBlockState at the neighboring position Block neighbourBlock = neighbourState.getBlock(); // Get the IBlockState's Block if (neighbourBlock == Generic.railControl && direction != EnumFacing.UP && direction != EnumFacing.DOWN || neighbourBlock == Generic.railStation && direction != EnumFacing.UP && direction != EnumFacing.DOWN || neighbourBlock == Generic.rail && direction != EnumFacing.UP && direction != EnumFacing.DOWN){ // If the neighbouring block is a Control Rail, if(direction == EnumFacing.NORTH){ this.rotation = 0; }else if(direction == EnumFacing.SOUTH){ this.rotation = 1; }else if(direction == EnumFacing.EAST){ this.rotation = 2; }else if(direction == EnumFacing.WEST){ this.rotation = 3; } } } } public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { for (EnumFacing direction : EnumFacing.VALUES){ // For each direction BlockPos neighbourPos = pos.offset(direction); // Offset the block's position by 1 block in the current direction IBlockState neighbourState = worldIn.getBlockState(neighbourPos); // Get the IBlockState at the neighboring position Block neighbourBlock = neighbourState.getBlock(); // Get the IBlockState's Block if (neighbourBlock == Generic.railControl && direction != EnumFacing.UP && direction != EnumFacing.DOWN || neighbourBlock == Generic.railStation && direction != EnumFacing.UP && direction != EnumFacing.DOWN || neighbourBlock == Generic.rail && direction != EnumFacing.UP && direction != EnumFacing.DOWN){ // If the neighbouring block is a Control Rail, if(direction == EnumFacing.NORTH){ this.rotation = 0; }else if(direction == EnumFacing.SOUTH){ this.rotation = 1; }else if(direction == EnumFacing.EAST){ this.rotation = 2; }else if(direction == EnumFacing.WEST){ this.rotation = 3; } } } } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){ if(this.rotation == 3){ return state.withProperty(ROTATION, EnumFacing.WEST); }else if(this.rotation == 2){ return state.withProperty(ROTATION, EnumFacing.EAST); }else if(this.rotation == 1){ return state.withProperty(ROTATION, EnumFacing.SOUTH); }else{ return state.withProperty(ROTATION, EnumFacing.NORTH); } } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { if (stack.hasDisplayName()) { ((genericTileEntity) worldIn.getTileEntity(pos)).setCustomName(stack.getDisplayName()); } } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { player.openGui(Generic.instance, GUIs.genericTileEntity.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); } return true; } } there are two errors, any they are both about not having byMetadata and getMetadata functions in EnumFacing: public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(ROTATION, EnumFacing.byMetadata(meta)); } public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(ROTATION)).getMetadata(); } should I remove these?
  3. ok, so how exactly do I get the entire script set up to work with EnumFacing, would i do a find and replace on Rotation Enum?
  4. I have this maintenance controller code: gist for the code here : https://gist.github.com/UltraTechX/928e14ca880a64339997 public class genericBlockTileEntity extends Block implements ITileEntityProvider { public static final PropertyEnum ROTATION = PropertyEnum.create("rotation", RotationEnum.class); private static String name = "genericBlockTileEntity"; private int rotation; public genericBlockTileEntity() { super(Material.iron); GameRegistry.registerTileEntity(genericTileEntity.class, name); GameRegistry.registerBlock(this, name); this.setCreativeTab(CreativeTabs.tabMisc); this.setUnlocalizedName(name); this.setDefaultState(this.blockState.getBaseState().withProperty(ROTATION, RotationEnum.NORTH)); this.rotation = 0; this.setHardness(2.0f); this.setResistance(6.0f); this.setHarvestLevel("pickaxe", 2); this.isBlockContainer = true; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new genericTileEntity(); } @Override public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) { super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam); TileEntity tileentity = worldIn.getTileEntity(pos); return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam); } public static String getName(){ return name; } public int getMetaFromState(IBlockState state) { return ((RotationEnum)state.getValue(ROTATION)).getMetadata(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { ROTATION }); } public IProperty getRotationProperty() { return ROTATION; } public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(ROTATION, RotationEnum.byMetadata(meta)); } @Override public void breakBlock(World world, BlockPos pos, IBlockState blockstate) { genericTileEntity te = (genericTileEntity) world.getTileEntity(pos); this.rotation = 0; super.breakBlock(world, pos, blockstate); } @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state){ genericTileEntity te = new genericTileEntity(); for (EnumFacing direction : EnumFacing.VALUES){ // For each direction BlockPos neighbourPos = pos.offset(direction); // Offset the block's position by 1 block in the current direction IBlockState neighbourState = worldIn.getBlockState(neighbourPos); // Get the IBlockState at the neighboring position Block neighbourBlock = neighbourState.getBlock(); // Get the IBlockState's Block if (neighbourBlock == Generic.railControl && direction != EnumFacing.UP && direction != EnumFacing.DOWN || neighbourBlock == Generic.railStation && direction != EnumFacing.UP && direction != EnumFacing.DOWN || neighbourBlock == Generic.rail && direction != EnumFacing.UP && direction != EnumFacing.DOWN){ // If the neighbouring block is a Control Rail, if(direction == EnumFacing.NORTH){ this.rotation = 0; }else if(direction == EnumFacing.SOUTH){ this.rotation = 1; }else if(direction == EnumFacing.EAST){ this.rotation = 2; }else if(direction == EnumFacing.WEST){ this.rotation = 3; } } } } public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { for (EnumFacing direction : EnumFacing.VALUES){ // For each direction BlockPos neighbourPos = pos.offset(direction); // Offset the block's position by 1 block in the current direction IBlockState neighbourState = worldIn.getBlockState(neighbourPos); // Get the IBlockState at the neighboring position Block neighbourBlock = neighbourState.getBlock(); // Get the IBlockState's Block if (neighbourBlock == Generic.railControl && direction != EnumFacing.UP && direction != EnumFacing.DOWN || neighbourBlock == Generic.railStation && direction != EnumFacing.UP && direction != EnumFacing.DOWN || neighbourBlock == Generic.rail && direction != EnumFacing.UP && direction != EnumFacing.DOWN){ // If the neighbouring block is a Control Rail, if(direction == EnumFacing.NORTH){ this.rotation = 0; }else if(direction == EnumFacing.SOUTH){ this.rotation = 1; }else if(direction == EnumFacing.EAST){ this.rotation = 2; }else if(direction == EnumFacing.WEST){ this.rotation = 3; } } } } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){ if(this.rotation == 3){ return state.withProperty(ROTATION, RotationEnum.WEST); }else if(this.rotation == 2){ return state.withProperty(ROTATION, RotationEnum.EAST); }else if(this.rotation == 1){ return state.withProperty(ROTATION, RotationEnum.SOUTH); }else{ return state.withProperty(ROTATION, RotationEnum.NORTH); } } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { if (stack.hasDisplayName()) { ((genericTileEntity) worldIn.getTileEntity(pos)).setCustomName(stack.getDisplayName()); } } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { player.openGui(Generic.instance, GUIs.genericTileEntity.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); } return true; } public static enum RotationEnum implements IStringSerializable { NORTH(0, "north"), SOUTH(1, "south"), EAST(2, "east"), WEST(3, "west"); private static final RotationEnum[] META_LOOKUP = new RotationEnum[values().length]; private final int meta; private final String name; private RotationEnum(int meta, String name) { this.meta = meta; this.name = name; } public int getMetadata() { return this.meta; } public String toString() { return this.name; } public String getName() { return this.name; } public static RotationEnum byMetadata(int meta) { if (meta < 0 || meta >= META_LOOKUP.length) { meta = 0; } return META_LOOKUP[meta]; } static { RotationEnum[] var0 = values(); int var1 = var0.length; for (int var2 = 0; var2 < var1; ++var2) { RotationEnum var3 = var0[var2]; META_LOOKUP[var3.getMetadata()] = var3; } } } } Its made so it will rotate if it detects my block next to it, but when one turns they all turn, and it only turns when I break the rail, any ideas? Thanks gist can be found here : https://gist.github.com/UltraTechX/928e14ca880a64339997
  5. PART is a PropertyEnum of EnumPartType , but you're trying to assign an int value to it ( this.part ). i saw that too, so I made this and it works! Thanks for all your help! @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){ if(this.part == 2){ return state.withProperty(PART, EnumPartType.RIGHT); }else if(this.part == 1){ return state.withProperty(PART, EnumPartType.LEFT); }else{ return state.withProperty(PART, EnumPartType.MIDDLE); } }
  6. you were right! Now the error changed to the line that i put in my block's class: Cannot set property PropertyEnum{name=part, clazz=class tutorial.generic.railControlBlock$EnumPartType, values=[middle, left, right]} to 0 on block generic:railControlBlock, it is not an allowed value here is the function that breaks it: @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){ return state.withProperty(PART, this.part); }
  7. whats the "bleeding edge" version of gradle and where can I find it?
  8. i dont use any SFX yet in the game, so I don't think that is the case
  9. ok then, here is the crash report: [16:05:00] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:-1]: ---- Minecraft Crash Report ---- // Shall we play a game? Time: 10/4/15 4:05 PM Description: Unexpected error java.lang.NullPointerException: Unexpected error at net.minecraft.crash.CrashReportCategory.firstTwoElementsOfStackTraceMatch(Unknown Source) at net.minecraft.crash.CrashReport.makeCategoryDepth(Unknown Source) at net.minecraft.crash.CrashReport.makeCategory(Unknown Source) at net.minecraft.world.World.playAuxSFXAtEntity(Unknown Source) at net.minecraft.world.World.playAuxSFX(Unknown Source) at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerDestroyBlock(Unknown Source) at net.minecraft.client.multiplayer.PlayerControllerMP.func_178891_a(Unknown Source) at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(Unknown Source) at net.minecraft.client.Minecraft.clickMouse(Unknown Source) at net.minecraft.client.Minecraft.runTick(Unknown Source) at net.minecraft.client.Minecraft.runGameLoop(Unknown Source) at net.minecraft.client.Minecraft.run(Unknown Source) at net.minecraft.client.main.Main.main(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.crash.CrashReportCategory.firstTwoElementsOfStackTraceMatch(Unknown Source) at net.minecraft.crash.CrashReport.makeCategoryDepth(Unknown Source) at net.minecraft.crash.CrashReport.makeCategory(Unknown Source) at net.minecraft.world.World.playAuxSFXAtEntity(Unknown Source) at net.minecraft.world.World.playAuxSFX(Unknown Source) at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerDestroyBlock(Unknown Source) at net.minecraft.client.multiplayer.PlayerControllerMP.func_178891_a(Unknown Source) at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(Unknown Source) at net.minecraft.client.Minecraft.clickMouse(Unknown Source) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityPlayerSP['Player640'/0, l='MpServer', x=-587.43, y=56.00, z=-574.99]] Chunk stats: MultiplayerChunkCache: 599, 599 Level seed: 0 Level generator: ID 01 - flat, ver 0. Features enabled: false Level generator options: Level spawn location: -586.00,4.00,-567.00 - World: (-586,4,-567), Chunk: (at 6,0,9 in -37,-36; contains blocks -592,0,-576 to -577,255,-561), Region: (-2,-2; contains chunks -64,-64 to -33,-33, blocks -1024,0,-1024 to -513,255,-513) Level time: 15612 game time, 15468 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 1 total; [EntityPlayerSP['Player640'/0, l='MpServer', x=-587.43, y=56.00, z=-574.99]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(Unknown Source) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Unknown Source) at net.minecraft.client.Minecraft.run(Unknown Source) at net.minecraft.client.main.Main.main(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) -- System Details -- Details: Minecraft Version: 1.8 Operating System: Windows 8.1 (amd64) version 6.3 Java Version: 1.7.0_79, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 783627456 bytes (747 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.3.1519 4 mods loaded, 4 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) UCHIJAAAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.3.1519.jar) UCHIJAAAA Forge{11.14.3.1519} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1519.jar) UCHIJAAAA generic{0.0.0} [Generic Mod] (bin) Loaded coremods (and transformers): GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.5.13399 Compatibility Profile Context 15.200.1062.1004' Renderer: 'AMD Radeon HD 7800 Series' Launched Version: 1.8 LWJGL: 2.9.1 OpenGL: AMD Radeon HD 7800 Series GL version 4.5.13399 Compatibility Profile Context 15.200.1062.1004, ATI Technologies Inc. GL Caps: Using GL 1.3 multitexturing. Using GL 1.3 texture combiners. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Shaders are available because OpenGL 2.1 is supported. VBOs are available because OpenGL 1.5 is supported. Using VBOs: No Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: English (US) Profiler Position: N/A (disabled)
  10. it just says unexpected error when I break the block, here is the gist : https://gist.github.com/UltraTechX/ed19605d8b0b241ff1e7
  11. it started crashing after i added this to the blocks main class: @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) /* */ { return state.withProperty(PART, this.part); } i dont know whats wrong now.
  12. something is different now, i added PART to everything that only had shape to get this code: package tutorial.generic; import net.minecraft.block.Block; import net.minecraft.block.BlockRail; import net.minecraft.block.BlockRailBase; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.IStringSerializable; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class railControlBlock extends BlockRail implements ITileEntityProvider { public static final PropertyEnum PART = PropertyEnum.create("part", EnumPartType.class); public static final PropertyEnum SHAPE = PropertyEnum.create("shape", BlockRailBase.EnumRailDirection.class); private static String name = "railControlBlock"; public railControlBlock(int pnum) { super(); GameRegistry.registerTileEntity(railControl.class, name); if(pnum == 0) { setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.MIDDLE).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH)); }else if(pnum == 1){ setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.LEFT).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH)); }else if(pnum == 2){ setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.RIGHT).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH)); } GameRegistry.registerBlock(this, name); this.setCreativeTab(CreativeTabs.tabMisc); this.setUnlocalizedName(name); this.setHardness(2.0f); setBlockBounds(); this.setResistance(6.0f); this.setHarvestLevel("pickaxe", 2); this.isBlockContainer = true; } @Override public String toString() { return getName(); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new railControl(); } public static String getName(){ return name; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) { setBlockBoundsBasedOnState(worldIn, pos); return super.getSelectedBoundingBox(worldIn, pos); } public IProperty getShapeProperty() { return SHAPE; } public IProperty getPartProperty() { return PART; } public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(PART, EnumPartType.byMetadata(meta)).withProperty(SHAPE, BlockRailBase.EnumRailDirection.byMetadata(meta)); } @Override public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) { setBlockBounds(); } private void setBlockBounds() { setBlockBounds(0F, 0.0F, 0F, 1F, 0.125F, 1F); } public int getMetaFromState(IBlockState state) { return ((EnumPartType)state.getValue(PART)).getMetadata(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { PART, SHAPE }); } public boolean isOpaqueCube() { return false; } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } public int getRenderBlockPass() { return 1; } protected void onNeighborChangedInternal(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { //whenever the blocks around it change } public static enum EnumPartType implements IStringSerializable { MIDDLE(0, "middle"), LEFT(1, "left"), RIGHT(2, "right"); private static final EnumPartType[] META_LOOKUP = new EnumPartType[values().length]; private final int meta; private final String name; private EnumPartType(int meta, String name) { this.meta = meta; this.name = name; } public int getMetadata() { return this.meta; } public String toString() { return this.name; } public String getName() { return this.name; } public static EnumPartType byMetadata(int meta) { if (meta < 0 || meta >= META_LOOKUP.length) { meta = 0; } return META_LOOKUP[meta]; } static { EnumPartType[] var0 = values(); int var1 = var0.length; for (int var2 = 0; var2 < var1; ++var2) { EnumPartType var3 = var0[var2]; META_LOOKUP[var3.getMetadata()] = var3; } } } } but here is what made it work: i changed: public int getMetaFromState(IBlockState state) { return ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).getMetadata(); } to: public int getMetaFromState(IBlockState state) { return ((EnumPartType)state.getValue(PART)).getMetadata(); } but now the block will not rotate anymore, how can I return both Blockstate's metadata?
  13. ok, here is all of the missing blockstates: [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=north_south not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=ascending_west not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=north_east not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=middle,shape=ascending_north not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=ascending_south not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=ascending_north not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=south_west not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=ascending_east not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=east_west not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=north_east not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=south_west not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=east_west not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=middle,shape=ascending_west not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=ascending_south not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=middle,shape=ascending_south not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=south_east not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=north_west not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=ascending_north not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=south_east not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=ascending_east not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=north_south not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=right,shape=ascending_west not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=middle,shape=ascending_east not found [07:52:27] [Client thread/ERROR] [FML]: Model definition for location generic:railControlBlock#part=left,shape=north_west not found here is the reason i think its not that some are missing, its because the following should be true: "part=middle,shape=north_south": { "model": "generic:railControlBlock" }, because of these lines in the block code that are run in the constructor: setDefaultState(this.blockState.getBaseState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH).withProperty(PART, EnumPartType.MIDDLE));
  14. In case this helps here is the block class (enum is in the class as well): package tutorial.generic; import net.minecraft.block.Block; import net.minecraft.block.BlockRail; import net.minecraft.block.BlockRailBase; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.IStringSerializable; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class railControlBlock extends BlockRail implements ITileEntityProvider { public static final PropertyEnum SHAPE = PropertyEnum.create("shape", BlockRailBase.EnumRailDirection.class); public static final PropertyEnum PART = PropertyEnum.create("part", EnumPartType.class); private static String name = "railControlBlock"; public railControlBlock() { super(); GameRegistry.registerTileEntity(railControl.class, name); setDefaultState(this.blockState.getBaseState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH).withProperty(PART, EnumPartType.MIDDLE)); GameRegistry.registerBlock(this, name); this.setCreativeTab(CreativeTabs.tabMisc); this.setUnlocalizedName(name); this.setHardness(2.0f); setBlockBounds(); this.setResistance(6.0f); this.setHarvestLevel("pickaxe", 2); this.isBlockContainer = true; } @Override public String toString() { return getName(); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new railControl(); } public static String getName(){ return name; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) { setBlockBoundsBasedOnState(worldIn, pos); return super.getSelectedBoundingBox(worldIn, pos); } public IProperty getShapeProperty() { return SHAPE; } public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.byMetadata(meta)); } @Override public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) { setBlockBounds(); } private void setBlockBounds() { setBlockBounds(0F, 0.0F, 0F, 1F, 0.125F, 1F); } public int getMetaFromState(IBlockState state) { return ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).getMetadata(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { SHAPE, PART }); } public boolean isOpaqueCube() { return false; } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } public int getRenderBlockPass() { return 1; } protected void onNeighborChangedInternal(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { //whenever the blocks around it change } public static enum EnumPartType implements IStringSerializable { MIDDLE("middle"), LEFT("left"), RIGHT("right"); private final String name; private EnumPartType(String name) { this.name = name; } public String toString() { return this.name; } public String getName() { return this.name; } } }
  15. right now im just testing the north_south and east_west directions, so it should not be that the blockstates are missing
  16. sorry about that, the problem is that no matter what I do, the texture comes up as the unknown purple checkerboard
  17. I have these 3 json files to tell my block how to work with the given states: railControlBlock.json (blockstate): { "variants": { "normal": { "model": "generic:railControlBlock" }, "part=middle,shape=north_south": { "model": "generic:railControlBlock" }, "shape=ascending_east": { "model": "generic:railControlBlock", "y": 90 }, "shape=ascending_west": { "model": "generic:railControlBlock", "y": 90 }, "shape=ascending_north": { "model": "generic:railControlBlock" }, "shape=ascending_south": { "model": "generic:railControlBlock" }, "part=middle,shape=east_west": { "model": "generic:railControlBlock", "y": 90 }, "part=middle,shape=south_east": { "model": "generic:railControlBlock" }, "part=middle,shape=south_west": { "model": "generic:railControlBlock", "y": 90 }, "part=middle,shape=north_west": { "model": "generic:railControlBlock", "y": 180 }, "part=middle,shape=north_east": { "model": "generic:railControlBlock", "y": 270 } } } controlRail.json (block model): { "__comment": "Model generated using MrCrayfish's Model Creator (http://mrcrayfish.com/modelcreator/)", "textures": { "particle": "generic:blocks/railControlBlock", "0": "generic:blocks/railControlBlock" }, "elements": [ { "name": "rail bottom", "from": [ 0.0, 0.0, 13.0 ], "to": [ 16.0, 1.0, 15.0 ], "faces": { "north": { "texture": "#0", "uv": [ 11.0, 10.0, 12.0, 11.0 ] }, "east": { "texture": "#0", "uv": [ 11.0, 5.0, 13.0, 6.0 ] }, "south": { "texture": "#0", "uv": [ 12.0, 6.0, 13.0, 5.0 ] }, "west": { "texture": "#0", "uv": [ 13.0, 10.0, 11.0, 11.0 ] }, "up": { "texture": "#0", "uv": [ 11.0, 9.0, 13.0, 10.0 ] }, "down": { "texture": "#0", "uv": [ 11.0, 10.0, 13.0, 11.0 ] } } }, { "name": "rail bottom", "from": [ 0.0, 0.0, 9.0 ], "to": [ 16.0, 1.0, 11.0 ], "faces": { "north": { "texture": "#0", "uv": [ 11.0, 10.0, 12.0, 11.0 ] }, "east": { "texture": "#0", "uv": [ 11.0, 5.0, 13.0, 6.0 ] }, "south": { "texture": "#0", "uv": [ 12.0, 6.0, 13.0, 5.0 ] }, "west": { "texture": "#0", "uv": [ 13.0, 10.0, 11.0, 11.0 ] }, "up": { "texture": "#0", "uv": [ 11.0, 9.0, 13.0, 10.0 ] }, "down": { "texture": "#0", "uv": [ 11.0, 10.0, 13.0, 11.0 ] } } }, { "name": "rail bottom", "from": [ 0.0, 0.0, 5.0 ], "to": [ 16.0, 1.0, 7.0 ], "faces": { "north": { "texture": "#0", "uv": [ 11.0, 10.0, 12.0, 11.0 ] }, "east": { "texture": "#0", "uv": [ 11.0, 5.0, 13.0, 6.0 ] }, "south": { "texture": "#0", "uv": [ 12.0, 6.0, 13.0, 5.0 ] }, "west": { "texture": "#0", "uv": [ 13.0, 10.0, 11.0, 11.0 ] }, "up": { "texture": "#0", "uv": [ 11.0, 9.0, 13.0, 10.0 ] }, "down": { "texture": "#0", "uv": [ 11.0, 10.0, 13.0, 11.0 ] } } }, { "name": "rail bottom", "from": [ 0.0, 0.0, 1.0 ], "to": [ 16.0, 1.0, 3.0 ], "faces": { "north": { "texture": "#0", "uv": [ 11.0, 10.0, 12.0, 11.0 ] }, "east": { "texture": "#0", "uv": [ 11.0, 5.0, 13.0, 6.0 ] }, "south": { "texture": "#0", "uv": [ 12.0, 6.0, 13.0, 5.0 ] }, "west": { "texture": "#0", "uv": [ 13.0, 10.0, 11.0, 11.0 ] }, "up": { "texture": "#0", "uv": [ 11.0, 9.0, 13.0, 10.0 ] }, "down": { "texture": "#0", "uv": [ 11.0, 10.0, 13.0, 11.0 ] } } }, { "name": "Center Track", "from": [ 6.0, 1.0, 0.0 ], "to": [ 10.0, 2.0, 16.0 ], "faces": { "north": { "texture": "#0", "uv": [ 13.0, 6.0, 14.0, 7.0 ] }, "east": { "texture": "#0", "uv": [ 2.0, 8.0, 3.0, 9.0 ] }, "south": { "texture": "#0", "uv": [ 2.0, 8.0, 3.0, 9.0 ] }, "west": { "texture": "#0", "uv": [ 2.0, 5.0, 3.0, 6.0 ] }, "up": { "texture": "#0", "uv": [ 2.0, 0.0, 3.0, 16.0 ] }, "down": { "texture": "#0", "uv": [ 2.0, 0.0, 3.0, 16.0 ] } } } ] } controlRailBlock.json (block model pointer): { "parent": "generic:block/controlRail", "textures": { "rail": "generic:blocks/railControlBlock" } } any help? Thanks!
  18. ok, but what if I created another entity later that needed this data? then what would I do?
  19. oh right! my code! genericTileEntity.java: package tutorial.generic; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.server.gui.IUpdatePlayerListBox; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.IChatComponent; import net.minecraft.world.World; public class genericTileEntity extends TileEntity implements IInventory { private ItemStack[] inventory; public static String name = ""; public static float maxSpeed = 0; private String customName; public static NBTTagCompound maxSpeedTag = new NBTTagCompound(); public static NBTTagCompound nameTag = new NBTTagCompound(); public genericTileEntity() { this.inventory = new ItemStack[this.getSizeInventory()]; } public String getCustomName() { return this.customName; } public void setCustomName(String customName) { this.customName = customName; } @Override public String getName() { return this.hasCustomName() ? this.customName : "container.tutorial_tile_entity"; } @Override public boolean hasCustomName() { return this.customName != null && !this.customName.equals(""); } @Override public IChatComponent getDisplayName() { return this.hasCustomName() ? new ChatComponentText(this.getName()) : new ChatComponentTranslation(this.getName()); } @Override public int getSizeInventory() { return 9; } @Override public ItemStack getStackInSlot(int index) { if (index < 0 || index >= this.getSizeInventory()) return null; return this.inventory[index]; } @Override public ItemStack decrStackSize(int index, int count) { if (this.getStackInSlot(index) != null) { ItemStack itemstack; if (this.getStackInSlot(index).stackSize <= count) { itemstack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); this.markDirty(); return itemstack; } else { itemstack = this.getStackInSlot(index).splitStack(count); if (this.getStackInSlot(index).stackSize <= 0) { this.setInventorySlotContents(index, null); } else { //Just to show that changes happened this.setInventorySlotContents(index, this.getStackInSlot(index)); } this.markDirty(); return itemstack; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int index) { ItemStack stack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); return stack; } @Override public void setInventorySlotContents(int index, ItemStack stack) { if (index < 0 || index >= this.getSizeInventory()) return; if (stack != null && stack.stackSize > this.getInventoryStackLimit()) stack.stackSize = this.getInventoryStackLimit(); if (stack != null && stack.stackSize == 0) stack = null; this.inventory[index] = stack; this.markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64; } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { } @Override public int getFieldCount() { return 0; } @Override public void clear() { for (int i = 0; i < this.getSizeInventory(); i++) this.setInventorySlotContents(i, null); } public static void processActivate(EntityPlayer par5EntityPlayer, World world) { name = guiGenericTileEntity.textField.getText(); maxSpeed = guiGenericTileEntity.mySlider.sliderValue; } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setString("name",name); nbt.setFloat("maxSpeed", maxSpeed); System.out.println("saved!"); } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); name = nbt.getString("name"); maxSpeed = nbt.getFloat("maxSpeed"); System.out.println("loaded!"); } public void setName(String name) { this.name = name; this.markForUpdate(); } public void setMaxSpeed(float maxSpeed) { this.maxSpeed = maxSpeed; this.markForUpdate(); } public void markForUpdate() { BlockPos pos = this.getPos(); this.worldObj.markBlockForUpdate(pos); this.markDirty(); } } guiGenericTileEntity.java: package tutorial.generic; import java.awt.Color; import java.io.IOException; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiSlider; import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.World; public class guiGenericTileEntity extends GuiScreen{ public static NBTTagCompound nameTag = new NBTTagCompound(); private int x, y, z; private EntityPlayer player; private World world; private int xSize, ySize; public static GuiTextField textField; public static GuiSliderFixed mySlider; public static NBTTagCompound maxSpeedTag = new NBTTagCompound(); public guiGenericTileEntity(EntityPlayer player, World world, int x, int y, int z) { this.x = x; this.y = y; this.z = z; this.player = player; this.world = world; xSize = 176; ySize = 214; } private ResourceLocation backgroundimage = new ResourceLocation(Generic.MODID.toLowerCase() + ":" + "textures/gui/guiBackGenericTileEntity.png"); @Override public void drawScreen(int mouseX, int mouseY, float renderPartialTicks) { this.mc.getTextureManager().bindTexture(backgroundimage); int x = (this.width - xSize) / 2; int y = (this.height - ySize) / 2; drawTexturedModalRect(x, y, 0, 0, xSize, ySize); fontRendererObj.drawString("MTTA System", (int) (width / 2 - (width / 13)), height / 15, ; fontRendererObj.drawString("Train Name :", (int) (width / 2 - (width / 13)), (int) (height / 7., ; fontRendererObj.drawString("Max Speed :", (int) (width / 2 - (width / 13)), (int) (height / 3.5), ; textField.drawTextBox(); super.drawScreen(mouseX, mouseY, renderPartialTicks); } @Override public boolean doesGuiPauseGame() { return false; } @Override public void updateScreen(){ textField.updateCursorCounter(); super.updateScreen(); } @Override protected void keyTyped(char typedChar, int keyCode) throws IOException{ textField.textboxKeyTyped(typedChar, keyCode); super.keyTyped(typedChar, keyCode); } @Override public void initGui(){ buttonList.add(new GuiButton(1, (int) (xSize / 3 * 2.35), ySize - (ySize / 18), xSize - 20, height / 12, "Save And Close")); mySlider = new GuiSliderFixed(3, width / 2 - 75, height / 3, "MPH ", 1.0F, 100.0F, 1.0F); buttonList.add(mySlider); mySlider.sliderValue = maxSpeedTag.getFloat("MaxSpeed"); textField = new GuiTextField(width / 2, fontRendererObj, width / 2 - 50, (int) (height / 6), 100, 20); textField.setMaxStringLength(30); textField.setText(nameTag.getString("Name")); textField.setFocused(true); textField.setCanLoseFocus(false); super.initGui(); } @Override protected void actionPerformed(GuiButton guibutton) { //id is the id you give your button switch(guibutton.id) { case 1: player.closeScreen(); nameTag.setString("Name", textField.getText()); maxSpeedTag.setFloat("MaxSpeed", mySlider.sliderValue); genericTileEntity.processActivate(player, world); player.addChatMessage(new ChatComponentText("Saved the current settings for " + textField.getText() + "!")); break; } //Packet code here //PacketDispatcher.sendPacketToServer(packet); //send packet } } Hope this helps!
  20. How can I have nbt data specific to a block, I mean like if i place two of the same block, I want each to have its own nbt compound, the reason I am asking this is because I was able to pull it off, but both of the blocks would share the same nbt tag, how can I fix this? Thanks in advance!
  21. ok, I figured it out, you need to create a separate slider other than the default, then call it from there. My Slider Code: package tutorial.generic; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.opengl.GL11; public class GuiSliderFixed extends GuiButton { public float sliderValue = 1.0F; public float sliderMaxValue = 1.0F; public float sliderMinValue = 1.0F; public boolean dragging = false; public String label; public GuiSliderFixed(int id, int x, int y, String label, float startingValue, float maxValue, float minValue) { super(id, x, y, 150, 20, label); this.label = label; this.sliderValue = startingValue; this.sliderMaxValue = maxValue; this.sliderMinValue = minValue; } protected int getHoverState(boolean par1) { return 0; } @Override public void drawButton(Minecraft mc, int mouseX, int mouseY) { if (this.visible) { FontRenderer fontrenderer = mc.fontRendererObj; mc.getTextureManager().bindTexture(buttonTextures); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; int k = this.getHoverState(this.hovered); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.blendFunc(770, 771); this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height); this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height); this.mouseDragged(mc, mouseX, mouseY); int l = 14737632; if (packedFGColour != 0) { l = packedFGColour; } else if (!this.enabled) { l = 10526880; } else if (this.hovered) { l = 16777120; } this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - / 2, l); } } protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) { if (this.enabled && this.visible && this.packedFGColour == 0) { if (this.dragging) { this.sliderValue = (float) (par2 - (this.xPosition + 4)) / (float) (this.width - ; if (this.sliderValue < 0.0F) { this.sliderValue = 0.0F; } if (this.sliderValue > 1.0F) { this.sliderValue = 1.0F; } } this.displayString = label + ": " + (int) (sliderValue * sliderMaxValue); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.drawTexturedModalRect(this.xPosition + (int) (this.sliderValue * (float) (this.width - ), this.yPosition, 0, 66, 4, 20); this.drawTexturedModalRect(this.xPosition + (int) (this.sliderValue * (float) (this.width - ) + 4, this.yPosition, 196, 66, 4, 20); } } public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) { if (super.mousePressed(par1Minecraft, par2, par3)) { this.sliderValue = (float) (par2 - (this.xPosition + 4)) / (float) (this.width - ; if (this.sliderValue < 0.0F) { this.sliderValue = 0.0F; } if (this.sliderValue > 1.0F) { this.sliderValue = 1.0F; } this.dragging = true; return true; } else { return false; } } public void mouseReleased(int par1, int par2) { this.dragging = false; } } My GUI Code: package tutorial.generic; import java.awt.Color; import java.io.IOException; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiSlider; import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.World; public class guiGenericTileEntity extends GuiScreen{ public static NBTTagCompound nameTag = new NBTTagCompound(); private int x, y, z; private EntityPlayer player; private World world; private int xSize, ySize; public static GuiTextField textField; public static GuiSliderFixed mySlider; public static NBTTagCompound maxSpeedTag = new NBTTagCompound(); public guiGenericTileEntity(EntityPlayer player, World world, int x, int y, int z) { this.x = x; this.y = y; this.z = z; this.player = player; this.world = world; xSize = 176; ySize = 214; } private ResourceLocation backgroundimage = new ResourceLocation(Generic.MODID.toLowerCase() + ":" + "textures/gui/guiBackGenericTileEntity.png"); @Override public void drawScreen(int mouseX, int mouseY, float renderPartialTicks) { this.mc.getTextureManager().bindTexture(backgroundimage); int x = (this.width - xSize) / 2; int y = (this.height - ySize) / 2; drawTexturedModalRect(x, y, 0, 0, xSize, ySize); fontRendererObj.drawString("MTTA System", (int) (width / 2 - (width / 13)), height / 15, ; fontRendererObj.drawString("Train Name :", (int) (width / 2 - (width / 13)), (int) (height / 7., ; fontRendererObj.drawString("Max Speed :", (int) (width / 2 - (width / 13)), (int) (height / 3.5), ; textField.drawTextBox(); super.drawScreen(mouseX, mouseY, renderPartialTicks); } @Override public boolean doesGuiPauseGame() { return false; } @Override public void updateScreen(){ textField.updateCursorCounter(); super.updateScreen(); } @Override protected void keyTyped(char typedChar, int keyCode) throws IOException{ textField.textboxKeyTyped(typedChar, keyCode); super.keyTyped(typedChar, keyCode); } @Override public void initGui(){ buttonList.add(new GuiButton(1, (int) (xSize / 3 * 2.35), ySize - (ySize / 18), xSize - 20, height / 12, "Save And Close")); mySlider = new GuiSliderFixed(3, width / 2 - 75, height / 3, "MPH ", 1.0F, 100.0F, 1.0F); buttonList.add(mySlider); mySlider.sliderValue = maxSpeedTag.getFloat("MaxSpeed"); textField = new GuiTextField(width / 2, fontRendererObj, width / 2 - 50, (int) (height / 6), 100, 20); textField.setMaxStringLength(30); textField.setText(nameTag.getString("Name")); textField.setFocused(true); textField.setCanLoseFocus(false); super.initGui(); } @Override protected void actionPerformed(GuiButton guibutton) { //id is the id you give your button switch(guibutton.id) { case 1: player.closeScreen(); nameTag.setString("Name", textField.getText()); maxSpeedTag.setFloat("MaxSpeed", mySlider.sliderValue); genericTileEntity.processActivate(player, world); player.addChatMessage(new ChatComponentText("Saved the current settings for " + textField.getText() + "!")); break; } //Packet code here //PacketDispatcher.sendPacketToServer(packet); //send packet } } Calling the new Slider works like this: create a new GuiSliderFixed in the GUI code ---> example: ---> GuiSliderFixed mySlider = new GuiSliderFixed(); set the Parameters to this (int id, int x, int y, String label, float statingValue, float maxValue, float minValue) ---> example: ---> GuiSliderFixed mySlider = new GuiSliderFixed(3, width / 2 - 75, height / 3, "MPH ", 1.0F, 100.0F, 1.0F); add it to buttonList ---> example ---> buttonList.add(mySlider); Hope This Helps!
  22. ok i get that, but can you ellaborate on what to put, I can't figure out what goes where in all the parameters
  23. I recently started working on a mod and I ran into a GUI problem, I can;t figure out how to get a slider in my GUI, many things online say to use a controlList but I says its not there when i use this.controlList.add(); So can someone give me a slider code and how to get it working. Thanks!

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.