Posted September 9, 201510 yr Hey guys! I am trying to make a portal. There are 3 custom blocks on each side and in the middle, one block down, there is the a 9x9 hole filled with lava (Kinda like the end-portal in the stronghold). And I can't figure out how to turn the lava blocks to a portal block if the player throws (Q-Button) a netherstar in the lava. I thought maybe I can check the entityitem's position to locate if there is lava or not.. But I never did stuff with EntityItem's or something so maybe someone can help me? thanks for your support!
September 9, 201510 yr Author Like the twilight forest portal with the flowers. In this case, the flowers are my custom blocks and the water is the lava. The item to summon the portal is the nether star.
September 9, 201510 yr I can't think of a graceful way to do this if you are throwing a vanilla item. It can be done, but it is a bit ugly. Now, if you create a custom item you are throwing in, then you can have a custom entityitem for that item. In that custom entityitem you can search for the conditions. Also you can keep the entity item from going poof on contact with the lava. Wait, on second though, look around for entity death event, check if it is an entityitem, then if it is a netherstar, then look for your conditions. That will probably work and is fairly easy. Long time Bukkit & Forge Programmer Happy to try and help
September 9, 201510 yr Wait, on second though, look around for entity death event, check if it is an entityitem, then if it is a netherstar, then look for your conditions. That will probably work and is fairly easy. There's no such event. LivingDeathEvent is only for living entities (i.e. entities that extend EntityLivingBase ). Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
September 9, 201510 yr Well so much for my memory. go with the first option. Long time Bukkit & Forge Programmer Happy to try and help
September 9, 201510 yr Author So should I make a boolean method to check if the custom blocks are there? And in the method where it will check the contact with lava I will first write an if-Statement and check if the boolean method returns true. If it returns true, I will replace the lava with the portal block..
September 9, 201510 yr Author Hm I was looking at the src of Twilight Forest. He uses a TickHandler.. there he checks the entityItem (i think). Then he calld the method createPortal.. Couldnt understand much of it because it was not deobfuscated.
September 9, 201510 yr He is doing it the very involved way I thought of. Do what I suggested, it will be easier on you. When you see your custom entityitem die (onDeath or something like that), do your search and if it is satisfied, build your portal. Long time Bukkit & Forge Programmer Happy to try and help
September 10, 201510 yr Author Hey guys! I made a custom entity item! So, if you drop a nether star, its entity item will actually convert to my custom entity item. I wrote "this.isImmuneToFire = true;" in my custom entity item class. It is immune to fire, but if I check if its in lava, it doesn't call everything.. I used the boolean "isInLava"... So do you have any thoughts of why it doesn't equal to true? Heres my event handler and EntityItem class: Event Handler: package netcrafter.mods.event; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityZombie; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.network.play.server.S42PacketCombatEvent.Event; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import netcrafter.mods.aoto.entity.item.AOTOEntityItem; import netcrafter.mods.aoto.init.AOTOItems; import netcrafter.mods.event.item.EntityItemDeathEvent; import netcrafter.mods.util.Helper; import akka.actor.ActorSystem.Settings; public class AOTOEventHandler { /*Test code @SubscribeEvent public void onEntityDrop(LivingDropsEvent event) { if(event.entityLiving instanceof EntityZombie) { event.entityLiving.dropItem(Items.diamond, 1); } } *///End of test code @SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event) { if( !event.world.isRemote && event.entity instanceof EntityItem && !(event.entity instanceof AOTOEntityItem) ) { EntityItem eItem = (EntityItem) event.entity; ItemStack stack = eItem.getEntityItem(); if(eItem.getEntityItem().getItem().getUnlocalizedName().equals(Items.nether_star.getUnlocalizedName())) { System.out.println("Its the nether star! Trying to remove it and replace it with another entity item!"); AOTOEntityItem aEntityItem = new AOTOEntityItem(event.world, eItem, eItem.getEntityItem()); event.world.spawnEntityInWorld(aEntityItem); eItem.setDead(); //Checking if E is dead and A is here. if(eItem.isDead && aEntityItem.isEntityAlive()) { System.out.println("E is dead and A is alive"); } int dx = MathHelper.floor_double(aEntityItem.motionX); int dy = MathHelper.floor_double(aEntityItem.motionY); int dz = MathHelper.floor_double(aEntityItem.motionZ); if(aEntityItem.isInLava()) { System.out.println("Item is in Lava and died"); WorldInfo wInfo = event.world.getWorldInfo(); event.world.addWeatherEffect(new EntityLightningBolt(event.world, dx, dy, dz)); wInfo.setRainTime(1000); wInfo.setThunderTime(1000); wInfo.setRaining(true); wInfo.setThundering(true); aEntityItem.setDead(); event.setCanceled(true); } } } } } Entity Item import java.lang.reflect.Field; import java.util.Hashtable; import net.minecraft.block.material.Material; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import netcrafter.mods.event.item.EntityItemDeathEvent; import netcrafter.mods.event.item.EntityItemHurtEvent; public class AOTOEntityItem extends EntityItem { private DamageSource previousDamageSource; public AOTOEntityItem(World world) { super(world); } public AOTOEntityItem(World world, EntityItem oldEntity, ItemStack stack) { super(world, oldEntity.posX, oldEntity.posY, oldEntity.posZ, stack); this.motionX = oldEntity.motionX; this.motionY = oldEntity.motionY; this.motionZ = oldEntity.motionZ; //this.age = oldEntity.age; <-- age is now private in 1.8 this.setPickupDelay(10); this.hoverStart = oldEntity.hoverStart; this.lifespan = oldEntity.lifespan; this.isImmuneToFire = true; } } Thanks to delpi for giving me the suggestion to create the custom entity item class.
September 10, 201510 yr Author I guess this.isImmuneToFire = true is not the best way to make it immune to fire.. It somehow makes the entity item invisible.. If I walk to the block where it its, it pops up again..
September 10, 201510 yr You should compare Item instances directly (e.g. someItemStack.getItem() == Items.nether_star ), don't compare their unlocalised names. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
September 10, 201510 yr Author I tried this: event.world.isAABBInMaterial(aEntityItem.getBoundingBox(), Material.lava) to check if it is in lava.. if (event.world.isAABBInMaterial(aEntityItem.getBoundingBox(), Material.lava)) { int dx = MathHelper.floor_double(aEntityItem.motionX); int dy = MathHelper.floor_double(aEntityItem.motionY); int dz = MathHelper.floor_double(aEntityItem.motionZ); if (((BlockRVPortal)AOTOBlocks.rvPortal).tryToCreatePortal(event.world, dx, dy, dz)) { WorldInfo wInfo = event.world.getWorldInfo(); event.world.addWeatherEffect(new EntityLightningBolt(event.world, dx, dy, dz)); wInfo.setRainTime(1000); wInfo.setThunderTime(1000); wInfo.setRaining(true); wInfo.setThundering(true); aEntityItem.setDead(); event.setCanceled(true); } } Still doesn't work.. But if gives me an error if I throw the nether star.. (But it doesn't crash) [18:55:59] [server thread/ERROR] [FML]: Index: 3 Listeners: [18:55:59] [server thread/ERROR] [FML]: 0: HIGHEST [18:55:59] [server thread/ERROR] [FML]: 1: ASM: net.minecraftforge.common.ForgeInternalHandler@7fb27a08 onEntityJoinWorld(Lnet/minecraftforge/event/entity/EntityJoinWorldEvent;)V [18:55:59] [server thread/ERROR] [FML]: 2: NORMAL [18:55:59] [server thread/ERROR] [FML]: 3: ASM: netcrafter.mods.aoto.event.AOTOEventHandler@4bfb3772 onEntityJoinWorld(Lnet/minecraftforge/event/entity/EntityJoinWorldEvent;)V [18:55:59] [server thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.NullPointerException java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.7.0_79] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.7.0_79] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:715) [FMLCommonHandler.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:727) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.7.0_79] Caused by: java.lang.NullPointerException at net.minecraft.world.World.isAABBInMaterial(World.java:2318) ~[World.class:?] at netcrafter.mods.aoto.event.AOTOEventHandler.onEntityJoinWorld(AOTOEventHandler.java:54) ~[AOTOEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_AOTOEventHandler_onEntityJoinWorld_EntityJoinWorldEvent.invoke(.dynamic) ~[?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55) ~[ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?] at net.minecraft.world.World.spawnEntityInWorld(World.java:1230) ~[World.class:?] at net.minecraft.entity.player.EntityPlayer.joinEntityItemWithWorld(EntityPlayer.java:934) ~[EntityPlayer.class:?] at net.minecraftforge.common.ForgeHooks.onPlayerTossEvent(ForgeHooks.java:421) ~[ForgeHooks.class:?] at net.minecraft.entity.player.EntityPlayer.dropOneItem(EntityPlayer.java:854) ~[EntityPlayer.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:513) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:53) ~[C07PacketPlayerDigging.class:?] at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:76) ~[C07PacketPlayerDigging.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.7.0_79] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.7.0_79] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) ~[FMLCommonHandler.class:?] ... 5 more Your right.. I changed it: if(stack.getItem() == Items.nether_star)
September 10, 201510 yr Author Well, I was dumb and put the bounding box in.. But I needed the entity bounding box.. Still doesn't work if I throw the item in the lava.. is AABB (entity bounding box) In Material (Material.lava)? The entity of the boats in minecraft does this too with water (Material.water) if (event.world.isAABBInMaterial(aEntityItem.getEntityBoundingBox(), Material.lava)) { int dx = MathHelper.floor_double(aEntityItem.motionX); int dy = MathHelper.floor_double(aEntityItem.motionY); int dz = MathHelper.floor_double(aEntityItem.motionZ); if (((BlockRVPortal)AOTOBlocks.rvPortal).tryToCreatePortal(event.world, dx, dy, dz)) { WorldInfo wInfo = event.world.getWorldInfo(); event.world.addWeatherEffect(new EntityLightningBolt(event.world, dx, dy, dz)); wInfo.setRainTime(1000); wInfo.setThunderTime(1000); wInfo.setRaining(true); wInfo.setThundering(true); aEntityItem.setDead(); event.setCanceled(true); } [spoiler/]
September 10, 201510 yr I don't think this should be in your event handler, since the item usually won't be in lava at the moment it's dropped. Entity#setOnFireFromLava will be called when the item is in lava, you should be able to override this to check for the portal activation criteria. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
September 10, 201510 yr Author Thanks, Choonster! Got it working now finally.. Is it neccesary to check if the item is in lava? Because the method is basically being called if it catches fire of lava.. But anyways, thanks very much to delpi and Choonster!
September 10, 201510 yr Is it neccesary to check if the item is in lava? Because the method is basically being called if it catches fire of lava.. It shouldn't be necessary to check if it's in lava, the method should only be called if it's already known that it is in lava. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
September 11, 201510 yr Author Hey guy's, i've found a new problem.. If I throw the nether star into the lava, it creates the portal, but sometimes it doesn't check if it is in lava.. So it only creates a portal every 10 times or something.. Any thoughts on why this is so? Custom Entity Item package netcrafter.mods.aoto.entity.item; import java.lang.reflect.Field; import java.util.Hashtable; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.common.MinecraftForge; import netcrafter.mods.aoto.blocks.BlockRVPortal; import netcrafter.mods.aoto.event.item.EntityItemDeathEvent; import netcrafter.mods.aoto.event.item.EntityItemHurtEvent; import netcrafter.mods.aoto.init.AOTOBlocks; public class RVSummonerEntityItem extends EntityItem { private DamageSource previousDamageSource; public RVSummonerEntityItem(World world) { super(world); } public RVSummonerEntityItem(World world, EntityItem oldEntity, ItemStack stack) { super(world, oldEntity.posX, oldEntity.posY, oldEntity.posZ, stack); this.motionX = oldEntity.motionX; this.motionY = oldEntity.motionY; this.motionZ = oldEntity.motionZ; //this.age = oldEntity.getAge(); this.setPickupDelay(60); this.hoverStart = oldEntity.hoverStart; this.lifespan = oldEntity.lifespan; //this.isImmuneToFire = true; } @Override public boolean attackEntityFrom(DamageSource dmgSource, float attackPts) { return !dmgSource.isFireDamage() && super.attackEntityFrom(dmgSource, attackPts); } @Override public void setOnFireFromLava() { //if (worldObj.isAABBInMaterial(this.getEntityBoundingBox(), Material.lava)) { //Get the position of the entity item int dx = MathHelper.floor_double(this.getPosition().getX()); int dy = MathHelper.floor_double(this.getPosition().getY()); int dz = MathHelper.floor_double(this.getPosition().getZ()); //try to create portal if(((BlockRVPortal)AOTOBlocks.rvPortal).tryToCreatePortal(worldObj, dx, dy, dz)) { WorldInfo wInfo = worldObj.getWorldInfo(); worldObj.addWeatherEffect(new EntityLightningBolt(worldObj, dx, dy, dz)); worldObj.setWorldTime(18000); wInfo.setRainTime(18000); wInfo.setThunderTime(18000); wInfo.setRaining(true); wInfo.setThundering(true); worldObj.setRainStrength(2); worldObj.setThunderStrength(2); this.setDead(); } //} } } Portal Block: package netcrafter.mods.aoto.blocks; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.init.Blocks; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import netcrafter.mods.aoto.init.AOTOBlocks; public class BlockRVPortal extends Block { public BlockRVPortal(Material materialIn) { super(materialIn); } public boolean tryToCreatePortal(World world, int dx, int dy, int dz) { if (isGoodPortalPool(world, dx, dy, dz)) { world.addWeatherEffect(new EntityLightningBolt(world, dx, dy, dz)); System.out.println("Yeah!"); transmuteWaterToPortal(world, dx, dy, dz); return true; } return false; } public void transmuteWaterToPortal(World world, int dx, int dy, int dz){ int px = dx; int pz = dz; if (world.getBlockState(new BlockPos(px - 1, dy, pz)).getBlock().getMaterial() == Material.lava) { px--; } if (world.getBlockState(new BlockPos(px, dy, pz - 1)).getBlock().getMaterial() == Material.lava) { pz--; } world.setBlockState(new BlockPos(px + 0, dy, pz + 0), AOTOBlocks.rvPortal.getDefaultState()); world.setBlockState(new BlockPos(px + 1, dy, pz + 0), AOTOBlocks.rvPortal.getDefaultState()); world.setBlockState(new BlockPos(px + 1, dy, pz + 1), AOTOBlocks.rvPortal.getDefaultState()); world.setBlockState(new BlockPos(px + 0, dy, pz + 1), AOTOBlocks.rvPortal.getDefaultState()); } public boolean isGoodPortalPool(World world, int dx, int dy, int dz) { boolean flag = false; flag |= isGoodPortalPoolStrict(world, dx + 0, dy, dz + 0); flag |= isGoodPortalPoolStrict(world, dx - 1, dy, dz - 1); flag |= isGoodPortalPoolStrict(world, dx + 0, dy, dz - 1); flag |= isGoodPortalPoolStrict(world, dx + 1, dy, dz - 1); flag |= isGoodPortalPoolStrict(world, dx - 1, dy, dz + 0); flag |= isGoodPortalPoolStrict(world, dx + 1, dy, dz + 0); flag |= isGoodPortalPoolStrict(world, dx - 1, dy, dz + 1); flag |= isGoodPortalPoolStrict(world, dx + 0, dy, dz + 1); flag |= isGoodPortalPoolStrict(world, dx + 1, dy, dz + 1); return flag; } public boolean isGoodPortalPoolStrict(World world, int dx, int dy, int dz) { boolean flag = true; flag &= world.getBlockState(new BlockPos(dx + 0, dy, dz + 0)).getBlock().getMaterial() == Material.lava; flag &= world.getBlockState(new BlockPos(dx + 1, dy, dz + 0)).getBlock().getMaterial() == Material.lava; flag &= world.getBlockState(new BlockPos(dx + 1, dy, dz + 1)).getBlock().getMaterial() == Material.lava; flag &= world.getBlockState(new BlockPos(dx + 0, dy, dz + 1)).getBlock().getMaterial() == Material.lava; flag &= isGrassOrDirt(world, dx - 1, dy, dz - 1); flag &= isGrassOrDirt(world, dx - 1, dy, dz + 0); flag &= isGrassOrDirt(world, dx - 1, dy, dz + 1); flag &= isGrassOrDirt(world, dx - 1, dy, dz + 2); flag &= isGrassOrDirt(world, dx + 0, dy, dz - 1); flag &= isGrassOrDirt(world, dx + 1, dy, dz - 1); flag &= isGrassOrDirt(world, dx + 0, dy, dz + 2); flag &= isGrassOrDirt(world, dx + 1, dy, dz + 2); flag &= isGrassOrDirt(world, dx + 2, dy, dz - 1); flag &= isGrassOrDirt(world, dx + 2, dy, dz + 0); flag &= isGrassOrDirt(world, dx + 2, dy, dz + 1); flag &= isGrassOrDirt(world, dx + 2, dy, dz + 2); flag &= world.getBlockState(new BlockPos(dx + 0, dy - 1, dz + 0)).getBlock().getMaterial().isSolid(); flag &= world.getBlockState(new BlockPos(dx + 1, dy - 1, dz + 0)).getBlock().getMaterial().isSolid(); flag &= world.getBlockState(new BlockPos(dx + 1, dy - 1, dz + 1)).getBlock().getMaterial().isSolid(); flag &= world.getBlockState(new BlockPos(dx + 0, dy - 1, dz + 1)).getBlock().getMaterial().isSolid(); flag &= isNatureBlock(world, dx - 1, dy + 1, dz - 1); flag &= isNatureBlock(world, dx - 1, dy + 1, dz + 0); flag &= isNatureBlock(world, dx - 1, dy + 1, dz + 1); flag &= isNatureBlock(world, dx - 1, dy + 1, dz + 2); flag &= isNatureBlock(world, dx + 0, dy + 1, dz - 1); flag &= isNatureBlock(world, dx + 1, dy + 1, dz - 1); flag &= isNatureBlock(world, dx + 0, dy + 1, dz + 2); flag &= isNatureBlock(world, dx + 1, dy + 1, dz + 2); flag &= isNatureBlock(world, dx + 2, dy + 1, dz - 1); flag &= isNatureBlock(world, dx + 2, dy + 1, dz + 0); flag &= isNatureBlock(world, dx + 2, dy + 1, dz + 1); flag &= isNatureBlock(world, dx + 2, dy + 1, dz + 2); return flag; } public boolean isNatureBlock(World world, int dx, int dy, int dz) { Block block = world.getBlockState(new BlockPos(dx, dy, dz)).getBlock(); if (block == AOTOBlocks.red_void_blocks) { return true; } return false; } public void func_149695_a(World world, int x, int y, int z, Block notUsed) { boolean good = true; if (world.getBlockState(new BlockPos(x - 1, y, z)) == this) { good &= isGrassOrDirt(world, x + 1, y, z); } else if (world.getBlockState(new BlockPos(x + 1, y, z)) == this) { good &= isGrassOrDirt(world, x - 1, y, z); } else { good = false; } if (world.getBlockState(new BlockPos(x, y, z - 1)) == this) { good &= isGrassOrDirt(world, x, y, z + 1); } else if (world.getBlockState(new BlockPos(x, y, z + 1)) == this) { good &= isGrassOrDirt(world, x, y, z - 1); } else { good = false; } if (!good) { world.setBlockState(new BlockPos(x, y, z), Blocks.lava.getDefaultState()); } } protected boolean isGrassOrDirt(World world, int dx, int dy, int dz) { return (world.getBlockState(new BlockPos(dx, dy, dz)).getBlock() == Blocks.obsidian); } }
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.