Skip to content

Commit

Permalink
add wind generator blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Mar 16, 2019
1 parent 098472a commit 016e425
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/mekanism/common/config/GeneratorsConfig.java
Expand Up @@ -39,6 +39,8 @@ public class GeneratorsConfig extends BaseConfig

public final IntOption windGenerationMaxY = new IntOption(this, "generation", "WindGenerationMaxY", 255);

public final IntSetOption windGenerationBlacklist = new IntSetOption(this, "generation", "WindGenerationDimBlacklist", new int[0], "List of dimension ids where Wind Generator will not function and instead report that there is no wind");

public TypeConfigManager<BlockStateGenerator.GeneratorType> generatorsManager = new TypeConfigManager<>(this, "generators", BlockStateGenerator.GeneratorType.class, BlockStateGenerator.GeneratorType::getGeneratorsForConfig, t->t.blockName);

@Override
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/mekanism/common/config/IntSetOption.java
@@ -0,0 +1,104 @@
package mekanism.common.config;

import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

/**
* Created by Thiakil on 15/03/2019.
*/
@ParametersAreNonnullByDefault
public class IntSetOption extends Option
{
private final int[] defaultValue;
private IntSet value;
private boolean hasRange = false;
private int min;
private int max;

IntSetOption(BaseConfig owner, String category, String key, int[] defaultValue, @Nullable String comment)
{
super(owner, category, key, comment);
this.defaultValue = defaultValue;
this.value = new IntArraySet();
for(int i : defaultValue)
{
this.value.add(i);
}
}

IntSetOption(BaseConfig owner, String category, String key, int[] defaultValue){
this(owner, category, key, defaultValue, null);
}

IntSetOption(BaseConfig owner, String category, String key){
this(owner, category, key, new int[0], null);
}

IntSetOption(BaseConfig owner, String category, String key, int[] defaultValue, @Nullable String comment, int min, int max)
{
this(owner, category, key, defaultValue, comment);
this.hasRange = true;
this.min = min;
this.max = max;
}

public IntSet val()
{
return value;
}

public void set(IntSet value)
{
this.value = value;
}

@SuppressWarnings("Duplicates")//types are different
@Override
protected void load(Configuration config)
{
Property prop;

if (hasRange)
{
prop = config.get(this.category, this.key, this.defaultValue, this.comment, this.min, this.max);
} else {
prop = config.get(this.category, this.key, this.defaultValue, this.comment);
}

prop.setRequiresMcRestart(this.requiresGameRestart);
prop.setRequiresWorldRestart(this.requiresWorldRestart);

this.value.clear();
for(int i : prop.getIntList())
{
this.value.add(i);
}
}

@Override
protected void write(ByteBuf buf)
{
buf.writeInt(this.value.size());
for(int i : value)
{
buf.writeInt(i);
}
}

@Override
protected void read(ByteBuf buf)
{
int size = buf.readInt();
this.value.clear();
for(int i = 0; i < size; i++)
{
this.value.add(buf.readInt());
}
}
}
Expand Up @@ -58,7 +58,8 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
if(!tileEntity.getActive())
{
size += 9;
fontRenderer.drawString(EnumColor.DARK_RED + LangUtils.localize("gui.skyBlocked"), 51, size, 0x00CD00);
final String message = LangUtils.localize(tileEntity.isInBlacklistedDimension() ? "mekanism.gui.noWind" : "gui.skyBlocked");
fontRenderer.drawString(EnumColor.DARK_RED + message, 51, size, 0x00CD00);
}

super.drawGuiContainerForegroundLayer(mouseX, mouseY);
Expand Down
Expand Up @@ -81,7 +81,11 @@ public TileNetworkList getNetworkedData(TileNetworkList data)
/** Determines the current output multiplier, taking sky visibility and height into account. **/
public float getMultiplier()
{
if(world.canSeeSky(getPos().add(0, 4, 0)))
if (isInBlacklistedDimension())
{
return 0;
}
if(world.canSeeSky(getPos().add(0, 4, 0)))
{
final float minY = (float) MekanismConfig.current().generators.windGenerationMinY.val();
final float maxY = (float) MekanismConfig.current().generators.windGenerationMaxY.val();
Expand All @@ -101,6 +105,11 @@ public float getMultiplier()
}
}

public boolean isInBlacklistedDimension()
{
return MekanismConfig.current().generators.windGenerationBlacklist.val().contains(world.provider.getDimension());
}

@Override
@SideOnly(Side.CLIENT)
public float getVolume()
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/mekanism/lang/en_us.lang
Expand Up @@ -511,6 +511,7 @@ gui.producing=Producing
gui.maxOutput=Max Output
gui.storing=Storing
gui.skyBlocked=Sky blocked
mekanism.gui.noWind=No wind
gui.using=Using
gui.needed=Needed
mekanism.gui.bufferfree=Free Buffer
Expand Down

0 comments on commit 016e425

Please sign in to comment.