Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
552e5e33
Commit
552e5e33
authored
Jul 03, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing issues with setting attacker and not allowing entities to target or attack themselves
parent
437a3695
Pipeline
#12564
passed with stages
in 2 minutes 11 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
6 deletions
+11
-6
AttackPlayerGoal.java
src/main/java/com/owlmaddie/goals/AttackPlayerGoal.java
+10
-5
ProtectPlayerGoal.java
src/main/java/com/owlmaddie/goals/ProtectPlayerGoal.java
+1
-1
No files found.
src/main/java/com/owlmaddie/goals/AttackPlayerGoal.java
View file @
552e5e33
...
@@ -33,11 +33,6 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
...
@@ -33,11 +33,6 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
this
.
attackerEntity
=
attackerEntity
;
this
.
attackerEntity
=
attackerEntity
;
this
.
speed
=
speed
;
this
.
speed
=
speed
;
this
.
setControls
(
EnumSet
.
of
(
Control
.
MOVE
,
Control
.
LOOK
,
Control
.
TARGET
));
this
.
setControls
(
EnumSet
.
of
(
Control
.
MOVE
,
Control
.
LOOK
,
Control
.
TARGET
));
// Set the target
if
(
this
.
targetEntity
!=
null
)
{
this
.
attackerEntity
.
setTarget
(
this
.
targetEntity
);
}
}
}
@Override
@Override
...
@@ -59,6 +54,11 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
...
@@ -59,6 +54,11 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
return
false
;
return
false
;
}
}
// Set the attack target (if not self)
if
(!
this
.
attackerEntity
.
equals
(
this
.
targetEntity
))
{
this
.
attackerEntity
.
setTarget
(
this
.
targetEntity
);
}
// Is nearby to target
// Is nearby to target
boolean
isNearby
=
this
.
attackerEntity
.
squaredDistanceTo
(
this
.
targetEntity
)
<
MOVE_DISTANCE
;
boolean
isNearby
=
this
.
attackerEntity
.
squaredDistanceTo
(
this
.
targetEntity
)
<
MOVE_DISTANCE
;
...
@@ -82,6 +82,11 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
...
@@ -82,6 +82,11 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
}
}
private
void
performAttack
()
{
private
void
performAttack
()
{
// Track the attacker (needed for protect to work)
if
(!
this
.
attackerEntity
.
equals
(
this
.
targetEntity
))
{
this
.
targetEntity
.
setAttacker
(
this
.
attackerEntity
);
}
// For passive entities (or hostile in creative mode), apply minimal damage to simulate a 'leap' / 'melee' attack
// For passive entities (or hostile in creative mode), apply minimal damage to simulate a 'leap' / 'melee' attack
this
.
targetEntity
.
damage
(
this
.
attackerEntity
.
getDamageSources
().
generic
(),
1.0
F
);
this
.
targetEntity
.
damage
(
this
.
attackerEntity
.
getDamageSources
().
generic
(),
1.0
F
);
...
...
src/main/java/com/owlmaddie/goals/ProtectPlayerGoal.java
View file @
552e5e33
...
@@ -21,7 +21,7 @@ public class ProtectPlayerGoal extends AttackPlayerGoal {
...
@@ -21,7 +21,7 @@ public class ProtectPlayerGoal extends AttackPlayerGoal {
public
boolean
canStart
()
{
public
boolean
canStart
()
{
MobEntity
lastAttackedByEntity
=
(
MobEntity
)
this
.
protectedEntity
.
getLastAttacker
();
MobEntity
lastAttackedByEntity
=
(
MobEntity
)
this
.
protectedEntity
.
getLastAttacker
();
int
i
=
this
.
protectedEntity
.
getLastAttackedTime
();
int
i
=
this
.
protectedEntity
.
getLastAttackedTime
();
if
(
i
!=
this
.
lastAttackedTime
&&
lastAttackedByEntity
!=
null
)
{
if
(
i
!=
this
.
lastAttackedTime
&&
lastAttackedByEntity
!=
null
&&
!
this
.
attackerEntity
.
equals
(
lastAttackedByEntity
)
)
{
// Set target to attack
// Set target to attack
this
.
lastAttackedTime
=
i
;
this
.
lastAttackedTime
=
i
;
this
.
targetEntity
=
lastAttackedByEntity
;
this
.
targetEntity
=
lastAttackedByEntity
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment