Skip to content

Commit

Permalink
Lots and lots of work. Now functional on 1.21!
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Jul 6, 2024
1 parent d56b02e commit afd5723
Show file tree
Hide file tree
Showing 335 changed files with 3,591 additions and 2,547 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ runs {

client {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
jvmArguments.addAll('-Xmx4G')
}

server {
Expand Down Expand Up @@ -156,8 +157,8 @@ dependencies {

compileOnly("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}")
compileOnly("mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}")
// runtimeOnly("mezz.jei:jei-${minecraft_version}-common:${jei_version}")
// runtimeOnly("mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}")
runtimeOnly("mezz.jei:jei-${minecraft_version}-common:${jei_version}")
runtimeOnly("mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}")

compileOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}:api")
// runtimeOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}")
Expand All @@ -168,8 +169,8 @@ dependencies {
compileOnly("vazkii.patchouli:Patchouli:${patchouli_version}:api")
//runtimeOnly("vazkii.patchouli:Patchouli:${patchouli_version}")

compileOnly("cc.tweaked:cc-tweaked-1.20.6-forge-api:${cc_tweaked_version}")
//runtimeOnly("cc.tweaked:cc-weaked-1.20.4-forge:${cc_tweaked_version}")
compileOnly("cc.tweaked:cc-tweaked-1.21-forge-api:${cc_tweaked_version}")
runtimeOnly("cc.tweaked:cc-tweaked-1.21-forge:${cc_tweaked_version}")

compileOnly("dev.ftb.mods:ftb-filter-system-neoforge:${ffs_version}") { transitive = false }

Expand Down
14 changes: 8 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ org.gradle.daemon=false
#########################################################
minecraft_version=1.21
minecraft_version_range=[1.21,)
neo_version=21.0.21-beta
neo_version_range=[21.0.21-beta,)
neo_version=21.0.52-beta
neo_version_range=[21.0.40-beta,)
loader_version_range=[4,)
mappings_version=1.20.6-2024.06.02
pack_format_number=18
neogradle.subsystems.parchment.minecraftVersion=1.21
neogradle.subsystems.parchment.mappingsVersion=2024.06.23

#########################################################
# Mod version
Expand All @@ -32,18 +34,18 @@ curse_project_id=281849
#########################################################
# API versions
#########################################################
jei_version=19.0.0.9
jei_version=19.1.0.17
curios_version=8.0.0-beta+1.20.6
top_version=1.21_neo-12.0.0-1
ffs_version=3.0.0
jade_curse_id = 5427817
jade_curse_id = 5493270
crafttweaker_version=20.0.4
cc_tweaked_version=1.111.0
mekanism_version=1.21-10.6.4.50

# TODO update deps when available
mekanism_version=1.20.4-10.5.19.40
immersive_engineering_version=1.20.4-11.1.0-172.110
patchouli_version=1.20.4-85-NEOFORGE-SNAPSHOT
cc_tweaked_version=1.111.0

# more out-of-date deps :p
botania_version=1.20.1-441-FORGE-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

package me.desht.pneumaticcraft.api.crafting.recipe;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.ByteBufCodecs;
Expand All @@ -33,6 +37,7 @@

import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
* Recipes which define the heat properties of a block; its temperature, thermal resistance, heat capacity, and the
Expand Down Expand Up @@ -156,13 +161,24 @@ public Component getInputDisplayName() {
new ItemStack(getBlock()).getHoverName();
}

private static final Codec<BlockState> BLOCKSTATE_STRING_CODEC = Codec.STRING.comapFlatMap(
string -> {
try {
return DataResult.success(BlockStateParser.parseForBlock(BuiltInRegistries.BLOCK.asLookup(), string, false).blockState());
} catch (CommandSyntaxException e) {
return DataResult.error(() -> "invalid blockstate definition: " + string);
}
},
BlockStateParser::serialize
);

public record Transforms(Optional<BlockState> hot, Optional<BlockState> cold,
Optional<BlockState> hotFlowing, Optional<BlockState> coldFlowing) {
public static final Codec<Transforms> CODEC = RecordCodecBuilder.create(builder -> builder.group(
BlockState.CODEC.optionalFieldOf("hot").forGetter(Transforms::hot),
BlockState.CODEC.optionalFieldOf("cold").forGetter(Transforms::cold),
BlockState.CODEC.optionalFieldOf("hot_flowing").forGetter(Transforms::hotFlowing),
BlockState.CODEC.optionalFieldOf("cold_flowing").forGetter(Transforms::coldFlowing)
BLOCKSTATE_STRING_CODEC.optionalFieldOf("hot").forGetter(Transforms::hot),
BLOCKSTATE_STRING_CODEC.optionalFieldOf("cold").forGetter(Transforms::cold),
BLOCKSTATE_STRING_CODEC.optionalFieldOf("hot_flowing").forGetter(Transforms::hotFlowing),
BLOCKSTATE_STRING_CODEC.optionalFieldOf("cold_flowing").forGetter(Transforms::coldFlowing)
).apply(builder, Transforms::new));
public static final StreamCodec<RegistryFriendlyByteBuf, Transforms> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.optional(ByteBufCodecs.fromCodec(BlockState.CODEC)), Transforms::hot,
Expand All @@ -171,5 +187,10 @@ public record Transforms(Optional<BlockState> hot, Optional<BlockState> cold,
ByteBufCodecs.optional(ByteBufCodecs.fromCodec(BlockState.CODEC)), Transforms::coldFlowing,
Transforms::new
);

public static final Transforms NONE = new Transforms(
Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ public final int getInputFluidAmount() {
return getInputFluid().map(SizedFluidIngredient::amount).orElse(0);
}

/**
* Test if this fluid is OK for this recipe. The fluid amount of the itemstack is ignored here; we're just
* interested if the fluid is acceptable.
* @param fluid the fluid stack to check
* @return true if this recipe accepts this fluid type, false otherwise
*/
public final boolean testFluid(FluidStack fluid) {
return getInputFluid().map(i -> i.test(fluid)).orElse(false);
// map sized ingredient to plain ingredient because we're not interested in amount here, just the fluid type
return getInputFluid().map(i -> i.ingredient().test(fluid)).orElse(false);
}

public final boolean testItem(ItemStack stack) {
Expand Down Expand Up @@ -155,8 +162,8 @@ public record Outputs(FluidStack outputFluid, ItemStack outputItem) {
.forGetter(Outputs::outputItem)
).apply(builder, Outputs::new));
public static StreamCodec<RegistryFriendlyByteBuf, Outputs> STREAM_CODEC = StreamCodec.composite(
FluidStack.STREAM_CODEC, Outputs::outputFluid,
ItemStack.STREAM_CODEC, Outputs::outputItem,
FluidStack.OPTIONAL_STREAM_CODEC, Outputs::outputFluid,
ItemStack.OPTIONAL_STREAM_CODEC, Outputs::outputItem,
Outputs::new
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static class Blocks extends PneumaticCraftTags {
public static final TagKey<Block> PROBE_TARGET = modTag("probe_target");
public static final TagKey<Block> JACKHAMMER_ORES = modTag("jackhammer_ores");
public static final TagKey<Block> ELECTROSTATIC_GRID = modTag("electrostatic_grid");
public static final TagKey<Block> CROP_SUPPORT_GROWABLE = modTag("crop_support_growable");

public static final TagKey<Block> STORAGE_BLOCKS_COMPRESSED_IRON = commonTag("storage_blocks/compressed_iron");

Expand Down
19 changes: 3 additions & 16 deletions src/api/java/me/desht/pneumaticcraft/api/drone/IProgWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package me.desht.pneumaticcraft.api.drone;

import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.core.HolderLookup;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.goal.Goal;
Expand Down Expand Up @@ -156,18 +156,9 @@ default String getTranslationKey() {
*/
boolean isAvailable();

// /**
// * At least do <code>tag.putString("name", getTypeID().toString());</code>
// * <p>Note that the base implementation {@link ProgWidget} does this.</p>
// *
// * @param tag NBT tag to write to
// * @param provider
// */
// void writeToNBT(CompoundTag tag, HolderLookup.Provider provider);
//
// void readFromNBT(CompoundTag tag, HolderLookup.Provider provider);
Optional<? extends IProgWidget> copy(HolderLookup.Provider provider);

Optional<? extends IProgWidget> copy();
IProgWidget copyWidget();

boolean canBeRunByComputers(IDrone drone, IProgWidget widget);

Expand All @@ -177,10 +168,6 @@ default boolean isDifficultyOK(WidgetDifficulty difficulty) {

WidgetDifficulty getDifficulty();

void readFromPacket(RegistryFriendlyByteBuf buf);

void writeToPacket(RegistryFriendlyByteBuf buf);

@Nonnull
List<Component> getExtraStringInfo();

Expand Down
16 changes: 12 additions & 4 deletions src/api/java/me/desht/pneumaticcraft/api/drone/ProgWidgetType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,28 @@
package me.desht.pneumaticcraft.api.drone;

import com.mojang.serialization.MapCodec;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;

import java.util.function.Supplier;

/**
* Represents the type of a progwidget. You do not need to use this directly.
* Handles serialization of progwidgets, as well as default instance creation.
*/
public class ProgWidgetType<P extends IProgWidget> {
private final Supplier<? extends P> defaultSupplier;
private final MapCodec<? extends IProgWidget> codec;
private final StreamCodec<RegistryFriendlyByteBuf,? extends IProgWidget> streamCodec;
private String descriptionId;

private ProgWidgetType(Supplier<P> defaultSupplier, MapCodec<P> codec) {
private ProgWidgetType(Supplier<P> defaultSupplier, MapCodec<P> codec, StreamCodec<RegistryFriendlyByteBuf,P> streamCodec) {
this.defaultSupplier = defaultSupplier;
this.codec = codec;
this.streamCodec = streamCodec;
}

public static <P extends IProgWidget> ProgWidgetType<P> createType(Supplier<P> factory, MapCodec<P> codec) {
return new ProgWidgetType<>(factory, codec);
public static <P extends IProgWidget> ProgWidgetType<P> createType(Supplier<P> factory, MapCodec<P> codec, StreamCodec<RegistryFriendlyByteBuf,P> streamCodec) {
return new ProgWidgetType<>(factory, codec, streamCodec);
}

public P create() {
Expand All @@ -57,4 +61,8 @@ public P cast(IProgWidget widget) {
public MapCodec<? extends IProgWidget> codec() {
return codec;
}

public StreamCodec<RegistryFriendlyByteBuf, ? extends IProgWidget> streamCodec() {
return streamCodec;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public AreaType(String name) {

public abstract AreaTypeSerializer<? extends AreaType> getSerializer();

public AreaType copy() {
// TODO copy via codec
return this;
}
/**
* Implement this to return a copy of this area type, ensuring any mutable fields of the object are copied!
*
* @return a copy of this area type
*/
public abstract AreaType copy();

public String getName() {
return name;
Expand Down Expand Up @@ -104,12 +106,12 @@ public enum AreaAxis implements ITranslatableEnum, StringRepresentable {
private final String name;

AreaAxis(String name) {
this.name = "pneumaticcraft.gui.progWidget.area.type.axis." + name;
this.name = name;
}

@Override
public String getTranslationKey() {
return name;
return "pneumaticcraft.gui.progWidget.area.type.axis." + name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@

package me.desht.pneumaticcraft.api.item;

import net.minecraft.core.component.DataComponentType;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;

import java.util.Map;
import java.util.Set;

/**
* Represents the entity types contained in a Spawner Core. Retrieve an instance of this with
Expand All @@ -37,7 +35,7 @@ public interface ISpawnerCoreStats {
/**
* Get an unmodifiable set of the entity types stored in this spawner core.
*
* @return a set of entity types
* @return a map of entity type to percentage occupied
*/
Map<EntityType<?>,Integer> getEntities();

Expand All @@ -57,18 +55,20 @@ public interface ISpawnerCoreStats {
int getUnusedPercentage();

/**
* Update the percentage level for the given entity type. The update level will be clamped so that does not go
* Update the percentage occupation for the given entity type. The update level will be clamped so that does not go
* below zero, or leaves the total occupation of the core greater than 100%.
* <p>
* The updated level is not automatically serialized to an ItemStack; use
* {@link #saveSpawnerCoreStats(ItemStack, ISpawnerCoreStats)} for that.
*
* @param type an entity type
* @param toAdd the amount to adjust by, may be negative
* @return a new stats object, which may or may not have been modified
* @return a new stats object if a modification was made, otherwise this object
*/
ISpawnerCoreStats addAmount(EntityType<?> type, int toAdd);

/**
* Serialize this object onto a ItemStack via data component.
*
* @param stack the stack to save onto
*/
void save(ItemStack stack);

/**
Expand All @@ -84,12 +84,4 @@ public interface ISpawnerCoreStats {
* {@return an empty spawner core stats object}
*/
ISpawnerCoreStats empty();

// /**
// * Serialize the current stats onto the given ItemStack, which must be a Spawner Core
// *
// * @param stack an ItemStack
// * @throws IllegalArgumentException if the ItemStack is not a Spawner Core
// */
// void serialize(ItemStack stack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public interface ISemiBlock {
BlockEntity getCachedTileEntity();

/**
* Written to the dropped item (under the "EntityTag" subtag) when the semiblock is broken, to persisted entity
* data by {@code Entity#addAdditionalSaveData()}, and displayed by info mods such as TOP or Waila. Use this method
* rather than {@code addAdditionalSaveData()} for fields that either need to be serialized to the dropped item, or
* displayed on TOP/Waila.
* Written to the dropped item (in the "pneumaticcraft:semiblock_data" component) when the semiblock is broken,
* to persisted entity data by {@code Entity#addAdditionalSaveData()}, and displayed by info mods such as TOP or
* Waila. Use this method rather than {@code addAdditionalSaveData()} for fields that either need to be serialized
* to the dropped item, or displayed on TOP/Waila.
* <p>
*
* @param tag NBT tag to write data to
* @param provider
* @param provider the lookup provider
* @implNote Data written to itemstacks is automatically applied to newly-spawned entities by
* {@link net.minecraft.world.entity.EntityType#updateCustomEntityTag(Level, Player, Entity, CustomData)} when the
* semiblock entity is spawned from an item (i.e. placed by a player).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SemiblockEvent extends Event {
private final BlockPos pos;
private final ISemiBlock semiblock;

private SemiblockEvent(Level world, BlockPos pos, ISemiBlock semiblock) {
protected SemiblockEvent(Level world, BlockPos pos, ISemiBlock semiblock) {
this.world = world;
this.pos = pos;
this.semiblock = semiblock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.ApiStatus;

import javax.annotation.Nullable;
import java.util.Collection;
Expand Down Expand Up @@ -131,6 +132,9 @@ public interface IAirHandlerMachine extends IAirHandler, IManoMeasurable {

void deserializeNBT(CompoundTag tag);

@ApiStatus.Internal
void addPendingAir(int pendingAir);

/**
* Represents a connection to a neighbouring air handler.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"pneumaticcraft:compressed_iron_chestplate",
"pneumaticcraft:pneumatic_chestplate"
]
}
Loading

0 comments on commit afd5723

Please sign in to comment.