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
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/com/blamejared/crafttweaker/api/zencode/expands/ExpandBool.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,16 @@ | ||
package com.blamejared.crafttweaker.api.zencode.expands; | ||
|
||
import com.blamejared.crafttweaker.api.annotations.*; | ||
import com.blamejared.crafttweaker.api.data.*; | ||
import com.blamejared.crafttweaker.impl.data.*; | ||
import org.openzen.zencode.java.*; | ||
|
||
@ZenRegister | ||
@ZenCodeType.Expansion("bool") | ||
public class ExpandBool { | ||
|
||
@ZenCodeType.Caster(implicit = true) | ||
public static IData asData(boolean _this) { | ||
return new BoolData(_this); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/blamejared/crafttweaker/impl/data/BoolData.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,62 @@ | ||
package com.blamejared.crafttweaker.impl.data; | ||
|
||
import com.blamejared.crafttweaker.api.annotations.*; | ||
import com.blamejared.crafttweaker.api.data.*; | ||
import com.blamejared.crafttweaker_annotations.annotations.*; | ||
import net.minecraft.nbt.*; | ||
import org.openzen.zencode.java.*; | ||
|
||
/** | ||
* Careful with BoolData: While it works for specifying boolean attributes in JSON syntax, | ||
* using it in Tags will instead use a {@link ByteData} object. Reason for this is that | ||
* Minecraft does not have Boolean NBT values. | ||
* | ||
* @docParam this true | ||
*/ | ||
@ZenCodeType.Name("crafttweaker.api.data.BoolData") | ||
@ZenRegister | ||
@Document("vanilla/api/data/BoolData") | ||
public class BoolData implements IData { | ||
|
||
private final boolean internal; | ||
|
||
@ZenCodeType.Constructor | ||
public BoolData(boolean internal) { | ||
this.internal = internal; | ||
} | ||
|
||
/** | ||
* Converts this BoolData to a {@link ByteData} object. | ||
* This will be used when this Data is converted to NBT | ||
*/ | ||
@ZenCodeType.Caster | ||
@ZenCodeType.Method | ||
public ByteData getByteData() { | ||
return new ByteData(ByteNBT.valueOf(internal)); | ||
} | ||
|
||
@Override | ||
public IData copy() { | ||
return new BoolData(internal); | ||
} | ||
|
||
@Override | ||
public IData copyInternal() { | ||
return new BoolData(internal); | ||
} | ||
|
||
@Override | ||
public INBT getInternal() { | ||
return getByteData().getInternal(); | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return Boolean.toString(internal); | ||
} | ||
|
||
@Override | ||
public String toJsonString() { | ||
return internal + " as bool"; | ||
} | ||
} |