How to modify this script to work on server or client?

Started by WolfmanFrey on

Topic category: Advanced modding

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to modify this script to work on server or client?

Howdy all,

This is my first post on here.  I usually research and trial and error my way through PC related things, but I'm am completely stumped.  I have background in playing in C# with Unity3D.  I have not actually done much with Java and trying to learn to code and mod Minecraft.  I have a workspace on MCreator with literally the only thing I have added is a plant mod for testing and I'm trying to get it to work on a multiplayer server.  I have completed the plant correctly because it works fine in single player.  Here is the script for the plant.  I have played around with changing the ".CLIENT" to server but nothing.  Can someone show me what needs to change to make this plant spawn and behave like a regular plant on a server please?

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
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.WorldGenFlowers;
import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.NonNullList;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
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.SoundType;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.Block;

import java.util.Random;

public class mcreator_plant01 {

	public mcreator_plant01() {
	}

	public static Block block;

	public static Object instance;

	public void generateNether(World world, Random random, int chunkX, int chunkZ) {
	}

	public int addFuel(ItemStack fuel) {
		return 0;
	}

	public void serverLoad(FMLServerStartingEvent event) {
	}

	public void preInit(FMLPreInitializationEvent event) {
		block = (Block) (new BlockCustomFlower()).setHardness(0.01F).setResistance(2.0F).setLightLevel(0.0F).setUnlocalizedName("plant01");
		block.setRegistryName("plant01");
		ForgeRegistries.BLOCKS.register(block);
		ForgeRegistries.ITEMS.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
	}

	public void registerRenderers() {
	}

	public void load(FMLInitializationEvent event) {
		if (event.getSide() == Side.CLIENT) {
			Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
					.register(Item.getItemFromBlock(block), 0, new ModelResourceLocation("%MAINMODNAME%:plant01", "inventory"));
		}
	}

	public void generateSurface(World world, java.util.Random randomGenerator, int chunkX, int chunkZ) {
		for (int i = 0; i < 20; i++) {
			int l6 = chunkX + randomGenerator.nextInt(16) + 8;
			int i11 = randomGenerator.nextInt(128);
			int l14 = chunkZ + randomGenerator.nextInt(16) + 8;
			(new WorldGenFlowers(((BlockFlower) mcreator_plant01.block), BlockFlower.EnumFlowerType.DANDELION)).generate(world, randomGenerator,
					new BlockPos(l6, i11, l14));
		}
	}

	public static class BlockCustomFlower extends BlockFlower {

		public BlockCustomFlower() {
			super();
			setSoundType(SoundType.GROUND);

			this.setCreativeTab(CreativeTabs.DECORATIONS);
		}

		@Override
		public BlockFlower.EnumFlowerColor getBlockType() {
			return BlockFlower.EnumFlowerColor.YELLOW;
		}

		@SideOnly(Side.CLIENT)
		@SuppressWarnings("unchecked")
		@Override
		public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
			for (BlockFlower.EnumFlowerType blockflower$enumflowertype : BlockFlower.EnumFlowerType.getTypes(this.getBlockType())) {
				list.add(new ItemStack(this, 1, blockflower$enumflowertype.getMeta()));
			}
		}

		@Override
		public int quantityDropped(Random par1Random) {
			return 1;
		}

		@Override
		public Item getItemDropped(IBlockState state, Random rand, int fortune) {
			return new ItemStack(Items.DIAMOND).getItem();
		}
	}
}

 

Joined Apr 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hmmm It should work on…
Fri, 04/20/2018 - 21:47

Hmmm It should work on server did you tried to run Server in MCreator Menu 
As much as I know If you want to have your function to apper only for person thats triggered it for example Chest Gui
@SideOnly(Side.CLIENT) This line is used to prevent comand that shows specyfic chest Gui from openig for every player even when player didn't right clicked on the chest but for server side you dont put that also Plant is some caind of block and Blocks generation does not use Sides to work so it should wor on server too
You can also try to increase Generation rate and that search or simply pick it from Creative invetory to check if this mod is on the server 

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks for the reply.  I…
Sat, 04/21/2018 - 17:54

Thanks for the reply.  I found out that I'm a dummy.  I was starting the server with the minecraft.jar and not the forge.jar.  So the mod was never being loaded.  I hope this might help any other folks out there that are making the same mistake if this thread pops up on a google search.