Skip to content

Commit 06dd395

Browse files
eleksplodedJulia
andauthored
Fix fuel tanks and fuel storage interface (#638) (#644)
* Fix fuel tanks and fuel storage interface * Revert IntelliJ's wildcard import change --------- Co-authored-by: Julia <julia.martin.0429@gmail.com>
1 parent 1ee84fe commit 06dd395

File tree

7 files changed

+99
-4
lines changed

7 files changed

+99
-4
lines changed

common/src/main/java/com/railwayteam/railways/mixin/MixinContraption.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838

3939
@Mixin(Contraption.class)
4040
public abstract class MixinContraption implements IContraptionFuel {
41-
@Shadow(remap = false) protected MountedStorageManager storage;
41+
42+
@Shadow public abstract MountedStorageManager getStorage();
4243

4344
@Inject(method = "removeBlocksFromWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;removeBlockEntity(Lnet/minecraft/core/BlockPos;)V"))
4445
private void applyPreTransformCallback(Level world, BlockPos offset, CallbackInfo ci, @Local(name="add") BlockPos add) {
@@ -56,6 +57,6 @@ private void applyPreTransformCallback(Level world, BlockPos offset, CallbackInf
5657

5758
@Override
5859
public MountedFluidStorageWrapper railways$getFluidFuels() {
59-
return ((IFuelInventory) storage).railways$getFluidFuels();
60+
return ((IFuelInventory) getStorage()).railways$getFluidFuels();
6061
}
6162
}

fabric/src/main/java/com/railwayteam/railways/content/fuel/psi/PortableFuelInterfaceBlockEntity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.railwayteam.railways.content.fuel.psi;
2020

2121
import com.railwayteam.railways.mixin_interfaces.IContraptionFuel;
22+
import com.simibubi.create.api.contraption.storage.fluid.MountedFluidStorageWrapper;
2223
import com.simibubi.create.content.contraptions.Contraption;
2324
import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceBlockEntity;
2425
import com.simibubi.create.foundation.utility.fabric.ListeningStorageView;
@@ -49,7 +50,8 @@ public PortableFuelInterfaceBlockEntity(BlockEntityType<?> type, BlockPos pos, B
4950

5051
@Override
5152
public void startTransferringTo(Contraption contraption, float distance) {
52-
capability.setWrapped(((IContraptionFuel) contraption).railways$getFluidFuels());
53+
MountedFluidStorageWrapper fuels = ((IContraptionFuel) contraption).railways$getFluidFuels();
54+
capability.setWrapped(fuels != null ? fuels : Storage.empty());
5355
super.startTransferringTo(contraption, distance);
5456
}
5557

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Steam 'n' Rails
3+
* Copyright (c) 2025 The Railways Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.railwayteam.railways.content.fuel.tank;
20+
21+
import com.simibubi.create.api.behaviour.movement.MovementBehaviour;
22+
import com.simibubi.create.content.contraptions.behaviour.MovementContext;
23+
import net.minecraft.world.level.block.entity.BlockEntity;
24+
25+
public class FuelTankMovementBehavior implements MovementBehaviour {
26+
@Override
27+
public boolean mustTickWhileDisabled() {
28+
return true;
29+
}
30+
31+
@Override
32+
public void tick(MovementContext context) {
33+
if(!context.world.isClientSide)
34+
return;
35+
36+
BlockEntity be = context.contraption.presentBlockEntities.get(context.localPos);
37+
if(be instanceof FuelTankBlockEntity fuelTank) {
38+
fuelTank.getFluidLevel().tickChaser();
39+
}
40+
}
41+
}

fabric/src/main/java/com/railwayteam/railways/registry/fabric/CRBlocksImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import com.railwayteam.railways.content.fuel.tank.FuelTankGenerator;
2525
import com.railwayteam.railways.content.fuel.tank.FuelTankItem;
2626
import com.railwayteam.railways.content.fuel.tank.FuelTankModel;
27+
import com.railwayteam.railways.content.fuel.tank.FuelTankMovementBehavior;
2728
import com.simibubi.create.AllTags;
29+
import com.simibubi.create.api.behaviour.movement.MovementBehaviour;
2830
import com.simibubi.create.api.contraption.storage.fluid.MountedFluidStorageType;
2931
import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceMovement;
3032
import com.simibubi.create.foundation.data.AssetLookup;
@@ -51,6 +53,7 @@ public class CRBlocksImpl {
5153
.blockstate(new FuelTankGenerator()::generate)
5254
.onRegister(CreateRegistrate.blockModel(() -> FuelTankModel::standard))
5355
.transform(MountedFluidStorageType.mountedFluidStorage(CRMountedStorageTypesImpl.FUEL_TANK))
56+
.onRegister(MovementBehaviour.movementBehaviour(new FuelTankMovementBehavior()))
5457
.addLayer(() -> RenderType::cutoutMipped)
5558
.item(FuelTankItem::new)
5659
.model(AssetLookup.customBlockItemModel("_", "block_single_window"))

forge/src/main/java/com/railwayteam/railways/content/fuel/psi/PortableFuelInterfaceBlockEntity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.railwayteam.railways.content.fuel.psi;
2020

2121
import com.railwayteam.railways.mixin_interfaces.IContraptionFuel;
22+
import com.simibubi.create.api.contraption.storage.fluid.MountedFluidStorageWrapper;
2223
import com.simibubi.create.content.contraptions.Contraption;
2324
import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceBlockEntity;
2425
import net.minecraft.core.BlockPos;
@@ -43,7 +44,10 @@ public PortableFuelInterfaceBlockEntity(BlockEntityType<?> type, BlockPos pos, B
4344
@Override
4445
public void startTransferringTo(Contraption contraption, float distance) {
4546
LazyOptional<IFluidHandler> oldcap = capability;
46-
capability = LazyOptional.of(() -> new InterfaceFluidHandler(((IContraptionFuel) contraption).railways$getFluidFuels()));
47+
capability = LazyOptional.of(() -> {
48+
MountedFluidStorageWrapper fuels = ((IContraptionFuel) contraption).railways$getFluidFuels();
49+
return new InterfaceFluidHandler(fuels != null ? fuels : new FluidTank(0));
50+
});
4751
oldcap.invalidate();
4852
super.startTransferringTo(contraption, distance);
4953
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Steam 'n' Rails
3+
* Copyright (c) 2025 The Railways Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.railwayteam.railways.content.fuel.tank;
20+
21+
import com.simibubi.create.api.behaviour.movement.MovementBehaviour;
22+
import com.simibubi.create.content.contraptions.behaviour.MovementContext;
23+
import net.minecraft.world.level.block.entity.BlockEntity;
24+
25+
public class FuelTankMovementBehavior implements MovementBehaviour {
26+
@Override
27+
public boolean mustTickWhileDisabled() {
28+
return true;
29+
}
30+
31+
@Override
32+
public void tick(MovementContext context) {
33+
if(!context.world.isClientSide)
34+
return;
35+
36+
BlockEntity be = context.contraption.presentBlockEntities.get(context.localPos);
37+
if(be instanceof FuelTankBlockEntity fuelTank) {
38+
fuelTank.getFluidLevel().tickChaser();
39+
}
40+
}
41+
}

forge/src/main/java/com/railwayteam/railways/registry/forge/CRBlocksImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import com.railwayteam.railways.content.fuel.tank.FuelTankBlock;
2424
import com.railwayteam.railways.content.fuel.tank.FuelTankItem;
2525
import com.railwayteam.railways.content.fuel.tank.FuelTankModel;
26+
import com.railwayteam.railways.content.fuel.tank.FuelTankMovementBehavior;
2627
import com.simibubi.create.AllTags;
28+
import com.simibubi.create.api.behaviour.movement.MovementBehaviour;
2729
import com.simibubi.create.api.contraption.storage.fluid.MountedFluidStorageType;
2830
import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceMovement;
2931
import com.simibubi.create.foundation.data.AssetLookup;
@@ -51,6 +53,7 @@ public class CRBlocksImpl {
5153
//.blockstate(new FuelTankGenerator()::generate) Handled by fabric subproject
5254
.onRegister(CreateRegistrate.blockModel(() -> FuelTankModel::standard))
5355
.transform(MountedFluidStorageType.mountedFluidStorage(CRMountedStorageTypesImpl.FUEL_TANK))
56+
.onRegister(MovementBehaviour.movementBehaviour(new FuelTankMovementBehavior()))
5457
.addLayer(() -> RenderType::cutoutMipped)
5558
.item(FuelTankItem::new)
5659
.model(AssetLookup.customBlockItemModel("_", "block_single_window"))

0 commit comments

Comments
 (0)