Jump to content

Triphion

Members
  • Posts

    122
  • Joined

  • Last visited

Posts posted by Triphion

  1. 21 hours ago, DefectiveProgram said:

    You're trying to call a client only function on the server.

     

    
    @Nullable
    @SideOnly(Side.CLIENT)
    public RayTraceResult rayTrace(double blockReachDistance, float partialTicks)
    {
        Vec3d vec3d = this.getPositionEyes(partialTicks);
        Vec3d vec3d1 = this.getLook(partialTicks);
        Vec3d vec3d2 = vec3d.addVector(vec3d1.xCoord * blockReachDistance, vec3d1.yCoord * blockReachDistance, vec3d1.zCoord * blockReachDistance);
        return this.world.rayTraceBlocks(vec3d, vec3d2, false, false, true);
    }

     

     

    14 hours ago, jabelar said:

    As mentioned you are trying to call a client method. Just copy the code (and any further client-only code involved) into your own method. You'll also need to modify the part regarding the reach distance. Overall ray-tracing is pretty simple concept so you should be able to implement your own version.

    Worked for me. A massive thanks to everyone who helped me! :D

  2. I do have a logger function, but only one that gets called preinit. If i want the logger function to get called, this way of doing it does work when im on singleplayer, however in server window, the log function never gets mentioned? 

    	@Override
    	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
    	{
    		if (!worldIn.isRemote)
    		{
    			EntityLivingBase player = ((EntityLivingBase)playerIn);
    			
    			RayTraceResult pos = player.rayTrace(22.0D, 20.0F);
    			double x = pos.getBlockPos().getX();
    			double y = pos.getBlockPos().getY() + 1.0D;
    			double z = pos.getBlockPos().getZ();
    			Utils.getLogger().info("Raytrace: " + pos.toString().substring(5));
    				
    				if (player.attemptTeleport(x, y, z)) 
    				{
    					player.getHeldItem(handIn).damageItem(1, playerIn);
    				}
    			}
    		else{
    		    return new ActionResult(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
    		}
    		
            return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    	}

     

  3. 49 minutes ago, Cadiboo said:

    Find out why (you think that) it’s not working

    Found it. 

    java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: net.minecraft.entity.EntityLivingBase.rayTrace(DF)Lnet/minecraft/util/math/RayTraceResult;
    	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_151]
    	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_151]
    	at net.minecraft.util.Util.runTask(Util.java:30) [Util.class:?]
    	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:754) [MinecraftServer.class:?]
    	at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:402) [DedicatedServer.class:?]
    	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:699) [MinecraftServer.class:?]
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:548) [MinecraftServer.class:?]
    	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
    Caused by: java.lang.NoSuchMethodError: net.minecraft.entity.EntityLivingBase.rayTrace(DF)Lnet/minecraft/util/math/RayTraceResult;
    	at com.triphion.ancient.items.ItemTheCosmician.onItemRightClick(ItemTheCosmician.java:45) ~[ItemTheCosmician.class:?]
    	at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:213) ~[ItemStack.class:?]
    	at net.minecraft.server.management.PlayerInteractionManager.processRightClick(PlayerInteractionManager.java:387) ~[PlayerInteractionManager.class:?]
    	at net.minecraft.network.NetHandlerPlayServer.processTryUseItem(NetHandlerPlayServer.java:739) ~[NetHandlerPlayServer.class:?]
    	at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:43) ~[CPacketPlayerTryUseItem.class:?]
    	at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:9) ~[CPacketPlayerTryUseItem.class:?]
    	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_151]
    	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_151]
    	at net.minecraft.util.Util.runTask(Util.java:29) ~[Util.class:?]
    	... 5 more
    [14:11:24] [Server thread/FATAL]: Error executing task

    This is the error and i have no idea how to fix it. The line that is the problem is the raytracing line that i talked about but i don't know more than this. 

    This is line 45:

    			RayTraceResult pos = player.rayTrace(22.0D, 20.0F);

    Any ideas? 

  4. Yes, that is the one. But now i realize the if(!worldIn.isRemote) but the raytracing isn't working serverside. Anything i'm missing? 

    Quote

        @Override
        public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
        {
            if (!worldIn.isRemote)
            {
                scala.Console.print("worki. ");
                
                EntityLivingBase player = ((EntityLivingBase)playerIn);
                    
                RayTraceResult pos = player.rayTrace(22.0D, 20.0F);
                double x = pos.getBlockPos().getX();
                double y = pos.getBlockPos().getY() + 1.0D;
                double z = pos.getBlockPos().getZ();
                    
                    if (player.attemptTeleport(x, y, z)) 
                    {
                        scala.Console.print("Teleported. ");
                        player.getHeldItem(handIn).damageItem(1, playerIn);
                    }
                }
            else{
                return new ActionResult(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
            }
            
            return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
        }

    Also, i added added a cast to the player saying it's an entitylivingbase, although the player class does extend entitylivingbase but i thought it could help just being even more specific. 

  5. So i tried with console-printing and when im on the server it doesn't get called after the if(!worldIn.isRemote) check for some reason. 

    	@Override
    	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
    	{
    		scala.Console.print("Gets called. ");
    		if (!worldIn.isRemote)
    		{
    			scala.Console.print("worki. ");
    			
    			RayTraceResult pos = playerIn.rayTrace(22.0D, 0.0F);
    			double x = pos.getBlockPos().getX();
    			double y = pos.getBlockPos().getY() + 1.0D;
    			double z = pos.getBlockPos().getZ();
    			
    			if (playerIn.attemptTeleport(x, y, z)) 
    			{
    				scala.Console.print("Teleported. ");
    				playerIn.getHeldItem(handIn).damageItem(1, playerIn);
    			}
    		}
    		else{
    		    return new ActionResult(EnumActionResult.FAIL, playerIn.getHeldItem(handIn));
    		}
    		
    		return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    	}

    Anything that seems to doesn't work on server here? 

     

    EDIT: I got a message from the server window that there's a problem with my raytracing apparently? Doesn't that get called correctly on server side, am i missing some important raytracing check for serverside? 

  6. 	@Override
    	public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
    	{
    		if(!playerIn.world.isRemote)
    		{
    			RayTraceResult pos = playerIn.rayTrace(22.0D, 0.0F);
    			double x = pos.getBlockPos().getX();
    			double y = pos.getBlockPos().getY() + 1.0D;
    			double z = pos.getBlockPos().getZ();
    			playerIn.setPositionAndUpdate(x, y, z);
    			playerIn.getHeldItem(handIn).damageItem(1, playerIn);
    			
    			return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    		}
    		
    		return new ActionResult(EnumActionResult.FAIL, playerIn.getHeldItem(handIn));
    	}

    I tried this, but now it doesn't work at all in server. Also tried with only checking if(!worldIn.isremote) but doesn't work in servers either. 

  7. So to get rid of a misunderstanding here, i can use the item, and it does teleport me if i click on the ground or something like 5 blocks away. However if i click beyond that then i will teleport to the position im looking at but right after the server will teleport me straight back to my beginning-position. It works on singleplayer, and the raytrace is further away than 5 blocks, it's actually a raytrace distance of 22 blocks. Any help would be much appreciated. 

    	@Override
    	public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
    	{
    		if(!playerIn.world.isRemote)
    		{
    			RayTraceResult pos = playerIn.rayTrace(22.0D, 0.0F);
    			double x = pos.getBlockPos().getX();
    			double y = pos.getBlockPos().getY() + 1.0D;
    			double z = pos.getBlockPos().getZ();
    			playerIn.setPositionAndUpdate(x, y, z);
    			worldIn.updateEntities();
    			playerIn.getHeldItem(handIn).damageItem(1, playerIn);
    			
    			return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    		}
    		
    		else if(playerIn.world.isRemote)
    		{
    			RayTraceResult pos = playerIn.rayTrace(22.0D, 0.0F);
    			double x = pos.getBlockPos().getX();
    			double y = pos.getBlockPos().getY() + 1.0D;
    			double z = pos.getBlockPos().getZ();
    			playerIn.setPositionAndUpdate(x, y, z);
    			worldIn.updateEntities();
    			playerIn.getHeldItem(handIn).damageItem(1, playerIn);
    			
    			return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    		}
    		
    		return new ActionResult(EnumActionResult.FAIL, playerIn.getHeldItem(handIn));
    	}

     

  8. 53 minutes ago, Draco18s said:

    Also, new EntityUndead is not the entity you clicked on. It's a new entity (as evidenced by the new keyword).

    Okay, so if i want the one i click on, i need to do it another way? This doesn't work unless i initialize it, but how do i initialize it properly?

    	@Override
    	public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer playerIn, EntityLivingBase entity, EnumHand hand) 
    	{
            if (entity.world.isRemote)
            {
                return false;
            }
            if (entity instanceof EntityUndead)
            {
            	EntityUndead undead;
            	undead.becomeAlly();
                return true;
            }
            return false;
        }

    I can't initialize it like i did before right? Since that'll not be called for the one i chose.

  9. 1 hour ago, diesieben07 said:

    Are you sure you are calling this method on the server and only the server?

    This is the code that i use to call the function in the entityclass. I use this in the itemclass. I think this is server only? Or is it the other way around?

    	@Override
    	public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer playerIn, EntityLivingBase entity, EnumHand hand) 
    	{
    		EntityUndead undead;
    		undead = new EntityUndead(entity.world);
    		
    		World world;
    		
            if (entity.world.isRemote)
            {
                return false;
            }
            if (entity instanceof EntityUndead)
            {
            	undead.becomeAlly();
                return true;
            }
            return false;
        }
  10. Well, the thing is that the for statement isn't getting executed. However the function gets executed as i wrote earlier. How would i execute the for statement properly?

    	public void becomeAlly() 
    	{
    		for(Object task : this.targetTasks.taskEntries.toArray())
    		{
    			 EntityAIBase ai = ((EntityAITaskEntry) task).action;
    			 if(ai instanceof EntityAINearestAttackableTarget)
    				 this.targetTasks.removeTask(ai); 
    		}
    		this.targetTasks.addTask(0, new EntityAINearestAttackableTarget(this, EntityMob.class, false)); 
     	}

    Tested a bit more and realized that the task that i added isn't getting added. Do i have to do this some other way altogether since the tasks doesn't seem to get updated? 

  11. 11 minutes ago, diesieben07 said:

    Why are you removing tasks while the entity is already alive?

    I'm doing that since the item that i use is supposed to turn a hostile undead into a friendly undead that attacks other mobs. That is why it needs to be alive, if i wanted it to be every new entity then that wouldn't be a problem but it needs to convert when i click the item. 

  12. The reason i know that the "becomeAlly" function is getting called is because i checked through console-printing. So i'm completely sure that the function gets called. 

    I have also tried putting brackets after the "if" such as this. 

        			 	if(ai instanceof EntityAINearestAttackableTarget){
        			 		this.targetTasks.removeTask(ai);}
    

    But that doesn't make any difference. 

  13. So, the problem lies in the code specifically since i can get access to the main function, but it won't remove or add my tasks. 

    Here is the function: 

    	public void becomeAlly() 
    	{
     		scala.Console.print("Success! ");
    		for(Object task : this.targetTasks.taskEntries.toArray())
        		{
        			 EntityAIBase ai = ((EntityAITaskEntry) task).action;
        			 	if(ai instanceof EntityAINearestAttackableTarget)
        			 		this.targetTasks.removeTask(ai); 
        		}
    		this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityMob.class, false)); 
    	}

     

  14. Is there a way to change the position and size of where the texture is being read? I'd really like to change it to something like the ghasts texture lineup without the need to change the model. I've been trying to change this for a while, but to no prevail. Any help is greatly appreciated. ^^

     

    The model and render gist - https://gist.github.com/triphion/a74e19a63f2522885da61adcb77617de

     

    EDIT: Could be worth pointing out that the model itself is like a square but a bit shorter in height. Also, the texture i have, is not the actual texture, but a test texture to see where the texture is being read. 

  15. Like this?

    LootPool pool = new LootPool(new LootEntry[] {entry = new LootEntryItem(itemIn, weightIn, qualityIn, functionsIn, conditionsIn, entryName)}, new LootCondition[0], 3, 2, "scrolls_pool");

    Well, i don't understand why 

    new LootEntryItem

    is the way to go though. 

    Also, what is the "function" parameter?

    This gives me a bunch of errors

    LootPool pool = new LootPool(new LootEntry[] {entry = new LootEntryItem(ModScrolls.scroll, 0, 0, 0, new LootCondition[0], "scroll")}, new LootCondition[0], 3, 2, "scrolls_pool");

    Lol, im hopeless, wow. 

  16. Aight, then what exactly does all the other parameters mean? Such as

    Quote
    
    <weight>, <quality>, <conditions>, <entryName>
    
    <conditions>, <rolls>, <bonusRolls>, <name>

    Like, what does that to my loot table? And what should i put in? 

     

    Would this be valid? 

    	@SubscribeEvent
    	public void lootLoad(LootTableLoadEvent evt) {
    	        /* do stuff with evt.getTable() like
    			LootTable table = evt.getTable();
    			LootTable merge = MyCustomTable;
    			table.mergePool(merge.getPool("main");
    			evt.setTable(table);
    			*/
    			String prefix = "minecraft:chests/";
    			String name = evt.getName().toString();
    
    			if (name.startsWith(prefix)) {
    				String file = name.substring(name.indexOf(prefix) + prefix.length());
    				switch (file) {
    				case "abandoned_mineshaft":
    				case "desert_pyramid":
    				case "jungle_temple":
    				case "simple_dungeon": evt.getTable().addPool(getInjectPool(file)); break;
    				case "spawn_bonus_chest":
    				case "stronghold_corridor":
    				case "village_blacksmith": evt.getTable().addPool(getInjectPool(file)); break;
    				default: break;
    				}
    			}
    	    }
    		private LootPool getInjectPool(String entryName) {
    			return new LootPool(new LootEntry[] { getInjectEntry(entryName, 1) }, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(0, 1), "dungeon_scrolls_pool");
    		}
    
    		private LootEntryTable getInjectEntry(String name, int weight) {
    			return new LootEntryTable(new ResourceLocation(Reference.MODID, "scrolls/" + name), weight, 0, new LootCondition[0], "dungeon_scrolls_entry");
    		}

    I do not quite understand the break function still tho. 

×
×
  • Create New...

Important Information

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