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
1
Merge Requests
1
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
26ef75a1
Commit
26ef75a1
authored
Apr 03, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replacing reflection to use a mixin for accessing the GoalSelector.
parent
fa1841d6
Pipeline
#11931
passed with stage
in 20 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
19 deletions
+20
-19
GoalUtils.java
src/main/java/com/owlmaddie/goals/GoalUtils.java
+3
-18
MixinMobEntity.java
src/main/java/com/owlmaddie/mixin/MixinMobEntity.java
+15
-0
mobgpt.mixins.json
src/main/resources/mobgpt.mixins.json
+2
-1
No files found.
src/main/java/com/owlmaddie/goals/GoalUtils.java
View file @
26ef75a1
package
com
.
owlmaddie
.
goals
;
package
com
.
owlmaddie
.
goals
;
import
com.owlmaddie.mixin.MixinMobEntity
;
import
net.minecraft.entity.ai.goal.GoalSelector
;
import
net.minecraft.entity.ai.goal.GoalSelector
;
import
net.minecraft.entity.mob.MobEntity
;
import
net.minecraft.entity.mob.MobEntity
;
import
java.lang.reflect.Field
;
/**
/**
* The {@code GoalUtils} class uses reflection to extend the MobEntity class
* The {@code GoalUtils} class uses reflection to extend the MobEntity class
...
@@ -11,23 +11,8 @@ import java.lang.reflect.Field;
...
@@ -11,23 +11,8 @@ import java.lang.reflect.Field;
*/
*/
public
class
GoalUtils
{
public
class
GoalUtils
{
private
static
Field
goalSelectorField
;
static
{
try
{
goalSelectorField
=
MobEntity
.
class
.
getDeclaredField
(
"goalSelector"
);
goalSelectorField
.
setAccessible
(
true
);
}
catch
(
NoSuchFieldException
e
)
{
// Handle the exception, perhaps the field name has changed
}
}
public
static
GoalSelector
getGoalSelector
(
MobEntity
mobEntity
)
{
public
static
GoalSelector
getGoalSelector
(
MobEntity
mobEntity
)
{
try
{
MixinMobEntity
mixingEntity
=
(
MixinMobEntity
)
mobEntity
;
return
(
GoalSelector
)
goalSelectorField
.
get
(
mobEntity
);
return
mixingEntity
.
getGoalSelector
();
}
catch
(
IllegalAccessException
e
)
{
// Handle the exception
return
null
;
}
}
}
}
}
src/main/java/com/owlmaddie/mixin/MixinMobEntity.java
0 → 100644
View file @
26ef75a1
package
com
.
owlmaddie
.
mixin
;
import
org.spongepowered.asm.mixin.Mixin
;
import
net.minecraft.entity.mob.MobEntity
;
import
org.spongepowered.asm.mixin.gen.Accessor
;
import
net.minecraft.entity.ai.goal.GoalSelector
;
/**
* The {@code MixinMobEntity} mixin class exposes the goalSelector field from the MobEntity class.
*/
@Mixin
(
MobEntity
.
class
)
public
interface
MixinMobEntity
{
@Accessor
(
"goalSelector"
)
public
GoalSelector
getGoalSelector
();
}
\ No newline at end of file
src/main/resources/mobgpt.mixins.json
View file @
26ef75a1
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
"package"
:
"com.owlmaddie.mixin"
,
"package"
:
"com.owlmaddie.mixin"
,
"compatibilityLevel"
:
"JAVA_17"
,
"compatibilityLevel"
:
"JAVA_17"
,
"mixins"
:
[
"mixins"
:
[
"ExampleMixin"
"ExampleMixin"
,
"MixinMobEntity"
],
],
"injectors"
:
{
"injectors"
:
{
"defaultRequire"
:
1
"defaultRequire"
:
1
...
...
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