Jump to content

CBUltimate

Members
  • Posts

    46
  • Joined

  • Last visited

Everything posted by CBUltimate

  1. InputEvent.KeyInputEvent is not cancelable though, how should I cancel it?
  2. I can't find a played move event to cancel. Is there a way to cancel all player events or do I have to cancel each(block placed, break, item use.. etc) one by one?
  3. I'm trying to make the Renderer for the custom arrow but it gets quite complicated with RenderManager. How do I just use Minecraft's Vanilla Arrow Renderer? RenderingRegistry.registerEntityRenderingHandler(EntityDullArrow.class, new RenderDullArrow()); // RenderDullArrow() requires RenderManager package mod.cbultimate.stranded.entity; import net.minecraft.client.renderer.entity.RenderArrow; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderDullArrow extends RenderArrow<EntityDullArrow> { public static final ResourceLocation RES_ARROW = new ResourceLocation("textures/entity/projectiles/arrow.png"); public RenderDullArrow(RenderManager renderManagerIn) { super(renderManagerIn); } /** * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. */ protected ResourceLocation getEntityTexture(EntityDullArrow entity) { return RES_ARROW; } }
  4. What should I put for IRenderFactory?
  5. My arrow entity is a white box, how do I fix that? How do I use the resource location of vanilla Minecraft arrows? EntityRegistry.registerModEntity(new ResourceLocation(StrandedMod.MODID, "dull_arrow"), EntityDullArrow.class, "entity_dull_arrow", 1, StrandedMod.instance,16, 1, false);
  6. I am working on a command called /home for players to teleport home after 30 seconds of not moving, if player moves, intermission is canceled. How do I check if player moved to cancel the teleportation? My code so far. package mod.cbultimate.stranded.command;//Created by CBU on 23/1/2017. import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.server.MinecraftServer; import java.util.Timer; import java.util.TimerTask; public class CommandHome extends CommandBase { private Timer timer = new Timer(); private TimerTask cooldown; private TimerTask intermission; @Override public String getCommandName() { return "home"; } @Override public String getCommandUsage(ICommandSender sender) { return "Return to your spawn location after 30 seconds. Moving may interupt the teleportation."; } @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { intermission = new transmission(); timer.schedule(intermission, 5000); } private class transmission extends TimerTask{ @Override public void run() { System.out.println("Teleported."); } } }
  7. Is this what you mean? EntityRegistry.registerModEntity(new ResourceLocation(StrandedMod.MODID, "dull_arrow"), EntityDullArrow.class, "entity_dull_arrow", 1, "mod.cbultimate.stranded.StrandedMod",1, 1, false);
  8. net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Stranded Mod (cbu_strandedmod) Caused by: java.lang.NullPointerException at net.minecraftforge.fml.common.registry.EntityRegistry.doModEntityRegistration(EntityRegistry.java:183) at net.minecraftforge.fml.common.registry.EntityRegistry.registerModEntity(EntityRegistry.java:149) at mod.cbultimate.stranded.item.ModItems.registerItems(ModItems.java:49) at mod.cbultimate.stranded.item.ModItems.preInit(ModItems.java:36) at mod.cbultimate.stranded.StrandedMod.preInit(StrandedMod.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:621) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:243) at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:221) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:145) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:615) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:264) at net.minecraft.client.Minecraft.startGame(Minecraft.java:476) at net.minecraft.client.Minecraft.run(Minecraft.java:385) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
  9. How do I register a command in 1.11?
  10. It crashes when I try to start it. EntityRegistry.registerModEntity(new ResourceLocation(StrandedMod.MODID, "dull_arrow"), EntityDullArrow.class, "entity_dull_arrow", 1, StrandedMod.class,1, 1, false); Where should I register the entity? I tried to register it in FMLPreInitializationEvent.
  11. I came across this error, what should I do? "Don't know how to add class mod.cbultimate.stranded.entity.EntityDullArrow" package mod.cbultimate.stranded.entity;//Created by CBU on 22/1/2017. import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class EntityDullArrow extends EntityArrow { public EntityDullArrow(World worldIn) { super(worldIn); } public EntityDullArrow(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } public EntityDullArrow(World worldIn, EntityLivingBase shooter) { super(worldIn, shooter); } @Override protected ItemStack getArrowStack() { return null; } } package mod.cbultimate.stranded.item;//Created by CBU on 22/1/2017. import mod.cbultimate.stranded.entity.EntityDullArrow; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.ItemArrow; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ItemDullArrow extends ItemArrow { @Override public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter) { EntityDullArrow entityDullArrow = new EntityDullArrow(worldIn, shooter); entityDullArrow.setDamage(1); entityDullArrow.setKnockbackStrength(0); entityDullArrow.pickupStatus = EntityArrow.PickupStatus.DISALLOWED; return entityDullArrow; } } [04:29:25] [server thread/ERROR]: "Silently" catching entity tracking error. net.minecraft.util.ReportedException: Adding entity to track at net.minecraft.entity.EntityTracker.addEntityToTracker(EntityTracker.java:259) [EntityTracker.class:?] at net.minecraft.entity.EntityTracker.trackEntity(EntityTracker.java:101) [EntityTracker.class:?] at net.minecraft.world.ServerWorldEventHandler.onEntityAdded(ServerWorldEventHandler.java:43) [serverWorldEventHandler.class:?] at net.minecraft.world.World.onEntityAdded(World.java:1304) [World.class:?] at net.minecraft.world.WorldServer.onEntityAdded(WorldServer.java:1179) [WorldServer.class:?] at net.minecraft.world.World.spawnEntityInWorld(World.java:1295) [World.class:?] at net.minecraft.world.WorldServer.spawnEntityInWorld(WorldServer.java:1125) [WorldServer.class:?] at net.minecraft.item.ItemBow.onPlayerStoppedUsing(ItemBow.java:143) [itemBow.class:?] at net.minecraft.item.ItemStack.onPlayerStoppedUsing(ItemStack.java:528) [itemStack.class:?] at net.minecraft.entity.EntityLivingBase.stopActiveHand(EntityLivingBase.java:2985) [EntityLivingBase.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:626) [NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:56) [CPacketPlayerDigging.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:12) [CPacketPlayerDigging.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) [PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_111] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_111] at net.minecraft.util.Util.runTask(Util.java:26) [util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111] Caused by: java.lang.IllegalArgumentException: Don't know how to add class mod.cbultimate.stranded.entity.EntityDullArrow! at net.minecraft.entity.EntityTrackerEntry.createSpawnPacket(EntityTrackerEntry.java:670) ~[EntityTrackerEntry.class:?] at net.minecraft.entity.EntityTrackerEntry.updatePlayerEntity(EntityTrackerEntry.java:391) ~[EntityTrackerEntry.class:?] at net.minecraft.entity.EntityTrackerEntry.updatePlayerEntities(EntityTrackerEntry.java:501) ~[EntityTrackerEntry.class:?] at net.minecraft.entity.EntityTracker.addEntityToTracker(EntityTracker.java:233) ~[EntityTracker.class:?] ... 21 more
  12. The custom arrows called Dull Arrows should be shot out.
  13. But then the arrows shot out are normal arrow entities. How should I fix that?
  14. The vanilla bow checks for ItemArrow but how can I make the vanilla bow check for ItemDullArrow?
  15. I need EntityPlayerMP for sending packets but event only provides EntityPlayer event.getEntityPlayer(). Thanks in advance.
  16. How to reduce a skeleton's shoot speed and damage?
  17. I figure out that it is caused by client side not canceling the event from tests. It doesn't cancel events because client can't load the same WorldSavedData saved. How should I fix this?
  18. How to make player respawn in random areas? /setspawnpoint sets a cord as spawn point but I want to be able to spawn players in random locations. It's ok if it's in a 500 blocks radius of the spawn point. Help, thanks in advance.
  19. So, What should I do to cancel the event? I've the lower part of the Oak Door gets canceled properly but when I interact with the upper part, it doesn't get canceled properly.
  20. For some reason the upper part of an Oak Door bypass event.setCanceled(true); while the lower part of an Oak Door works perfectly. Meanwhile, Iron Doors triggers the event 2 times.
  21. Who else can still place a Chest block even though you set to cancel the BlockEvent.PlaceEvent event?
  22. package mod.cbultimate.stranded; import mod.cbultimate.stranded.block.ModBlocks; import mod.cbultimate.stranded.tileentity.TileEntityToolCupboard; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.ArrayList; //Created by CBU on 14/1/2017. public class ModEventHandler { private final String cupboard_dataIdentifier = "ToolCupboards"; private static ArrayList<Block> protectedBlockList = new ArrayList<Block>(); private static ArrayList<Item> blacklistedItems = new ArrayList<Item>(); public static void Init(){ protectedBlockList.add(Blocks.OAK_DOOR); protectedBlockList.add(Blocks.IRON_DOOR); protectedBlockList.add(Blocks.ACACIA_DOOR); protectedBlockList.add(Blocks.BIRCH_DOOR); protectedBlockList.add(Blocks.DARK_OAK_DOOR); protectedBlockList.add(Blocks.JUNGLE_DOOR); protectedBlockList.add(Blocks.SPRUCE_DOOR); protectedBlockList.add(Blocks.TRAPDOOR); protectedBlockList.add(Blocks.IRON_TRAPDOOR); protectedBlockList.add(Blocks.STONE_BUTTON); protectedBlockList.add(Blocks.WOODEN_BUTTON); protectedBlockList.add(Blocks.STONE_PRESSURE_PLATE); protectedBlockList.add(Blocks.WOODEN_PRESSURE_PLATE); protectedBlockList.add(Blocks.LEVER); blacklistedItems.add(Items.LAVA_BUCKET); blacklistedItems.add(Items.WATER_BUCKET); } @SubscribeEvent public void onWorldLoad(WorldEvent.Load event){ World world = event.getWorld(); ModWorldSavedData modWorldSavedData = (ModWorldSavedData) world.getPerWorldStorage().getOrLoadData(ModWorldSavedData.class, cupboard_dataIdentifier); if (modWorldSavedData == null) { modWorldSavedData = new ModWorldSavedData(cupboard_dataIdentifier); } for (int i=0; i < modWorldSavedData.ToolCupboards.size(); i ++){ BlockPos currentPosition = modWorldSavedData.ToolCupboards.get(i); if (world.isAirBlock(currentPosition) || world.getBlockState(currentPosition).getBlock() != ModBlocks.woodenToolCupboard){ modWorldSavedData.ToolCupboards.remove(i); } } modWorldSavedData.markDirty(); } @SubscribeEvent public void blockPlacedEvent(BlockEvent.PlaceEvent event){ World world = event.getWorld(); ModWorldSavedData modWorldSavedData = (ModWorldSavedData) world.getPerWorldStorage().getOrLoadData(ModWorldSavedData.class, cupboard_dataIdentifier); if (modWorldSavedData == null) { modWorldSavedData = new ModWorldSavedData(cupboard_dataIdentifier); } boolean cancelPlacement = false; for (int i=0; i < modWorldSavedData.ToolCupboards.size(); i ++){ BlockPos currentPosition = modWorldSavedData.ToolCupboards.get(i); if (event.getPos().getDistance(currentPosition.getX(), currentPosition.getY(), currentPosition.getZ()) < 16){ if (event.getPlacedBlock().getBlock() == ModBlocks.woodenToolCupboard) { cancelPlacement = true; event.getPlayer().addChatMessage(new TextComponentString("There is already a tool cupboard in this region.")); event.setCanceled(true); break; } else { TileEntity cupboardEntity = world.getTileEntity(currentPosition); if (cupboardEntity instanceof TileEntityToolCupboard){ boolean authorized = ((TileEntityToolCupboard) cupboardEntity).checkAuthorized(event.getPlayer().getName()); if (!authorized){ cancelPlacement = true; event.getPlayer().addChatMessage(new TextComponentString("You are not authorized to build here.")); event.setCanceled(true); world.setBlockToAir(event.getPos()); } } } } } if (event.getPlacedBlock().getBlock() == ModBlocks.woodenToolCupboard){ if (!cancelPlacement){ modWorldSavedData.ToolCupboards.add(new BlockPos(event.getPos().getX(), event.getPos().getY(), event.getPos().getZ())); world.getPerWorldStorage().setData(cupboard_dataIdentifier, modWorldSavedData); modWorldSavedData.markDirty(); } } } @SubscribeEvent public void blockBreakEvent(BlockEvent.BreakEvent event){ World world = event.getWorld(); ModWorldSavedData modWorldSavedData = (ModWorldSavedData) world.getPerWorldStorage().getOrLoadData(ModWorldSavedData.class, cupboard_dataIdentifier); if (modWorldSavedData == null) { modWorldSavedData = new ModWorldSavedData(cupboard_dataIdentifier); } if (event.getState().getBlock() == ModBlocks.woodenToolCupboard ){ for(int i=0; i<modWorldSavedData.ToolCupboards.size(); i++){ BlockPos currentCupboard = modWorldSavedData.ToolCupboards.get(i); if (event.getPos().getX() == currentCupboard.getX() && event.getPos().getY() == currentCupboard.getY() && event.getPos().getZ() == currentCupboard.getZ()){ modWorldSavedData.ToolCupboards.remove(i); world.getPerWorldStorage().setData(cupboard_dataIdentifier, modWorldSavedData); modWorldSavedData.markDirty(); break; } } } } @SubscribeEvent public void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event){ if (!event.getWorld().isRemote){ System.out.println("Right clicked with " + event.getItemStack().getUnlocalizedName()); String targetName = null; for (int p=0; p<protectedBlockList.size(); p++){ if (event.getWorld().getBlockState(event.getPos()).getBlock() == protectedBlockList.get(p)){ targetName = protectedBlockList.get(p).getLocalizedName(); break; } } for (int q=0; q<blacklistedItems.size(); q++){ if (event.getItemStack().getItem() == blacklistedItems.get(q)){ targetName = blacklistedItems.get(q).getItemStackDisplayName(new ItemStack(blacklistedItems.get(q))); break; } } if (targetName != null){ World world = event.getWorld(); ModWorldSavedData modWorldSavedData = (ModWorldSavedData) world.getPerWorldStorage().getOrLoadData(ModWorldSavedData.class, cupboard_dataIdentifier); if (modWorldSavedData == null) { modWorldSavedData = new ModWorldSavedData(cupboard_dataIdentifier); } for (int i=0; i < modWorldSavedData.ToolCupboards.size(); i ++){ BlockPos currentPosition = modWorldSavedData.ToolCupboards.get(i); if (event.getPos().getDistance(currentPosition.getX(), currentPosition.getY(), currentPosition.getZ()) < 16){ TileEntity cupboardEntity = world.getTileEntity(currentPosition); if (cupboardEntity instanceof TileEntityToolCupboard){ boolean authorized = ((TileEntityToolCupboard) cupboardEntity).checkAuthorized(event.getEntityPlayer().getName()); if (!authorized){ event.getEntityPlayer().addChatMessage(new TextComponentString("You are not authorized to use " + targetName)); event.setCanceled(true); } } } } } } } } This is the full version of the code. It runs without errors, but bucket of lava, water and blocks of chests can still be placed.
  23. Still doesn't work, I also found that placing chest is also not canceled. This is really strange. Please help, thanks in advance.
  24. I've made it not to use unlocalized name. But it still doesn't cancel the lava placement, I do get the message, but lava still get placed down. Help, thanks in advance. @SubscribeEvent public void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event){ if (!event.getWorld().isRemote){ //System.out.println("Event Triggered with " + event.getWorld().getBlockState(event.getPos()).getBlock().getLocalizedName()); System.out.println("Right clicked with " + event.getItemStack().getUnlocalizedName()); boolean itemInteraction = false; if (event.getItemStack() == new ItemStack(Items.LAVA_BUCKET) || event.getItemStack() == new ItemStack(Items.WATER_BUCKET) || event.getItemStack() == new ItemStack(Blocks.CHEST)){ itemInteraction = true; } if (itemInteraction){ event.getEntityPlayer().addChatMessage(new TextComponentString("You are not authorized use that item here.")); event.setCanceled(true); } } }
  25. I've used it here. But the lava still get placed down, even though I've set it to cancel the event. Help, Thanks in advance. @SubscribeEvent public void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event){ if (!event.getWorld().isRemote){ System.out.println("Right clicked with " + event.getItemStack().getUnlocalizedName()); boolean itemInteraction = false; if (event.getItemStack().getUnlocalizedName().equals("item.bucketLava") || event.getItemStack().getUnlocalizedName().equals("tile.chest") || event.getItemStack().getUnlocalizedName().equals("tile.bucketWater")){ itemInteraction = true; } if (itemInteraction){ event.getEntityPlayer().addChatMessage(new TextComponentString("You are not authorized use that item here.")); event.setCanceled(true); } } } I've shorten the code abit, these are the keyparts.
×
×
  • Create New...

Important Information

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