Skip to content

Commit

Permalink
Add circle and donut shaped arena, make blocks used in the arena conf…
Browse files Browse the repository at this point in the history
…igurable
  • Loading branch information
thecatcore committed Aug 10, 2020
1 parent 2b7d8f6 commit 5851390
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 38 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Plasmid
modImplementation "net.gegy1000:plasmid:0.1.0+build.32"
modImplementation "net.gegy1000:plasmid:0.1.0+build.36"

modRuntime ("com.github.jellysquid3:sodium-fabric:b9c2ad3c38b16275cf2f1a81dcfb2fee1563905b")
modRuntime ("com.github.jellysquid3:phosphor-fabric:0749029a498e8f6574643285bae7aecb2eda76b8")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.16.1
yarn_mappings=1.16.1+build.21
loader_version=0.9.0+build.204
# Mod Properties
mod_version=1.0.8
mod_version=1.1.0
maven_group=fr.catcore
archives_base_name=deacoudre
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public PlayerRef nextPlayer(boolean newTurn) {
break;
}
}
if (next == this.nextJumper) {
if (next == this.nextJumper && !this.ignoreWinState) {
DeACoudre.LOGGER.warn("next is equals to nextJumper, something might be wrong!");
}
return next;
Expand Down
111 changes: 104 additions & 7 deletions src/main/java/fr/catcore/deacoudre/game/map/DeACoudreMapConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,126 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.gegy1000.plasmid.game.map.template.MapTemplate;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;

public class DeACoudreMapConfig {

public static final Codec<DeACoudreMapConfig> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(
Codec.INT.fieldOf("radius").forGetter(map -> map.radius),
Codec.INT.fieldOf("height").forGetter(map -> map.height)
Codec.INT.fieldOf("height").forGetter(map -> map.height),
Codec.STRING.fieldOf("shape").forGetter(map -> map.shape),
Codec.INT.optionalFieldOf("in_circle_radius", 3).forGetter(map -> map.inCircleRadius),
BlockState.CODEC.fieldOf("spawn_block").forGetter(map -> map.spawnBlock),
BlockState.CODEC.fieldOf("pool_outline_block").forGetter(map -> map.poolOutlineBlock),
BlockState.CODEC.fieldOf("jump_platform_block").forGetter(map -> map.jumpPlatformBlock)
).apply(instance, DeACoudreMapConfig::new);
});

public final int height;
public final int radius;
public final String shape;
public final int inCircleRadius;
public final BlockState spawnBlock;
public final BlockState poolOutlineBlock;
public final BlockState jumpPlatformBlock;

