Skip to content

Commit

Permalink
SignHistorian - Added chat notification option for grief prevention.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed Apr 8, 2024
1 parent 9fa87fa commit 7118dfa
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/main/java/dev/stardust/modules/SignHistorian.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,20 @@ public SignHistorian() {
.build()
);

private final Setting<Boolean> chatNotification = sgPrevention.add(
new BoolSetting.Builder()
.name("Chat Notification")
.description("Warns you in chat when nearby signs are in danger of an approaching creeper.")
.defaultValue(true)
.build()
);

private final Setting<Double> alarmVolume = sgPrevention.add(
new DoubleSetting.Builder()
.name("Volume")
.sliderMax(0)
.sliderMax(200)
.defaultValue(100)
.defaultValue(0)
.build()
);

Expand Down Expand Up @@ -496,7 +504,9 @@ private boolean containsBlacklistedText(SignBlockEntity sbe) {
private boolean hasNearbySigns() {
if (mc.player == null || mc.world == null) return false;
for (BlockPos pos : BlockPos.iterateOutwards(mc.player.getBlockPos(), 5, 5, 5)) {
if (mc.world.getBlockEntity(pos) instanceof SignBlockEntity) return true;
if (mc.world.getBlockEntity(pos) instanceof SignBlockEntity sbe) {
if (sbe.getFrontText().hasText(mc.player) || sbe.getBackText().hasText(mc.player)) return true;
}
}
return false;
}
Expand Down Expand Up @@ -622,8 +632,6 @@ private void onBlockAttack(PacketEvent.Send event) {
+" | §3§lColor§7§l: "+ghost.getText(true).getColor().name()
+" | §f§lGlow Ink§7§l: "+ghost.getText(true).isGlowing()
));
event.cancel();
return;
}
}
}
Expand Down Expand Up @@ -703,11 +711,17 @@ else if (targeted == null) {
}
} else if (griefPrevention.get()) {
approachingCreepers.removeIf(Entity::isRemoved);
approachingCreepers.removeIf(creeper -> !creeper.getBlockPos().isWithinDistance(mc.player.getBlockPos(), 15));
approachingCreepers.removeIf(creeper -> !creeper.getBlockPos().isWithinDistance(mc.player.getBlockPos(), 12));
approachingCreepers.removeIf(creep -> creep.getBlockPos().isWithinDistance(trackedCreepers.get(creep.getId()), 2));

if (!approachingCreepers.isEmpty() && hasNearbySigns()) {
if (pingTicks == 0) {
mc.player.playSound(SoundEvents.ENTITY_PHANTOM_HURT, alarmVolume.get().floatValue(), 1f);
if (chatNotification.get()) {
mc.player.sendMessage(Text.of(
"§8<"+ StardustUtil.rCC()+"✨§8> [§5SignHistorian§8] §c§lNEARBY SIGNS IN DANGER OF MOB GRIEFING§7§l."
));
}
}
++pingTicks;
if (pingTicks >= 50) pingTicks = 0;
Expand All @@ -721,7 +735,7 @@ else if (hasNearbySigns()) {
BlockPos newPos = creeper.getBlockPos();
BlockPos lastPos = trackedCreepers.get(id);
if (!pPos.isWithinDistance(newPos, 15)) continue;
if (newPos.isWithinDistance(lastPos, 1)) {
if (newPos.isWithinDistance(lastPos, 2)) {
approachingCreepers.remove(creeper);
continue;
}
Expand Down Expand Up @@ -852,7 +866,7 @@ private void onRender3D(Render3DEvent event) {
}

approachingCreepers.removeIf(Entity::isRemoved);
approachingCreepers.removeIf(creeper -> !creeper.getBlockPos().isWithinDistance(mc.player.getBlockPos(), 15));
approachingCreepers.removeIf(creeper -> !creeper.getBlockPos().isWithinDistance(mc.player.getBlockPos(), 12));
if (griefPrevention.get() && !approachingCreepers.isEmpty() && hasNearbySigns()) {
SettingColor dangerColor = new SettingColor(255, 0, 25, 255);
for (CreeperEntity creeper : approachingCreepers) {
Expand Down

0 comments on commit 7118dfa

Please sign in to comment.