-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial functionality complete, NMS v1_12_R1
- Loading branch information
1 parent
2f7b5c5
commit 5fc8620
Showing
3 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
out/ | ||
.idea/ | ||
UnbreakableSpawners.iml |
49 changes: 49 additions & 0 deletions
49
src/com/gmail/profanedbane/UnbreakableSpawners/UnbreakableSpawners.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,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(); | ||
} | ||
} | ||
} | ||
|
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,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. |