-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cc6782
commit 6b0b9b8
Showing
18 changed files
with
731 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessWidener v1 named | ||
|
||
# ArgumentTypeInfos | ||
accessible field net/minecraft/world/level/block/LiquidBlock fluid Lnet/minecraft/world/level/material/FlowingFluid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
loader-fabric/src/main/java/org/cyclops/flopper/block/BlockFlopperConfigFabric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.cyclops.flopper.block; | ||
|
||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.SoundType; | ||
import net.minecraft.world.level.material.MapColor; | ||
import org.cyclops.cyclopscore.config.ConfigurablePropertyCommon; | ||
import org.cyclops.cyclopscore.config.ModConfigLocation; | ||
import org.cyclops.cyclopscore.init.ModBaseFabric; | ||
import org.cyclops.flopper.FlopperFabric; | ||
import org.cyclops.flopper.blockentity.BlockEntityFlopperFabric; | ||
|
||
/** | ||
* Config for the {@link BlockFlopper}. | ||
* @author rubensworks | ||
* | ||
*/ | ||
public class BlockFlopperConfigFabric extends BlockFlopperConfig<ModBaseFabric<?>> { | ||
|
||
@ConfigurablePropertyCommon(category = "machine", comment = "The maximum capacity in mB.", isCommandable = true, requiresMcRestart = true, configLocation = ModConfigLocation.SERVER) | ||
public static long capacityDroplets = 5 * FluidConstants.BUCKET; | ||
|
||
@ConfigurablePropertyCommon(category = "machine", comment = "The rate at which fluids can be pulled from other tanks.", isCommandable = true, configLocation = ModConfigLocation.SERVER) | ||
public static long pullFluidRateDroplets = FluidConstants.BUCKET / 10; | ||
|
||
@ConfigurablePropertyCommon(category = "machine", comment = "The rate at which fluids can be pushed to other tanks.", isCommandable = true, configLocation = ModConfigLocation.SERVER) | ||
public static long pushFluidRateDroplets = FluidConstants.BUCKET / 10; | ||
|
||
public BlockFlopperConfigFabric() { | ||
super( | ||
FlopperFabric._instance, | ||
eConfig -> new BlockFlopperFabric(Block.Properties.of() | ||
.mapColor(MapColor.STONE) | ||
.strength(3.0F, 4.8F) | ||
.sound(SoundType.METAL), BlockEntityFlopperFabric::new) | ||
); | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
loader-fabric/src/main/java/org/cyclops/flopper/block/BlockFlopperFabric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.cyclops.flopper.block; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.Storage; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.ItemInteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.BaseEntityBlock; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntityCommon; | ||
import org.cyclops.cyclopscore.helper.IFluidHelpersFabric; | ||
import org.cyclops.flopper.FlopperFabric; | ||
import org.cyclops.flopper.blockentity.BlockEntityFlopperFabric; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* @author rubensworks | ||
*/ | ||
public class BlockFlopperFabric extends BlockFlopper { | ||
public static final MapCodec<BlockFlopper> CODEC = BlockBehaviour.simpleCodec(properties -> new BlockFlopperFabric(properties, BlockEntityFlopperFabric::new)); | ||
|
||
public BlockFlopperFabric(Properties properties, BiFunction<BlockPos, BlockState, ? extends CyclopsBlockEntityCommon> blockEntitySupplier) { | ||
super(properties, blockEntitySupplier); | ||
} | ||
|
||
@Override | ||
protected MapCodec<? extends BaseEntityBlock> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
protected InteractionResult useWithoutItem(BlockState blockState, Level level, BlockPos pos, Player player, BlockHitResult rayTraceResult) { | ||
InteractionResult activatedSuper = super.useWithoutItem(blockState, level, pos, player, rayTraceResult); | ||
if (activatedSuper.consumesAction()) { | ||
return activatedSuper; | ||
} | ||
|
||
if (BlockFlopperConfig.showContentsStatusMessageOnClick) { | ||
Storage<FluidVariant> storage = FluidStorage.SIDED.find(level, pos, rayTraceResult.getDirection()); | ||
if (storage != null) { | ||
for (StorageView<FluidVariant> view : storage) { | ||
if (view.isResourceBlank()) { | ||
player.displayClientMessage(Component.literal("0 / " | ||
+ String.format("%,d", view.getCapacity())), true); | ||
} else { | ||
player.displayClientMessage(FluidVariantAttributes.getName(view.getResource()).plainCopy() | ||
.append(Component.literal(": " | ||
+ String.format("%,d", view.getAmount()) + " / " | ||
+ String.format("%,d", view.getCapacity()))), true); | ||
} | ||
} | ||
} | ||
} | ||
return InteractionResult.PASS; | ||
} | ||
|
||
@Override | ||
protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState blockState, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult rayTraceResult) { | ||
ItemInteractionResult activatedSuper = super.useItemOn(itemStack, blockState, level, pos, player, hand, rayTraceResult); | ||
if (activatedSuper.consumesAction()) { | ||
return activatedSuper; | ||
} | ||
|
||
IFluidHelpersFabric fh = FlopperFabric._instance.getModHelpers().getFluidHelpers(); | ||
Storage<FluidVariant> storageFlopper = FluidStorage.SIDED.find(level, pos, rayTraceResult.getDirection()); | ||
ContainerItemContext storageItemContext = ContainerItemContext.forPlayerInteraction(player, hand); | ||
Storage<FluidVariant> storageItem = storageItemContext.find(FluidStorage.ITEM); | ||
if (storageFlopper != null && storageItem != null) { | ||
long movedSimulate; | ||
if (!player.isCrouching() | ||
&& (movedSimulate = fh.moveFluid(storageItem, storageFlopper, fh.getBucketVolume(), player, true)) > 0) { | ||
// Move fluid from the item into the tank if not sneaking | ||
fh.moveFluid(storageItem, storageFlopper, movedSimulate, player, false); | ||
return ItemInteractionResult.SUCCESS; | ||
} else if (player.isCrouching() | ||
&& (movedSimulate = fh.moveFluid(storageFlopper, storageItem, fh.getBucketVolume(), player, true)) > 0) { | ||
// Move fluid from the tank into the item if sneaking | ||
fh.moveFluid(storageFlopper, storageItem, movedSimulate, player, false); | ||
return ItemInteractionResult.SUCCESS; | ||
} | ||
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; | ||
} | ||
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
loader-fabric/src/main/java/org/cyclops/flopper/block/IPlayerDisableableSneak.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.cyclops.flopper.block; | ||
|
||
/** | ||
* @author rubensworks | ||
*/ | ||
public interface IPlayerDisableableSneak { | ||
|
||
public void setTemporarilyDisableSneak(boolean setTemporarilyDisableSneak); | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...-fabric/src/main/java/org/cyclops/flopper/blockentity/BlockEntityFlopperConfigFabric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.cyclops.flopper.blockentity; | ||
|
||
import com.google.common.collect.Sets; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import org.cyclops.cyclopscore.init.ModBaseFabric; | ||
import org.cyclops.flopper.FlopperFabric; | ||
import org.cyclops.flopper.RegistryEntries; | ||
import org.cyclops.flopper.block.BlockFlopperConfig; | ||
import org.cyclops.flopper.client.render.blockentity.RenderBlockEntityFlopperFabric; | ||
|
||
/** | ||
* @author rubensworks | ||
*/ | ||
public class BlockEntityFlopperConfigFabric extends BlockEntityFlopperConfig<BlockEntityFlopperFabric, ModBaseFabric<?>> { | ||
public BlockEntityFlopperConfigFabric() { | ||
super( | ||
FlopperFabric._instance, | ||
(eConfig) -> new BlockEntityType<>(BlockEntityFlopperFabric::new, | ||
Sets.newHashSet(RegistryEntries.BLOCK_FLOPPER.value()), null) | ||
); | ||
} | ||
|
||
@Override | ||
public void onForgeRegistered() { | ||
super.onForgeRegistered(); | ||
|
||
// Fluid capability | ||
FluidStorage.SIDED.registerForBlockEntity((blockEntity, direction) -> blockEntity.getTank(), getInstance()); | ||
|
||
// Rendering | ||
if (getMod().getModHelpers().getMinecraftHelpers().isClientSide() && BlockFlopperConfig.renderFluid) { | ||
getMod().getProxy().registerRenderer(getInstance(), RenderBlockEntityFlopperFabric::new); | ||
} | ||
} | ||
} |
Oops, something went wrong.