public DeACoudreMapConfig(int radius, int height) {
public DeACoudreMapConfig(int radius, int height, String shape, int inCircleRadius, BlockState spawnBlock, BlockState poolOutlineBlock, BlockState jumpPlatformBlock) {
this.height = height + 1;
this.radius = radius;
this.shape = shape;
this.inCircleRadius = inCircleRadius;
this.spawnBlock = spawnBlock;
this.poolOutlineBlock = poolOutlineBlock;
this.jumpPlatformBlock = jumpPlatformBlock;
}

public int getHeight() {
return height;
}
public enum MapShape {
square((config, builder, mutablePosWater, mutablePosBorder) -> {
for (int z = 5; z <= 5 + (2 * config.radius); z++) {
for (int x = -config.radius; x <= config.radius; x++) {
mutablePosBorder.set(x, 1, z);
builder.setBlockState(mutablePosBorder, config.poolOutlineBlock);
}
}
for (int z = 5; z <= 5 + (2 * config.radius); z++) {
for (int x = -config.radius; x <= config.radius; x++) {
mutablePosBorder.set(x, 2, z);
mutablePosWater.set(x, 2, z);
if (z == 5 || z == 5 + (2 * config.radius) || x == -config.radius || x == config.radius)
builder.setBlockState(mutablePosBorder, config.poolOutlineBlock);
else builder.setBlockState(mutablePosWater, Blocks.WATER.getDefaultState());
}
}
}),
circle((config, builder, mutablePosWater, mutablePosBorder) -> {
int radius2 = config.radius * config.radius;
int outlineRadius2 = (config.radius - 1) * (config.radius - 1);
for (int z = -config.radius; z <= config.radius; z++) {
for (int x = -config.radius; x <= config.radius; x++) {
int distance2 = x * x + z * z;
// if (distance2 >= radius2) {
// continue;
// }

mutablePosBorder.set(x, 1, getRightZ(config, z));
builder.setBlockState(mutablePosBorder, config.poolOutlineBlock);

if (distance2 <= outlineRadius2) {
mutablePosWater.set(x, 2, getRightZ(config, z));
builder.setBlockState(mutablePosWater, Blocks.WATER.getDefaultState());
} else {
mutablePosBorder.set(x, 2, getRightZ(config, z));
builder.setBlockState(mutablePosBorder, config.poolOutlineBlock);
}
}
}
}),
donut((config, builder, mutablePosWater, mutablePosBorder) -> {
int radius2 = config.radius * config.radius;
int outlineRadius2 = (config.radius - 1) * (config.radius - 1);
int inlineRadius = (config.inCircleRadius - 1) * (config.inCircleRadius - 1);
for (int z = -config.radius; z <= config.radius; z++) {
for (int x = -config.radius; x <= config.radius; x++) {
int distance2 = x * x + z * z;
// if (distance2 >= radius2) {
// continue;
// }

mutablePosBorder.set(x, 1, getRightZ(config, z));
builder.setBlockState(mutablePosBorder, config.poolOutlineBlock);

if (distance2 <= outlineRadius2 && distance2 > inlineRadius) {
mutablePosWater.set(x, 2, getRightZ(config, z));
builder.setBlockState(mutablePosWater, Blocks.WATER.getDefaultState());
} else {
mutablePosBorder.set(x, 2, getRightZ(config, z));
builder.setBlockState(mutablePosBorder, config.poolOutlineBlock);
}
}
}
});

private GeneratePool generatePool;

MapShape(GeneratePool generatePool) {
this.generatePool = generatePool;
}

public void generatePool(DeACoudreMapConfig config, MapTemplate builder, BlockPos.Mutable mutablePosWater, BlockPos.Mutable mutablePosBorder) {
this.generatePool.generatePool(config, builder, mutablePosWater, mutablePosBorder);
}

private static int getRightZ(DeACoudreMapConfig config, int z) {
return 5 + (z - -config.radius);
}

private interface GeneratePool {

public int getRadius() {
return radius;
void generatePool(DeACoudreMapConfig config, MapTemplate builder, BlockPos.Mutable mutablePosWater, BlockPos.Mutable mutablePosBorder);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
public class DeACoudreMapGenerator {

private final DeACoudreMapConfig config;
private final DeACoudreMapConfig.MapShape shape;

public DeACoudreMapGenerator(DeACoudreMapConfig config) {
this.config = config;
this.shape = DeACoudreMapConfig.MapShape.valueOf(config.shape);
}

public CompletableFuture<DeACoudreMap> create() {
Expand All @@ -41,7 +43,7 @@ private void buildSpawn(MapTemplate builder) {
for (int x = -4; x <= 4; x++) {
for (int z = -4; z <= 4; z++) {
mutable.set(x, 2, z);
builder.setBlockState(mutable, Blocks.SPRUCE_PLANKS.getDefaultState());
builder.setBlockState(mutable, this.config.spawnBlock);
}
}

Expand All @@ -65,20 +67,7 @@ private void buildPool(MapTemplate builder) {
BlockPos.Mutable mutablePosWater = new BlockPos.Mutable();
BlockPos.Mutable mutablePosBorder = new BlockPos.Mutable();

for (int z = 5 + config.radius + (-config.radius); z <= 5 + (2* config.radius); z++) {
for (int x = -config.radius; x <= config.radius; x++) {
mutablePosBorder.set(x, 1, z);
builder.setBlockState(mutablePosBorder, Blocks.SPRUCE_WOOD.getDefaultState());
}
}
for (int z = 5 + config.radius + (-config.radius); z <= 5 + (2* config.radius); z++) {
for (int x = -config.radius; x <= config.radius; x++) {
mutablePosBorder.set(x, 2, z);
mutablePosWater.set(x, 2, z);
if (z == 5 + config.radius + (-config.radius) || z == 5 + (2* config.radius) || x == -config.radius || x == config.radius) builder.setBlockState(mutablePosBorder, Blocks.SPRUCE_WOOD.getDefaultState());
else builder.setBlockState(mutablePosWater, Blocks.WATER.getDefaultState());
}
}
shape.generatePool(this.config, builder, mutablePosWater, mutablePosBorder);
}

private void buildJumpingPlatform(MapTemplate builder) {
Expand All @@ -89,7 +78,7 @@ private void buildJumpingPlatform(MapTemplate builder) {
for (int z = minZ; z <= minZ + 3; z++) {
for (int x = -1; x <= 1; x++) {
mutable.set(x, config.height + 1, z);
builder.setBlockState(mutable, Blocks.SPRUCE_PLANKS.getDefaultState());
builder.setBlockState(mutable, this.config.jumpPlatformBlock);
}
}
BlockPos[] barrier = new BlockPos[]{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "deacoudre:deacoudre",
"map": {
"radius": 10,
"height": 100,
"shape": "circle",
"spawn_block": {
"Name": "minecraft:spruce_planks",
"Properties": {}
},
"pool_outline_block": {
"Name": "minecraft:spruce_wood",
"Properties": {
"axis": "y"
}
},
"jump_platform_block": {
"Name": "minecraft:spruce_planks",
"Properties": {}
}
},
"players": {
"min": 1,
"max": 100
},
"life": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"type": "deacoudre:deacoudre",
"map": {
"radius": 10,
"height": 100,
"shape": "donut",
"in_circle_radius": 3,
"spawn_block": {
"Name": "minecraft:spruce_planks",
"Properties": {}
},
"pool_outline_block": {
"Name": "minecraft:spruce_wood",
"Properties": {
"axis": "y"
}
},
"jump_platform_block": {
"Name": "minecraft:spruce_planks",
"Properties": {}
}
},
"players": {
"min": 1,
"max": 100
},
"life": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "deacoudre:deacoudre",
"map": {
"radius": 7,
"height": 50,
"shape": "square",
"spawn_block": {
"Name": "minecraft:spruce_planks",
"Properties": {}
},
"pool_outline_block": {
"Name": "minecraft:spruce_wood",
"Properties": {
"axis": "y"
}
},
"jump_platform_block": {
"Name": "minecraft:spruce_planks",
"Properties": {}
}
},
"players": {
"min": 1,
"max": 100
},
"life": 3
}

This file was deleted.

0 comments on commit 5851390

Please sign in to comment.