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() public BuilderNoteEditor()
{ {
this.setBlock(Blocks.NOTE_BLOCK.getRegistryName()); this.setBlock(Blocks.NOTE_BLOCK.getRegistryName());
this.setMode("replace"); this.setMode(EnumMode.REPLACE);
} }
public BuilderNoteEditor(int note) public BuilderNoteEditor(int note)
@@ -27,12 +27,12 @@ public class BuilderNoteEditor extends BuilderSetBlock
{ {
this(note); this(note);
this.setPosition(pos); 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) public void setNote(int note)
{ {
this.withState(BlockStateProperties.NOTE_0_24, note); this.setState(BlockStateProperties.NOTE_0_24, note);
} }
public BuilderNoteEditor getBuilderForNote(int note) public BuilderNoteEditor getBuilderForNote(int note)

View File

@@ -1,9 +1,9 @@
package exopandora.worldhandler.builder.impl; package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.BlockResourceLocation; import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.CoordinateInt; import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.builder.types.ArgumentType;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.IProperty; import net.minecraft.state.IProperty;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@@ -21,7 +21,7 @@ public class BuilderSetBlock extends BuilderBlockPos
super(0); super(0);
} }
public BuilderSetBlock(BlockPos pos, ResourceLocation block, String mode) public BuilderSetBlock(BlockPos pos, ResourceLocation block, EnumMode mode)
{ {
this(); this();
this.setPosition(pos); this.setPosition(pos);
@@ -29,7 +29,7 @@ public class BuilderSetBlock extends BuilderBlockPos
this.setMode(mode); 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();
this.setX(x); this.setX(x);
@@ -39,10 +39,9 @@ public class BuilderSetBlock extends BuilderBlockPos
this.setMode(mode); 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); this.blockResourceLocation.setProperty(property, value);
return this;
} }
public void setBlock(ResourceLocation block) public void setBlock(ResourceLocation block)
@@ -51,16 +50,21 @@ public class BuilderSetBlock extends BuilderBlockPos
this.setNode(3, this.blockResourceLocation); 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 @Override
public void setNBT(CompoundNBT nbt) public void setNBT(CompoundNBT nbt)
{ {
this.blockResourceLocation.setNBT(nbt);
this.setNode(3, this.blockResourceLocation);
} }
@Override @Override
@@ -82,4 +86,18 @@ public class BuilderSetBlock extends BuilderBlockPos
return syntax; 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; 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.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
@@ -26,7 +25,7 @@ public class ConfigCategorySettings
private final IntValue noon; private final IntValue noon;
private final IntValue sunset; private final IntValue sunset;
private final IntValue midnight; private final IntValue midnight;
private final ConfigValue<String> blockPlacingMode; private final ConfigValue<EnumMode> blockPlacingMode;
public ConfigCategorySettings(ForgeConfigSpec.Builder builder) public ConfigCategorySettings(ForgeConfigSpec.Builder builder)
{ {
@@ -93,7 +92,7 @@ public class ConfigCategorySettings
this.blockPlacingMode = builder this.blockPlacingMode = builder
.translation("gui.worldhandler.config.settings.block_placing_mode") .translation("gui.worldhandler.config.settings.block_placing_mode")
.comment("Block placing mode (keep, replace, destroy)") .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(); builder.pop();
} }
@@ -238,12 +237,12 @@ public class ConfigCategorySettings
Config.set(this.midnight, ticks); Config.set(this.midnight, ticks);
} }
public String getBlockPlacingMode() public EnumMode getBlockPlacingMode()
{ {
return this.blockPlacingMode.get(); return this.blockPlacingMode.get();
} }
public void setBlockPlacingMode(String mode) public void setBlockPlacingMode(EnumMode mode)
{ {
Config.set(this.blockPlacingMode, mode); Config.set(this.blockPlacingMode, mode);
} }