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.

Toastyman23

Members
  • Joined

  • Last visited

  1. Am I changing the getBlockState after play.world, the one after Blocks.GRASS, or both?
  2. I made everything static and it still doesn't work. package toastyman231.broommodandmore.util.handlers; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.profiler.Profiler; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.relauncher.Side; import toastyman231.broommodandmore.init.ModBlocks; @EventBusSubscriber public class TickHandler { static Block blk = ModBlocks.TEST_BLOCK; static IBlockState state = blk.getDefaultState(); public static void ReplaceBlocks(EntityPlayer play, BlockPos loc1, BlockPos loc2) { Iterable<BlockPos> poses = BlockPos.getAllInBox(loc1, loc2); for(BlockPos blockPos : poses) { if(play.world.getBlockState(blockPos) == Blocks.GRASS.getBlockState()) { play.world.setBlockState(blockPos, state); } } } @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) /*throws InterruptedException*/ { if(event.phase == TickEvent.Phase.START) { EntityPlayer player = event.player; //TimeUnit.SECONDS.sleep(30); BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ); BlockPos pos1 = new BlockPos(pos.getX()-24, pos.getY()-24, pos.getZ()-24); BlockPos pos2 = new BlockPos(pos.getX()+25, pos.getY()+25, pos.getZ()+25); ReplaceBlocks(player, pos1, pos2); } } }
  3. Ok I think I made the right changes, but it still doesn't work. package toastyman231.broommodandmore.util.handlers; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.profiler.Profiler; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.relauncher.Side; import toastyman231.broommodandmore.init.ModBlocks; @EventBusSubscriber public class TickHandler { Block blk = ModBlocks.TEST_BLOCK; IBlockState state = blk.getDefaultState(); public void ReplaceBlocks(EntityPlayer play, BlockPos loc1, BlockPos loc2) { Iterable<BlockPos> poses = BlockPos.getAllInBox(loc1, loc2); for(BlockPos blockPos : poses) { if(play.world.getBlockState(blockPos) == Blocks.GRASS.getBlockState()) { play.world.setBlockState(blockPos, state); } } } @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) /*throws InterruptedException*/ { if(event.phase == TickEvent.Phase.START) { EntityPlayer player = event.player; //TimeUnit.SECONDS.sleep(30); BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ); BlockPos pos1 = new BlockPos(pos.getX()-24, pos.getY()-24, pos.getZ()-24); BlockPos pos2 = new BlockPos(pos.getX()+25, pos.getY()+25, pos.getZ()+25); ReplaceBlocks(player, pos1, pos2); } } }
  4. How exactly would I go about doing that? Ok I fixed that. I didn't realize list.getIndexOf() was a thing.
  5. That cycles through every BlockPos stored in the list of BlockPoses poses. Idk it threw me an error and said doing that would fix it.
  6. I go into the world and nothing happens. It's just really laggy and no blocks change.
  7. So then the player I'm passing in should work, right? I removed the reference to World and changed the setBlockState line to use the world from event.player. However it still doesn't work. package toastyman231.broommodandmore.util.handlers; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.profiler.Profiler; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.relauncher.Side; import toastyman231.broommodandmore.init.ModBlocks; @EventBusSubscriber public class TickHandler { Block blk = ModBlocks.TEST_BLOCK; IBlockState state = blk.getDefaultState(); public void ReplaceBlocks(EntityPlayer play, BlockPos loc1, BlockPos loc2) { BlockPos position = (BlockPos) BlockPos.getAllInBox(loc1, loc2); List<BlockPos> poses = new ArrayList<BlockPos>(); poses.add(position); int index = 0; for(BlockPos blockPos : poses) { if(play.world.getBlockState(poses.get(index)) == Blocks.GRASS.getBlockState()) { play.world.setBlockState(poses.get(index), state); index++; } } } @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) /*throws InterruptedException*/ { if(event.phase == TickEvent.Phase.START) { EntityPlayer player = event.player; //TimeUnit.SECONDS.sleep(30); BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ); BlockPos pos1 = new BlockPos(pos.getX()-24, pos.getY()-24, pos.getZ()-24); BlockPos pos2 = new BlockPos(pos.getX()+25, pos.getY()+25, pos.getZ()+25); ReplaceBlocks(player, pos1, pos2); } } }
  8. Where do I get the world given to me by the event? I didn't code Minecraft, I don't know how it handles this stuff.
  9. I figured it would inherit what it needed from World, but I guess not. What am I supposed to set it to? I tried World worldRef = new World(); but it just says it can't instantiate the type World because World is an abstract class. What exactly am I supposed to be doing here?
  10. I took a class in Java but I'm more experienced with C# and Unity. Turns out I was just being stupid and was using the wrong type of reference. I have it error free without extending World now, but it still doesn't work. package toastyman231.broommodandmore.util.handlers; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.profiler.Profiler; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.relauncher.Side; import toastyman231.broommodandmore.init.ModBlocks; @EventBusSubscriber public abstract class TickHandler { World worldRef; Block blk = ModBlocks.TEST_BLOCK; IBlockState state = blk.getDefaultState(); public void ReplaceBlocks(EntityPlayer play, BlockPos loc1, BlockPos loc2) { BlockPos position = (BlockPos) BlockPos.getAllInBox(loc1, loc2); List<BlockPos> poses = new ArrayList<BlockPos>(); poses.add(position); int index = 0; for(BlockPos blockPos : poses) { if(play.world.getBlockState(poses.get(index)) == Blocks.GRASS.getBlockState()) { worldRef.setBlockState(poses.get(index), state); index++; } } } @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) /*throws InterruptedException*/ { if(event.phase == TickEvent.Phase.START) { EntityPlayer player = event.player; //TimeUnit.SECONDS.sleep(30); BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ); BlockPos pos1 = new BlockPos(pos.getX()-24, pos.getY()-24, pos.getZ()-24); BlockPos pos2 = new BlockPos(pos.getX()+25, pos.getY()+25, pos.getZ()+25); ReplaceBlocks(player, pos1, pos2); } } }
  11. How do I do it without extending World then? I tried just setting a reference but it kept trying to tell me that TickHandler didn't have a function called setBlockState. I did it once before I made this thread too, without any issues, but now it doesn't work.
  12. Okay so I've been working on the mod for a little bit and I've hit another wall. I did what diesieben07 said and switched to PlayerTickEvent and checked TickEvent.Phase, however it still does nothing upon running. Here's the new code: package toastyman231.broommodandmore.util.handlers; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.profiler.Profiler; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.relauncher.Side; import toastyman231.broommodandmore.init.ModBlocks; @EventBusSubscriber public class TickHandler extends World { Block blk = ModBlocks.TEST_BLOCK; IBlockState state = blk.getDefaultState(); protected TickHandler(ISaveHandler saveHandlerIn, WorldInfo info, WorldProvider providerIn, Profiler profilerIn, boolean client) { super(saveHandlerIn, info, providerIn, profilerIn, client); } public void ReplaceBlocks(BlockPos loc1, BlockPos loc2) { BlockPos position = (BlockPos) BlockPos.getAllInBox(loc1, loc2); List<BlockPos> poses = new ArrayList<BlockPos>(); poses.add(position); int index = 0; for(BlockPos blockPos : poses) { if(Minecraft.getMinecraft().world.getBlockState(poses.get(index)) == Blocks.GRASS.getBlockState()) { setBlockState((BlockPos) poses.get(index), state); index++; } } } @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) /*throws InterruptedException*/ { if(event.phase == TickEvent.Phase.START) { EntityPlayer player = event.player; //TimeUnit.SECONDS.sleep(30); BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ); BlockPos pos1 = new BlockPos(pos.getX()-24, pos.getY()-24, pos.getZ()-24); BlockPos pos2 = new BlockPos(pos.getX()+25, pos.getY()+25, pos.getZ()+25); ReplaceBlocks(pos1, pos2); } } @Override protected IChunkProvider createChunkProvider() { // TODO Auto-generated method stub return null; } @Override protected boolean isChunkLoaded(int x, int z, boolean allowEmpty) { // TODO Auto-generated method stub return false; } } What did I do wrong this time folks?
  13. I tried just importing World and calling it that way, but it didn't work until I put extends World back. If I'm doing it wrong, how am I supposed to be doing it?
  14. I'm extending World so I can use setBlockState easier. As for the rest, thanks a bunch, I'll update with the result once I make the changes.

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.