forked from flagmaggot/blocktopograph
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimentally adapted to support 1.13+'s new block format i.e. name …
…+ states (nbt tags) instead of name + val (1~15).
- Loading branch information
meow
committed
Jan 8, 2020
1 parent
bcb4505
commit 47251af
Showing
45 changed files
with
5,800 additions
and
439 deletions.
There are no files selected for viewing
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
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
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/mithrilmania/blocktopograph/block/Block.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,84 @@ | ||
package com.mithrilmania.blocktopograph.block; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.mithrilmania.blocktopograph.nbt.tags.CompoundTag; | ||
import com.mithrilmania.blocktopograph.nbt.tags.Tag; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Block { | ||
|
||
@NonNull | ||
private BlockType blockType; | ||
|
||
@Nullable | ||
private KnownBlockRepr legacyBlock; | ||
|
||
@NonNull | ||
private CompoundTag states; | ||
|
||
private int version; | ||
|
||
Block(@NonNull BlockType blockType, @NonNull CompoundTag states, int version) { | ||
this.blockType = blockType; | ||
this.states = states; | ||
this.version = version; | ||
legacyBlock = BlockWithStatesToLegacyBlockMapper.getBestRepr(this); | ||
if (legacyBlock == null) legacyBlock = KnownBlockRepr.guessBlockNew(blockType.getName()); | ||
} | ||
|
||
Block(@NonNull BlockType blockType, @NonNull KnownBlockRepr legacyBlock, int version) { | ||
this.blockType = blockType; | ||
this.states = new CompoundTag("", new ArrayList<>()); | ||
this.version = version; | ||
this.legacyBlock = legacyBlock; | ||
} | ||
|
||
@NonNull | ||
public String getMinecraftBlockTypeNoPrefix() { | ||
String name = blockType.getName(); | ||
int index = name.indexOf(':'); | ||
if (index != -1 && name.substring(0, index).equals("minecraft")) | ||
name = name.substring(index + 1); | ||
return name; | ||
} | ||
|
||
@NonNull | ||
public String getBlockType() { | ||
return blockType.getName(); | ||
} | ||
|
||
public int getVersion() { | ||
return version; | ||
} | ||
|
||
public boolean isOfSameType(Block block) { | ||
return blockType == block.blockType; | ||
} | ||
|
||
public Tag getState(String key) { | ||
return states.getChildTagByKey(key); | ||
} | ||
|
||
@Nullable | ||
public KnownBlockRepr getLegacyBlock() { | ||
return legacyBlock; | ||
} | ||
|
||
@NonNull | ||
public CompoundTag getStates() { | ||
return states; | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object obj) { | ||
if (!(obj instanceof Block)) return false; | ||
Block another = (Block) obj; | ||
// Ref compare. | ||
if (blockType != another.blockType) return false; | ||
return states.equals(another.states); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/mithrilmania/blocktopograph/block/BlockRegistry.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,46 @@ | ||
package com.mithrilmania.blocktopograph.block; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.mithrilmania.blocktopograph.nbt.tags.CompoundTag; | ||
|
||
import java.util.Hashtable; | ||
import java.util.Map; | ||
|
||
public class BlockRegistry { | ||
|
||
private int limitedTypes; | ||
private Map<String, BlockType> blockTypes; | ||
|
||
public BlockRegistry() { | ||
blockTypes = new Hashtable<>(1024); | ||
} | ||
|
||
public BlockRegistry(int limitedTypes) { | ||
this(); | ||
this.limitedTypes = limitedTypes; | ||
} | ||
|
||
@NonNull | ||
private BlockType getBlockType(String name) { | ||
BlockType ret = blockTypes.get(name); | ||
if (ret == null) { | ||
ret = new BlockType(name); | ||
if (limitedTypes > 0 && blockTypes.size() >= limitedTypes) | ||
throw new RuntimeException("Block types exceeds your set limit."); | ||
blockTypes.put(name, ret); | ||
} | ||
return ret; | ||
} | ||
|
||
@NonNull | ||
public Block createBlock(@NonNull String name, @NonNull CompoundTag states, int version) { | ||
return new Block(getBlockType(name), states, version); | ||
} | ||
|
||
@NonNull | ||
public Block createBlock(@NonNull KnownBlockRepr legacyBlock) { | ||
return new Block(getBlockType(legacyBlock.str), legacyBlock, 1); | ||
} | ||
|
||
} |
Oops, something went wrong.