use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.
the class TileShelf method onClicked.
protected boolean onClicked(float hitX, float hitY, float hitZ, EntityPlayer player) {
int slotId = getSlotId(hitX, hitY, hitZ);
if (slotId < 0)
return false;
if (handler.getStackInSlot(slotId).isEmpty()) {
slotId = toNonBookSlotId(slotId);
}
ItemStack stack = handler.getStackInSlot(slotId);
if (stack.isEmpty())
return false;
handler.setStackInSlot(slotId, ItemStack.EMPTY);
markBlockForUpdate();
ItemUtils.giveOrSpawnItemEntity(player, getWorld(), new Vec3d(pos).addVector(hitX, hitY, hitZ), stack, 0, 0, 0, 0, true);
return true;
}
use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.
the class BlockShelf method onBlockClicked.
@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
if (worldIn.isRemote)
return;
IBlockState state = worldIn.getBlockState(pos);
RayTraceResult result = RayTraceUtils.getCollision(worldIn, pos, playerIn, getBoundingBox(state, worldIn, pos));
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.sideHit == state.getValue(Properties.FACING4).getOpposite()) {
TileShelf bookshelf = (TileShelf) worldIn.getTileEntity(pos);
if (bookshelf != null) {
Vec3d v = result.hitVec.subtract(pos.getX(), pos.getY(), pos.getZ());
bookshelf.onClicked((float) v.x, (float) v.y, (float) v.z, playerIn);
}
}
}
use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.
the class BlockShelf method getStateForPlacement.
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
Vec3d placementVec = new Vec3d(hitX - 0.5F, hitY - 0.5F, hitZ - 0.5F).subtract(facing.getFrontOffsetX(), facing.getFrontOffsetY(), facing.getFrontOffsetZ());
placementVec = placementVec.rotateYaw(placer.getHorizontalFacing().getHorizontalAngle() / 180 * (float) Math.PI);
return this.getDefaultState().withProperty(Properties.FACING4, placer.getHorizontalFacing()).withProperty(BACK, placementVec.z > 0);
}
use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.
the class TileRecordPlayer method activate.
public boolean activate(EntityPlayer player, EnumFacing side, EnumHand hand, Vec3d hitPos) {
if (player.isSneaking() && side.getAxis() != EnumFacing.Axis.Y) {
if (!world.isRemote) {
player.openGui(ModCharset.instance, GuiHandlerCharset.RECORD_PLAYER, getWorld(), getPos().getX(), getPos().getY(), getPos().getZ());
}
return true;
}
Vec3d realPos = hitPos.subtract(0.5, 0.5, 0.5).rotateYaw((float) (getFacing().getHorizontalAngle() * Math.PI / 180));
if (side == EnumFacing.UP) {
if (realPos.x > -0.075 && realPos.z > -0.25 && !getStack().isEmpty()) {
if (realPos.x > 0.4) {
if (!world.isRemote) {
setState(TraitRecordPlayer.State.STOPPED);
}
return true;
} else {
if (player.isSneaking()) {
// TODO: Store state, allow for recording turning off
if (getState() == TraitRecordPlayer.State.PAUSED) {
if (!world.isRemote) {
setState(TraitRecordPlayer.State.PLAYING);
markBlockForUpdate();
}
return true;
} else if (getState() == TraitRecordPlayer.State.PLAYING) {
if (!world.isRemote) {
setState(TraitRecordPlayer.State.PAUSED);
markBlockForUpdate();
}
return true;
} else if (getState() == TraitRecordPlayer.State.RECORDING) {
return true;
}
} else {
if (!world.isRemote) {
if (getState() == TraitRecordPlayer.State.STOPPED) {
setState(TraitRecordPlayer.State.PLAYING);
}
// 0.05f = 0.12f
// 0.25f = 0.35f
float fmul = 0.0085f;
float fsub = 0.05f;
float fstart = (CharsetAudioStorage.quartzDisc.getArmStartPosition(holder.getStack()) * fmul) - fsub;
float fend = (32f * fmul) - fsub;
// System.out.println(fstart + " . " + fend);
float newPos = 1f - ((float) (realPos.x - fstart) / (fend - fstart));
if (newPos < 0.0f)
newPos = 0.0f;
else if (newPos > 1.0f)
newPos = 1.0f;
IDataStorage storage = this.getStorage();
if (storage != null) {
storage.setPosition(Math.round((storage.getSize() - 1) * newPos));
updateProgressClient();
this.player.stopAudioPlayback();
}
markBlockForUpdate();
}
return true;
}
}
}
if (getStack().isEmpty() || (player.getHeldItem(hand).isEmpty() && player.isSneaking())) {
if (holder.activate(this, player, side, hand)) {
markBlockForUpdate();
return true;
}
}
}
return false;
}
use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.
the class BlockScaffold method neighborChanged.
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
if (!canStay(worldIn, pos)) {
ItemStack droppedStack = new ItemStack(this);
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileBase) {
droppedStack = ((TileBase) tile).getDroppedBlock(state);
}
ItemUtils.spawnItemEntity(worldIn, new Vec3d(pos).addVector(0.5, 0.5, 0.5), droppedStack, 0.1f, 0.1f, 0.1f, 1.0f);
worldIn.setBlockToAir(pos);
}
}
Aggregations