Files
SoundPadMod/src/main/java/com/example/soundmod/gameplay/block/SoundPlayerBlock.java
T

96 lines
3.9 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* net.minecraft.block.AbstractBlock$Properties
* net.minecraft.block.Block
* net.minecraft.block.BlockState
* net.minecraft.entity.player.PlayerEntity
* net.minecraft.entity.player.ServerPlayerEntity
* net.minecraft.inventory.container.INamedContainerProvider
* net.minecraft.tileentity.TileEntity
* net.minecraft.tileentity.TileEntityType
* net.minecraft.util.ActionResultType
* net.minecraft.util.Hand
* net.minecraft.util.math.BlockPos
* net.minecraft.util.math.BlockRayTraceResult
* net.minecraft.world.IBlockReader
* net.minecraft.world.World
* net.minecraftforge.fml.network.NetworkHooks
*/
package com.example.soundmod.gameplay.block;
import com.example.soundmod.client.audio.AudioPlaybackService;
import com.example.soundmod.gameplay.tile.SoundPlayerTileEntity;
import com.example.soundmod.registry.ModTileEntities;
import java.util.Random;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkHooks;
public class SoundPlayerBlock extends Block {
public SoundPlayerBlock(AbstractBlock.Properties properties) {
super(properties);
}
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return ((TileEntityType)ModTileEntities.SOUND_PLAYER_TILE.get()).create();
}
@Override
public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
TileEntity te = world.getBlockEntity(pos);
if (!world.isClientSide && te instanceof SoundPlayerTileEntity && player instanceof ServerPlayerEntity) {
SoundPlayerTileEntity soundTe = (SoundPlayerTileEntity)te;
if (player.isShiftKeyDown()) {
soundTe.playFromClick((ServerPlayerEntity)player);
} else {
NetworkHooks.openGui((ServerPlayerEntity)((ServerPlayerEntity)player), (INamedContainerProvider)soundTe, (BlockPos)pos);
}
}
return ActionResultType.sidedSuccess(world.isClientSide);
}
@Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean moving) {
TileEntity te = world.getBlockEntity(pos);
if (te instanceof SoundPlayerTileEntity) {
((SoundPlayerTileEntity)te).onRedstoneChanged(world.hasNeighborSignal(pos));
}
}
@Override
@OnlyIn(Dist.CLIENT)
public void animateTick(BlockState state, World world, BlockPos pos, Random rand) {
if (world.isClientSide && AudioPlaybackService.get().isPlaying("sound_player:" + pos.asLong())) {
double px = (double) pos.getX() + 0.5 + (rand.nextDouble() - 0.5) * 0.5;
double py = (double) pos.getY() + 1.05 + rand.nextDouble() * 0.25;
double pz = (double) pos.getZ() + 0.5 + (rand.nextDouble() - 0.5) * 0.5;
double noteColor = (double) rand.nextInt(25) / 24.0;
world.addParticle(ParticleTypes.NOTE, px, py, pz, noteColor, 0.0, 0.0);
}
}
}