update blocks data

This commit is contained in:
Tnze
2024-06-15 18:12:27 +08:00
parent fff914a786
commit c43d9048ba
9 changed files with 162 additions and 35 deletions

Binary file not shown.

Binary file not shown.

View File

@ -44,8 +44,9 @@ var EntityList = [...]Entity{
ChiseledBookshelfEntity{}, ChiseledBookshelfEntity{},
BrushableBlockEntity{}, BrushableBlockEntity{},
DecoratedPotEntity{}, DecoratedPotEntity{},
// CrafterEntity{}, CrafterEntity{},
// TrialSpawnerEntity{}, TrialSpawnerEntity{},
VaultEntity{},
} }
func (FurnaceEntity) ID() string { return "minecraft:furnace" } func (FurnaceEntity) ID() string { return "minecraft:furnace" }
@ -89,9 +90,9 @@ func (SculkShriekerEntity) ID() string { return "minecraft:sculk_shrieke
func (ChiseledBookshelfEntity) ID() string { return "minecraft:chiseled_bookshelf" } func (ChiseledBookshelfEntity) ID() string { return "minecraft:chiseled_bookshelf" }
func (BrushableBlockEntity) ID() string { return "minecraft:brushable_block" } func (BrushableBlockEntity) ID() string { return "minecraft:brushable_block" }
func (DecoratedPotEntity) ID() string { return "minecraft:decorated_pot" } func (DecoratedPotEntity) ID() string { return "minecraft:decorated_pot" }
func (CrafterEntity) ID() string { return "minecraft:crafter" }
// func (CrafterEntity) ID() string { return "minecraft:crafter" } func (TrialSpawnerEntity) ID() string { return "minecraft:trial_spawner" }
// func (TrialSpawnerEntity) ID() string { return "minecraft:trial_spawner" } func (VaultEntity) ID() string { return "minecraft:vault" }
func (f FurnaceEntity) IsValidBlock(block Block) bool { func (f FurnaceEntity) IsValidBlock(block Block) bool {
return block.ID() == "minecraft:furnace" return block.ID() == "minecraft:furnace"
@ -429,10 +430,14 @@ func (d DecoratedPotEntity) IsValidBlock(block Block) bool {
return block.ID() == "minecraft:decorated_pot" return block.ID() == "minecraft:decorated_pot"
} }
// func (c CrafterEntity) IsValidBlock(block Block) bool { func (c CrafterEntity) IsValidBlock(block Block) bool {
// return block.ID() == "minecraft:crafter" return block.ID() == "minecraft:crafter"
// } }
//
// func (t TrialSpawnerEntity) IsValidBlock(block Block) bool { func (t TrialSpawnerEntity) IsValidBlock(block Block) bool {
// return block.ID() == "minecraft:trial_spawner" return block.ID() == "minecraft:trial_spawner"
// } }
func (v VaultEntity) IsValidBlock(block Block) bool {
return block.ID() == "minecraft:vault"
}

View File

@ -49,6 +49,9 @@ type (
SuspiciousSandEntity struct{} SuspiciousSandEntity struct{}
BrushableBlockEntity struct{} BrushableBlockEntity struct{}
DecoratedPotEntity struct{} DecoratedPotEntity struct{}
CrafterEntity struct{}
TrialSpawnerEntity struct{}
VaultEntity struct{}
) )
type EntityType int32 type EntityType int32

View File

@ -3452,8 +3452,17 @@ type (
Triggered Boolean `nbt:"triggered"` Triggered Boolean `nbt:"triggered"`
} }
TrialSpawner struct { TrialSpawner struct {
Ominous Boolean `nbt:"ominous"`
Trial_spawner_state TrialSpawnerState `nbt:"trial_spawner_state"` Trial_spawner_state TrialSpawnerState `nbt:"trial_spawner_state"`
} }
Vault struct {
Facing Direction `nbt:"facing"`
Ominous Boolean `nbt:"ominous"`
Vault_state VaultState `nbt:"vault_state"`
}
HeavyCore struct {
Waterlogged Boolean `nbt:"waterlogged"`
}
) )
func (Air) ID() string { return "minecraft:air" } func (Air) ID() string { return "minecraft:air" }
@ -4520,6 +4529,8 @@ func (ReinforcedDeepslate) ID() string { return "minecraft:reinforced_d
func (DecoratedPot) ID() string { return "minecraft:decorated_pot" } func (DecoratedPot) ID() string { return "minecraft:decorated_pot" }
func (Crafter) ID() string { return "minecraft:crafter" } func (Crafter) ID() string { return "minecraft:crafter" }
func (TrialSpawner) ID() string { return "minecraft:trial_spawner" } func (TrialSpawner) ID() string { return "minecraft:trial_spawner" }
func (Vault) ID() string { return "minecraft:vault" }
func (HeavyCore) ID() string { return "minecraft:heavy_core" }
var FromID = map[string]Block{ var FromID = map[string]Block{
"minecraft:air": Air{}, "minecraft:air": Air{},
@ -5580,4 +5591,6 @@ var FromID = map[string]Block{
"minecraft:decorated_pot": DecoratedPot{}, "minecraft:decorated_pot": DecoratedPot{},
"minecraft:crafter": Crafter{}, "minecraft:crafter": Crafter{},
"minecraft:trial_spawner": TrialSpawner{}, "minecraft:trial_spawner": TrialSpawner{},
"minecraft:vault": Vault{},
"minecraft:heavy_core": HeavyCore{},
} }

Binary file not shown.

View File

@ -1,6 +1,5 @@
package pers.tnze.gomc.gen; package pers.tnze.gomc.gen;
import com.google.common.collect.ImmutableMap;
import net.minecraft.SharedConstants; import net.minecraft.SharedConstants;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.*; import net.minecraft.nbt.*;
@ -16,8 +15,10 @@ import net.minecraft.world.level.block.state.properties.Property;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.lang.reflect.Field;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
public class GenBlocks { public class GenBlocks {
@ -54,26 +55,14 @@ public class GenBlocks {
BlockState state = block.defaultBlockState(); BlockState state = block.defaultBlockState();
CompoundTag b = new CompoundTag(); CompoundTag b = new CompoundTag();
b.putString("Name", BuiltInRegistries.BLOCK.getKey(block).toString()); b.putString("Name", BuiltInRegistries.BLOCK.getKey(block).toString());
ImmutableMap<Property<?>, Comparable<?>> values = state.getValues(); Map<Property<?>, Comparable<?>> values = state.getValues();
if (!values.isEmpty()) { if (!values.isEmpty()) {
CompoundTag meta = new CompoundTag(); CompoundTag meta = new CompoundTag();
for (Map.Entry<Property<?>, Comparable<?>> entry : values.entrySet()) { for (Map.Entry<Property<?>, Comparable<?>> entry : values.entrySet()) {
Property<?> key = entry.getKey(); Property<?> key = entry.getKey();
Comparable<?> value = entry.getValue(); Comparable<?> value = entry.getValue();
String name = key.getName(); String name = key.getName();
String typeName; String typeName = getTypeName(key, value);
if (key instanceof EnumProperty<?>) {
if (value.getClass().getName().contains("net.minecraft.core.Direction$Axis")) {
typeName = "Axis";
} else {
typeName = value.getClass().getSimpleName();
}
if (typeName.isBlank()) {
throw new Exception("Type is blank: " + value.getClass().getName());
}
} else {
typeName = key.getClass().getSimpleName();
}
meta.putString(name, typeName); meta.putString(name, typeName);
} }
b.put("Meta", meta); b.put("Meta", meta);
@ -83,6 +72,26 @@ public class GenBlocks {
return list; return list;
} }
private static String getTypeName(Property<?> key, Comparable<?> value) throws Exception {
String typeName;
if (key instanceof EnumProperty<?>) {
Class<?> clazz = value.getClass();
if (clazz.getName().contains("net.minecraft.core.Direction$Axis")) {
typeName = "Axis";
} else if(clazz.getName().contains("net.minecraft.world.level.block.entity.vault.VaultState")) {
typeName = "VaultState";
} else {
typeName = clazz.getSimpleName();
}
if (typeName.isBlank()) {
throw new Exception("Type is blank: " + clazz.getName());
}
} else {
typeName = key.getClass().getSimpleName();
}
return typeName;
}
private static ListTag getBlockStates() { private static ListTag getBlockStates() {
ListTag list = new ListTag(); ListTag list = new ListTag();
for (BlockState blockState : Block.BLOCK_STATE_REGISTRY) { for (BlockState blockState : Block.BLOCK_STATE_REGISTRY) {
@ -93,10 +102,26 @@ public class GenBlocks {
private static ListTag genBlockEntities() { private static ListTag genBlockEntities() {
ListTag list = new ListTag(); ListTag list = new ListTag();
Field validBlocksField;
try {
validBlocksField = BlockEntityType.class.getDeclaredField("validBlocks");
validBlocksField.setAccessible(true);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
for (BlockEntityType<?> blockEntity : BuiltInRegistries.BLOCK_ENTITY_TYPE) { for (BlockEntityType<?> blockEntity : BuiltInRegistries.BLOCK_ENTITY_TYPE) {
ResourceLocation value = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(blockEntity); ResourceLocation value = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(blockEntity);
ListTag validBlocksList = new ListTag(); ListTag validBlocksList = new ListTag();
for (Block validBlock : blockEntity.validBlocks){
Set<Block> validBlocks;
try {
Object validBlocksObj = validBlocksField.get(blockEntity);
validBlocks = (Set<Block>) validBlocksObj;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
for (Block validBlock : validBlocks){
validBlocksList.add(StringTag.valueOf(BuiltInRegistries.BLOCK.getKey(validBlock).toString())); validBlocksList.add(StringTag.valueOf(BuiltInRegistries.BLOCK.getKey(validBlock).toString()));
} }
CompoundTag be = new CompoundTag(); CompoundTag be = new CompoundTag();

View File

@ -54,6 +54,10 @@ var EnumProperties = []EnumProperty{
"up_east", "up_north", "up_south", "up_west", "up_east", "up_north", "up_south", "up_west",
"west_up", "east_up", "north_up", "south_up", "west_up", "east_up", "north_up", "south_up",
}}, }},
{Name: "VaultState", Values: []string{"inactive", "active", "unlocking", "ejecting"}},
{Name: "TrialSpawnerState", Values: []string{
"inactive", "waiting_for_players", "active", "waiting_for_reward_ejection", "ejecting_reward", "cooldown",
}},
} }
//go:embed properties_enum.go.tmpl //go:embed properties_enum.go.tmpl

View File

@ -1001,13 +1001,90 @@ func (f *FrontAndTop) UnmarshalText(text []byte) error {
return nil return nil
} }
type TrialSpawnerState = string type VaultState byte
const ( const (
TrailSpawnerActive = "active" VaultStateInactive VaultState = iota
TrailSpawnerCooldown = "cooldown" VaultStateActive
TrailSpawnerEjectingReward = "ejecting_reward" VaultStateUnlocking
TrailSpawnerInactive = "inactive" VaultStateEjecting
TrailSpawnerWaitingForPlayers = "waiting_for_players"
TrailSpawnerWaitingForRewardEjection = "waiting_for_reward_ejection"
) )
var strVaultState = [...]string{"inactive", "active", "unlocking", "ejecting"}
func (v VaultState) String() string {
if int(v) < len(strVaultState) {
return strVaultState[v]
}
return "invalid VaultState"
}
func (v VaultState) MarshalText() (text []byte, err error) {
if int(v) < len(strVaultState) {
return []byte(strVaultState[v]), nil
}
return nil, errors.New("invalid VaultState: " + strconv.Itoa(int(v)))
}
func (v *VaultState) UnmarshalText(text []byte) error {
switch str := string(text); str {
case "inactive":
*v = VaultStateInactive
case "active":
*v = VaultStateActive
case "unlocking":
*v = VaultStateUnlocking
case "ejecting":
*v = VaultStateEjecting
default:
return errors.New("unknown VaultState: " + str)
}
return nil
}
type TrialSpawnerState byte
const (
TrialSpawnerStateInactive TrialSpawnerState = iota
TrialSpawnerStateWaitingForPlayers
TrialSpawnerStateActive
TrialSpawnerStateWaitingForRewardEjection
TrialSpawnerStateEjectingReward
TrialSpawnerStateCooldown
)
var strTrialSpawnerState = [...]string{"inactive", "waiting_for_players", "active", "waiting_for_reward_ejection", "ejecting_reward", "cooldown"}
func (t TrialSpawnerState) String() string {
if int(t) < len(strTrialSpawnerState) {
return strTrialSpawnerState[t]
}
return "invalid TrialSpawnerState"
}
func (t TrialSpawnerState) MarshalText() (text []byte, err error) {
if int(t) < len(strTrialSpawnerState) {
return []byte(strTrialSpawnerState[t]), nil
}
return nil, errors.New("invalid TrialSpawnerState: " + strconv.Itoa(int(t)))
}
func (t *TrialSpawnerState) UnmarshalText(text []byte) error {
switch str := string(text); str {
case "inactive":
*t = TrialSpawnerStateInactive
case "waiting_for_players":
*t = TrialSpawnerStateWaitingForPlayers
case "active":
*t = TrialSpawnerStateActive
case "waiting_for_reward_ejection":
*t = TrialSpawnerStateWaitingForRewardEjection
case "ejecting_reward":
*t = TrialSpawnerStateEjectingReward
case "cooldown":
*t = TrialSpawnerStateCooldown
default:
return errors.New("unknown TrialSpawnerState: " + str)
}
return nil
}