Changed block_placing_mode from String to EnumMode, Fixed nbt setter for BuilderSetBlock, Renamed BuilderSetBlock#withState to BuilderSetBlock#setState

This commit is contained in:
Marcel Konrad
2020-05-24 20:34:54 +02:00
parent 6e4f26b66e
commit 5e92194c05
3 changed files with 36 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ public class BuilderNoteEditor extends BuilderSetBlock
public BuilderNoteEditor()
{
this.setBlock(Blocks.NOTE_BLOCK.getRegistryName());
this.setMode("replace");
this.setMode(EnumMode.REPLACE);
}
public BuilderNoteEditor(int note)
@@ -27,12 +27,12 @@ public class BuilderNoteEditor extends BuilderSetBlock
{
this(note);
this.setPosition(pos);
this.withState(BlockStateProperties.NOTE_BLOCK_INSTRUMENT, NoteBlockInstrument.byState(Minecraft.getInstance().world.getBlockState(pos.down())));
this.setState(BlockStateProperties.NOTE_BLOCK_INSTRUMENT, NoteBlockInstrument.byState(Minecraft.getInstance().world.getBlockState(pos.down())));
}
public void setNote(int note)
{
this.withState(BlockStateProperties.NOTE_0_24, note);
this.setState(BlockStateProperties.NOTE_0_24, note);
}
public BuilderNoteEditor getBuilderForNote(int note)

View File

@@ -1,9 +1,9 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.builder.types.ArgumentType;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.IProperty;
import net.minecraft.util.ResourceLocation;
@@ -21,7 +21,7 @@ public class BuilderSetBlock extends BuilderBlockPos
super(0);
}
public BuilderSetBlock(BlockPos pos, ResourceLocation block, String mode)
public BuilderSetBlock(BlockPos pos, ResourceLocation block, EnumMode mode)
{
this();
this.setPosition(pos);
@@ -29,7 +29,7 @@ public class BuilderSetBlock extends BuilderBlockPos
this.setMode(mode);
}
public BuilderSetBlock(CoordinateInt x, CoordinateInt y, CoordinateInt z, ResourceLocation block, String mode)
public <T extends Comparable<T>> BuilderSetBlock(CoordinateInt x, CoordinateInt y, CoordinateInt z, ResourceLocation block, EnumMode mode)
{
this();
this.setX(x);
@@ -39,10 +39,9 @@ public class BuilderSetBlock extends BuilderBlockPos
this.setMode(mode);
}
public <T extends Comparable<T>> BuilderSetBlock withState(IProperty<T> property, T value)
public <T extends Comparable<T>> void setState(IProperty<T> property, T value)
{
this.blockResourceLocation.withState(property, value);
return this;
this.blockResourceLocation.setProperty(property, value);
}
public void setBlock(ResourceLocation block)
@@ -51,16 +50,21 @@ public class BuilderSetBlock extends BuilderBlockPos
this.setNode(3, this.blockResourceLocation);
}
public void setMode(String mode)
public void setMode(EnumMode mode)
{
this.setNode(4, mode);
this.setNode(4, mode.toString());
}
public void setBlockNBT(CompoundNBT nbt)
{
this.blockResourceLocation.setNBT(nbt);
this.setNode(3, this.blockResourceLocation);
}
@Override
public void setNBT(CompoundNBT nbt)
{
this.blockResourceLocation.setNBT(nbt);
this.setNode(3, this.blockResourceLocation);
}
@Override
@@ -82,4 +86,18 @@ public class BuilderSetBlock extends BuilderBlockPos
return syntax;
}
@OnlyIn(Dist.CLIENT)
public static enum EnumMode
{
KEEP,
REPLACE,
DESTROY;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,7 +1,6 @@
package exopandora.worldhandler.config;
import java.util.Arrays;
import exopandora.worldhandler.builder.impl.BuilderSetBlock.EnumMode;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ForgeConfigSpec;
@@ -26,7 +25,7 @@ public class ConfigCategorySettings
private final IntValue noon;
private final IntValue sunset;
private final IntValue midnight;
private final ConfigValue<String> blockPlacingMode;
private final ConfigValue<EnumMode> blockPlacingMode;
public ConfigCategorySettings(ForgeConfigSpec.Builder builder)
{
@@ -93,7 +92,7 @@ public class ConfigCategorySettings
this.blockPlacingMode = builder
.translation("gui.worldhandler.config.settings.block_placing_mode")
.comment("Block placing mode (keep, replace, destroy)")
.defineInList("block_placing_mode", "keep", Arrays.asList("keep", "replace", "destroy"));
.defineEnum("block_placing_mode", EnumMode.KEEP, EnumMode.values());
builder.pop();
}
@@ -238,12 +237,12 @@ public class ConfigCategorySettings
Config.set(this.midnight, ticks);
}
public String getBlockPlacingMode()
public EnumMode getBlockPlacingMode()
{
return this.blockPlacingMode.get();
}
public void setBlockPlacingMode(String mode)
public void setBlockPlacingMode(EnumMode mode)
{
Config.set(this.blockPlacingMode, mode);
}