Skip to content

Commit

Permalink
Cleaning up SnipeData and fixing handling of ink modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
lipian committed Oct 13, 2019
1 parent 9e6b867 commit b67939a
Show file tree
Hide file tree
Showing 25 changed files with 488 additions and 387 deletions.
48 changes: 42 additions & 6 deletions src/main/java/com/thevoxelbox/voxelsniper/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.thevoxelbox.voxelsniper;

import com.thevoxelbox.voxelsniper.brush.PerformBrush;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.text.Text;
Expand Down Expand Up @@ -62,7 +63,8 @@ public void brushName(String brushName) {
* Display Center Parameter.
*/
public void center() {
this.snipeData.sendMessage(TextColors.DARK_BLUE, "Brush Center: ", TextColors.DARK_RED, this.snipeData.getcCen());
this.snipeData.sendMessage(TextColors.DARK_BLUE, "Brush Center: ",
TextColors.DARK_RED, this.snipeData.getCylinderCenter());
}

/**
Expand All @@ -86,19 +88,53 @@ public void height() {
}

/**
* Display performer.
* Display performer data.
*
* @param performerName
* @param placeMethod
* @param replaceMethod
* @param usePhysics
*/
public void performerName(String performerName) {
this.snipeData.sendMessage(TextColors.DARK_PURPLE, "Performer: ", TextColors.DARK_GREEN, performerName);
public void performerData(PerformBrush.PerformerType placeMethod,
PerformBrush.PerformerType replaceMethod,
boolean usePhysics) {
String physics = usePhysics ? "On" : "Off";
this.snipeData.sendMessage(
TextColors.DARK_PURPLE,
"Performers:",
TextColors.GREEN,
" place=",
TextColors.AQUA,
performerTypeToString(placeMethod),
TextColors.GREEN,
" replace=",
TextColors.AQUA,
performerTypeToString(replaceMethod),
TextColors.GREEN,
" physics=",
TextColors.AQUA,
physics);
}

private String performerTypeToString(PerformBrush.PerformerType type) {
switch (type) {
case TRAITS:
return "Ink";
case TYPE:
return "Material";
case COMBO:
return "Combo";
case NONE:
return "None";
}

return "Unkown";
}

/**
* Display replace material.
*/
public void replace() {
this.snipeData.sendMessage(TextColors.AQUA, "Replace Material: ", TextColors.RED, this.snipeData.getReplaceId());
this.snipeData.sendMessage(TextColors.DARK_BLUE, "Replace Material: ", TextColors.RED, this.snipeData.getReplaceId());
}

/**
Expand Down
164 changes: 76 additions & 88 deletions src/main/java/com/thevoxelbox/voxelsniper/SnipeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,55 @@
*/
package com.thevoxelbox.voxelsniper;

import com.thevoxelbox.voxelsniper.util.BlockHelper;
import com.thevoxelbox.voxelsniper.util.VoxelList;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.data.key.Key;
import org.spongepowered.api.data.value.BaseValue;
import org.spongepowered.api.block.trait.BlockTrait;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.world.World;

import java.util.Optional;
import java.util.*;

public class SnipeData {

private Sniper owner;
private Message voxelMessage;

private double brushSize = VoxelSniperConfiguration.DEFAULT_BRUSH_SIZE;
private BlockState voxelId = Sponge.getRegistry().getType(BlockState.class, VoxelSniperConfiguration.DEFAULT_VOXEL_ID).orElse(BlockTypes.AIR.getDefaultState());
private BlockState replaceId =
Sponge.getRegistry().getType(BlockState.class, VoxelSniperConfiguration.DEFAULT_REPLACE_ID).orElse(BlockTypes.AIR.getDefaultState());
private VoxelList voxelList = new VoxelList();
private Key<?> voxelInkKey = null;
private Object voxelInkValue = null;
private Key<?> replaceInkKey = null;
private Object replaceInkValue = null;

private int voxelHeight = VoxelSniperConfiguration.DEFAULT_VOXEL_HEIGHT;
private int cCen = VoxelSniperConfiguration.DEFAULT_CYLINDER_CENTER;
private int range = 0;
private boolean ranged = false;
private boolean lightning = false;
private double brushSize;
private BlockState voxelState;
private BlockState replaceState;
private VoxelList voxelList;
private Map<BlockTrait<?>, Object> voxelInkTraits;
private Map<BlockTrait<?>, Object> replaceInkTraits;

private int voxelHeight;
private int cCen;
private int range;
private boolean ranged;
private boolean lightning;

public SnipeData(Sniper vs) {
this.owner = vs;
owner = vs;

voxelState = Sponge.getRegistry().getType(BlockState.class, VoxelSniperConfiguration.DEFAULT_VOXEL_ID)
.orElse(BlockTypes.AIR.getDefaultState());
replaceState = Sponge.getRegistry().getType(BlockState.class, VoxelSniperConfiguration.DEFAULT_REPLACE_ID)
.orElse(BlockTypes.AIR.getDefaultState());

brushSize = VoxelSniperConfiguration.DEFAULT_BRUSH_SIZE;
voxelList = new VoxelList();
voxelHeight = VoxelSniperConfiguration.DEFAULT_VOXEL_HEIGHT;
cCen = VoxelSniperConfiguration.DEFAULT_CYLINDER_CENTER;
range = 0;

ranged = false;
lightning = false;

voxelInkTraits = new HashMap<>();
replaceInkTraits = new HashMap<>();
}

// @Cleanup these method names are all over the place
Expand All @@ -71,11 +85,11 @@ public void setBrushSize(double brushSize) {
this.brushSize = brushSize;
}

public int getcCen() {
public int getCylinderCenter() {
return this.cCen;
}

public void setcCen(int cCen) {
public void setCylinderCenter(int cCen) {
this.cCen = cCen;
}

Expand All @@ -88,24 +102,17 @@ public void setRange(int range) {
}

public String getReplaceId() {
return this.replaceId.getId();
return this.replaceState.getId();
}

public BlockState getReplaceIdState() {
return this.replaceId;
public BlockState getReplaceState() {
return this.replaceState;
}

public boolean setReplaceId(String replaceId) {
Optional<BlockState> state = Sponge.getRegistry().getType(BlockState.class, replaceId);
if (state.isPresent()) {
this.replaceId = state.get();
return true;
}
return false;
}

public void setReplaceId(BlockState state) {
this.replaceId = state;
public void setReplaceState(BlockState state) {
replaceState = state;
replaceInkTraits.clear();
replaceInkTraits.putAll(state.getTraitMap());
}

public int getVoxelHeight() {
Expand All @@ -117,108 +124,89 @@ public void setVoxelHeight(int voxelHeight) {
}

public String getVoxelId() {
return this.voxelId.getId();
return voxelState.getId();
}

public BlockState getVoxelIdState() {
return this.voxelId;
public BlockState getVoxelState() {
return voxelState;
}

public boolean setVoxelId(String voxelId) {
Optional<BlockState> state = Sponge.getRegistry().getType(BlockState.class, voxelId);
if (state.isPresent()) {
this.voxelId = state.get();
return true;
}
return false;
}

public void setVoxelId(BlockState state) {
this.voxelId = state;
public void setVoxelState(BlockState state) {
voxelState = state;
voxelInkTraits.clear();
voxelInkTraits.putAll(state.getTraitMap());
}

public VoxelList getVoxelList() {
return this.voxelList;
return voxelList;
}

public void setVoxelList(VoxelList voxelList) {
this.voxelList = voxelList;
}

public Message getVoxelMessage() {
return this.voxelMessage;
return voxelMessage;
}

public void setVoxelMessage(Message voxelMessage) {
this.voxelMessage = voxelMessage;
}

public World getWorld() {
return this.owner.getPlayer().getWorld();
return owner.getPlayer().getWorld();
}

public boolean isLightningEnabled() {
return this.lightning;
return lightning;
}

public void setLightningEnabled(boolean lightning) {
this.lightning = lightning;
}

public boolean isRanged() {
return this.ranged;
return ranged;
}

public void setRanged(boolean ranged) {
this.ranged = ranged;
}

public Key<? extends BaseValue<?>> getVoxelInkKey() {
return this.voxelInkKey;
}

public Object getVoxelInkValue() {
return this.voxelInkValue;
}

public <V extends BaseValue<T>, T> void setVoxelInk(Key<V> key, T value) {
this.voxelInkKey = key;
this.voxelInkValue = value;
public Map<BlockTrait<?>, Object> getVoxelInkTraits() {
return Collections.unmodifiableMap(voxelInkTraits);
}

public Key<? extends BaseValue<?>> getReplaceInkKey() {
return this.replaceInkKey;
// Attempts to add the traitValues as the current placement ink. If the trait values can't be used with the current
// voxel state, no changes are made.
public void setVoxelInkTraits(Map<BlockTrait<?>, Object> traitValues) {
Optional<BlockState> optState = BlockHelper.addTraits(voxelState.getType().getDefaultState(), traitValues);
if (optState.isPresent()) {
voxelState = optState.get();
voxelInkTraits.clear();
voxelInkTraits.putAll(traitValues);
}
}

public Object getReplaceInkValue() {
return this.replaceInkValue;
public Map<BlockTrait<?>, Object> getReplaceInkTraits() {
return Collections.unmodifiableMap(replaceInkTraits);
}

public <V extends BaseValue<T>, T> void setReplaceInk(Key<V> key, T value) {
this.replaceInkKey = key;
this.replaceInkValue = value;
// Attempts to add the traitValues as the current replacement ink. If the trait values can't be used with the
// current replacement state, no changes are made.
public void setReplaceInkTraits(Map<BlockTrait<?>, Object> traitValues) {
Optional<BlockState> optState = BlockHelper.addTraits(replaceState.getType().getDefaultState(), traitValues);
if (optState.isPresent()) {
replaceState = optState.get();
replaceInkTraits.clear();
replaceInkTraits.putAll(traitValues);
}
}

public Sniper owner() {
return this.owner;
}

/**
* Reset to default values.
*/
public void reset() {
this.voxelId = Sponge.getRegistry().getType(BlockState.class, VoxelSniperConfiguration.DEFAULT_VOXEL_ID).orElse(BlockTypes.AIR.getDefaultState());
this.replaceId = Sponge.getRegistry().getType(BlockState.class, VoxelSniperConfiguration.DEFAULT_REPLACE_ID).orElse(BlockTypes.AIR.getDefaultState());
this.brushSize = VoxelSniperConfiguration.DEFAULT_BRUSH_SIZE;
this.voxelHeight = VoxelSniperConfiguration.DEFAULT_VOXEL_HEIGHT;
this.cCen = VoxelSniperConfiguration.DEFAULT_CYLINDER_CENTER;
this.voxelList = new VoxelList();

this.voxelInkKey = null;
this.voxelInkValue = null;
this.replaceInkKey = null;
this.replaceInkValue = null;
}

public void sendMessage(Object... args) {
this.owner.getPlayer().sendMessage(Text.of(args));
Expand Down
Loading

0 comments on commit b67939a

Please sign in to comment.