Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rotgruengelb committed Mar 28, 2024
1 parent 033585b commit 61418a6
Show file tree
Hide file tree
Showing 52 changed files with 516 additions and 176 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ allprojects {

repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://oss.sonatype.org/service/local/repositories/snapshots/content' }
exclusiveContent {
forRepository {
maven { name = "Modrinth"; url = "https://api.modrinth.com/maven" }
Expand All @@ -48,22 +47,23 @@ allprojects {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation(annotationProcessor("net.rotgruengelb:nixienaut:${project.nixienaut_version}"))

include (modImplementation 'me.lucko:fabric-permissions-api:0.2-SNAPSHOT')
include (implementation(annotationProcessor("net.rotgruengelb:nixienaut:${project.nixienaut_version}")))
include (modImplementation 'me.lucko:fabric-permissions-api:0.3-SNAPSHOT')
}

processResources {
inputs.property "version", project.version
inputs.property "minecraft_version", project.minecraft_version
inputs.property "loader_version", project.loader_version
inputs.property "nixienaut_version", project.nixienaut_version
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.version,
"minecraft_version": project.minecraft_version,
"loader_version": project.loader_version,
"quirl_version": project.quirl_version
"nixienaut_version": project.nixienaut_version
}
}

Expand Down
9 changes: 4 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ org.gradle.parallel=true
# check these on https://fabricmc.net/develop
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.6
loader_version=0.15.7

# Mod Properties
mod_version = 0.1.0
mod_version = 1.0.0
maven_group = net.rotgruengelb
archives_base_name = landscape

# Dependencies
fabric_version=0.95.1+1.20.4
quirl_version=3.0.1+1.20.2
nixienaut_version=0.3.0
fabric_version=0.96.4+1.20.4
nixienaut_version=1.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import net.rotgruengelb.landscape.block.entity.ZoneBlockBlockEntity;
import net.rotgruengelb.landscape.block.enums.ZoneBlockMode;
import net.rotgruengelb.landscape.network.UpdateZoneBlockC2SPacket;
import net.rotgruengelb.nixienaut.ClampedNum;
import net.rotgruengelb.nixienaut.math.ClampedNum;
import org.lwjgl.glfw.GLFW;

import java.util.Objects;
Expand Down Expand Up @@ -59,7 +59,7 @@ public ZoneBlockScreen(ZoneBlockBlockEntity zoneBlock) {
this.originalMode = zoneBlock.getMode();
this.originalShowZones = zoneBlock.shouldShowZones();
this.originalPriority = zoneBlock.getZoneManagerContext().priority();
this.newPriority.adjustAndSetValue(this.originalPriority);
this.newPriority.adjustSet(this.originalPriority);
this.newRuleSet = zoneBlock.getRuleSet().getIdentifierString();
this.newMode = this.originalMode;
this.newShowZones = this.originalShowZones;
Expand All @@ -78,17 +78,18 @@ private NbtCompound processZones() {
try {
return StringNbtReader.parse(this.inputZones.getText());
} catch (CommandSyntaxException e) {
LandscapeClient.C_LOGGER.debug("Failed to parse zones NBT: " + e.getMessage());
return this.originalZones;
}
}

private int processPriority() {
try {
newPriority.adjustAndSetValue(Integer.parseInt(this.inputPriority.getText()));
newPriority.adjustSet(Integer.parseInt(this.inputPriority.getText()));
} catch (NumberFormatException e) {
newPriority.adjustAndSetValue(this.originalPriority);
newPriority.adjustSet(this.originalPriority);
}
return newPriority.getValue();
return newPriority.get();
}

@Override
Expand Down Expand Up @@ -132,7 +133,7 @@ public boolean charTyped(char chr, int modifiers) {
}
};
this.inputPriority.setMaxLength(2);
this.inputPriority.setText(this.newPriority.getValue().toString());
this.inputPriority.setText(this.newPriority.get().toString());
this.addSelectableChild(this.inputPriority);
this.inputRuleSet = new TextFieldWidget(this.textRenderer, this.width / 2 - 152, 120, 300, 20, Text.translatable("text.landscape.zone_block.input_ruleset")) {
};
Expand Down Expand Up @@ -167,6 +168,7 @@ public void resize(MinecraftClient client, int width, int height) {

private void updateWidgets(ZoneBlockMode mode) {
// TODO: Will maybe do something for the TRIGGER mode...

// switch (mode) {
// case TRIGGER: {
// Dummy._void();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.rotgruengelb.landscape.mixin.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.ClientConnection;
import net.minecraft.text.Text;
import net.rotgruengelb.landscape.feature.zones.manager.AvailableZoneManagers;
Expand All @@ -8,6 +10,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Environment(EnvType.CLIENT)
@Mixin(ClientConnection.class)
public class ClientConnectionMixin {

Expand Down
4 changes: 2 additions & 2 deletions src/client/resources/landscape.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"package": "net.rotgruengelb.landscape.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"ClientConnectionMixin",
"ClientPlayerEntityMixin",
"IntegratedServerNoBackupPromptMixin",
"ClientConnectionMixin"
"IntegratedServerNoBackupPromptMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/rotgruengelb/landscape/Landscape.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import net.rotgruengelb.landscape.block.ModBlocks;
import net.rotgruengelb.landscape.block.entity.ModBlockEntities;
import net.rotgruengelb.landscape.command.ModCommandNodes;
import net.rotgruengelb.landscape.item.ModItemGroups;
import net.rotgruengelb.landscape.network.receive.ModC2SReceivers;
import net.rotgruengelb.landscape.util.resource.ModResources;
import net.rotgruengelb.nixienaut.annotation.CallerAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Landscape implements ModInitializer {

public static final String MOD_ID = "landscape";
public static final Logger LOGGER = LoggerFactory.getLogger("Landscape");
private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
public static final boolean DEV_ENV = Boolean.parseBoolean(System.getProperty("landscape.dev-env"));

@Override
Expand All @@ -23,5 +26,11 @@ public void onInitialize() {
ModBlockEntities.registerModBlockEntities();
ModC2SReceivers.registerModC2SReceivers();
ModResources.registerModResourceReloadListeners();
ModItemGroups.registerItemGroups();
}

@CallerAware
public static Logger getClassLogger() {
return LoggerFactory.getLogger("Landscape | " + STACK_WALKER.getCallerClass());
}
}
13 changes: 2 additions & 11 deletions src/main/java/net/rotgruengelb/landscape/block/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package net.rotgruengelb.landscape.block;

import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
Expand All @@ -19,6 +16,7 @@ public class ModBlocks {

public static final Block ZONE_BLOCK = registerBlockNoItem("zone_block", new ZoneBlock(FabricBlockSettings.copyOf(Blocks.STRUCTURE_BLOCK)));
public static final Item ZONE_BLOCK_ITEM = registerBlockItem("zone_block", new ZoneBlockItem(ZONE_BLOCK, new FabricItemSettings()));
public static final Block TILED_BEDROCK = registerBlock("tiled_bedrock", new Block(FabricBlockSettings.copyOf(Blocks.BEDROCK)));

private static Block registerBlockNoItem(String name, Block block) {
return Registry.register(Registries.BLOCK, new Identifier(Landscape.MOD_ID, name), block);
Expand All @@ -34,13 +32,6 @@ private static BlockItem registerBlockItem(String name, BlockItem blockItem) {
}

public static void registerModBlocks() {
Landscape.LOGGER.info("Registering ModBlocks for " + Landscape.MOD_ID);
modifyItemGroups();
}

private static void modifyItemGroups() {
/* ZONE_BLOCK */
ItemGroupEvents.modifyEntriesEvent(ItemGroups.OPERATOR)
.register(content -> content.addAfter(Items.COMMAND_BLOCK_MINECART, ZONE_BLOCK));
Landscape.LOGGER.debug("Registering ModBlocks for " + Landscape.MOD_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.rotgruengelb.landscape.feature.zones.rule.AvailableRuleSets;
import net.rotgruengelb.landscape.feature.zones.rule.RuleSet;
import net.rotgruengelb.landscape.util.math.BlockZone;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand All @@ -34,18 +35,24 @@ public class ZoneBlockBlockEntity extends BlockEntity implements BlockEntityProv
private static final HashMap<ZoneBlockMode, RuleSet> MODE_RULESETS = new HashMap<>() {{
put(ZoneBlockMode.CUSTOM_RULESET, null);
put(ZoneBlockMode.TRIGGER, RuleSet.of(AvailableRuleSets.EMPTY_RULESET));
put(ZoneBlockMode.DENY_WORLD_MODIFY, RuleSet.of("landscape:rulesets/test"));
put(ZoneBlockMode.DENY_WORLD_MODIFY, RuleSet.of("landscape:rulesets/zone_block/deny_world_modify"));
put(ZoneBlockMode.ALLOW_WORLD_MODIFY, RuleSet.of("landscape:rulesets/zone_block/allow_world_modify"));
put(ZoneBlockMode.DENY_BREAK, RuleSet.of("landscape:rulesets/zone_block/deny_break"));
put(ZoneBlockMode.ALLOW_BREAK, RuleSet.of("landscape:rulesets/zone_block/allow_break"));
put(ZoneBlockMode.DENY_PLACE, RuleSet.of("landscape:rulesets/zone_block/deny_place"));
put(ZoneBlockMode.ALLOW_PLACE, RuleSet.of("landscape:rulesets/zone_block/allow_place"));
}};
private ZoneBlockMode mode;
private boolean showZones = false;
private boolean powered;
private RuleSet ruleSet = RuleSet.of(AvailableRuleSets.EMPTY_RULESET);
@NotNull private RuleSet ruleSet = RuleSet.of(AvailableRuleSets.EMPTY_RULESET);
private int priority = 0;
private List<BlockZone> zones = new ArrayList<>();

public ZoneBlockBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.ZONE_BLOCK_BLOCK_ENTITY, pos, state);
this.mode = state.get(ZoneBlock.MODE);
this.zones.add(new BlockZone(new BlockPos(1, 0, 1), new BlockPos(11, 10, 11)));
}

@Override
Expand Down Expand Up @@ -208,11 +215,15 @@ public List<BlockZone> getZones(boolean wantRaw) {
return rotatedZones;
}

public RuleSet getRuleSet() {
public @NotNull RuleSet getRuleSet() {
return this.ruleSet;
}

public void setRuleSet(RuleSet ruleSet) {
if (ruleSet == null) {
this.ruleSet = RuleSet.of(AvailableRuleSets.EMPTY_RULESET);
return;
}
this.ruleSet = ruleSet;
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/net/rotgruengelb/landscape/feature/zones/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class API {

public static Optional<Boolean> allowsActionAtPos(BlockPos pos, String rule, World world, boolean includeNull) {
public static Optional<Boolean> allowsAction(BlockPos pos, String rule, World world, boolean includeNull) {
if (pos == null || rule == null || world == null) {
return Optional.empty();
}
Expand Down Expand Up @@ -47,20 +47,20 @@ public static Optional<Boolean> allowsActionAtPos(BlockPos pos, String rule, Wor
return result;
}

public static boolean allowsActionAtPos(@NotNull BlockPos pos, @NotNull String rule, @NotNull World world) {
return allowsActionAtPos(pos, rule, world, false).orElseThrow(() -> new IllegalStateException("Result should not be null"));
public static boolean allowsAction(@NotNull BlockPos pos, @NotNull String rule, @NotNull World world) {
return allowsAction(pos, rule, world, false).orElseThrow(() -> new IllegalStateException("Result should not be null"));
}

public static boolean allowsActionAtPos(BlockPos pos, String rule, World world, String extendedRule) {
return allowsActionAtPos(pos, mergeRuleParts(rule, extendedRule), world, true).orElseGet(() -> allowsActionAtPos(pos, rule, world));
public static boolean allowsAction(BlockPos pos, String rule, World world, String extendedRule) {
return allowsAction(pos, mergeRuleParts(rule, extendedRule), world, true).orElseGet(() -> allowsAction(pos, rule, world));
}

public static boolean denysActionAtPos(BlockPos pos, String rule, World world) {
return !allowsActionAtPos(pos, rule, world);
public static boolean denysAction(BlockPos pos, String rule, World world) {
return !allowsAction(pos, rule, world);
}

public static boolean denysActionAtPos(BlockPos pos, String rule, World world, String extendedRule) {
return !allowsActionAtPos(pos, rule, world, extendedRule);
public static boolean denysAction(BlockPos pos, String rule, World world, String extendedRule) {
return !allowsAction(pos, rule, world, extendedRule);
}

public static String mergeRuleParts(String rule, String extendedRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand Down Expand Up @@ -63,6 +64,13 @@ public static void removeZoneManager(BlockPos pos, World world) {
}
}

public static void sendClientInitialSync(ServerPlayerEntity player) {
zoneManagers.forEach((key, value) -> value.values().forEach(manager -> {
Landscape.LOGGER.debug("Sending ZoneManagerSyncS2CPacket ADD (INITIAL) for " + manager.pos() + " in " + key + " to " + player.getName().getString());
ServerPlayNetworking.send(player, PacketIds.S2C_ZONE_MANAGER_SYNC_PACKET_ID, new ZoneManagerSyncS2CPacket(ZoneManagerSyncS2CPacket.OperationType.ADD, manager, player.getServerWorld()).create());
}));
}

public static void updateZoneManager(ZoneManagerContext manager, World world) {
if (!world.isClient) {
getOrCreateZoneManagers(world).replace(manager.pos(), manager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.JsonObject;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.rotgruengelb.landscape.feature.zones.rule.AvailableRuleSets;
import net.rotgruengelb.landscape.feature.zones.rule.RuleSet;
import net.rotgruengelb.landscape.util.math.BlockZone;
import net.rotgruengelb.landscape.util.math.PositionUtils;
Expand Down Expand Up @@ -38,6 +39,12 @@ public static List<BlockZone> zonesFromJson(String jsonString) {
return zones;
}

@Override
public RuleSet ruleSet() {
if (this.ruleSet == null) { return RuleSet.of(AvailableRuleSets.EMPTY_RULESET); }
return ruleSet;
}

public boolean isBlockPosInZone(BlockPos pos, boolean isRelative) {
if (!isRelative) {
pos = PositionUtils.blockPosToRelative(pos, this.pos());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class AvailableRuleSets {

private static Map<Identifier, RuleSet> RULE_SETS = new HashMap<>();

public static void apply(Map<Identifier, RuleSet> resource) { RULE_SETS = resource; }
public static void apply(Map<Identifier, RuleSet> resource) {
RULE_SETS = resource;
}

public static Map<Identifier, RuleSet> getRuleSets() { return RULE_SETS; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.rotgruengelb.landscape.feature.zones.rule;

import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Objects;
Expand All @@ -9,10 +10,10 @@ public class RuleSet {

private final HashMap<String, Boolean> rules = new HashMap<>();
private final String name;
private final Identifier identifier;
@NotNull private final Identifier identifier;

public RuleSet(String name, Identifier identifier) {
this.name = name;
public RuleSet(String name, @NotNull Identifier identifier) {
this.name = Objects.requireNonNullElse(name, identifier.getPath());
this.identifier = identifier;
}

Expand All @@ -37,7 +38,7 @@ public String getName() {
return name;
}

public Identifier getIdentifier() {
public @NotNull Identifier getIdentifier() {
return identifier;
}

Expand Down

0 comments on commit 61418a6

Please sign in to comment.