This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
agowa338's profile picture

ShootyTurtle damage Player

Started by agowa338, 28 February 2015 - 08:13 PM
agowa338 #1
Posted 28 February 2015 - 09:13 PM
I've written a small mod, that adds a ShootyTurtle (a Turtle with a bow).
Nearly everything is working except that players didn't get any damage, but Mobs do.

package de.agowa338.computercraft.turtle.turtle;

public class shootyTurtle extends anyToolTurtle {
	@Override
	public TurtleCommandResult useTool(ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction) {
		if (verb == TurtleVerb.Attack) {
			ItemStack currentItemStack = turtle.getInventory().getStackInSlot(turtle.getSelectedSlot());
			if (currentItemStack == null || !currentItemStack.getItem().equals(net.minecraft.item.Item.getItemById(262))) {
				return TurtleCommandResult.failure();
			} else {
				World world = turtle.getWorld();
				ChunkCoordinates chunkCoordinates = turtle.getPosition();
				TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer(world, chunkCoordinates, turtle, direction);

				EntityArrow entityArrow = new EntityArrow(world, turtlePlayer, 5F);
				//entityArrow.setDamage(2);
				//entityArrow.setIsCritical(true);
				//entityArrow.setKnockbackStrength(20);
				world.spawnEntityInWorld(entityArrow);
				//TODO: Player doesn't get any damage, Arrow is bouncing off players
				this.itemBow.onPlayerStoppedUsing(this.getItemStack(), world, turtlePlayer, 71971);

				return TurtleCommandResult.success();
			}
		} else {
			return TurtleCommandResult.failure("This Turtle cannot dig.");
		}
	}
}


Full Code: https://github.com/a...omputerCraftMod
Grim Reaper #2
Posted 04 March 2015 - 07:36 AM
I'm not familiar at all with Forge, Minecraft, or the code behind ComputerCraft, but my guess is that, perhaps, the turtle is recognized as an ally or something to that effect. Therefore, the arrow, having been fired by an allied entity, will cause the player no harm.
HPWebcamAble #3
Posted 05 March 2015 - 12:43 AM
I'm not familiar at all with Forge, Minecraft, or the code behind ComputerCraft, but my guess is that, perhaps, the turtle is recognized as an ally or something to that effect. Therefore, the arrow, having been fired by an allied entity, will cause the player no harm.

I don't think so. I guess you are referring to scoreboard teams because there is a setting where players on the same team can't damage each other. I don't think anything but players can be affected by it.

I don't code Mods often but this is what I would do
-Make sure you are in survival
-Does the arrow fired from the turtle behave like regular arrows in every other way?

If that doesn't help, try google if you haven't (Like 'minecraft forge adding arrows' or something)
agowa338 #4
Posted 07 March 2015 - 11:24 AM
The arrow behaves like any other arrow shooted by players and yes I'm in survival mode.

Ok, I found the bug, it's in the FakePlayer class which TurtlePlayer extends. There is the function canAttackPlayer which returns false.