Skip to content

Commit

Permalink
initial functionality complete, NMS v1_12_R1
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfanedBane committed Apr 8, 2020
1 parent 2f7b5c5 commit 5fc8620
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
out/
.idea/
UnbreakableSpawners.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.gmail.profanedbane.UnbreakableSpawners;

import net.minecraft.server.v1_12_R1.Block;
import org.bukkit.plugin.java.JavaPlugin;

import java.lang.reflect.Field;

// overrides mob spawners to be bedrock tier
public class UnbreakableSpawners extends JavaPlugin {

// store old field values to revert to on stop
private Block spawner = Block.getByName("mob_spawner");
private Field durability;
private Field strength;
private float oldDurability;
private float oldStrength;

@Override
public void onLoad(){
try {
durability = Block.class.getDeclaredField("durability");
strength = Block.class.getDeclaredField("strength");
durability.setAccessible(true);
strength.setAccessible(true);

oldDurability = durability.getFloat(spawner);
oldStrength = strength.getFloat(spawner);

durability.set(spawner, 3600000f);
strength.set(spawner, -1f);

} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}

// apparantly best practice is to revert on stop
@Override
public void onDisable(){
try {
durability.set(spawner, oldDurability);
strength.set(spawner, oldStrength);

} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}

5 changes: 5 additions & 0 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: UnbreakableSpawners
version: 1.0.0
author: ProfanedBane
main: com.gmail.profanedbane.UnbreakableSpawners.UnbreakableSpawners
description: NMS override to make mob spawners as strong as bedrock.

0 comments on commit 5fc8620

Please sign in to comment.