Skip to content

Commit

Permalink
Fix creative mode interactions
Browse files Browse the repository at this point in the history
Fixes #269
  • Loading branch information
Matyrobbrt committed Jul 17, 2024
1 parent c6da801 commit 17e077a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.hrznstudio.titanium.recipe.generator.IJsonFile;
import com.hrznstudio.titanium.recipe.generator.TitaniumSerializableProvider;
import com.hrznstudio.titanium.recipe.serializer.GenericSerializer;
import com.hrznstudio.titanium.util.TileUtil;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.data.recipes.FinishedRecipe;
Expand Down Expand Up @@ -62,6 +63,7 @@
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.util.NonNullLazy;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
Expand Down Expand Up @@ -178,6 +180,22 @@ public FunctionalStorage() {
NBTManager.getInstance().scanTileClassForAnnotations(FluidDrawerTile.class);
NBTManager.getInstance().scanTileClassForAnnotations(SimpleCompactingDrawerTile.class);
NBTManager.getInstance().scanTileClassForAnnotations(FramedSimpleCompactingDrawerTile.class);

EventManager.forge(PlayerInteractEvent.LeftClickBlock.class)
.process(event -> {
var state = event.getLevel().getBlockState(event.getPos());
if (event.getLevel().getBlockState(event.getPos()).getBlock() instanceof Drawer drawer) {
final int hit = drawer.getHit(state, event.getLevel(), event.getPos(), event.getEntity());
if (hit != -1) {
TileUtil.getTileEntity(event.getLevel(), event.getPos(), ControllableDrawerTile.class)
.ifPresent(be -> {
be.onClicked(event.getEntity(), hit);
event.setCanceled(true);
});
}
}
})
.subscribe();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import java.util.Optional;
import java.util.function.Consumer;

public class CompactingDrawerBlock extends RotatableBlock<CompactingDrawerTile> {
public class CompactingDrawerBlock extends RotatableBlock<CompactingDrawerTile> implements Drawer {

public static Multimap<Direction, VoxelShape> CACHED_SHAPES = MultimapBuilder.hashKeys().arrayListValues().build();

Expand Down Expand Up @@ -143,6 +143,7 @@ public void attack(BlockState state, Level worldIn, BlockPos pos, Player player)
TileUtil.getTileEntity(worldIn, pos, CompactingDrawerTile.class).ifPresent(drawerTile -> drawerTile.onClicked(player, getHit(state, worldIn, pos, player)));
}

@Override
public int getHit(BlockState state, Level worldIn, BlockPos pos, Player player) {
HitResult result = RayTraceUtils.rayTraceSimple(worldIn, player, 32, 0);
if (result instanceof BlockHitResult) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/buuz135/functionalstorage/block/Drawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.buuz135.functionalstorage.block;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public interface Drawer {
int getHit(BlockState state, Level worldIn, BlockPos pos, Player player);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
import java.util.Optional;
import java.util.function.Consumer;

public class DrawerBlock extends RotatableBlock<DrawerTile> {
public class DrawerBlock extends RotatableBlock<DrawerTile> implements Drawer {

public static HashMap<FunctionalStorage.DrawerType, Multimap<Direction, VoxelShape>> CACHED_SHAPES = new HashMap<>();

Expand Down Expand Up @@ -188,6 +188,7 @@ public void attack(BlockState state, Level worldIn, BlockPos pos, Player player)
TileUtil.getTileEntity(worldIn, pos, DrawerTile.class).ifPresent(drawerTile -> drawerTile.onClicked(player, getHit(state, worldIn, pos, player)));
}

@Override
public int getHit(BlockState state, Level worldIn, BlockPos pos, Player player) {
HitResult result = RayTraceUtils.rayTraceSimple(worldIn, player, 32, 0);
if (result instanceof BlockHitResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

import static com.buuz135.functionalstorage.block.DrawerBlock.LOCKED;

public class EnderDrawerBlock extends RotatableBlock<EnderDrawerTile> {
public class EnderDrawerBlock extends RotatableBlock<EnderDrawerTile> implements Drawer {

public EnderDrawerBlock() {
super("ender_drawer", Properties.copy(Blocks.ENDER_CHEST), EnderDrawerTile.class);
Expand Down Expand Up @@ -125,6 +125,7 @@ public void attack(BlockState state, Level worldIn, BlockPos pos, Player player)
TileUtil.getTileEntity(worldIn, pos, EnderDrawerTile.class).ifPresent(drawerTile -> drawerTile.onClicked(player, getHit(state, worldIn, pos, player)));
}

@Override
public int getHit(BlockState state, Level worldIn, BlockPos pos, Player player) {
HitResult result = RayTraceUtils.rayTraceSimple(worldIn, player, 32, 0);
if (result instanceof BlockHitResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import java.util.Optional;
import java.util.function.Consumer;

public class FluidDrawerBlock extends RotatableBlock<FluidDrawerTile> {
public class FluidDrawerBlock extends RotatableBlock<FluidDrawerTile> implements Drawer {

/**
* Framed version
Expand Down Expand Up @@ -139,6 +139,7 @@ public void attack(BlockState state, Level worldIn, BlockPos pos, Player player)
TileUtil.getTileEntity(worldIn, pos, FluidDrawerTile.class).ifPresent(drawerTile -> drawerTile.onClicked(player, getHit(state, worldIn, pos, player)));
}

@Override
public int getHit(BlockState state, Level worldIn, BlockPos pos, Player player) {
HitResult result = RayTraceUtils.rayTraceSimple(worldIn, player, 32, 0);
if (result instanceof BlockHitResult) {
Expand Down

0 comments on commit 17e077a

Please sign in to comment.