Skip to content

Commit

Permalink
Multiple bugfixes and configurable void air
Browse files Browse the repository at this point in the history
- Change machine color to be actual MachineColor, and take either hex or int values
- Fix? broken particle textures on machine blocks
- Add relocation not supported tag to several blocks (walls, bound machines)
- Disable test command
- Change allow-outside config to not damage players
    - this is now handled by a new setting for applying damage
- Poison effect on void air changed to confusion and movement slowdown
- Fix machines not dropping with their [dyed] colors
- Reset player tracking when they leave the Compact dimension
  • Loading branch information
robotgryphon committed Aug 8, 2024
1 parent 7745fa4 commit 0272e12
Show file tree
Hide file tree
Showing 36 changed files with 234 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public static DimensionDataStorage getDataStorage(@NotNull LevelStorageSource.Le
}

public static boolean isLevelCompact(Level level) {
return level.dimension().equals(LEVEL_KEY);
return isLevelCompact(level.dimension());
}

public static boolean isLevelCompact(ResourceKey<Level> level) {
return level.equals(LEVEL_KEY);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.compactmods.machines.api.item.component;

import com.mojang.serialization.Codec;
import dev.compactmods.machines.api.machine.MachineColor;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -23,8 +24,8 @@ public interface MachineComponents {
.persistent(ResourceLocation.CODEC)
.networkSynchronized(ResourceLocation.STREAM_CODEC);

UnaryOperator<DataComponentType.Builder<Integer>> MACHINE_COLOR = (builder) -> builder
.persistent(Codec.INT)
.networkSynchronized(ByteBufCodecs.INT);
UnaryOperator<DataComponentType.Builder<MachineColor>> MACHINE_COLOR = (builder) -> builder
.persistent(MachineColor.CODEC)
.networkSynchronized(MachineColor.STREAM_CODEC);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.util.FastColor;
import net.minecraft.world.item.DyeColor;

import java.util.Locale;

Expand All @@ -18,7 +19,9 @@ public static MachineColor fromARGB(int argb) {
return new MachineColor(red, green, blue);
}

public static final Codec<MachineColor> CODEC = Codec.STRING.comapFlatMap(str -> {
public static final Codec<MachineColor> INT_CODEC = Codec.INT.xmap(MachineColor::fromARGB, MachineColor::rgb);

public static final Codec<MachineColor> HEX_CODEC = Codec.STRING.comapFlatMap(str -> {
if (!str.startsWith("#")) {
return DataResult.error(() -> "Not a color code: " + str);
} else {
Expand All @@ -35,8 +38,14 @@ public static MachineColor fromARGB(int argb) {
}
}, MachineColor::formatValue);

public static final Codec<MachineColor> CODEC = Codec.withAlternative(HEX_CODEC, INT_CODEC);

public static final StreamCodec<ByteBuf, MachineColor> STREAM_CODEC = ByteBufCodecs.INT.map(MachineColor::fromARGB, MachineColor::rgb);

public static MachineColor fromDyeColor(DyeColor color) {
return MachineColor.fromARGB(color.getFireworkColor());
}

public int rgb() {
return FastColor.ARGB32.color(red, green, blue);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.compactmods.machines.api.room;

import dev.compactmods.machines.api.machine.MachineColor;
import dev.compactmods.machines.api.room.spatial.IRoomBoundaries;
import dev.compactmods.machines.api.room.spatial.IRoomChunks;
import dev.compactmods.machines.api.room.spawn.IRoomSpawnManager;

import java.util.function.Supplier;

public record RoomInstance(String code, int defaultMachineColor, IRoomBoundaries boundaries) {
public record RoomInstance(String code, MachineColor defaultMachineColor, IRoomBoundaries boundaries) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ public interface IRoomBuilder {

IRoomBuilder owner(UUID owner);

default IRoomBuilder defaultMachineColor(MachineColor color) {
return defaultMachineColor(color.rgb());
}

IRoomBuilder defaultMachineColor(int color);
IRoomBuilder defaultMachineColor(MachineColor color);

RoomInstance build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected void registerStatesAndModels() {
// New machine block
final var m = models
.withExistingParent("block/machine/machine", mcLoc("block/block"))
.texture("particle", modLoc("block/machine/tint"))
.texture("border", modLoc("block/machine/border"))
.texture("tint", modLoc("block/machine/tint"))
.texture("overlay", modLoc("block/machine/overlay"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,49 @@

import dev.compactmods.machines.api.CompactMachines;
import dev.compactmods.machines.api.machine.MachineConstants;
import dev.compactmods.machines.dimension.Dimension;
import dev.compactmods.machines.machine.Machines;
import dev.compactmods.machines.room.Rooms;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.PackOutput;
import net.minecraft.tags.BlockTags;
import net.neoforged.neoforge.common.Tags;
import net.neoforged.neoforge.common.data.BlockTagsProvider;
import net.neoforged.neoforge.common.data.ExistingFileHelper;

import java.util.concurrent.CompletableFuture;

public class BlockTagGenerator extends BlockTagsProvider {

public BlockTagGenerator(PackOutput packOut, ExistingFileHelper files, CompletableFuture<HolderLookup.Provider> lookup) {
super(packOut, lookup, CompactMachines.MOD_ID, files);
}

@Override
protected void addTags(HolderLookup.Provider provider) {
var breakableWall = Rooms.Blocks.BREAKABLE_WALL.get();
var boundMachine = Machines.Blocks.BOUND_MACHINE.get();
var unboundMachine = Machines.Blocks.UNBOUND_MACHINE.get();

tag(MachineConstants.MACHINE_BLOCK)
.add(boundMachine, unboundMachine);

tag(MachineConstants.UNBOUND_MACHINE_BLOCK)
.add(unboundMachine);

tag(BlockTags.MINEABLE_WITH_PICKAXE)
.add(breakableWall)
.add(boundMachine, unboundMachine);

tag(BlockTags.NEEDS_IRON_TOOL)
.add(breakableWall)
.add(boundMachine, unboundMachine);
}
public BlockTagGenerator(PackOutput packOut, ExistingFileHelper files, CompletableFuture<HolderLookup.Provider> lookup) {
super(packOut, lookup, CompactMachines.MOD_ID, files);
}

@Override
protected void addTags(HolderLookup.Provider provider) {
final var breakableWall = Rooms.Blocks.BREAKABLE_WALL.get();
final var solidWall = Rooms.Blocks.SOLID_WALL.get();
final var boundMachine = Machines.Blocks.BOUND_MACHINE.get();
final var unboundMachine = Machines.Blocks.UNBOUND_MACHINE.get();
final var voidAir = Dimension.BLOCK_MACHINE_VOID_AIR.get();

tag(MachineConstants.MACHINE_BLOCK)
.add(boundMachine, unboundMachine);

tag(MachineConstants.UNBOUND_MACHINE_BLOCK)
.add(unboundMachine);

tag(BlockTags.MINEABLE_WITH_PICKAXE)
.add(breakableWall)
.add(boundMachine, unboundMachine);

tag(BlockTags.NEEDS_IRON_TOOL)
.add(breakableWall)
.add(boundMachine, unboundMachine);

tag(Tags.Blocks.RELOCATION_NOT_SUPPORTED)
.add(boundMachine)
.add(solidWall)
.add(voidAir);
}
}
6 changes: 5 additions & 1 deletion neoforge-main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ repositories {
}
}

maven("https://maven.pkg.github.com/compactmods/compactmachines-core") {
maven("https://maven.pkg.github.com/compactmods/feather") {
name = "Github PKG Core"
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.token") as String? ?: System.getenv("GITHUB_TOKEN")
}

content {
includeGroup("dev.compactmods")
}
}

maven("https://maven.blamejared.com/") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.compactmods.machines.config;
package dev.compactmods.machines;

import net.neoforged.neoforge.common.ModConfigSpec;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import dev.compactmods.machines.api.CompactMachines;
import dev.compactmods.machines.command.Commands;
import dev.compactmods.machines.compat.InterModCompat;
import dev.compactmods.machines.config.CommonConfig;
import dev.compactmods.machines.config.ServerConfig;
import dev.compactmods.machines.server.ServerConfig;
import dev.compactmods.machines.dimension.Dimension;
import dev.compactmods.machines.dimension.WorldBorderFixer;
import dev.compactmods.machines.machine.Machines;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class MachineColors {

public static final ItemColor ITEM = (stack, pTintIndex) -> {
if (!stack.is(MachineConstants.MACHINE_ITEM)) return DEFAULT;
return pTintIndex == 0 ? stack.getOrDefault(Machines.DataComponents.MACHINE_COLOR, DEFAULT) : DEFAULT;
return pTintIndex == 0 ? stack.getOrDefault(Machines.DataComponents.MACHINE_COLOR, dev.compactmods.machines.machine.MachineColors.WHITE).rgb()
: DEFAULT;
};

public static final BlockColor BLOCK = (state, level, pos, tintIndex) -> {
Expand All @@ -20,7 +21,7 @@ public class MachineColors {

var be = level.getBlockEntity(pos);
if (be != null)
return tintIndex == 0 ? be.getData(Machines.Attachments.MACHINE_COLOR) : DEFAULT;
return tintIndex == 0 ? be.getData(Machines.Attachments.MACHINE_COLOR).rgb() : DEFAULT;

return DEFAULT;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ public static void onCommandsRegister(final RegisterCommandsEvent event) {
Commands.CM_COMMAND_ROOT.then(CMGiveMachineSubcommand.make());
Commands.CM_COMMAND_ROOT.then(SpawnSubcommand.make());

CM_COMMAND_ROOT.then(net.minecraft.commands.Commands.literal("test").executes(ctx -> {
final var player = ctx.getSource().getPlayerOrException();

final var diamondAxe = new ItemStack(Items.DIAMOND_AXE);

final var treecutter = new TreeCutterUpgrade();

final var upgrades = new RoomUpgradeList(List.of(treecutter));

diamondAxe.set(RoomUpgrades.UPGRADE_LIST_COMPONENT, upgrades);

player.addItem(diamondAxe);

return 0;
}));
// CM_COMMAND_ROOT.then(net.minecraft.commands.Commands.literal("test").executes(ctx -> {
// final var player = ctx.getSource().getPlayerOrException();
//
// final var diamondAxe = new ItemStack(Items.DIAMOND_AXE);
//
// final var treecutter = new TreeCutterUpgrade();
//
// final var upgrades = new RoomUpgradeList(List.of(treecutter));
//
// diamondAxe.set(RoomUpgrades.UPGRADE_LIST_COMPONENT, upgrades);
//
// player.addItem(diamondAxe);
//
// return 0;
// }));

event.getDispatcher().register(Commands.CM_COMMAND_ROOT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.compactmods.machines.api.CompactMachines;
import dev.compactmods.machines.api.room.template.RoomTemplate;
import dev.compactmods.machines.LoggingUtil;
import dev.compactmods.machines.api.command.CommandTranslations;
import dev.compactmods.machines.api.room.RoomTranslations;
import dev.compactmods.machines.api.room.template.RoomTemplateHelper;
import dev.compactmods.machines.command.argument.Suggestors;
import dev.compactmods.machines.config.ServerConfig;
import dev.compactmods.machines.server.ServerConfig;
import dev.compactmods.machines.machine.Machines;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import dev.compactmods.machines.api.CompactMachines;
import dev.compactmods.machines.api.machine.MachineTranslations;
import dev.compactmods.machines.LoggingUtil;
import dev.compactmods.machines.config.ServerConfig;
import dev.compactmods.machines.server.ServerConfig;
import dev.compactmods.machines.machine.block.BoundCompactMachineBlockEntity;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import dev.compactmods.machines.api.room.RoomTranslations;
import dev.compactmods.machines.api.room.history.RoomEntryPoint;
import dev.compactmods.machines.command.argument.Suggestors;
import dev.compactmods.machines.config.ServerConfig;
import dev.compactmods.machines.server.ServerConfig;
import dev.compactmods.machines.room.RoomHelper;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import dev.compactmods.machines.LoggingUtil;
import dev.compactmods.machines.api.dimension.CompactDimension;
import dev.compactmods.machines.api.machine.MachineTranslations;
import dev.compactmods.machines.config.ServerConfig;
import dev.compactmods.machines.server.ServerConfig;
import dev.compactmods.machines.machine.Machines;
import dev.compactmods.machines.machine.block.BoundCompactMachineBlockEntity;
import net.minecraft.commands.CommandSourceStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.mojang.brigadier.context.CommandContext;
import dev.compactmods.machines.api.CompactMachines;
import dev.compactmods.machines.api.command.CommandTranslations;
import dev.compactmods.machines.config.ServerConfig;
import dev.compactmods.machines.server.ServerConfig;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.compactmods.machines.dimension;

import dev.compactmods.machines.config.ServerConfig;
import dev.compactmods.machines.api.dimension.CompactDimension;
import dev.compactmods.machines.room.Rooms;
import dev.compactmods.machines.server.ServerConfig;
import dev.compactmods.machines.util.PlayerUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -39,21 +41,44 @@ public boolean canHarvestBlock(BlockState state, BlockGetter level, BlockPos pos

@Override
public void entityInside(BlockState pState, Level pLevel, BlockPos pPos, Entity pEntity) {
if (ServerConfig.isAllowedOutsideOfMachine()) return;
if (pLevel.isClientSide) return;
if (!CompactDimension.isLevelCompact(pLevel)) return;

// TODO: Configurable behavior
if (pEntity instanceof ServerPlayer player) {
if (player.isCreative()) return;
// If players are allowed outside of machine bounds, early exit -- but damage them if configured
if (ServerConfig.isAllowedOutsideOfMachine()) {
tryDamagingAdventurousPlayer(pLevel, player);
return;
}

player.addEffect(new MobEffectInstance(MobEffects.POISON, 5 * 20));
player.addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 5 * 20));
player.hurt(pLevel.damageSources().fellOutOfWorld(), 1);
tryDamagingAdventurousPlayer(pLevel, player);

// FIXME - Achievement
// PlayerUtil.howDidYouGetThere(player);
// player.getCapability(RoomCapabilities.ROOM_HISTORY).ifPresent(IRoomHistory::clear);
PlayerUtil.teleportPlayerToRespawnOrOverworld(player.server, player);
}
}

/**
* Attempts to inflict the bad effects on players that are touching a void air block.
* Does nothing to players that are in creative mode.
*
* @param pLevel
* @param player
*/
private static void tryDamagingAdventurousPlayer(Level pLevel, ServerPlayer player) {
if (player.isCreative()) return;

if (ServerConfig.damagePlayersOutOfBounds()) {
if(!player.hasEffect(MobEffects.CONFUSION)) {
player.addEffect(new MobEffectInstance(MobEffects.CONFUSION, 5 * 20));
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 5 * 20));
player.addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 5 * 20));
}

if (player.getHealth() > 1) {
player.hurt(pLevel.damageSources().fellOutOfWorld(), player.getHealth() - 1);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.compactmods.machines.machine;

import dev.compactmods.machines.api.machine.MachineColor;
import net.minecraft.util.CommonColors;

public interface MachineColors {

MachineColor WHITE = MachineColor.fromARGB(CommonColors.WHITE);
}
Loading

0 comments on commit 0272e12

Please sign in to comment.