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
d39dd9e8
Commit
d39dd9e8
authored
Jul 16, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't allow interaction or damage messages from whitelist or blacklist entities
parent
05e3c903
Pipeline
#12673
passed with stages
in 2 minutes 5 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
MixinLivingEntity.java
src/main/java/com/owlmaddie/mixin/MixinLivingEntity.java
+22
-0
MixinMobEntity.java
src/main/java/com/owlmaddie/mixin/MixinMobEntity.java
+21
-0
No files found.
src/main/java/com/owlmaddie/mixin/MixinLivingEntity.java
View file @
d39dd9e8
package
com
.
owlmaddie
.
mixin
;
import
com.owlmaddie.chat.ChatDataManager
;
import
com.owlmaddie.commands.ConfigurationHandler
;
import
com.owlmaddie.network.ServerPackets
;
import
com.owlmaddie.utils.LivingEntityInterface
;
import
net.minecraft.entity.Entity
;
...
...
@@ -10,8 +11,10 @@ import net.minecraft.entity.mob.MobEntity;
import
net.minecraft.entity.passive.TameableEntity
;
import
net.minecraft.entity.player.PlayerEntity
;
import
net.minecraft.item.ItemStack
;
import
net.minecraft.registry.Registries
;
import
net.minecraft.server.network.ServerPlayerEntity
;
import
net.minecraft.text.Text
;
import
net.minecraft.util.Identifier
;
import
net.minecraft.world.World
;
import
org.spongepowered.asm.mixin.Mixin
;
import
org.spongepowered.asm.mixin.injection.At
;
...
...
@@ -19,6 +22,8 @@ import org.spongepowered.asm.mixin.injection.Inject;
import
org.spongepowered.asm.mixin.injection.callback.CallbackInfo
;
import
org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
;
import
java.util.List
;
@Mixin
(
LivingEntity
.
class
)
public
class
MixinLivingEntity
implements
LivingEntityInterface
{
...
...
@@ -44,6 +49,23 @@ public class MixinLivingEntity implements LivingEntityInterface {
// If PLAYER attacks MOB then
if
(
attacker
instanceof
PlayerEntity
&&
thisEntity
instanceof
MobEntity
&&
!
thisEntity
.
isDead
())
{
// Get config (whitelist / blacklist)
ConfigurationHandler
.
Config
config
=
new
ConfigurationHandler
(
ServerPackets
.
serverInstance
).
loadConfig
();
List
<
String
>
whitelist
=
config
.
getWhitelist
();
List
<
String
>
blacklist
=
config
.
getBlacklist
();
Identifier
entityId
=
Registries
.
ENTITY_TYPE
.
getId
(
thisEntity
.
getType
());
String
entityIdString
=
entityId
.
toString
();
if
(
blacklist
.
contains
(
entityIdString
))
{
// entity is black listed (no interacting)
return
;
}
if
(!
whitelist
.
isEmpty
()
&&
!
whitelist
.
contains
(
entityIdString
))
{
// entity is not white listed (no interacting)
return
;
}
// Generate attacked message (only if the previous user message was not an attacked message)
// We don't want to constantly generate messages during a prolonged, multi-damage event
ChatDataManager
chatDataManager
=
ChatDataManager
.
getServerInstance
();
...
...
src/main/java/com/owlmaddie/mixin/MixinMobEntity.java
View file @
d39dd9e8
package
com
.
owlmaddie
.
mixin
;
import
com.owlmaddie.chat.ChatDataManager
;
import
com.owlmaddie.commands.ConfigurationHandler
;
import
com.owlmaddie.network.ServerPackets
;
import
net.minecraft.entity.mob.MobEntity
;
import
net.minecraft.entity.player.PlayerEntity
;
import
net.minecraft.item.Item
;
import
net.minecraft.item.ItemStack
;
import
net.minecraft.item.Items
;
import
net.minecraft.registry.Registries
;
import
net.minecraft.server.network.ServerPlayerEntity
;
import
net.minecraft.util.ActionResult
;
import
net.minecraft.util.Hand
;
import
net.minecraft.util.Identifier
;
import
org.spongepowered.asm.mixin.Mixin
;
import
org.spongepowered.asm.mixin.injection.At
;
import
org.spongepowered.asm.mixin.injection.Inject
;
import
org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
;
import
java.util.List
;
/**
* The {@code MixinMobEntity} mixin class exposes the goalSelector field from the MobEntity class.
*/
...
...
@@ -26,6 +31,22 @@ public class MixinMobEntity {
ItemStack
itemStack
=
player
.
getStackInHand
(
hand
);
MobEntity
thisEntity
=
(
MobEntity
)
(
Object
)
this
;
// Get config (whitelist / blacklist)
ConfigurationHandler
.
Config
config
=
new
ConfigurationHandler
(
ServerPackets
.
serverInstance
).
loadConfig
();
List
<
String
>
whitelist
=
config
.
getWhitelist
();
List
<
String
>
blacklist
=
config
.
getBlacklist
();
Identifier
entityId
=
Registries
.
ENTITY_TYPE
.
getId
(
thisEntity
.
getType
());
String
entityIdString
=
entityId
.
toString
();
if
(
blacklist
.
contains
(
entityIdString
))
{
// entity is black listed (no interacting)
return
;
}
if
(!
whitelist
.
isEmpty
()
&&
!
whitelist
.
contains
(
entityIdString
))
{
// entity is not white listed (no interacting)
return
;
}
// Determine if the item is a bucket
// We don't want to interact on buckets
Item
item
=
itemStack
.
getItem
();
...
...
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