Topic category: Help with Minecraft modding (Java Edition)
After the loading workspace, the changed block code becomes the code, when the block was created. I create block in GUI and remake the part of code.
Default
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.Block;
import java.util.Random;
public class mcreator_cobaltShardOre {
public mcreator_cobaltShardOre() {
}
public static BlockCobaltShardOre block;
public static Object instance;
public int addFuel(ItemStack fuel) {
return 0;
}
public void serverLoad(FMLServerStartingEvent event) {
}
public void preInit(FMLPreInitializationEvent event) {
}
public void registerRenderers() {
}
public void load(FMLInitializationEvent event) {
if (event.getSide() == Side.CLIENT) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(Item.getItemFromBlock(block), 0, new ModelResourceLocation("TestEnvironmentMod:CobaltShardOre", "inventory"));
}
}
static {
block = (BlockCobaltShardOre) (new BlockCobaltShardOre().setHardness(8.0F).setResistance(25.0F).setLightLevel(0.0F)
.setUnlocalizedName("CobaltShardOre").setLightOpacity(0).setCreativeTab(CreativeTabs.BUILDING_BLOCKS));
block.setHarvestLevel("pickaxe", 4);
}
public void generateSurface(World world, java.util.Random rand, int chunkX, int chunkZ) {
for (int i = 0; i < 10; i++) {
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(113) + 15;
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(mcreator_cobaltShardOre.block.getDefaultState(), 16)).generate(world, rand, new BlockPos(randPosX, randPosY,
randPosZ));
}
}
public void generateNether(World world, Random random, int chunkX, int chunkZ) {
}
static class BlockCobaltShardOre extends Block {
int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0;
boolean red = false;
protected BlockCobaltShardOre() {
super(Material.IRON);
GameRegistry.registerBlock(this, "CobaltShardOre");
setSoundType(SoundType.STONE);
}
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
world.scheduleUpdate(new BlockPos(i, j, k), this, this.tickRate(world));
}
@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return red ? 15 : 0;
}
@Override
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return red ? 15 : 0;
}
@SideOnly(Side.CLIENT)
@Override
public BlockRenderLayer getBlockLayer() {
return BlockRenderLayer.SOLID;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
}
@Override
public int tickRate(World world) {
return 10;
}
@Override
public int quantityDropped(Random par1Random) {
return 1;
}
@Override
public Item getItemDropped(IBlockState state, Random par2Random, int par3) {
return new ItemStack(mcreator_cobaltShard.block).getItem();
}
}
}
Need
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.Block;
import java.util.Random;
public class mcreator_cobaltShardOre {
public mcreator_cobaltShardOre() {
}
public static BlockCobaltShardOre block;
public static Object instance;
public int addFuel(ItemStack fuel) {
return 0;
}
public void serverLoad(FMLServerStartingEvent event) {
}
public void preInit(FMLPreInitializationEvent event) {
}
public void registerRenderers() {
}
public void load(FMLInitializationEvent event) {
if (event.getSide() == Side.CLIENT) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(Item.getItemFromBlock(block), 0, new ModelResourceLocation("TestEnvironmentMod:CobaltShardOre", "inventory"));
}
}
static {
block = (BlockCobaltShardOre) (new BlockCobaltShardOre().setHardness(8.0F).setResistance(25.0F).setLightLevel(0.0F)
.setUnlocalizedName("CobaltShardOre").setLightOpacity(0).setCreativeTab(CreativeTabs.BUILDING_BLOCKS));
block.setHarvestLevel("pickaxe", 4);
}
public void generateSurface(World world, java.util.Random rand, int chunkX, int chunkZ) {
for (int i = 0; i < 6; i++) {
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(36) + 15;
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(mcreator_cobaltShardOre.block.getDefaultState(), 3)).generate(world, rand, new BlockPos(randPosX, randPosY,
randPosZ));
}
}
public void generateNether(World world, Random random, int chunkX, int chunkZ) {
}
static class BlockCobaltShardOre extends Block {
int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0;
boolean red = false;
protected BlockCobaltShardOre() {
super(Material.IRON);
GameRegistry.registerBlock(this, "CobaltShardOre");
setSoundType(SoundType.STONE);
}
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
world.scheduleUpdate(new BlockPos(i, j, k), this, this.tickRate(world));
}
@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return red ? 15 : 0;
}
@Override
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return red ? 15 : 0;
}
@SideOnly(Side.CLIENT)
@Override
public BlockRenderLayer getBlockLayer() {
return BlockRenderLayer.SOLID;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
}
@Override
public int tickRate(World world) {
return 10;
}
@Override
public int quantityDropped(Random par1Random) {
return 1 +(int)(Math.random()*3);
}
@Override
public Item getItemDropped(IBlockState state, Random par2Random, int par3) {
return new ItemStack(mcreator_cobaltShard.block).getItem();
}
}
}
How to change the code, that it has not changed later?
You can lock your code in 1.7.5 but if you have a older version you can't, or if you edit the code don't reopen the UI version or it will reset it.
@#1 Thanks you.
@#1.1 No problem's MCreator can be a pain at times for sure :)