Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
656f13c
commit 1ebd4c3
Showing
3 changed files
with
219 additions
and
2 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/main/java/com/blamejared/crafttweaker/impl/actions/blocks/ActionSetBlockProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.blamejared.crafttweaker.impl.actions.blocks; | ||
|
||
import com.blamejared.crafttweaker.api.actions.IUndoableAction; | ||
import com.blamejared.crafttweaker.impl_native.blocks.ExpandBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraftforge.fml.LogicalSide; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public class ActionSetBlockProperty<T> implements IUndoableAction { | ||
|
||
private final Block block; | ||
private final String propertyName; | ||
private final T newValue; | ||
private final T oldValue; | ||
private final Consumer<T> valueSetter; | ||
private Function<T, String> valueNameGetter; | ||
|
||
public ActionSetBlockProperty(Block block, String propertyName, T newValue, T oldValue, Consumer<T> valueSetter) { | ||
|
||
this.block = block; | ||
this.propertyName = propertyName; | ||
this.newValue = newValue; | ||
this.oldValue = oldValue; | ||
this.valueSetter = valueSetter; | ||
this.valueNameGetter = Object::toString; | ||
} | ||
|
||
public ActionSetBlockProperty(Block block, String propertyName, T newValue, T oldValue, Consumer<T> valueSetter, Function<T, String> valueNameGetter) { | ||
|
||
this.block = block; | ||
this.propertyName = propertyName; | ||
this.newValue = newValue; | ||
this.oldValue = oldValue; | ||
this.valueSetter = valueSetter; | ||
this.valueNameGetter = valueNameGetter; | ||
} | ||
|
||
@Override | ||
public void apply() { | ||
|
||
this.valueSetter.accept(newValue); | ||
} | ||
|
||
@Override | ||
public String describe() { | ||
|
||
return "Set the value of " + propertyName + " on " + ExpandBlock.getCommandString(block) + " to: '" + this.valueNameGetter | ||
.apply(newValue) + "'"; | ||
} | ||
|
||
@Override | ||
public void undo() { | ||
|
||
this.valueSetter.accept(oldValue); | ||
} | ||
|
||
@Override | ||
public String describeUndo() { | ||
|
||
return "Reset the value of " + propertyName + " on " + ExpandBlock.getCommandString(block) + " to: '" + this.valueNameGetter | ||
.apply(oldValue) + "'"; | ||
} | ||
|
||
@Override | ||
public boolean shouldApplyOn(LogicalSide side) { | ||
|
||
return shouldApplySingletons(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters