Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make End Enderman have teleport cooldowns via configuration #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"config.endermanoverhaul.allowPickingUpBlocks": "Allow Picking Up Blocks",
"config.endermanoverhaul.allowSpawning": "Allow Spawning",
"config.endermanoverhaul.endEndermanTeleportChance": "End Enderman Teleport Chance",
"config.endermanoverhaul.endEndermanTeleportCooldown": "End Enderman Teleport Cooldown",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be replaced every time datagen is run. Must be put in the ModLangProvider. then run datagen

"config.endermanoverhaul.friendlyEndermanDespawn": "Friendly Enderman Despawn",
"config.endermanoverhaul.friendlyEndermanTeleport": "Friendly Enderman Teleport",
"config.endermanoverhaul.replaceDefaultEnderman": "Replace Default Enderman",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,12 @@ public final class EndermanOverhaulConfig {
)
@Comment("The chance that an End Enderman will teleport you when it hits you")
public static float endEndermanTeleportChance = 0.5f;

@ConfigEntry(
id = "endEndermanTeleportCooldown",
type = EntryType.INTEGER,
translation = "config.endermanoverhaul.endEndermanTeleportCooldown"
)
@Comment("The cooldown time in seconds that enderman have before they can teleport you again")
public static int endEndermanTeleportCooldown = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
import tech.alexnijjar.endermanoverhaul.common.entities.base.BaseEnderman;
import tech.alexnijjar.endermanoverhaul.common.registry.ModSoundEvents;

import java.util.Date;

public class EndEnderman extends BaseEnderman {
private static final EntityDataAccessor<Integer> DATA_BITING_TICKS = SynchedEntityData.defineId(EndEnderman.class, EntityDataSerializers.INT);

private long lastTeleportTime = 0L;
public EndEnderman(EntityType<? extends EnderMan> entityType, Level level) {
super(entityType, level);
xpReward = 8;
Expand Down Expand Up @@ -128,8 +131,11 @@ public boolean doHurtTarget(@NotNull Entity target) {
if (super.doHurtTarget(target)) {
this.playSound(SoundEvents.PHANTOM_BITE, 10.0f, 0.95f + this.random.nextFloat() * 0.1f);
entityData.set(DATA_BITING_TICKS, 7);
if (target instanceof LivingEntity entity && random.nextFloat() < EndermanOverhaulConfig.endEndermanTeleportChance) {
final long currentTime = new Date().getTime();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use Date. Find the difference using tickcount.

final long differenceSeconds = (currentTime - this.lastTeleportTime) / 1000;
if (target instanceof LivingEntity entity && random.nextFloat() < EndermanOverhaulConfig.endEndermanTeleportChance && differenceSeconds > EndermanOverhaulConfig.endEndermanTeleportCooldown) {
ModUtils.teleportTarget(level(), entity, 24);
this.lastTeleportTime = currentTime;
}
return true;
} else {
Expand Down