Skip to content

Commit

Permalink
add spawner highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
heckenmann committed May 7, 2020
1 parent d52d1cd commit 9149ecb
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 15 deletions.
Binary file removed screenshot.png
Binary file not shown.
Binary file removed screenshot2.png
Binary file not shown.
10 changes: 10 additions & 0 deletions src/main/java/de/heckenmann/mc/itemsonground/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class Configuration {
*/
private boolean enabled;

private boolean spawnerHighlightingEnabled;

/*
* Refresh-Threshold in ms.
*/
Expand All @@ -27,4 +29,12 @@ public void setEnabled(boolean enabled) {
public boolean isEnabled() {
return enabled;
}

public boolean isSpawnerHighlightingEnabled() {
return spawnerHighlightingEnabled;
}

public void setSpawnerHighlightingEnabled(boolean spawnerHighlightingEnabled) {
this.spawnerHighlightingEnabled = spawnerHighlightingEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
public class ItemsOnGroundAddon extends LabyModAddon {

private final Configuration configuration;
private ItemsOnGroundForgeListener listener;

private final String FIELD_NAME_ENABLED = "enabled";
private final String FIELD_NAME_SPAWNER_HIGHTLIGHTING_ENABLED = "spawnerHighlightingEnabled";
private final String FIELD_NAME_REFRESH_THRESHOLD = "refreshThreshold";

public ItemsOnGroundAddon() {
Expand All @@ -29,8 +29,9 @@ public void onEnable() {}
@Override
public void init(String addonName, UUID uuid) {
super.init(addonName, uuid);
this.listener = new ItemsOnGroundForgeListener(this.configuration);
getApi().registerForgeListener(this.listener);

getApi().registerForgeListener(new ItemsOnGroundHighlighter(this.configuration));
getApi().registerForgeListener(new SpawnerHighlighter(this.configuration));
}

@Override
Expand All @@ -39,6 +40,10 @@ public void loadConfig() {
getConfig().has(FIELD_NAME_ENABLED)
? getConfig().get(FIELD_NAME_ENABLED).getAsBoolean()
: true);
this.configuration.setSpawnerHighlightingEnabled(
getConfig().has(FIELD_NAME_SPAWNER_HIGHTLIGHTING_ENABLED)
? getConfig().get(FIELD_NAME_SPAWNER_HIGHTLIGHTING_ENABLED).getAsBoolean()
: false);
this.configuration.setRefreshThreshold(
getConfig().has(FIELD_NAME_REFRESH_THRESHOLD)
? getConfig().get(FIELD_NAME_REFRESH_THRESHOLD).getAsInt()
Expand All @@ -52,7 +57,7 @@ protected void fillSettings(List<SettingsElement> subSettings) {
new BooleanElement(
"Enabled",
this,
new ControlElement.IconData(Material.LEVER),
new ControlElement.IconData(Material.REDSTONE_LAMP_ON),
FIELD_NAME_ENABLED,
this.configuration.isEnabled()));
subSettings.add(
Expand All @@ -63,5 +68,12 @@ protected void fillSettings(List<SettingsElement> subSettings) {
FIELD_NAME_REFRESH_THRESHOLD,
this.configuration.getRefreshThreshold())
.setRange(0, 2000));
subSettings.add(
new BooleanElement(
"Spawner highlighting",
this,
new ControlElement.IconData(Material.MOB_SPAWNER),
FIELD_NAME_SPAWNER_HIGHTLIGHTING_ENABLED,
this.configuration.isSpawnerHighlightingEnabled()));
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package de.heckenmann.mc.itemsonground;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.*;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleCloud;
import net.minecraft.client.particle.ParticleFlame;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.stream.IntStream;
import java.util.stream.Stream;

/** @author heckenmann */
public class ItemsOnGroundForgeListener {
/**
* Dieser Listener highlightet Items, die auf dem Boden liegen.
*
* @author heckenmann
*/
public class ItemsOnGroundHighlighter {

private long lastTriggerTimestamp = 0;
private ParticleFlame.Factory particleFlameFactory;
private ParticleCloud.Factory particleCloudFactory;
private final Configuration configuration;

public ItemsOnGroundForgeListener(Configuration configuration) {
public ItemsOnGroundHighlighter(Configuration configuration) {
this.configuration = configuration;
this.createParticleFactory();
}
Expand All @@ -31,16 +34,16 @@ public void onTick(FOVUpdateEvent event) {
World world = Minecraft.getMinecraft().world;
long currentTriggerTimestamp = System.currentTimeMillis();
long timestampDelta = currentTriggerTimestamp - this.lastTriggerTimestamp;
if (!this.configuration.isEnabled()
|| world == null
if (world == null
|| !this.configuration.isEnabled()
|| timestampDelta < this.configuration.getRefreshThreshold()) return;
this.lastTriggerTimestamp = currentTriggerTimestamp;
// Highlight Items on Ground

world
.getLoadedEntityList()
.parallelStream()
.filter(entity -> EntityItem.class.equals(entity.getClass()))
.filter(entity -> entity.onGround || entity.isAirBorne)
// .filter(entity -> entity.onGround || entity.isAirBorne)
.map(entity -> createParticles(world, entity))
.flatMap(particleStream -> particleStream)
.sequential()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.heckenmann.mc.itemsonground;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleTotem;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.stream.IntStream;
import java.util.stream.Stream;

/** Dieser Listener highlightet Spawner über die gesamte Y-Achse. */
public class SpawnerHighlighter {

private long lastTriggerTimestamp = 0;
private final long thresholdMinMs = 500;
private final Configuration configuration;
private final IParticleFactory particleFactory;

public SpawnerHighlighter(Configuration configuration) {
this.configuration = configuration;
this.particleFactory = new ParticleTotem.Factory();
}

@SubscribeEvent
public void onTick(FOVUpdateEvent event) {
World world = Minecraft.getMinecraft().world;
long currentTriggerTimestamp = System.currentTimeMillis();
long timestampDelta = currentTriggerTimestamp - this.lastTriggerTimestamp;
if (world == null
|| !this.configuration.isEnabled()
|| !this.configuration.isSpawnerHighlightingEnabled()
|| timestampDelta < this.configuration.getRefreshThreshold() + this.thresholdMinMs) return;
this.lastTriggerTimestamp = currentTriggerTimestamp;

world
.loadedTileEntityList
.parallelStream()
.filter(entity -> TileEntityMobSpawner.class.equals(entity.getClass()))
.map(entity -> createParticlesForSpawner(world, entity.getPos()))
.flatMap(particleStream -> particleStream)
.sequential()
.forEach(particle -> Minecraft.getMinecraft().effectRenderer.addEffect(particle));
}

private Stream<Particle> createParticlesForSpawner(World world, BlockPos position) {
return IntStream.range(1, world.getActualHeight())
.asDoubleStream()
.mapToObj(
d ->
this.particleFactory.createParticle(
0, world, position.getX() + 0.5d, d, position.getZ() + 0.5d, 0.0, 1.0, 0.0));
}
}

0 comments on commit 9149ecb

Please sign in to comment.