Jump to content

Toastyman23

Members
  • Posts

    16
  • Joined

  • Last visited

Everything posted by Toastyman23

  1. Finally, it works. Thanks for your help!
  2. Am I changing the getBlockState after play.world, the one after Blocks.GRASS, or both?
  3. 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); } } }
  4. 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); } } }
  5. How exactly would I go about doing that? Ok I fixed that. I didn't realize list.getIndexOf() was a thing.
  6. 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.
  7. I go into the world and nothing happens. It's just really laggy and no blocks change.
  8. 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); } } }
  9. 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.
  10. 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?
  11. 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); } } }
  12. 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.
  13. 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?
  14. 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?
  15. 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.
  16. I'm making a mod that adds a broom to Minecraft so I can learn how things work. I basically just want certain blocks to get dirty over time, and a right click from my broom will set them back to normal. The way I want to do this is by setting every plank block in a certain radius(maybe 50 blocks) to my own custom block, which will just be the plank but dirtier. Then I'll make it so if the block is activated with the broom in hand, it'll set the block back to the default plank texture. What I haven't figured out is how exactly you set blocks to other blocks. Here's what I've tried so far. package toastyman231.broommodandmore.util.handlers; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; //import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; 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 toastyman231.broommodandmore.init.ModBlocks; @EventBusSubscriber public class TickHandler extends World { EntityPlayer player; BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ); Block blk = ModBlocks.TEST_BLOCK; BlockPos pos1 = new BlockPos(pos.getX()+2, pos.getY(), pos.getZ()); IBlockState state = blk.getDefaultState(); protected TickHandler(ISaveHandler saveHandlerIn, WorldInfo info, WorldProvider providerIn, Profiler profilerIn, boolean client) { super(saveHandlerIn, info, providerIn, profilerIn, client); } @SubscribeEvent public void onWorldTick(TickEvent.WorldTickEvent event) { pos = new BlockPos(player.posX, player.posY, player.posZ); destroyBlock(pos, true); setBlockState(pos1, state); } @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; } } So far this doesn't do anything, and I don't know if it's because I set up the tick event wrong or if setBlockState just isn't how you replace blocks or what. What exactly am I doing wrong here, and how do I get every block of a certain type within 50 blocks of the player and set them to another block?
×
×
  • Create New...

Important Information

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