Skip to content

Commit

Permalink
revert: revert code format related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Dec 17, 2024
1 parent 4222eef commit 92a5134
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.world.biome.PlatformBiome;


/**
* @author daoge_cmd
*/
Expand Down Expand Up @@ -82,8 +81,8 @@ public void runPossiblyUnsafeTask(@NotNull Runnable task) {
@Override
public void register(TypeRegistry registry) {
super.register(registry);
registry.registerLoader(BlockState.class, ($, o, $$, $$$) -> ALLAY_WORLD_HANDLE.createBlockState((String) o));
registry.registerLoader(PlatformBiome.class, ($, o, $$, depthTracker) -> parseBiome((String) o, depthTracker));
registry.registerLoader(BlockState.class, ($, o, $$, $$$) -> ALLAY_WORLD_HANDLE.createBlockState((String) o))
.registerLoader(PlatformBiome.class, ($, o, $$, depthTracker) -> parseBiome((String) o, depthTracker));
}

protected AllayBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ public class JeBlockState {
protected final TreeMap<String, String> properties;
protected int hash = Integer.MAX_VALUE;

public static JeBlockState fromString(String data) {
return new JeBlockState(data);
}

public static JeBlockState create(String identifier, TreeMap<String, String> properties) {
return new JeBlockState(identifier, properties);
}

private JeBlockState(String data) {
String[] strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(",");
this.identifier = strings[0];
this.properties = new TreeMap<>();
if(strings.length > 1) {
for(int i = 1; i < strings.length; i++) {
if (strings.length > 1) {
for (int i = 1; i < strings.length; i++) {
final String tmp = strings[i];
final int index = tmp.indexOf("=");
properties.put(tmp.substring(0, index), tmp.substring(index + 1));
Expand All @@ -28,19 +36,6 @@ private JeBlockState(String data) {
completeMissingProperties();
}

private JeBlockState(String identifier, TreeMap<String, String> properties) {
this.identifier = identifier;
this.properties = properties;
}

public static JeBlockState fromString(String data) {
return new JeBlockState(data);
}

public static JeBlockState create(String identifier, TreeMap<String, String> properties) {
return new JeBlockState(identifier, properties);
}

public String getPropertyValue(String key) {
return properties.get(key);
}
Expand All @@ -50,24 +45,31 @@ private void completeMissingProperties() {
if(properties.size() == defaultProperties.size()) {
return;
}
defaultProperties.entrySet().stream()
defaultProperties
.entrySet()
.stream()
.filter(entry -> !properties.containsKey(entry.getKey()))
.forEach(entry -> properties.put(entry.getKey(), entry.getValue()));
}

private JeBlockState(String identifier, TreeMap<String, String> properties) {
this.identifier = identifier;
this.properties = properties;
}

public String toString(boolean includeProperties) {
if(!includeProperties) return identifier;
StringBuilder builder = new StringBuilder(identifier).append(";");
properties.forEach((k, v) -> builder.append(k).append("=").append(v).append(";"));
String str = builder.toString();
if(hash == Integer.MAX_VALUE) {
if (hash == Integer.MAX_VALUE) {
hash = HashUtils.fnv1a_32(str.getBytes());
}
return str;
}

public int getHash() {
if(hash == Integer.MAX_VALUE) {
if (hash == Integer.MAX_VALUE) {
hash = HashUtils.fnv1a_32(toString(true).getBytes());
}
return hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import com.dfsek.terra.api.world.biome.PlatformBiome;


/**
* @author daoge_cmd
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.properties.Property;


/**
* @author daoge_cmd
*/
public final class AllayBlockState implements com.dfsek.terra.api.block.state.BlockState {
public static final AllayBlockState AIR = new AllayBlockState(
BlockTypes.AIR.getDefaultState(),
JeBlockState.fromString("minecraft:air")
);

public static final AllayBlockState AIR = new AllayBlockState(BlockTypes.AIR.getDefaultState(),
JeBlockState.fromString("minecraft:air"));

private final BlockState allayBlockState;
private final JeBlockState jeBlockState;
Expand Down Expand Up @@ -68,15 +66,9 @@ public BlockState getHandle() {
return allayBlockState;
}

public BlockState allayBlockState() {
return allayBlockState;
}
public BlockState allayBlockState() { return allayBlockState; }

public boolean containsWater() {
return containsWater;
}
public boolean containsWater() { return containsWater; }

public JeBlockState jeBlockState() {
return jeBlockState;
}
public JeBlockState jeBlockState() { return jeBlockState; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;


/**
* @author daoge_cmd
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.ServerWorld;


/**
* @author daoge_cmd
*/
public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfsek.terra.api.world.chunk.Chunk {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(
BlockPropertyTypes.LIQUID_DEPTH.createValue(0)
);

private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));

@Override
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
AllayBlockState allayBlockState = (AllayBlockState) data;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
boolean containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
if (containsWater) {
allayChunk.setBlockState(x, y, z, WATER, 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.inventory.item.Enchantment;


/**
* @author daoge_cmd
*/
public record AllayEnchantment(EnchantmentType allayEnchantment) implements Enchantment {
@Override
public boolean canEnchantItem(ItemStack itemStack) {
return ((AllayItemStack) itemStack).allayItemStack().checkEnchantmentCompatibility(allayEnchantment);
return ((AllayItemStack)itemStack).allayItemStack().checkEnchantmentCompatibility(allayEnchantment);
}

@Override
public boolean conflictsWith(Enchantment other) {
return ((AllayEnchantment) other).allayEnchantment.isIncompatibleWith(allayEnchantment);
return ((AllayEnchantment)other).allayEnchantment.isIncompatibleWith(allayEnchantment);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.ServerWorld;


/**
* NOTICE: Entity is not supported currently, and this is a fake implementation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.dfsek.terra.api.inventory.item.Enchantment;
import com.dfsek.terra.api.inventory.item.ItemMeta;


/**
* @author daoge_cmd
*/
Expand All @@ -24,7 +23,7 @@ public void addEnchantment(Enchantment enchantment, int level) {
@Override
public Map<Enchantment, Integer> getEnchantments() {
Map<Enchantment, Integer> results = new HashMap<>();
for(EnchantmentInstance allayEnchantmentInstance : allayItemStack.getEnchantments()) {
for (EnchantmentInstance allayEnchantmentInstance : allayItemStack.getEnchantments()) {
results.put(new AllayEnchantment(allayEnchantmentInstance.getType()), allayEnchantmentInstance.getLevel());
}
return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.ItemMeta;


/**
* @author daoge_cmd
*/
public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terra.api.inventory.ItemStack {
public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terra.api.inventory.ItemStack{
@Override
public int getAmount() {
return allayItemStack.getCount();
Expand All @@ -35,7 +34,7 @@ public ItemMeta getItemMeta() {
public void setItemMeta(ItemMeta meta) {
ItemStack targetItem = ((AllayItemMeta) meta).allayItemStack();
allayItemStack.removeAllEnchantments();
for(EnchantmentInstance enchantment : targetItem.getEnchantments()) {
for (EnchantmentInstance enchantment : targetItem.getEnchantments()) {
allayItemStack.addEnchantment(enchantment.getType(), enchantment.getLevel());
}
allayItemStack.setLore(targetItem.getLore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;


/**
* @author daoge_cmd
*/
public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(
BlockPropertyTypes.LIQUID_DEPTH.createValue(0)
);
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));

@Override
public int getMaxHeight() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;


/**
* @author daoge_cmd
*/
public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAccessibleContext context) implements ProtoWorld {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(
BlockPropertyTypes.LIQUID_DEPTH.createValue(0)
);
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));

@Override
public int centerChunkX() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.dfsek.terra.api.world.chunk.Chunk;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;


/**
* @author daoge_cmd
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.api.world.info.WorldProperties;


/**
* @author daoge_cmd
*/
public class AllayGeneratorWrapper implements GeneratorWrapper {

protected static final String OPTION_PACK_NAME = "pack";
protected static final String OPTION_SEED = "seed";

Expand All @@ -46,7 +46,6 @@ public AllayGeneratorWrapper(String preset) {
if(packName == null) {
throw new IllegalArgumentException("Missing config pack name");
}

this.seed = Long.parseLong(options.getOrDefault(OPTION_SEED, "0"));
this.configPack = getConfigPack(packName);
this.chunkGenerator = createGenerator(this.configPack);
Expand All @@ -60,6 +59,7 @@ public AllayGeneratorWrapper(String preset) {
.onDimensionSet(dimension -> {
this.allayServerWorld = new AllayServerWorld(this, dimension);
this.worldProperties = new WorldProperties() {

private final Object fakeHandle = new Object();

@Override
Expand All @@ -82,19 +82,8 @@ public Object getHandle() {
return fakeHandle;
}
};
}).build();
}

protected static ConfigPack getConfigPack(String packName) {
Optional<ConfigPack> byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName);
return byId.orElseGet(
() -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH))
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName))
);
}

protected static ChunkGenerator createGenerator(ConfigPack configPack) {
return configPack.getGeneratorProvider().newInstance(configPack);
})
.build();
}

@Override
Expand Down Expand Up @@ -123,8 +112,8 @@ public WorldGenerator getAllayWorldGenerator() {
return this.allayWorldGenerator;
}


protected class AllayNoiser implements Noiser {

@Override
public boolean apply(NoiseContext context) {
UnsafeChunk chunk = context.getCurrentChunk();
Expand Down Expand Up @@ -156,8 +145,8 @@ public String getName() {
}
}


protected class AllayPopulator implements Populator {

@Override
public boolean apply(PopulateContext context) {
AllayProtoWorld tmp = new AllayProtoWorld(allayServerWorld, context);
Expand All @@ -176,4 +165,16 @@ public String getName() {
return "TERRA_POPULATOR";
}
}

protected static ConfigPack getConfigPack(String packName) {
Optional<ConfigPack> byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName);
return byId.orElseGet(
() -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH))
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName))
);
}

protected static ChunkGenerator createGenerator(ConfigPack configPack) {
return configPack.getGeneratorProvider().newInstance(configPack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.Enchantment;


/**
* @author daoge_cmd
*/
Expand Down
Loading

0 comments on commit 92a5134

Please sign in to comment.