Skip to content
Merged
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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/java/org/cyclops/integrateddynamics/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public static void registerBlocks(ConfigHandler configHandler) {
configHandler.addConfigurable(new DataComponentWrenchTargetBlockPosConfig());
configHandler.addConfigurable(new DataComponentWrenchTargetDirectionConfig());
configHandler.addConfigurable(new DataComponentWrenchModeConfig());
configHandler.addConfigurable(new DataComponentWrenchPartConfigConfig());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public class RegistryEntries {
public static final DeferredHolder<DataComponentType<?>, DataComponentType<BlockPos>> DATACOMPONENT_WRENCH_TARGET_BLOCKPOS = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("integrateddynamics:wrench_target_blockpos"));
public static final DeferredHolder<DataComponentType<?>, DataComponentType<Direction>> DATACOMPONENT_WRENCH_TARGET_DIRECTION = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("integrateddynamics:wrench_target_direction"));
public static final DeferredHolder<DataComponentType<?>, DataComponentType<ItemWrench.Mode>> DATACOMPONENT_WRENCH_MODE = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("integrateddynamics:wrench_mode"));
public static final DeferredHolder<DataComponentType<?>, DataComponentType<CompoundTag>> DATACOMPONENT_WRENCH_PART_CONFIG = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("integrateddynamics:wrench_part_config"));


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
import org.cyclops.integrateddynamics.GeneralConfig;
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.network.INetworkElement;
Expand Down Expand Up @@ -68,6 +69,17 @@ public interface IPartState<P extends IPartType> {
*/
public int getUpdateInterval();

/**
* This is separate from the protected default update interval that part states can override,
* as making that one public would break every part state outside of this mod that overrides it.
*
* @return The tick interval that this part has before a player configures it.
*/
// TODO: make non-default in nextmajor
public default int getDefaultUpdateIntervalPublic() {
return GeneralConfig.defaultPartUpdateFreq;
}

/**
* Set the priority of this part in the network.
* @deprecated Should only be called from {@link org.cyclops.integrateddynamics.api.network.INetwork#setPriorityAndChannel(INetworkElement, int, int)}}!
Expand Down
109 changes: 109 additions & 0 deletions src/main/java/org/cyclops/integrateddynamics/api/part/IPartType.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@
import org.cyclops.integrateddynamics.api.network.INetworkEventListener;
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
import org.cyclops.integrateddynamics.api.network.IPartNetworkElement;
import org.cyclops.integrateddynamics.core.helper.PartConfigHelpers;
import org.cyclops.integrateddynamics.core.part.PartConfigApplyResult;
import org.cyclops.integrateddynamics.core.part.PartConfigSection;
import org.cyclops.integrateddynamics.core.part.PartConfigSnapshot;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.Set;

/**
* A type of part that can be inserted into a {@link IPartContainer}.
Expand Down Expand Up @@ -205,6 +210,110 @@ public default void onAspectVariablesChanged(PartTarget target, S state) {
state.markAspectVariablesChanged();
}

/**
* Take a snapshot of the configuration of this part, so that it can be pasted onto another part.
* @param valueDeseralizationContext A value deserialization context.
* @param state The state.
* @param sections The configuration sections to include.
* @return The snapshot.
*/
// TODO: make non-default in nextmajor
public default PartConfigSnapshot snapshotConfig(ValueDeseralizationContext valueDeseralizationContext, S state,
Set<PartConfigSection> sections) {
return PartConfigHelpers.snapshot(valueDeseralizationContext, this, state, sections);
}

/**
* Paste a configuration snapshot onto this part.
*
* This is only called server-side.
*
* @param valueDeseralizationContext A value deserialization context.
* @param network The network of this part, or null if it is not in a network.
* @param partNetwork The part network of this part, or null if it is not in a network.
* @param target The target block.
* @param state The state.
* @param snapshot The snapshot to paste.
* @param sections The configuration sections to paste.
* @param player The player that is pasting, whose inventory is used for the variable cards.
* @return The outcome.
*/
// TODO: make non-default in nextmajor
public default PartConfigApplyResult applyConfig(ValueDeseralizationContext valueDeseralizationContext,
@Nullable INetwork network, @Nullable IPartNetwork partNetwork,
PartTarget target, S state, PartConfigSnapshot snapshot,
Set<PartConfigSection> sections, Player player) {
return PartConfigHelpers.apply(valueDeseralizationContext, network, target, this, state, snapshot, sections, player);
}

/**
* Take a snapshot of the state that {@link PartConfigSnapshot} does not know about itself.
*
* This is the extension point for part types that hold their own state,
* such as the part types that addons add.
* Implementations should only store what the player configured,
* so that pasting does not overwrite anything that was left at its default,
* and should keep the format stable, as a snapshot can outlive a world reload.
*
* This is only called server-side.
*
* @param valueDeseralizationContext A value deserialization context.
* @param state The state.
* @param section The configuration section that is being copied.
* @return What to store for that section, or an empty tag to store nothing.
*/
// TODO: make non-default in nextmajor
public default CompoundTag snapshotConfigExtra(ValueDeseralizationContext valueDeseralizationContext, S state,
PartConfigSection section) {
return new CompoundTag();
}

/**
* Paste back what {@link #snapshotConfigExtra(ValueDeseralizationContext, IPartState, PartConfigSection)} stored.
*
* This is only called for the sections that are being pasted,
* and only when the snapshot holds something for them.
* Since the subset modes of the Wrench can paste onto another part type,
* implementations should check {@link PartConfigSnapshot#sourcePartType()}
* before reading anything that only makes sense for their own part types.
*
* Anything that had to be consumed from the player can be reported through the given result,
* so that the player is told about it.
*
* This is only called server-side.
*
* @param valueDeseralizationContext A value deserialization context.
* @param target The target block.
* @param state The state.
* @param section The configuration section that is being pasted.
* @param snapshot The snapshot that is being pasted,
* holding the stored state in {@link PartConfigSnapshot#getExtraData(PartConfigSection)}.
* @param player The player that is pasting.
* @param result The outcome to report into.
*/
// TODO: make non-default in nextmajor
public default void applyConfigExtra(ValueDeseralizationContext valueDeseralizationContext, PartTarget target,
S state, PartConfigSection section, PartConfigSnapshot snapshot,
Player player, PartConfigApplyResult result) {

}

/**
* What a player needs in their inventory before
* {@link #applyConfigExtra(ValueDeseralizationContext, PartTarget, IPartState, PartConfigSection, PartConfigSnapshot, Player, PartConfigApplyResult)}
* can paste everything, to be shown in the tooltip of the Wrench.
*
* This is called on the part type that the snapshot was taken from, on both sides.
*
* @param snapshot The snapshot that is being pasted.
* @param section The configuration section that would be pasted.
* @return One line per requirement, or nothing if pasting needs nothing from the player.
*/
// TODO: make non-default in nextmajor
public default List<Component> getConfigExtraRequirements(PartConfigSnapshot snapshot, PartConfigSection section) {
return List.of();
}

/**
* @param state The state
* @return If this element should be updated. This method is only called once during network initialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.cyclops.integrateddynamics.api.network.IPartNetworkElement;
import org.cyclops.integrateddynamics.api.network.event.INetworkEvent;
import org.cyclops.integrateddynamics.core.part.PartStateAspectVariablesHandler;
import org.cyclops.integrateddynamics.core.part.PartStateOffsetHandler;

import javax.annotation.Nullable;
import java.util.Collections;
Expand Down Expand Up @@ -137,7 +138,7 @@ public PartTarget getTarget(PartPos pos, S state) {
}

protected boolean hasOffsetVariables(S state) {
NonNullList<ItemStack> inventory = state.getInventoryNamed("offsetVariablesInventory");
NonNullList<ItemStack> inventory = state.getInventoryNamed(PartStateOffsetHandler.INVENTORY_NAME);
return inventory != null && inventory.stream().anyMatch(item -> !item.isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import org.cyclops.cyclopscore.helper.RenderHelpers;
import org.cyclops.integrateddynamics.api.part.IPartContainer;
import org.cyclops.integrateddynamics.api.part.IPartType;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.core.block.BlockRayTraceResultComponent;
import org.cyclops.integrateddynamics.core.block.VoxelShapeComponents;
import org.cyclops.integrateddynamics.core.block.VoxelShapeComponentsFactory;
import org.cyclops.integrateddynamics.core.helper.CableHelpers;
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
import org.cyclops.integrateddynamics.core.helper.WrenchHelpers;
import org.cyclops.integrateddynamics.item.ItemBlockCable;
import org.cyclops.integrateddynamics.item.ItemWrench;

import javax.annotation.Nullable;
import java.util.Collection;
Expand Down Expand Up @@ -107,7 +109,13 @@ public BakedModel getBreakingBaseModel(Level world, BlockPos pos) {
@Override
public InteractionResult onBlockActivated(BlockState state, Level world, BlockPos blockPos, Player player, InteractionHand hand, BlockRayTraceResultComponent hit) {
ItemStack heldItem = player.getItemInHand(hand);
if(WrenchHelpers.isWrench(player, heldItem, world, blockPos, hit.getDirection()) && player.isSecondaryUseActive()) {
if(heldItem.getItem() instanceof ItemWrench itemWrench
&& itemWrench.getMode(heldItem).isConfig()
&& player.isSecondaryUseActive()) {
// Copy the configuration of this part into the wrench, instead of removing the part
itemWrench.copyPartConfig(heldItem, player, PartPos.of(world, blockPos, direction));
return InteractionResult.SUCCESS;
} else if(WrenchHelpers.isWrench(player, heldItem, world, blockPos, hit.getDirection()) && player.isSecondaryUseActive()) {
// Remove part from cable
if (!world.isClientSide()) {
destroy(world, blockPos, player, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.cyclops.integrateddynamics.component;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.codec.ByteBufCodecs;
import org.cyclops.cyclopscore.config.extendedconfig.DataComponentConfig;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.core.helper.Codecs;

/**
* @author rubensworks
*/
public class DataComponentWrenchPartConfigConfig extends DataComponentConfig<CompoundTag> {

public DataComponentWrenchPartConfigConfig() {
super(IntegratedDynamics._instance, "wrench_part_config", builder -> builder
.persistent(Codecs.COMPOUND_TAG)
.networkSynchronized(ByteBufCodecs.COMPOUND_TAG));
}
}
Loading
Loading