-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added satellite radio and audio uploading/streaming
- Adjusted multi source sound weighting - Fixed custom note block sounds
- Loading branch information
1 parent
7f5fbe8
commit 5f3df26
Showing
37 changed files
with
1,477 additions
and
105 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
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
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
123 changes: 123 additions & 0 deletions
123
src/main/java/io/github/foundationgames/phonos/block/SatelliteStationBlock.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,123 @@ | ||
package io.github.foundationgames.phonos.block; | ||
|
||
import io.github.foundationgames.phonos.block.entity.SatelliteStationBlockEntity; | ||
import io.github.foundationgames.phonos.network.PayloadPackets; | ||
import io.github.foundationgames.phonos.util.PhonosUtil; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityTicker; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class SatelliteStationBlock extends HorizontalFacingBlock implements BlockEntityProvider { | ||
private static final VoxelShape SHAPE = createCuboidShape(0, 0, 0, 16, 7, 16); | ||
private static final BooleanProperty POWERED = Properties.POWERED; | ||
|
||
public SatelliteStationBlock(Settings settings) { | ||
super(settings); | ||
setDefaultState(getDefaultState().with(FACING, Direction.NORTH).with(POWERED, false)); | ||
} | ||
|
||
@Override | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
var side = hit.getSide(); | ||
var facing = state.get(FACING); | ||
|
||
if (side == Direction.DOWN || side == Direction.UP) { | ||
return ActionResult.PASS; | ||
} | ||
|
||
if (player.canModifyBlocks() && world.getBlockEntity(pos) instanceof SatelliteStationBlockEntity be) { | ||
if (!world.isClient()) { | ||
if (PhonosUtil.holdingAudioCable(player)) { | ||
return ActionResult.PASS; | ||
} | ||
|
||
if (side != facing) { | ||
if (be.outputs.tryRemoveConnection(world, hit, !player.isCreative())) { | ||
be.sync(); | ||
return ActionResult.SUCCESS; | ||
} | ||
} else { | ||
if (player instanceof ServerPlayerEntity sPlayer) { | ||
PayloadPackets.sendOpenSatelliteStationScreen(sPlayer, pos); | ||
} | ||
|
||
return ActionResult.CONSUME; | ||
} | ||
} else if (side == facing) { | ||
return ActionResult.SUCCESS; | ||
} | ||
} | ||
|
||
return super.onUse(state, world, pos, player, hand, hit); | ||
} | ||
|
||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { | ||
boolean powered = world.isReceivingRedstonePower(pos); | ||
if (powered != state.get(POWERED)) { | ||
if (!world.isClient() && world.getBlockEntity(pos) instanceof SatelliteStationBlockEntity be) { | ||
if (powered) { | ||
be.play(); | ||
} else { | ||
be.stop(); | ||
} | ||
} | ||
|
||
world.setBlockState(pos, state.with(POWERED, powered), 3); | ||
} | ||
} | ||
|
||
@Override | ||
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { | ||
if (!newState.isOf(this) && world.getBlockEntity(pos) instanceof SatelliteStationBlockEntity be) { | ||
be.onDestroyed(); | ||
} | ||
|
||
super.onStateReplaced(state, world, pos, newState, moved); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite()); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
super.appendProperties(builder); | ||
|
||
builder.add(FACING, POWERED); | ||
} | ||
|
||
@Override | ||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { | ||
return SHAPE; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new SatelliteStationBlockEntity(pos, state); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { | ||
return PhonosUtil.blockEntityTicker(type, PhonosBlocks.SATELLITE_STATION_ENTITY); | ||
} | ||
} |
Oops, something went wrong.