-
Posts
16 -
Joined
-
Last visited
Everything posted by Toastyman23
-
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); } } }
-
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); } } }
-
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); } } }
-
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); } } }
-
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?
-
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?