Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
plugins {
id "fabric-loom" version "1.10.5"
id "fabric-loom" version "1.15-SNAPSHOT"
id "maven-publish"
}

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
}


repositories {
maven {
name = "Fabric"
Expand All @@ -21,7 +25,7 @@ repositories {
dependencies {
// Main
minecraft("com.mojang:minecraft:${project.minecraft_version}")
mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2")
mappings loom.officialMojangMappings()
modImplementation("net.fabricmc:fabric-loader:${project.loader_version}")

// Fabric API
Expand All @@ -39,16 +43,24 @@ processResources {
}
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType(JavaCompile) {
options.release = 21
options.encoding = "UTF-8"
}

jar {
from "LICENSE"
inputs.property "archivesName", project.base.archivesName

from("LICENSE") {
rename { "${it}_${inputs.properties.archivesName}"}
}
}
9 changes: 4 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ mod_version = 1.0.0
org.gradle.jvmargs = -Xmx1G

# Versions
minecraft_version = 1.21.4
yarn_mappings = 1.21.4+build.8
loader_version = 0.16.14
fabric_version = 0.119.2+1.21.4
minecraft_version = 1.21.11
loader_version = 0.18.4
fabric_version = 0.141.3+1.21.11

plasmid_version = 0.6.3+1.21.4
plasmid_version = 0.6.7-SNAPSHOT+1.21.11
4 changes: 2 additions & 2 deletions src/main/java/io/github/haykam821/anvildrop/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.github.haykam821.anvildrop.game.AnvilDropConfig;
import io.github.haykam821.anvildrop.game.phase.AnvilDropWaitingPhase;
import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;
import net.minecraft.resources.Identifier;
import xyz.nucleoid.plasmid.api.game.GameType;

public class Main implements ModInitializer {
Expand All @@ -18,6 +18,6 @@ public void onInitialize() {
}

public static Identifier identifier(String path) {
return Identifier.of(MOD_ID, path);
return Identifier.fromNamespaceAndPath(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@

import io.github.haykam821.anvildrop.game.map.AnvilDropMapConfig;
import net.minecraft.SharedConstants;
import net.minecraft.util.math.intprovider.ConstantIntProvider;
import net.minecraft.util.math.intprovider.IntProvider;
import net.minecraft.util.valueproviders.ConstantInt;
import net.minecraft.util.valueproviders.IntProvider;
import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig;

public class AnvilDropConfig {
public static final MapCodec<AnvilDropConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> {
return instance.group(
AnvilDropMapConfig.CODEC.fieldOf("map").forGetter(AnvilDropConfig::getMapConfig),
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(AnvilDropConfig::getPlayerConfig),
IntProvider.NON_NEGATIVE_CODEC.optionalFieldOf("ticks_until_close", ConstantIntProvider.create(SharedConstants.TICKS_PER_SECOND * 5)).forGetter(AnvilDropConfig::getTicksUntilClose),
Codec.INT.optionalFieldOf("delay", 20 * 2).forGetter(AnvilDropConfig::getDelay),
Codec.DOUBLE.optionalFieldOf("chance", 0.4).forGetter(AnvilDropConfig::getChance),
Codec.INT.optionalFieldOf("drop_height", 15).forGetter(AnvilDropConfig::getDropHeight),
Codec.INT.optionalFieldOf("stack_height", 0).forGetter(AnvilDropConfig::getStackHeight),
Codec.BOOL.optionalFieldOf("breaking", false).forGetter(AnvilDropConfig::isBreaking)
).apply(instance, AnvilDropConfig::new);
});
public static final MapCodec<AnvilDropConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
AnvilDropMapConfig.CODEC.fieldOf("map").forGetter(AnvilDropConfig::getMapConfig),
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(AnvilDropConfig::getPlayerConfig),
IntProvider.NON_NEGATIVE_CODEC.optionalFieldOf("ticks_until_close", ConstantInt.of(SharedConstants.TICKS_PER_SECOND * 5)).forGetter(AnvilDropConfig::getTicksUntilClose),
Codec.INT.optionalFieldOf("delay", 20 * 2).forGetter(AnvilDropConfig::getDelay),
Codec.DOUBLE.optionalFieldOf("chance", 0.4).forGetter(AnvilDropConfig::getChance),
Codec.INT.optionalFieldOf("drop_height", 15).forGetter(AnvilDropConfig::getDropHeight),
Codec.INT.optionalFieldOf("stack_height", 0).forGetter(AnvilDropConfig::getStackHeight),
Codec.BOOL.optionalFieldOf("breaking", false).forGetter(AnvilDropConfig::isBreaking)
).apply(instance, AnvilDropConfig::new));

private final AnvilDropMapConfig mapConfig;
private final WaitingLobbyConfig playerConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
import java.util.Iterator;

import io.github.haykam821.anvildrop.game.AnvilDropConfig;
import net.minecraft.block.AnvilBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.world.level.block.AnvilBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.AABB;
import net.minecraft.core.Direction;
import net.minecraft.world.level.chunk.ChunkGenerator;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.map_templates.MapTemplate;
import xyz.nucleoid.plasmid.api.game.world.generator.TemplateChunkGenerator;

public class AnvilDropMap {
private static final BlockState CLEAR_STATE = Blocks.AIR.getDefaultState();
private static final BlockState ANVIL_STATE = Blocks.ANVIL.getDefaultState();
private static final BlockState ALTERNATE_ANVIL_STATE = Blocks.ANVIL.getDefaultState().with(AnvilBlock.FACING, Direction.EAST);
private static final BlockState CLEAR_STATE = Blocks.AIR.defaultBlockState();
private static final BlockState ANVIL_STATE = Blocks.ANVIL.defaultBlockState();
private static final BlockState ALTERNATE_ANVIL_STATE = Blocks.ANVIL.defaultBlockState().setValue(AnvilBlock.FACING, Direction.EAST);

private final MapTemplate template;
private final AnvilDropConfig config;
private final BlockBounds platformBounds;
private final Box box;
private final AABB box;
private final BlockBounds clearBounds;
private final BlockBounds dropBounds;

Expand All @@ -33,7 +33,7 @@ public AnvilDropMap(MapTemplate template, AnvilDropConfig config, BlockBounds pl
this.config = config;

this.platformBounds = platformBounds;
this.box = this.platformBounds.asBox().expand(-1, -0.5, -1);
this.box = this.platformBounds.asBox().inflate(-1, -0.5, -1);

this.clearBounds = clearBounds;
this.dropBounds = dropBounds;
Expand All @@ -43,30 +43,26 @@ public BlockBounds getPlatformBounds() {
return this.platformBounds;
}

public Box getBox() {
public AABB getBox() {
return this.box;
}

public void clearAnvils(ServerWorld world) {
Iterator<BlockPos> iterator = this.clearBounds.iterator();
while (iterator.hasNext()) {
BlockPos pos = iterator.next();
if (this.config.isBreaking() && !world.isAir(pos)) {
world.breakBlock(pos.withY(0), false);
}
world.setBlockState(pos, CLEAR_STATE);
}
public void clearAnvils(ServerLevel world) {
for (BlockPos pos : this.clearBounds) {
if (this.config.isBreaking() && !world.isEmptyBlock(pos)) {
world.destroyBlock(pos.atY(0), false);
}
world.setBlockAndUpdate(pos, CLEAR_STATE);
}
}

public void dropAnvils(ServerWorld world) {
Iterator<BlockPos> iterator = this.dropBounds.iterator();
while (iterator.hasNext()) {
BlockPos pos = iterator.next();
if (world.getRandom().nextDouble() < this.config.getChance()) {
BlockState state = world.getRandom().nextBoolean() ? ANVIL_STATE : ALTERNATE_ANVIL_STATE;
world.setBlockState(pos, state, 0);
}
}
public void dropAnvils(ServerLevel world) {
for (BlockPos pos : this.dropBounds) {
if (world.getRandom().nextDouble() < this.config.getChance()) {
BlockState state = world.getRandom().nextBoolean() ? ANVIL_STATE : ALTERNATE_ANVIL_STATE;
world.setBlock(pos, state, 0);
}
}
}

public ChunkGenerator createGenerator(MinecraftServer server) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import java.util.Iterator;

import io.github.haykam821.anvildrop.game.AnvilDropConfig;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.map_templates.MapTemplate;

public class AnvilDropMapBuilder {
private static final BlockState FLOOR = Blocks.SMOOTH_STONE.getDefaultState();
private static final BlockState FLOOR_OUTLINE = Blocks.NETHERITE_BLOCK.getDefaultState();
private static final BlockState WALL = Blocks.END_STONE_BRICK_WALL.getDefaultState();
private static final BlockState WALL_TOP = Blocks.BIRCH_SLAB.getDefaultState();
private static final BlockState BARRIER = Blocks.BARRIER.getDefaultState();
private static final BlockState FLOOR = Blocks.SMOOTH_STONE.defaultBlockState();
private static final BlockState FLOOR_OUTLINE = Blocks.NETHERITE_BLOCK.defaultBlockState();
private static final BlockState WALL = Blocks.END_STONE_BRICK_WALL.defaultBlockState();
private static final BlockState WALL_TOP = Blocks.BIRCH_SLAB.defaultBlockState();
private static final BlockState BARRIER = Blocks.BARRIER.defaultBlockState();

private final AnvilDropConfig config;

Expand All @@ -26,7 +26,7 @@ public AnvilDropMap create() {
MapTemplate template = MapTemplate.createEmpty();
AnvilDropMapConfig mapConfig = this.config.getMapConfig();

BlockBounds bounds = BlockBounds.of(BlockPos.ORIGIN, new BlockPos(mapConfig.getX() + 1, this.config.getStackHeight() + 3, mapConfig.getZ() + 1));
BlockBounds bounds = BlockBounds.of(BlockPos.ZERO, new BlockPos(mapConfig.getX() + 1, this.config.getStackHeight() + 3, mapConfig.getZ() + 1));
this.build(bounds, template, mapConfig);

BlockBounds clearBounds = createInnerBounds(mapConfig, this.config.getStackHeight() + 1);
Expand Down Expand Up @@ -67,14 +67,11 @@ private BlockState getBlockState(BlockPos pos, BlockBounds bounds, AnvilDropMapC
}

public void build(BlockBounds bounds, MapTemplate template, AnvilDropMapConfig mapConfig) {
Iterator<BlockPos> iterator = bounds.iterator();
while (iterator.hasNext()) {
BlockPos pos = iterator.next();

BlockState state = this.getBlockState(pos, bounds, mapConfig);
if (state != null) {
template.setBlockState(pos, state);
}
}
for (BlockPos pos : bounds) {
BlockState state = this.getBlockState(pos, bounds, mapConfig);
if (state != null) {
template.setBlockState(pos, state);
}
}
}
}
Loading