-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
422 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
React/src/main/java/com/volmit/react/content/feature/FeatureSpawnOptimizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.volmit.react.content.feature; | ||
|
||
import com.volmit.react.React; | ||
import com.volmit.react.api.feature.ReactFeature; | ||
import com.volmit.react.content.sampler.SamplerEntities; | ||
import com.volmit.react.core.NMS; | ||
import com.volmit.react.core.controller.EntityController; | ||
import com.volmit.react.model.ReactEntity; | ||
import com.volmit.react.util.format.Form; | ||
import com.volmit.react.util.math.RNG; | ||
import com.volmit.react.util.scheduling.J; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Chunk; | ||
import org.bukkit.Location; | ||
import org.bukkit.attribute.Attribute; | ||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.CreatureSpawnEvent; | ||
import org.bukkit.event.entity.EntityDamageByBlockEvent; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
import org.bukkit.event.entity.EntitySpawnEvent; | ||
import org.bukkit.util.Vector; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class FeatureSpawnOptimizer extends ReactFeature implements Listener { | ||
public static final String ID = "spawn-optimizer"; | ||
private transient Map<Chunk, List<EntityType>> spawns; | ||
private transient Map<Chunk, Location> averageLocation; | ||
private transient FeatureMobStacking stacker; | ||
|
||
public FeatureSpawnOptimizer() { | ||
super(ID); | ||
} | ||
|
||
@Override | ||
public void onActivate() { | ||
spawns = new HashMap<>(); | ||
averageLocation = new HashMap<>(); | ||
stacker = React.feature(FeatureMobStacking.class); | ||
} | ||
|
||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) | ||
public void on(CreatureSpawnEvent e) { | ||
if(e.getEntityType().equals(EntityType.GLOW_SQUID)) { | ||
return; | ||
} | ||
|
||
if(e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) || e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.BEEHIVE) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.DISPENSE_EGG) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NETHER_PORTAL) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.PATROL) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SILVERFISH_BLOCK) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.VILLAGE_INVASION) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.RAID) | ||
|| e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.REINFORCEMENTS) | ||
|
||
) { | ||
e.setCancelled(true); | ||
Chunk c = e.getLocation().getChunk(); | ||
spawns.computeIfAbsent(c, k -> new ArrayList<>()).add(e.getEntityType()); | ||
averageLocation.put(c, e.getLocation()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDeactivate() { | ||
|
||
} | ||
|
||
@Override | ||
public int getTickInterval() { | ||
return 1000; | ||
} | ||
|
||
public void push(Chunk c) { | ||
List<EntityType> entities = spawns.get(c); | ||
|
||
if(entities != null && !entities.isEmpty()) { | ||
Location at = averageLocation.get(c); | ||
Map<EntityType, Integer> oc = new HashMap<>(); | ||
|
||
for(EntityType i : entities) { | ||
oc.compute(i, (k,v) -> v == null ? 1 : v + 1); | ||
} | ||
|
||
for(EntityType i : oc.keySet()) { | ||
if(stacker.isEnabled()) { | ||
int r = oc.get(i); | ||
while(r > 0) { | ||
Entity e = c.getWorld().spawnEntity(at, i); | ||
int max = Math.min(r, stacker.getTheoreticalMaxStackCount(e)); | ||
stacker.setStackCount(e, max); | ||
r -= max; | ||
} | ||
} | ||
|
||
else { | ||
for(int j = 0; j < oc.get(i); j++) { | ||
c.getWorld().spawnEntity(at, i); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onTick() { | ||
J.s(() -> { | ||
for(Chunk i : spawns.keySet()) { | ||
push(i); | ||
} | ||
|
||
spawns.clear(); | ||
averageLocation.clear(); | ||
}); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
React/src/main/java/com/volmit/react/content/tweak/TweakFastEntityIncineration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.volmit.react.content.tweak; | ||
|
||
import com.volmit.react.React; | ||
import com.volmit.react.api.tweak.ReactTweak; | ||
import com.volmit.react.core.controller.EntityController; | ||
import com.volmit.react.model.ReactEntity; | ||
import com.volmit.react.util.scheduling.J; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Monster; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class TweakFastEntityIncineration extends ReactTweak implements Listener { | ||
public static final String ID = "fast-entity-incineration"; | ||
private double incinerationBeyondNearestPlayer = 32; | ||
|
||
public TweakFastEntityIncineration() { | ||
super(ID); | ||
} | ||
|
||
@Override | ||
public void onActivate() { | ||
|
||
} | ||
|
||
@EventHandler | ||
public void on(EntityDamageEvent e) { | ||
if(e.getCause().equals(EntityDamageEvent.DamageCause.FIRE_TICK) && e.getEntity() instanceof Monster m && React.hasNearbyPlayer(m.getLocation(), incinerationBeyondNearestPlayer)) { | ||
m.damage(1000); | ||
} | ||
} | ||
|
||
private void kill(Entity entity) { | ||
J.s(() -> React.kill(entity), (int) (20 * Math.random())); | ||
} | ||
|
||
@Override | ||
public void onDeactivate() { | ||
|
||
} | ||
|
||
@Override | ||
public int getTickInterval() { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public void onTick() { | ||
|
||
} | ||
} |
Oops, something went wrong.