Skip to content

Commit

Permalink
add battery bank output toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassiobsk8 committed Dec 18, 2024
1 parent ed35ec6 commit cbc34c2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import net.cassiokf.industrialrenewal.block.abstracts.BlockAbstractHorizontalFacing;
import net.cassiokf.industrialrenewal.blockentity.BlockEntityBatteryBank;
import net.cassiokf.industrialrenewal.init.ModBlockEntity;
import net.cassiokf.industrialrenewal.item.ItemScrewdriver;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
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.Block;
import net.minecraft.world.level.block.EntityBlock;
Expand All @@ -15,6 +20,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;

public class BlockBatteryBank extends BlockAbstractHorizontalFacing implements EntityBlock {
Expand Down Expand Up @@ -52,6 +58,22 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
builder.add(NORTH_OUTPUT, SOUTH_OUTPUT, EAST_OUTPUT, WEST_OUTPUT, UP_OUTPUT, DOWN_OUTPUT);
}

@Override
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
ItemStack heldItem = pPlayer.getItemInHand(pHand);
if (pHand.equals(InteractionHand.MAIN_HAND) && heldItem.getItem() instanceof ItemScrewdriver) {
BlockEntityBatteryBank tile = (BlockEntityBatteryBank) pLevel.getBlockEntity(pPos);
if (tile != null) {
Direction side = pHit.getDirection();
boolean change = tile.toggleFacing(side);
pState = pState.setValue(toggleOutput(side), change);
pLevel.setBlockAndUpdate(pPos, pState);
if (pLevel.isClientSide()) ItemScrewdriver.playSound(pLevel, pPos);
}
}
return super.use(pState, pLevel, pPos, pPlayer, pHand, pHit);
}

public BooleanProperty toggleOutput(Direction facing){
switch (facing){
case NORTH: return NORTH_OUTPUT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.cassiokf.industrialrenewal.item;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;

public class ItemScrewdriver extends IRBaseItem{

public ItemScrewdriver() {
Expand All @@ -9,4 +12,8 @@ public ItemScrewdriver() {
public ItemScrewdriver(Properties props) {
super(props);
}

public static void playSound(Level pLevel, BlockPos pPos) {
//TODO
}
}

0 comments on commit cbc34c2

Please sign in to comment.