Posted April 19, 201510 yr I'm currently using the method World.setBlockState() to change blocks in the world. However, these blocks disappear when you right click or reload the world. I'm guessing this has something to do with server/client synchronization, but I don't know for sure. I am using a Server-side Tickhandler.
April 20, 201510 yr There is no way, that using ServerTickEvent, this is causing problems. Show your code. 1.7.10 is no longer supported by forge, you are on your own.
April 20, 201510 yr Author My Tick event: @SubscribeEvent public void onServerTick(TickEvent.ServerTickEvent event) { EAPlugin.internalTick(); for(EAPluginContainer plugin : EALoader.instance().loadedPlugins) { plugin.plugin.onTick(); } } And the code that changes blocks: @Override public void onTick() { if(day <= 4) phase = day; else phase = 4; try { minecraft.theWorld.setBlockState(new BlockPos(minecraft.thePlayer.posX, minecraft.thePlayer.posY, minecraft.thePlayer.posZ), Blocks.dirt.getDefaultState()); } catch(Exception e) { System.err.println("Errorino"); } Random random = new Random(1337); int randX = random.nextInt(); int randZ = random.nextInt(); int randY = EAToolkit.getTopBlock(minecraft.theWorld, randX, randZ); try { if(phase == 1) { blockBuffer++; if(blockBuffer >= 20) { Block block = minecraft.theWorld.getChunkFromChunkCoords(randX, randZ).getBlock(randX, randY, randZ); if(block == Blocks.grass) { minecraft.theWorld.setBlockState(new BlockPos(randX, randY, randZ), Blocks.dirt.getDefaultState()); } if(block == Blocks.leaves) { minecraft.theWorld.setBlockState(new BlockPos(randX, randY, randZ), Blocks.air.getDefaultState()); } } } } catch(Exception e) { e.printStackTrace(); } } The first setBlockState call is for testing purposes, and right clicking the dirt that is created makes it disappear, breaking it in survival doesn't drop anything but still makes the sound, and world reload removes all dirt and resets my spawn.
April 20, 201510 yr Okay, so basically - this code will crash on Dedicated server. You can't access Minecraft.class inside ANY server methods, including ticks. You are accesting MC.theWorld - this is single, one and only client-sided world (the one your client player is in). Server has x worlds. You need to pick one or use WorldTickEvent to launch tick for all worlds (every world ticks separately). Note: TickEvents have Phases - START and END! Pick one or code will run twice. 1.7.10 is no longer supported by forge, you are on your own.
April 20, 201510 yr Author I have started using WorldServer instead of World for my tickhandler, but MinecraftServer.worldServers has nothing in it. It returns ArrayIndexOutOfBounds for whatever number I put in, and if I use a for() loop to get the first WorldServer I can it always uses the default null variable.
April 20, 201510 yr In WorldTIckEvent you don't need any of that. This event is launched ONLY ON SERVER SIDE for EVERY world there is. event.world - will give you direct access. Edit: Just a note: "event is launched ONLY ON SERVER SIDE" might have changed lately, just make sure. (I don't know really, it might also work for client) 1.7.10 is no longer supported by forge, you are on your own.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.