Skip to content

Commit d738d07

Browse files
fixed engine recipe
1 parent 2680d83 commit d738d07

File tree

12 files changed

+198
-22
lines changed

12 files changed

+198
-22
lines changed

src/main/java/com/rae/creatingspace/content/datagen/recipe/CSChemicalSynthesisRecipeGen.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import com.rae.creatingspace.content.recipes.chemical_synthesis.ChemicalSynthesisRecipe;
55
import com.rae.creatingspace.init.ingameobject.FluidInit;
66
import com.rae.creatingspace.init.RecipeInit;
7-
import com.simibubi.create.api.data.recipe.ProcessingRecipeGen;
7+
import com.simibubi.create.api.data.recipe.StandardProcessingRecipeGen;
88
import com.simibubi.create.content.processing.recipe.HeatCondition;
9-
import com.simibubi.create.content.processing.recipe.ProcessingRecipeParams;
9+
import com.simibubi.create.content.processing.recipe.StandardProcessingRecipe;
1010
import com.simibubi.create.foundation.recipe.IRecipeTypeInfo;
1111
import net.minecraft.core.HolderLookup;
1212
import net.minecraft.data.PackOutput;
@@ -16,11 +16,7 @@
1616
import java.util.concurrent.CompletableFuture;
1717

1818
@SuppressWarnings("unused")
19-
public class CSChemicalSynthesisRecipeGen extends ProcessingRecipeGen<
20-
ProcessingRecipeParams,
21-
ChemicalSynthesisRecipe,
22-
ChemicalSynthesisRecipe.Builder<ChemicalSynthesisRecipe>
23-
> {
19+
public class CSChemicalSynthesisRecipeGen extends StandardProcessingRecipeGen<ChemicalSynthesisRecipe> {
2420

2521
public CSChemicalSynthesisRecipeGen(PackOutput output, CompletableFuture<HolderLookup.Provider> lookup) {
2622
super(output, lookup, CreatingSpace.MODID);
@@ -32,8 +28,8 @@ protected IRecipeTypeInfo getRecipeType() {
3228
}
3329

3430
@Override
35-
protected ChemicalSynthesisRecipe.Builder<ChemicalSynthesisRecipe> getBuilder(ResourceLocation id) {
36-
return new ChemicalSynthesisRecipe.Builder<>(ChemicalSynthesisRecipe::new, id);
31+
protected StandardProcessingRecipe.Builder<ChemicalSynthesisRecipe> getBuilder(ResourceLocation id) {
32+
return new ChemicalSynthesisRecipe.Builder(id);
3733
}
3834

3935
{

src/main/java/com/rae/creatingspace/content/recipes/chemical_synthesis/CatalystCarrierBlock.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,31 @@
55
import com.simibubi.create.AllShapes;
66
import com.simibubi.create.content.kinetics.base.HorizontalKineticBlock;
77
import com.simibubi.create.foundation.block.IBE;
8+
import net.createmod.catnip.platform.CatnipServices;
89
import net.minecraft.core.BlockPos;
910
import net.minecraft.core.Direction;
1011
import net.minecraft.core.Direction.Axis;
12+
import net.minecraft.world.InteractionHand;
13+
import net.minecraft.world.InteractionResult;
14+
import net.minecraft.world.ItemInteractionResult;
1115
import net.minecraft.world.entity.player.Player;
16+
import net.minecraft.world.item.ItemStack;
1217
import net.minecraft.world.item.context.BlockPlaceContext;
1318
import net.minecraft.world.level.BlockGetter;
19+
import net.minecraft.world.level.Level;
1420
import net.minecraft.world.level.LevelReader;
1521
import net.minecraft.world.level.block.entity.BlockEntityType;
1622
import net.minecraft.world.level.block.state.BlockState;
1723
import net.minecraft.world.level.pathfinder.PathComputationType;
24+
import net.minecraft.world.phys.BlockHitResult;
1825
import net.minecraft.world.phys.shapes.CollisionContext;
1926
import net.minecraft.world.phys.shapes.EntityCollisionContext;
2027
import net.minecraft.world.phys.shapes.VoxelShape;
28+
import org.lwjgl.system.NonnullDefault;
2129

30+
import java.util.Objects;
31+
import java.util.function.Function;
32+
@NonnullDefault
2233
public class CatalystCarrierBlock extends HorizontalKineticBlock implements IBE<CatalystCarrierBlockEntity> {
2334

2435
public CatalystCarrierBlock(Properties properties) {
@@ -44,7 +55,7 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
4455
Direction prefferedSide = getPreferredHorizontalFacing(context);
4556
if (prefferedSide != null)
4657
return defaultBlockState().setValue(HORIZONTAL_FACING, prefferedSide);
47-
return super.getStateForPlacement(context);
58+
return Objects.requireNonNull(super.getStateForPlacement(context));
4859
}
4960

5061
@Override
@@ -74,4 +85,31 @@ protected boolean isPathfindable(BlockState state, PathComputationType pathCompu
7485
return false;
7586
}
7687

88+
@Override
89+
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
90+
if (!level.isClientSide) {
91+
if (stack.getItem() instanceof CatalystItem) {
92+
withBlockEntityDo(level, pos, be -> be.setCatalyst(stack));
93+
return ItemInteractionResult.CONSUME;
94+
95+
}
96+
}
97+
return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
98+
}
99+
100+
@Override
101+
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
102+
103+
if (!level.isClientSide) {
104+
withBlockEntityDo(level, pos, be -> be.setCatalyst(ItemStack.EMPTY));
105+
return InteractionResult.SUCCESS;
106+
}
107+
return super.useWithoutItem(state, level, pos, player, hitResult);
108+
}
109+
110+
@Override
111+
public InteractionResult onBlockEntityUse(BlockGetter world, BlockPos pos, Function<CatalystCarrierBlockEntity, InteractionResult> action) {
112+
return IBE.super.onBlockEntityUse(world, pos, action);
113+
}
114+
77115
}

src/main/java/com/rae/creatingspace/content/recipes/chemical_synthesis/CatalystCarrierBlockEntity.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@
2020
import net.minecraft.sounds.SoundSource;
2121
import net.minecraft.util.Mth;
2222
import net.minecraft.world.Container;
23+
import net.minecraft.world.item.ItemStack;
2324
import net.minecraft.world.item.crafting.Recipe;
2425
import net.minecraft.world.item.crafting.RecipeHolder;
26+
import net.minecraft.world.item.crafting.RecipeInput;
2527
import net.minecraft.world.level.block.entity.BlockEntityType;
2628
import net.minecraft.world.level.block.state.BlockState;
2729
import net.minecraft.world.phys.AABB;
2830
import net.minecraft.world.phys.Vec3;
2931
import net.neoforged.api.distmarker.Dist;
3032
import net.neoforged.api.distmarker.OnlyIn;
33+
import org.jetbrains.annotations.Nullable;
3134

3235
import java.util.List;
3336
import java.util.Optional;
37+
import java.util.stream.Collectors;
3438

3539
public class CatalystCarrierBlockEntity extends BasinOperatingBlockEntity {
3640

@@ -39,6 +43,7 @@ public class CatalystCarrierBlockEntity extends BasinOperatingBlockEntity {
3943
public int runningTicks;
4044
public int processingTicks;
4145
public boolean running;
46+
private ItemStack catalyst = ItemStack.EMPTY;//todo replace null values by air item
4247

4348
public CatalystCarrierBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
4449
super(type, pos, state);
@@ -82,6 +87,16 @@ protected void read(CompoundTag compound, HolderLookup.Provider registries,bool
8287
runningTicks = compound.getInt("Ticks");
8388
super.read(compound,registries, clientPacket);
8489

90+
CompoundTag catalyst = (CompoundTag) compound.get("catalyst");
91+
if (catalyst != null) {
92+
if (catalyst.isEmpty()) {
93+
this.catalyst = ItemStack.EMPTY;
94+
} else {
95+
this.catalyst = ItemStack.parseOptional(registries,catalyst);
96+
}
97+
} else {
98+
this.catalyst = ItemStack.EMPTY;
99+
}
85100
if (clientPacket && hasLevel())
86101
getBasin().ifPresent(bte -> bte.setAreFluidsMoving(running && runningTicks <= 20));
87102
}
@@ -90,6 +105,11 @@ protected void read(CompoundTag compound, HolderLookup.Provider registries,bool
90105
public void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
91106
compound.putBoolean("Running", running);
92107
compound.putInt("Ticks", runningTicks);
108+
assert level != null;
109+
if (!level.isClientSide) {
110+
if (!catalyst.isEmpty())
111+
compound.put("catalyst", catalyst.save(registries));
112+
}
93113
super.write(compound,registries, clientPacket);
94114
}
95115

@@ -110,7 +130,7 @@ public void tick() {
110130
renderParticles();
111131

112132
if ((!level.isClientSide || isVirtual()) && runningTicks == 20) {
113-
if (processingTicks < 0) {
133+
if (processingTicks < 0) {
114134
float recipeSpeed = 1;
115135
if (currentRecipe instanceof ProcessingRecipe) {
116136
int t = ((ProcessingRecipe<?,?>) currentRecipe).getProcessingDuration();
@@ -148,6 +168,14 @@ public void tick() {
148168
}
149169
}
150170

171+
@Override
172+
protected void applyBasinRecipe() {
173+
super.applyBasinRecipe();
174+
if (!catalyst.isEmpty()){
175+
catalyst.setDamageValue(catalyst.getDamageValue() + 1);
176+
}
177+
}
178+
151179
public void renderParticles() {
152180
}
153181

@@ -162,6 +190,13 @@ protected void spillParticle(ParticleOptions data) {
162190
level.addParticle(data, center.x, center.y - 1.75f, center.z, target.x, target.y, target.z);
163191
}
164192

193+
@Override
194+
protected <I extends RecipeInput> boolean matchBasinRecipe(Recipe<I> recipe) {
195+
return super.matchBasinRecipe(recipe) &&
196+
recipe instanceof ChemicalSynthesisRecipe chemicalSynthesisRecipe &&
197+
chemicalSynthesisRecipe.catalyst.test(catalyst);
198+
}
199+
165200
@Override
166201
protected boolean matchStaticFilters(RecipeHolder<? extends Recipe<?>> r) {
167202
return r.value().getType() == RecipeInit.CHEMICAL_SYNTHESIS.getType();
@@ -219,4 +254,17 @@ public void tickAudio() {
219254
*/
220255
}
221256

222-
}
257+
public ItemStack getCatalyst() {
258+
return catalyst;
259+
}
260+
261+
public void setCatalyst(@Nullable ItemStack held) {
262+
if (held == null) {
263+
catalyst = null;
264+
notifyUpdate();
265+
return;
266+
}
267+
catalyst = held.copy();
268+
notifyUpdate();
269+
}
270+
}

src/main/java/com/rae/creatingspace/content/recipes/chemical_synthesis/CatalystCarrierRenderer.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ protected void renderSafe(CatalystCarrierBlockEntity be, float partialTicks, Pos
4343

4444
float renderedHeadOffset =
4545
be.getRenderedHeadOffset(partialTicks);
46+
ItemStack catalyst = be.getCatalyst();
47+
if (catalyst != null) {
48+
if (!catalyst.isEmpty()) {
49+
ms.pushPose();
50+
ms.translate(0, -renderedHeadOffset, 0);
51+
renderCatalystFromTexture(ms,
52+
CreatingSpace.resource("textures/block/catalyst_carrier/catalyst/" +
53+
catalyst.getItemHolder().unwrapKey().orElseThrow().location().getPath() + ".png"), buffer);
54+
ms.popPose();
55+
}
56+
}
4657

4758
if (VisualizationManager.supportsVisualization(be.getLevel())) return;
4859

@@ -61,6 +72,11 @@ protected BlockState getRenderedBlockState(CatalystCarrierBlockEntity be) {
6172
return shaft(getRotationAxisOf(be));
6273
}
6374

75+
private void renderCatalystFromTexture(PoseStack stack, ResourceLocation texLocation, MultiBufferSource buffer) {
76+
ModelPart catalyst = createCatalyst();
77+
catalyst.render(stack, buffer.getBuffer(RenderType.entitySolid(texLocation)), LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY);
78+
}
79+
6480
public static ModelPart createCatalyst() {
6581
MeshDefinition meshdefinition = new MeshDefinition();
6682
PartDefinition partdefinition = meshdefinition.getRoot();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.rae.creatingspace.content.recipes.chemical_synthesis;
2+
3+
import com.mojang.serialization.MapCodec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import com.simibubi.create.content.processing.recipe.ProcessingRecipeParams;
6+
import net.minecraft.network.RegistryFriendlyByteBuf;
7+
import net.minecraft.network.codec.StreamCodec;
8+
import net.minecraft.world.item.crafting.Ingredient;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.util.function.Function;
12+
13+
public class ChemicalSynthesisParams extends ProcessingRecipeParams {
14+
public static MapCodec<ChemicalSynthesisParams> CODEC = RecordCodecBuilder.mapCodec(
15+
instance -> instance.group(
16+
codec(ChemicalSynthesisParams::new).forGetter(Function.identity()),
17+
Ingredient.CODEC.optionalFieldOf("catalyst", Ingredient.EMPTY)
18+
.forGetter( r -> r.catalyst)
19+
).apply(instance, (params, catalyst) -> {
20+
params.catalyst = catalyst;
21+
return params;
22+
}));
23+
public static StreamCodec<RegistryFriendlyByteBuf, ChemicalSynthesisParams> STREAM_CODEC = streamCodec(ChemicalSynthesisParams::new);
24+
25+
Ingredient catalyst;
26+
27+
@Override
28+
public void decode(@NotNull RegistryFriendlyByteBuf buffer) {
29+
super.decode(buffer);
30+
catalyst = Ingredient.CONTENTS_STREAM_CODEC.decode(buffer);
31+
32+
}
33+
34+
@Override
35+
public void encode(@NotNull RegistryFriendlyByteBuf buffer) {
36+
super.encode(buffer);
37+
Ingredient.CONTENTS_STREAM_CODEC.encode(buffer,catalyst);
38+
}
39+
}

src/main/java/com/rae/creatingspace/content/recipes/chemical_synthesis/ChemicalSynthesisRecipe.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,49 @@
22

33
import com.rae.creatingspace.init.RecipeInit;
44
import com.simibubi.create.content.processing.basin.BasinRecipe;
5+
import com.simibubi.create.content.processing.recipe.ProcessingRecipe;
6+
import com.simibubi.create.content.processing.recipe.ProcessingRecipeBuilder;
57
import com.simibubi.create.content.processing.recipe.ProcessingRecipeParams;
8+
import com.simibubi.create.content.processing.recipe.StandardProcessingRecipe;
9+
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.world.item.crafting.Ingredient;
11+
import org.jetbrains.annotations.NotNull;
612

713

814
public class ChemicalSynthesisRecipe extends BasinRecipe {
9-
15+
final Ingredient catalyst;
1016
public ChemicalSynthesisRecipe(ProcessingRecipeParams params) {
1117
super(RecipeInit.CHEMICAL_SYNTHESIS, params);
18+
if (params instanceof ChemicalSynthesisParams chemicalSynthesisParams) {
19+
catalyst = chemicalSynthesisParams.catalyst;
20+
} else {
21+
catalyst = Ingredient.EMPTY;
22+
}
1223
}
1324

25+
/*@FunctionalInterface
26+
public interface Factory<R extends BasinRecipe> extends StandardProcessingRecipe.Factory<R> {
27+
//@NotNull R create(@NotNull ChemicalSynthesisParams params);
28+
}*/
29+
30+
public static class Builder extends StandardProcessingRecipe.Builder<ChemicalSynthesisRecipe> {
31+
public Builder(ResourceLocation recipeId) {
32+
super((params) -> new ChemicalSynthesisRecipe((ChemicalSynthesisParams) params), recipeId);
33+
}
34+
35+
@Override
36+
protected @NotNull ChemicalSynthesisParams createParams() {
37+
return new ChemicalSynthesisParams();
38+
}
39+
40+
@Override
41+
public @NotNull Builder self() {
42+
return this;
43+
}
44+
45+
public ChemicalSynthesisRecipe.Builder toolNotConsumed() {
46+
//params.catalyst = true;
47+
return this;
48+
}
49+
}
1450
}

src/main/java/com/rae/creatingspace/init/CreativeModeTabsInit.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@
2929
import net.minecraft.client.renderer.entity.ItemRenderer;
3030
import net.minecraft.client.resources.model.BakedModel;
3131
import net.minecraft.core.HolderLookup;
32-
import net.minecraft.core.component.DataComponents;
3332
import net.minecraft.core.registries.BuiltInRegistries;
3433
import net.minecraft.core.registries.Registries;
35-
import net.minecraft.nbt.CompoundTag;
3634
import net.minecraft.network.chat.Component;
3735
import net.minecraft.world.item.*;
38-
import net.minecraft.world.item.component.CustomData;
3936
import net.minecraft.world.level.block.Block;
4037
import net.minecraft.world.level.material.Fluid;
4138
import net.neoforged.api.distmarker.Dist;

src/main/java/com/rae/creatingspace/init/RecipeInit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.rae.creatingspace.CreatingSpace;
44
import com.rae.creatingspace.content.recipes.air_liquefying.AirLiquefyingRecipe;
55
import com.rae.creatingspace.content.recipes.air_liquefying.AirLiquefyingRecipeParam;
6+
import com.rae.creatingspace.content.recipes.chemical_synthesis.ChemicalSynthesisParams;
67
import com.rae.creatingspace.content.recipes.chemical_synthesis.ChemicalSynthesisRecipe;
78
import com.rae.creatingspace.content.recipes.electrolysis.MechanicalElectrolysisRecipe;
89
import com.simibubi.create.AllTags;
@@ -63,11 +64,11 @@ public enum RecipeInit implements IRecipeTypeInfo , StringRepresentable {
6364

6465
RecipeInit(StandardProcessingRecipe.Factory<?> processingFactory) {
6566
this(() -> new StandardProcessingRecipe.Serializer<>(processingFactory));
66-
6767
}
6868
RecipeInit(ProcessingRecipe.Factory<AirLiquefyingRecipeParam, ? extends AirLiquefyingRecipe> liquefyingRecipeParamFactory) {
6969
this(() -> new AirLiquefyingRecipe.Serializer<>(liquefyingRecipeParamFactory));
7070
}
71+
7172
@ApiStatus.Internal
7273
public static void register(IEventBus modEventBus) {
7374
ShapedRecipePattern.setCraftingSize(9, 9);

0 commit comments

Comments
 (0)