Fix bug with bounds causing a crash
Implement in-game particle cycling
This commit is contained in:
@@ -72,9 +72,9 @@ public class CaveDust implements ClientModInitializer {
|
|||||||
|
|
||||||
for (int i = 0; i < probabilityNormalized * config.getParticleMultiplier() * 10; i++) {
|
for (int i = 0; i < probabilityNormalized * config.getParticleMultiplier() * 10; i++) {
|
||||||
try {
|
try {
|
||||||
double x = client.player.getPos().getX() + generateRandomDouble(-config.getDimensionsX(), config.getDimensionsX());
|
double x = client.player.getPos().getX() + generateRandomDouble(config.getDimensionsX() * -1, config.getDimensionsX());
|
||||||
double y = client.player.getPos().getY() + generateRandomDouble(-config.getDimensionsY(), config.getDimensionsY());
|
double y = client.player.getPos().getY() + generateRandomDouble(config.getDimensionsY() * -1, config.getDimensionsY());
|
||||||
double z = client.player.getPos().getZ() + generateRandomDouble(-config.getDimensionsZ(), config.getDimensionsZ());
|
double z = client.player.getPos().getZ() + generateRandomDouble(config.getDimensionsZ() * -1, config.getDimensionsZ());
|
||||||
BlockPos particlePos = new BlockPos(x, y, z);
|
BlockPos particlePos = new BlockPos(x, y, z);
|
||||||
|
|
||||||
if (!shouldParticlesSpawn(client, config, particlePos)){return;}
|
if (!shouldParticlesSpawn(client, config, particlePos)){return;}
|
||||||
|
|||||||
@@ -14,62 +14,59 @@ public class CaveDustConfig extends JsonFile {
|
|||||||
private transient final net.lizistired.cavedust.CaveDust CaveDust;
|
private transient final net.lizistired.cavedust.CaveDust CaveDust;
|
||||||
|
|
||||||
|
|
||||||
private int dimensionMaxX = 5;
|
private int dimensionX = 5;
|
||||||
private int dimensionMaxY = 5;
|
private int dimensionY = 5;
|
||||||
private int dimensionMaxZ = 5;
|
private int dimensionZ = 5;
|
||||||
private int dimensionMinX = -5;
|
|
||||||
private int dimensionMinY = -5;
|
|
||||||
private int dimensionMinZ = -5;
|
|
||||||
private int velocityRandomness = 1;
|
private int velocityRandomness = 1;
|
||||||
|
|
||||||
private boolean caveDustEnabled = true;
|
private boolean caveDustEnabled = true;
|
||||||
private String particleName = "white_ash";
|
|
||||||
private boolean seaLevelCheck = true;
|
private boolean seaLevelCheck = true;
|
||||||
private boolean superFlatStatus = false;
|
private boolean superFlatStatus = false;
|
||||||
//private boolean enhancedDetection = true;
|
|
||||||
private float upperLimit = 64;
|
private float upperLimit = 64;
|
||||||
private float lowerLimit = -64;
|
private float lowerLimit = -64;
|
||||||
private int particleMultiplier = 1;
|
private int particleMultiplier = 1;
|
||||||
|
|
||||||
|
private int particleID = 79;
|
||||||
|
|
||||||
public CaveDustConfig(Path file, net.lizistired.cavedust.CaveDust caveDust) {
|
public CaveDustConfig(Path file, net.lizistired.cavedust.CaveDust caveDust) {
|
||||||
super(file);
|
super(file);
|
||||||
this.CaveDust = caveDust;
|
this.CaveDust = caveDust;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float setDimensionsX(float size){
|
public float setDimensionsX(float size){
|
||||||
if (this.dimensionMinX != size) {
|
if (this.dimensionX != size) {
|
||||||
this.dimensionMinX = (int)size;
|
this.dimensionX = (int)size;
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
return getDimensionsX();
|
return getDimensionsX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float setDimensionsY(float size){
|
public float setDimensionsY(float size){
|
||||||
if (this.dimensionMinY != size) {
|
if (this.dimensionY != size) {
|
||||||
this.dimensionMinY = (int)size;
|
this.dimensionY = (int)size;
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
return getDimensionsY();
|
return getDimensionsY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float setDimensionsZ(float size){
|
public float setDimensionsZ(float size){
|
||||||
if (this.dimensionMinZ != size) {
|
if (this.dimensionZ != size) {
|
||||||
this.dimensionMinZ = (int)size;
|
this.dimensionZ = (int)size;
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
return getDimensionsZ();
|
return getDimensionsZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDimensionsX(){
|
public float getDimensionsX(){
|
||||||
return dimensionMinX;
|
return dimensionX;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDimensionsY(){
|
public float getDimensionsY(){
|
||||||
return dimensionMinY;
|
return dimensionY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDimensionsZ(){
|
public float getDimensionsZ(){
|
||||||
return dimensionMinZ;
|
return dimensionZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float setUpperLimit(float upperLimit){
|
public float setUpperLimit(float upperLimit){
|
||||||
@@ -125,20 +122,13 @@ public class CaveDustConfig extends JsonFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ParticleEffect setParticle(String particleType){
|
public ParticleEffect setParticle(String particleType){
|
||||||
particleName = particleType;
|
//particleName = particleType;
|
||||||
save();
|
save();
|
||||||
return getParticle();
|
return getParticle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParticleEffect getParticle(){
|
public ParticleEffect getParticle(){
|
||||||
try {
|
return (ParticleEffect) Registries.PARTICLE_TYPE.get(new Identifier(Registries.PARTICLE_TYPE.getEntry(getParticleID()).get().getKey().get().getValue().toString().toLowerCase()));
|
||||||
return (ParticleEffect) Registries.PARTICLE_TYPE.get(new Identifier(particleName.toLowerCase()));
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
LOGGER.error(e + "\nThere was an error loading the specified particle from the config, make sure a valid particle name is specified. Falling back to \"minecraft:white_ash\".");
|
|
||||||
particleName = "minecraft:white_ash";
|
|
||||||
save();
|
|
||||||
return ParticleTypes.WHITE_ASH;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSeaLevelCheck() {
|
public boolean getSeaLevelCheck() {
|
||||||
@@ -176,24 +166,24 @@ public class CaveDustConfig extends JsonFile {
|
|||||||
return getSuperFlatStatus();
|
return getSuperFlatStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public boolean getEnhancedDetection(){
|
public void iterateParticle(){
|
||||||
return enhancedDetection;
|
if(getParticleID() > Registries.PARTICLE_TYPE.size() - 2) {
|
||||||
|
particleID = 1;
|
||||||
|
save();
|
||||||
|
} else {
|
||||||
|
particleID = getParticleID() + 1;
|
||||||
|
save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setEnhancedDetection(){
|
public int getParticleID(){
|
||||||
enhancedDetection = !enhancedDetection;
|
return particleID;
|
||||||
save();
|
}
|
||||||
return getEnhancedDetection();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public void resetConfig(){
|
public void resetConfig(){
|
||||||
dimensionMinX = -5;
|
dimensionX = 5;
|
||||||
dimensionMinY = -5;
|
dimensionY = 5;
|
||||||
dimensionMinZ = -5;
|
dimensionZ = 5;
|
||||||
|
|
||||||
dimensionMaxX = 5;
|
|
||||||
dimensionMaxY = 5;
|
|
||||||
dimensionMaxZ = 5;
|
|
||||||
|
|
||||||
upperLimit = 64;
|
upperLimit = 64;
|
||||||
lowerLimit = -64;
|
lowerLimit = -64;
|
||||||
@@ -202,7 +192,7 @@ public class CaveDustConfig extends JsonFile {
|
|||||||
|
|
||||||
seaLevelCheck = true;
|
seaLevelCheck = true;
|
||||||
caveDustEnabled = true;
|
caveDustEnabled = true;
|
||||||
particleName = "minecraft:white_ash";
|
particleID = 79;
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.minelittlepony.common.client.gui.element.*;
|
|||||||
import net.lizistired.cavedust.utils.TranslatableTextHelper;
|
import net.lizistired.cavedust.utils.TranslatableTextHelper;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.particle.ParticleEffect;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -79,6 +81,12 @@ public class ModMenuConfigScreen extends GameGui {
|
|||||||
.setTextFormat(transText::formatVelocityRandomness)
|
.setTextFormat(transText::formatVelocityRandomness)
|
||||||
.getStyle().setTooltip(Text.translatable("menu.cavedust.velocityrandomness.tooltip"));
|
.getStyle().setTooltip(Text.translatable("menu.cavedust.velocityrandomness.tooltip"));
|
||||||
|
|
||||||
|
addButton(new Button(left, row += 24).onClick(sender ->{
|
||||||
|
config.iterateParticle();
|
||||||
|
sender.getStyle().setText("Particle: " + (getNameOfParticle()));
|
||||||
|
})).getStyle().setText("Particle: " + (getNameOfParticle()))
|
||||||
|
.setTooltip(Text.translatable("menu.cavedust.particle.tooltip"));
|
||||||
|
|
||||||
addButton(new Button(left, row += 24).onClick(sender -> {
|
addButton(new Button(left, row += 24).onClick(sender -> {
|
||||||
config.resetConfig();
|
config.resetConfig();
|
||||||
finish();
|
finish();
|
||||||
@@ -96,4 +104,9 @@ public class ModMenuConfigScreen extends GameGui {
|
|||||||
renderBackground(matrices);
|
renderBackground(matrices);
|
||||||
super.render(matrices, mouseX, mouseY, partialTicks);
|
super.render(matrices, mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
private String getNameOfParticle(){
|
||||||
|
CaveDustConfig config = CaveDust.getInstance().getConfig();
|
||||||
|
config.load();
|
||||||
|
return Registries.PARTICLE_TYPE.getEntry(config.getParticleID()).get().getKey().get().getValue().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package net.lizistired.cavedust.utils;
|
|||||||
import com.minelittlepony.common.client.gui.element.AbstractSlider;
|
import com.minelittlepony.common.client.gui.element.AbstractSlider;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
public class TranslatableTextHelper {
|
public class TranslatableTextHelper {
|
||||||
public Text formatMaxX(AbstractSlider<Float> slider) {
|
public Text formatMaxX(AbstractSlider<Float> slider) {
|
||||||
return Text.translatable("menu.cavedust.X", (int)Math.floor(slider.getValue()));
|
return Text.translatable("menu.cavedust.X", (int)Math.floor(slider.getValue()));
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
"menu.cavedust.superflatstatus.true": "Superflat particles: Enabled",
|
"menu.cavedust.superflatstatus.true": "Superflat particles: Enabled",
|
||||||
"menu.cavedust.superflatstatus.false": "Superflat particles: Disabled",
|
"menu.cavedust.superflatstatus.false": "Superflat particles: Disabled",
|
||||||
"menu.cavedust.superflatstatus.tooltip": "Should particles spawn on superflat worlds?",
|
"menu.cavedust.superflatstatus.tooltip": "Should particles spawn on superflat worlds?",
|
||||||
|
"menu.cavedust.particle": "Particle: ",
|
||||||
|
"menu.cavedust.particle.tooltip": "Particle to spawn. Click to cycle.",
|
||||||
|
|
||||||
"key.cavedust.reload": "Reload Config",
|
"key.cavedust.reload": "Reload Config",
|
||||||
"key.cavedust.toggle": "Toggle Particles",
|
"key.cavedust.toggle": "Toggle Particles",
|
||||||
|
|||||||
Reference in New Issue
Block a user